Attic/abacus.thy
author Sebastiaan Joosten <sebastiaan.joosten@uibk.ac.at>
Mon, 07 Jan 2019 13:44:19 +0100
changeset 292 293e9c6f22e1
parent 127 469c26d19f8e
permissions -rw-r--r--
Added myself to the comments at the start of all files
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
     1
header {* 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
     2
 {\em abacus} a kind of register machine
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
     3
*}
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
     4
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
     5
theory abacus
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
     6
imports Main turing_basic
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
     7
begin
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
     8
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
     9
text {*
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    10
  {\em Abacus} instructions:
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    11
*}
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    12
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    13
datatype abc_inst =
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    14
  -- {* @{text "Inc n"} increments the memory cell (or register) with address @{text "n"} by one.
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    15
     *}
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    16
     Inc nat
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    17
  -- {*
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    18
     @{text "Dec n label"} decrements the memory cell with address @{text "n"} by one. 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    19
      If cell @{text "n"} is already zero, no decrements happens and the executio jumps to
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    20
      the instruction labeled by @{text "label"}.
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    21
     *}
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    22
   | Dec nat nat
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    23
  -- {*
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    24
  @{text "Goto label"} unconditionally jumps to the instruction labeled by @{text "label"}.
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    25
  *}
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    26
   | Goto nat
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    27
  
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    28
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    29
text {*
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    30
  Abacus programs are defined as lists of Abacus instructions.
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    31
*}
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    32
type_synonym abc_prog = "abc_inst list"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    33
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    34
section {*
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    35
  Sample Abacus programs
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    36
  *}
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    37
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    38
text {*
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    39
  Abacus for addition and clearance.
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    40
*}
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    41
fun plus_clear :: "nat \<Rightarrow> nat \<Rightarrow> nat \<Rightarrow> abc_prog"  
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    42
  where
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    43
  "plus_clear m n e = [Dec m e, Inc n, Goto 0]"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    44
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    45
text {*
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    46
  Abacus for clearing memory untis.
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    47
*}
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    48
fun clear :: "nat \<Rightarrow> nat \<Rightarrow> abc_prog"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    49
  where
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    50
  "clear n e = [Dec n e, Goto 0]"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    51
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    52
fun plus:: "nat \<Rightarrow> nat \<Rightarrow> nat \<Rightarrow> nat \<Rightarrow> abc_prog"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    53
  where
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    54
  "plus m n p e = [Dec m 4, Inc n, Inc p,
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    55
                   Goto 0, Dec p e, Inc m, Goto 4]"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    56
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    57
fun mult :: "nat \<Rightarrow> nat \<Rightarrow> nat \<Rightarrow> nat \<Rightarrow> nat \<Rightarrow> abc_prog"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    58
  where
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    59
  "mult m1 m2 n p e = [Dec m1 e]@ plus m1 m2 p 1"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    60
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    61
fun expo :: "nat \<Rightarrow> nat \<Rightarrow> nat \<Rightarrow> nat \<Rightarrow> nat \<Rightarrow> abc_prog"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    62
  where
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    63
  "expo n m1 m2 p e = [Inc n, Dec m1 e] @ mult m2 n n p 2"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    64
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    65
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    66
text {*
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    67
  The state of Abacus machine.
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    68
  *}
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    69
type_synonym abc_state = nat
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    70
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    71
(* text {*
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    72
  The memory of Abacus machine is defined as a function from address to contents.
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    73
*}
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    74
type_synonym abc_mem = "nat \<Rightarrow> nat" *)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    75
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    76
text {*
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    77
  The memory of Abacus machine is defined as a list of contents, with 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    78
  every units addressed by index into the list.
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    79
  *}
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    80
type_synonym abc_lm = "nat list"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    81
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    82
text {*
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    83
  Fetching contents out of memory. Units not represented by list elements are considered
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    84
  as having content @{text "0"}.
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    85
*}
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    86
fun abc_lm_v :: "abc_lm \<Rightarrow> nat \<Rightarrow> nat"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    87
  where 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    88
    "abc_lm_v lm n = (if (n < length lm) then (lm!n) else 0)"         
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    89
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    90
(*
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    91
fun abc_l2m :: "abc_lm \<Rightarrow> abc_mem"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    92
  where 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    93
    "abc_l2m lm = abc_lm_v lm"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    94
*)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    95
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    96
text {*
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    97
  Set the content of memory unit @{text "n"} to value @{text "v"}.
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    98
  @{text "am"} is the Abacus memory before setting.
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    99
  If address @{text "n"} is outside to scope of @{text "am"}, @{text "am"} 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   100
  is extended so that @{text "n"} becomes in scope.
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   101
*}
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   102
fun abc_lm_s :: "abc_lm \<Rightarrow> nat \<Rightarrow> nat \<Rightarrow> abc_lm"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   103
  where
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   104
    "abc_lm_s am n v = (if (n < length am) then (am[n:=v]) else 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   105
                           am@ (replicate (n - length am) 0) @ [v])"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   106
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   107
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   108
text {*
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   109
  The configuration of Abaucs machines consists of its current state and its
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   110
  current memory:
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   111
*}
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   112
type_synonym abc_conf_l = "abc_state \<times> abc_lm"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   113
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   114
text {*
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   115
  Fetch instruction out of Abacus program:
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   116
*}
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   117
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   118
fun abc_fetch :: "nat \<Rightarrow> abc_prog \<Rightarrow> abc_inst option" 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   119
  where
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   120
  "abc_fetch s p = (if (s < length p) then Some (p ! s)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   121
                    else None)"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   122
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   123
text {*
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   124
  Single step execution of Abacus machine. If no instruction is feteched, 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   125
  configuration does not change.
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   126
*}
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   127
fun abc_step_l :: "abc_conf_l \<Rightarrow> abc_inst option \<Rightarrow> abc_conf_l"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   128
  where
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   129
  "abc_step_l (s, lm) a = (case a of 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   130
               None \<Rightarrow> (s, lm) |
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   131
               Some (Inc n)  \<Rightarrow> (let nv = abc_lm_v lm n in
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   132
                       (s + 1, abc_lm_s lm n (nv + 1))) |
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   133
               Some (Dec n e) \<Rightarrow> (let nv = abc_lm_v lm n in
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   134
                       if (nv = 0) then (e, abc_lm_s lm n 0) 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   135
                       else (s + 1,  abc_lm_s lm n (nv - 1))) |
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   136
               Some (Goto n) \<Rightarrow> (n, lm) 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   137
               )"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   138
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   139
text {*
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   140
  Multi-step execution of Abacus machine.
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   141
*}
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   142
fun abc_steps_l :: "abc_conf_l \<Rightarrow> abc_prog \<Rightarrow> nat \<Rightarrow> abc_conf_l"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   143
  where
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   144
  "abc_steps_l (s, lm) p 0 = (s, lm)" |
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   145
  "abc_steps_l (s, lm) p (Suc n) = abc_steps_l (abc_step_l (s, lm) (abc_fetch s p)) p n"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   146
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   147
section {*
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   148
  Compiling Abacus machines into Truing machines
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   149
*}
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   150
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   151
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   152
subsection {*
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   153
  Compiling functions
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   154
*}
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   155
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   156
text {*
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   157
  @{text "findnth n"} returns the TM which locates the represention of
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   158
  memory cell @{text "n"} on the tape and changes representation of zero
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   159
  on the way.
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   160
*}
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   161
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   162
fun findnth :: "nat \<Rightarrow> tprog"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   163
  where
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   164
  "findnth 0 = []" |
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   165
  "findnth (Suc n) = (findnth n @ [(W1, 2 * n + 1), 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   166
           (R, 2 * n + 2), (R, 2 * n + 3), (R, 2 * n + 2)])"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   167
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   168
text {*
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   169
  @{text "tinc_b"} returns the TM which increments the representation 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   170
  of the memory cell under rw-head by one and move the representation 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   171
  of cells afterwards to the right accordingly.
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   172
  *}
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   173
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   174
definition tinc_b :: "tprog"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   175
  where
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   176
  "tinc_b \<equiv> [(W1, 1), (R, 2), (W1, 3), (R, 2), (W1, 3), (R, 4), 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   177
             (L, 7), (W0, 5), (R, 6), (W0, 5), (W1, 3), (R, 6),
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   178
             (L, 8), (L, 7), (R, 9), (L, 7), (R, 10), (W0, 9)]" 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   179
34
22e5804b135c updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 0
diff changeset
   180
(*  FIXME: doubly defined
0
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   181
text {*
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   182
  @{text "tshift tm off"} shifts @{text "tm"} by offset @{text "off"}, leaving 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   183
  instructions concerning state @{text "0"} unchanged, because state @{text "0"} 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   184
  is the end state, which needs not be changed with shift operation.
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   185
  *}
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   186
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   187
fun tshift :: "tprog \<Rightarrow> nat \<Rightarrow> tprog"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   188
  where
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   189
  "tshift tp off = (map (\<lambda> (action, state). 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   190
       (action, (if state = 0 then 0
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   191
                 else state + off))) tp)"
34
22e5804b135c updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 0
diff changeset
   192
*)
0
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   193
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   194
text {*
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   195
  @{text "tinc ss n"} returns the TM which simulates the execution of 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   196
  Abacus instruction @{text "Inc n"}, assuming that TM is located at
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   197
  location @{text "ss"} in the final TM complied from the whole
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   198
  Abacus program.
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   199
*}
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   200
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   201
fun tinc :: "nat \<Rightarrow> nat \<Rightarrow> tprog"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   202
  where
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   203
  "tinc ss n = tshift (findnth n @ tshift tinc_b (2 * n)) (ss - 1)"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   204
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   205
text {*
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   206
  @{text "tinc_b"} returns the TM which decrements the representation 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   207
  of the memory cell under rw-head by one and move the representation 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   208
  of cells afterwards to the left accordingly.
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   209
  *}
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   210
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   211
definition tdec_b :: "tprog"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   212
  where
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   213
  "tdec_b \<equiv>  [(W1, 1), (R, 2), (L, 14), (R, 3), (L, 4), (R, 3),
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   214
              (R, 5), (W0, 4), (R, 6), (W0, 5), (L, 7), (L, 8),
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   215
              (L, 11), (W0, 7), (W1, 8), (R, 9), (L, 10), (R, 9),
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   216
              (R, 5), (W0, 10), (L, 12), (L, 11), (R, 13), (L, 11),
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   217
              (R, 17), (W0, 13), (L, 15), (L, 14), (R, 16), (L, 14),
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   218
              (R, 0), (W0, 16)]"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   219
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   220
text {*
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   221
  @{text "sete tp e"} attaches the termination edges (edges leading to state @{text "0"}) 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   222
  of TM @{text "tp"} to the intruction labelled by @{text "e"}.
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   223
  *}
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   224
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   225
fun sete :: "tprog \<Rightarrow> nat \<Rightarrow> tprog"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   226
  where
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   227
  "sete tp e = map (\<lambda> (action, state). (action, if state = 0 then e else state)) tp"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   228
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   229
text {*
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   230
  @{text "tdec ss n label"} returns the TM which simulates the execution of 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   231
  Abacus instruction @{text "Dec n label"}, assuming that TM is located at
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   232
  location @{text "ss"} in the final TM complied from the whole
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   233
  Abacus program.
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   234
*}
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   235
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   236
fun tdec :: "nat \<Rightarrow> nat \<Rightarrow> nat \<Rightarrow> tprog"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   237
  where
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   238
  "tdec ss n e = sete (tshift (findnth n @ tshift tdec_b (2 * n)) 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   239
                 (ss - 1)) e"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   240
 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   241
text {*
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   242
  @{text "tgoto f(label)"} returns the TM simulating the execution of Abacus instruction
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   243
  @{text "Goto label"}, where @{text "f(label)"} is the corresponding location of
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   244
  @{text "label"} in the final TM compiled from the overall Abacus program.
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   245
*}
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   246
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   247
fun tgoto :: "nat \<Rightarrow> tprog"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   248
  where
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   249
  "tgoto n = [(Nop, n), (Nop, n)]"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   250
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   251
text {*
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   252
  The layout of the final TM compiled from an Abacus program is represented
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   253
  as a list of natural numbers, where the list element at index @{text "n"} represents the 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   254
  starting state of the TM simulating the execution of @{text "n"}-th instruction
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   255
  in the Abacus program.
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   256
*}
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   257
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   258
type_synonym layout = "nat list"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   259
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   260
text {*
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   261
  @{text "length_of i"} is the length of the 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   262
  TM simulating the Abacus instruction @{text "i"}.
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   263
*}
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   264
fun length_of :: "abc_inst \<Rightarrow> nat"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   265
  where
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   266
  "length_of i = (case i of 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   267
                    Inc n   \<Rightarrow> 2 * n + 9 |
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   268
                    Dec n e \<Rightarrow> 2 * n + 16 |
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   269
                    Goto n  \<Rightarrow> 1)"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   270
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   271
text {*
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   272
  @{text "layout_of ap"} returns the layout of Abacus program @{text "ap"}.
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   273
*}
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   274
fun layout_of :: "abc_prog \<Rightarrow> layout"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   275
  where "layout_of ap = map length_of ap"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   276
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   277
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   278
text {*
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   279
  @{text "start_of layout n"} looks out the starting state of @{text "n"}-th
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   280
  TM in the finall TM.
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   281
*}
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   282
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   283
fun start_of :: "nat list \<Rightarrow> nat \<Rightarrow> nat"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   284
  where
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   285
  "start_of ly 0 = Suc 0" |
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   286
  "start_of ly (Suc as) = 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   287
        (if as < length ly then start_of ly as + (ly ! as)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   288
         else start_of ly as)"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   289
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   290
text {*
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   291
  @{text "ci lo ss i"} complies Abacus instruction @{text "i"}
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   292
  assuming the TM of @{text "i"} starts from state @{text "ss"} 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   293
  within the overal layout @{text "lo"}.
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   294
*}
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   295
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   296
fun ci :: "layout \<Rightarrow> nat \<Rightarrow> abc_inst \<Rightarrow> tprog"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   297
  where
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   298
  "ci ly ss i = (case i of 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   299
                    Inc n   \<Rightarrow> tinc ss n |
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   300
                    Dec n e \<Rightarrow> tdec ss n (start_of ly e) |
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   301
                    Goto n  \<Rightarrow> tgoto (start_of ly n))"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   302
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   303
text {*
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   304
  @{text "tpairs_of ap"} transfroms Abacus program @{text "ap"} pairing
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   305
  every instruction with its starting state.
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   306
*}
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   307
fun tpairs_of :: "abc_prog \<Rightarrow> (nat \<times> abc_inst) list"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   308
  where "tpairs_of ap = (zip (map (start_of (layout_of ap)) 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   309
                         [0..<(length ap)]) ap)"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   310
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   311
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   312
text {*
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   313
  @{text "tms_of ap"} returns the list of TMs, where every one of them simulates
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   314
  the corresponding Abacus intruction in @{text "ap"}.
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   315
*}
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   316
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   317
fun tms_of :: "abc_prog \<Rightarrow> tprog list"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   318
  where "tms_of ap = map (\<lambda> (n, tm). ci (layout_of ap) n tm) 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   319
                         (tpairs_of ap)"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   320
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   321
text {*
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   322
  @{text "tm_of ap"} returns the final TM machine compiled from Abacus program @{text "ap"}.
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   323
*}
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   324
fun tm_of :: "abc_prog \<Rightarrow> tprog"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   325
  where "tm_of ap = concat (tms_of ap)"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   326
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   327
text {*
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   328
  The following two functions specify the well-formedness of complied TM.
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   329
*}
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   330
fun t_ncorrect :: "tprog \<Rightarrow> bool"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   331
  where
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   332
  "t_ncorrect tp = (length tp mod 2 = 0)"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   333
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   334
fun abc2t_correct :: "abc_prog \<Rightarrow> bool"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   335
  where 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   336
  "abc2t_correct ap = list_all (\<lambda> (n, tm). 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   337
             t_ncorrect (ci (layout_of ap) n tm)) (tpairs_of ap)"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   338
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   339
lemma findnth_length: "length (findnth n) div 2 = 2 * n"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   340
apply(induct n, simp, simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   341
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   342
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   343
lemma ci_length : "length (ci ns n ai) div 2 = length_of ai"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   344
apply(auto simp: ci.simps tinc_b_def tdec_b_def findnth_length
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   345
                 split: abc_inst.splits)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   346
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   347
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   348
subsection {*
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   349
  Representation of Abacus memory by TM tape
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   350
*}
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   351
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   352
consts tape_of :: "'a \<Rightarrow> block list" ("<_>" 100)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   353
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   354
text {*
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   355
  @{text "tape_of_nat_list am"} returns the TM tape representing
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   356
  Abacus memory @{text "am"}.
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   357
  *}
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   358
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   359
fun tape_of_nat_list :: "nat list \<Rightarrow> block list"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   360
  where 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   361
  "tape_of_nat_list [] = []" |
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   362
  "tape_of_nat_list [n] = Oc\<^bsup>n+1\<^esup>" |
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   363
  "tape_of_nat_list (n#ns) = (Oc\<^bsup>n+1\<^esup>) @ [Bk] @ (tape_of_nat_list ns)"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   364
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   365
defs (overloaded)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   366
  tape_of_nl_abv: "<am> \<equiv> tape_of_nat_list am"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   367
  tape_of_nat_abv : "<(n::nat)> \<equiv> Oc\<^bsup>n+1\<^esup>"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   368
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   369
text {*
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   370
  @{text "crsp_l acf tcf"} meams the abacus configuration @{text "acf"}
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   371
  is corretly represented by the TM configuration @{text "tcf"}.
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   372
*}
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   373
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   374
fun crsp_l :: "layout \<Rightarrow> abc_conf_l \<Rightarrow> t_conf \<Rightarrow> block list \<Rightarrow> bool"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   375
  where 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   376
  "crsp_l ly (as, lm) (ts, (l, r)) inres = 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   377
           (ts = start_of ly as \<and> (\<exists> rn. r = <lm> @ Bk\<^bsup>rn\<^esup>)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   378
            \<and> l = Bk # Bk # inres)"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   379
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   380
declare crsp_l.simps[simp del]
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   381
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   382
subsection {*
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   383
  A more general definition of TM execution. 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   384
*}
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   385
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   386
(*
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   387
fun nnth_of :: "(taction \<times> nat) list \<Rightarrow> nat \<Rightarrow> nat \<Rightarrow> (taction \<times> nat)"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   388
  where
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   389
  "nnth_of p s b = (if 2*s < length p 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   390
                    then (p ! (2*s + b)) else (Nop, 0))"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   391
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   392
thm nth_of.simps
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   393
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   394
fun nfetch :: "tprog \<Rightarrow> nat \<Rightarrow> block \<Rightarrow> taction \<times> nat"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   395
  where
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   396
  "nfetch p 0 b = (Nop, 0)" |
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   397
  "nfetch p (Suc s) b = 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   398
             (case b of 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   399
                Bk \<Rightarrow> nnth_of p s 0 |
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   400
                Oc \<Rightarrow> nnth_of p s 1)"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   401
*)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   402
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   403
text {*
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   404
  @{text "t_step tcf (tp, ss)"} returns the result of one step exection of TM @{text "tp"}
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   405
  assuming @{text "tp"} starts from instial state @{text "ss"}.
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   406
*}
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   407
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   408
fun t_step :: "t_conf \<Rightarrow> (tprog \<times> nat) \<Rightarrow> t_conf"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   409
  where 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   410
  "t_step c (p, off) = 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   411
           (let (state, leftn, rightn) = c in
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   412
            let (action, next_state) = fetch p (state-off)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   413
                             (case rightn of 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   414
                                [] \<Rightarrow> Bk | 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   415
                                Bk # xs \<Rightarrow> Bk |
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   416
                                Oc # xs \<Rightarrow> Oc
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   417
                             ) 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   418
             in 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   419
            (next_state, new_tape action (leftn, rightn)))"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   420
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   421
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   422
text {*
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   423
  @{text "t_steps tcf (tp, ss) n"} returns the result of @{text "n"}-step exection 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   424
  of TM @{text "tp"} assuming @{text "tp"} starts from instial state @{text "ss"}.
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   425
*}
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   426
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   427
fun t_steps :: "t_conf \<Rightarrow> (tprog \<times> nat) \<Rightarrow> nat \<Rightarrow> t_conf"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   428
  where
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   429
  "t_steps c (p, off) 0 = c" |
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   430
  "t_steps c (p, off) (Suc n) = t_steps 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   431
                     (t_step c (p, off)) (p, off) n" 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   432
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   433
lemma stepn: "t_steps c (p, off) (Suc n) = 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   434
              t_step (t_steps c (p, off) n) (p, off)"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   435
apply(induct n arbitrary: c, simp add: t_steps.simps)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   436
apply(simp add: t_steps.simps)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   437
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   438
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   439
text {*
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   440
  The type of invarints expressing correspondence between 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   441
  Abacus configuration and TM configuration.
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   442
*}
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   443
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   444
type_synonym inc_inv_t = "abc_conf_l \<Rightarrow> t_conf \<Rightarrow> block list \<Rightarrow> bool"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   445
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   446
declare tms_of.simps[simp del] tm_of.simps[simp del]
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   447
        layout_of.simps[simp del] abc_fetch.simps [simp del]  
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   448
        t_step.simps[simp del] t_steps.simps[simp del] 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   449
        tpairs_of.simps[simp del] start_of.simps[simp del]
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   450
        fetch.simps [simp del] t_ncorrect.simps[simp del]
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   451
        new_tape.simps [simp del] ci.simps [simp del] length_of.simps[simp del] 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   452
        layout_of.simps[simp del] crsp_l.simps[simp del]
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   453
        abc2t_correct.simps[simp del]
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   454
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   455
lemma tct_div2: "t_ncorrect tp \<Longrightarrow> (length tp) mod 2 = 0"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   456
apply(simp add: t_ncorrect.simps)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   457
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   458
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   459
lemma t_shift_fetch: 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   460
    "\<lbrakk>t_ncorrect tp1; t_ncorrect tp; 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   461
      length tp1 div 2 < a \<and> a \<le> length tp1 div 2 + length tp div 2\<rbrakk>
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   462
    \<Longrightarrow> fetch tp (a - length tp1 div 2) b = 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   463
         fetch (tp1 @ tp @ tp2) a b"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   464
apply(subgoal_tac "\<exists> x. a = length tp1 div 2 + x", erule exE, simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   465
apply(case_tac x, simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   466
apply(subgoal_tac "length tp1 div 2 + Suc nat = 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   467
             Suc (length tp1 div 2 + nat)")
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   468
apply(simp only: fetch.simps nth_of.simps, auto)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   469
apply(case_tac b, simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   470
apply(subgoal_tac "2 * (length tp1 div 2) = length tp1", simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   471
apply(subgoal_tac "2 * nat < length tp", simp add: nth_append, simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   472
apply(simp add: t_ncorrect.simps, auto)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   473
apply(subgoal_tac "2 * (length tp1 div 2) = length tp1", simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   474
apply(subgoal_tac "2 * nat < length tp", simp add: nth_append, auto)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   475
apply(simp add: t_ncorrect.simps, auto)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   476
apply(rule_tac x = "a - length tp1 div 2" in exI, simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   477
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   478
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   479
lemma t_shift_in_step:
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   480
      "\<lbrakk>t_step (a, aa, ba) (tp, length tp1 div 2) = (s, l, r);
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   481
        t_ncorrect tp1; t_ncorrect tp;
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   482
        length tp1 div 2 < a \<and> a \<le> length tp1 div 2 + length tp div 2\<rbrakk>
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   483
       \<Longrightarrow> t_step (a, aa, ba) (tp1 @ tp @ tp2, 0) = (s, l, r)"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   484
apply(simp add: t_step.simps)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   485
apply(subgoal_tac "fetch tp (a - length tp1 div 2) (case ba of [] \<Rightarrow> 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   486
                   Bk | x # xs \<Rightarrow> x)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   487
             = fetch (tp1 @ tp @ tp2) a (case ba of [] \<Rightarrow> Bk | x # xs
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   488
                   \<Rightarrow> x)")
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   489
apply(case_tac "fetch tp (a - length tp1 div 2) (case ba of [] \<Rightarrow> Bk
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   490
                | x # xs \<Rightarrow> x)")
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   491
apply(auto intro: t_shift_fetch)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   492
apply(case_tac ba, simp, simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   493
apply(case_tac aaa, simp, simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   494
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   495
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   496
declare add_Suc_right[simp del]
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   497
lemma t_step_add: "t_steps c (p, off) (m + n) = 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   498
          t_steps (t_steps c (p, off) m) (p, off) n"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   499
apply(induct m arbitrary: n,  simp add: t_steps.simps, simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   500
apply(subgoal_tac "t_steps c (p, off) (Suc (m + n)) = 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   501
                         t_steps c (p, off) (m + Suc n)", simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   502
apply(subgoal_tac "t_steps (t_steps c (p, off) m) (p, off) (Suc n) =
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   503
                t_steps (t_step (t_steps c (p, off) m) (p, off)) 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   504
                         (p, off) n")
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   505
apply(simp, simp add: stepn)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   506
apply(simp only: t_steps.simps)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   507
apply(simp only: add_Suc_right)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   508
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   509
declare add_Suc_right[simp]
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   510
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   511
lemma s_out_fetch: "\<lbrakk>t_ncorrect tp; 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   512
        \<not> (length tp1 div 2 < a \<and> a \<le> length tp1 div 2 + 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   513
         length tp div 2)\<rbrakk>
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   514
      \<Longrightarrow> fetch tp (a - length tp1 div 2) b = (Nop, 0)"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   515
apply(auto)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   516
apply(simp add: fetch.simps)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   517
apply(subgoal_tac "\<exists> x. a - length tp1 div 2 = length tp div 2 + x")
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   518
apply(erule exE, simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   519
apply(case_tac x, simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   520
apply(auto simp add: fetch.simps)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   521
apply(subgoal_tac "2 * (length tp div 2) =  length tp")
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   522
apply(auto simp: t_ncorrect.simps split: block.splits)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   523
apply(rule_tac x = "a - length tp1 div 2 - length tp div 2" in exI
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   524
     , simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   525
done 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   526
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   527
lemma conf_keep_step: 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   528
      "\<lbrakk>t_ncorrect tp; 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   529
        \<not> (length tp1 div 2 < a \<and> a \<le> length tp1 div 2 + 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   530
       length tp div 2)\<rbrakk>
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   531
      \<Longrightarrow> t_step (a, aa, ba) (tp, length tp1 div 2) = (0, aa, ba)"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   532
apply(simp add: t_step.simps)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   533
apply(subgoal_tac "fetch tp (a - length tp1 div 2) (case ba of [] \<Rightarrow> 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   534
  Bk | Bk # xs \<Rightarrow> Bk | Oc # xs \<Rightarrow> Oc) = (Nop, 0)")
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   535
apply(simp add: new_tape.simps)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   536
apply(rule s_out_fetch, simp, simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   537
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   538
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   539
lemma conf_keep: 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   540
      "\<lbrakk>t_ncorrect tp; 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   541
        \<not> (length tp1 div 2 < a \<and>
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   542
        a \<le> length tp1 div 2 + length tp div 2); n > 0\<rbrakk>
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   543
      \<Longrightarrow> t_steps (a, aa, ba) (tp, length tp1 div 2) n = (0, aa, ba)"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   544
apply(induct n, simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   545
apply(case_tac n, simp add: t_steps.simps)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   546
apply(rule_tac conf_keep_step, simp+)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   547
apply(subgoal_tac " t_steps (a, aa, ba) 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   548
               (tp, length tp1 div 2) (Suc (Suc nat))
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   549
         = t_step (t_steps (a, aa, ba) 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   550
            (tp, length tp1 div 2) (Suc nat)) (tp, length tp1 div 2)")
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   551
apply(simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   552
apply(rule_tac conf_keep_step, simp, simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   553
apply(rule stepn)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   554
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   555
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   556
lemma state_bef_inside: 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   557
    "\<lbrakk>t_ncorrect tp1; t_ncorrect tp; 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   558
      t_steps (s0, l0, r0) (tp, length tp1 div 2) stp = (s, l, r);
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   559
      length tp1 div 2 < s0 \<and> 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   560
         s0 \<le> length tp1 div 2 + length tp div 2;
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   561
      length tp1 div 2 < s \<and> s \<le> length tp1 div 2 + length tp div 2; 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   562
      n < stp; t_steps (s0, l0, r0) (tp, length tp1 div 2) n = 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   563
      (a, aa, ba)\<rbrakk>
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   564
      \<Longrightarrow>  length tp1 div 2 < a \<and> 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   565
         a \<le> length tp1 div 2 + length tp div 2"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   566
apply(subgoal_tac "\<exists> x. stp = n + x", erule exE)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   567
apply(simp only: t_step_add)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   568
apply(rule classical)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   569
apply(subgoal_tac "t_steps (a, aa, ba) 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   570
          (tp, length tp1 div 2) x = (0, aa, ba)")
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   571
apply(simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   572
apply(rule conf_keep, simp, simp, simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   573
apply(rule_tac x = "stp - n" in exI, simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   574
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   575
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   576
lemma turing_shift_inside: 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   577
       "\<lbrakk>t_steps (s0, l0, r0) (tp, length tp1 div 2) stp = (s, l, r);
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   578
         length tp1 div 2 < s0 \<and> 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   579
         s0 \<le> length tp1 div 2 + length tp div 2; 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   580
         t_ncorrect tp1; t_ncorrect tp;
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   581
         length tp1 div 2 < s \<and> 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   582
         s \<le> length tp1 div 2 + length tp div 2\<rbrakk>
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   583
       \<Longrightarrow> t_steps (s0, l0, r0) (tp1 @ tp @ tp2, 0) stp = (s, l, r)"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   584
apply(induct stp arbitrary: s l r)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   585
apply(simp add: t_steps.simps)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   586
apply(subgoal_tac " t_steps (s0, l0, r0) 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   587
        (tp, length tp1 div 2) (Suc stp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   588
                  = t_step (t_steps (s0, l0, r0) 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   589
        (tp, length tp1 div 2) stp) (tp, length tp1 div 2)")
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   590
apply(case_tac "t_steps (s0, l0, r0) (tp, length tp1 div 2) stp")
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   591
apply(subgoal_tac "length tp1 div 2 < a \<and> 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   592
            a \<le> length tp1 div 2 + length tp div 2")
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   593
apply(subgoal_tac "t_steps (s0, l0, r0) 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   594
           (tp1 @ tp @ tp2, 0) stp = (a, b, c)")
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   595
apply(simp only: stepn, simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   596
apply(rule_tac t_shift_in_step, simp+)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   597
defer
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   598
apply(rule stepn)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   599
apply(rule_tac n = stp and stp = "Suc stp" and a = a 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   600
               and aa = b and ba = c in state_bef_inside, simp+)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   601
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   602
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   603
lemma take_Suc_last[elim]: "Suc as \<le> length xs \<Longrightarrow> 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   604
            take (Suc as) xs = take as xs @ [xs ! as]"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   605
apply(induct xs arbitrary: as, simp, simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   606
apply(case_tac as, simp, simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   607
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   608
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   609
lemma concat_suc: "Suc as \<le> length xs \<Longrightarrow> 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   610
       concat (take (Suc as) xs) = concat (take as xs) @ xs! as"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   611
apply(subgoal_tac "take (Suc as) xs = take as xs @ [xs ! as]", simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   612
by auto
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   613
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   614
lemma concat_take_suc_iff: "Suc n \<le> length tps \<Longrightarrow> 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   615
       concat (take n tps) @ (tps ! n) = concat (take (Suc n) tps)"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   616
apply(drule_tac concat_suc, simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   617
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   618
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   619
lemma concat_drop_suc_iff: 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   620
   "Suc n < length tps \<Longrightarrow> concat (drop (Suc n) tps) = 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   621
           tps ! Suc n @ concat (drop (Suc (Suc n)) tps)"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   622
apply(induct tps arbitrary: n, simp, simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   623
apply(case_tac tps, simp, simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   624
apply(case_tac n, simp, simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   625
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   626
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   627
declare append_assoc[simp del]
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   628
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   629
lemma  tm_append: "\<lbrakk>n < length tps; tp = tps ! n\<rbrakk> \<Longrightarrow> 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   630
           \<exists> tp1 tp2. concat tps = tp1 @ tp @ tp2 \<and> tp1 = 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   631
              concat (take n tps) \<and> tp2 = concat (drop (Suc n) tps)"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   632
apply(rule_tac x = "concat (take n tps)" in exI)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   633
apply(rule_tac x = "concat (drop (Suc n) tps)" in exI)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   634
apply(auto)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   635
apply(induct n, simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   636
apply(case_tac tps, simp, simp, simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   637
apply(subgoal_tac "concat (take n tps) @ (tps ! n) = 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   638
               concat (take (Suc n) tps)")
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   639
apply(simp only: append_assoc[THEN sym], simp only: append_assoc)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   640
apply(subgoal_tac " concat (drop (Suc n) tps) = tps ! Suc n @ 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   641
                  concat (drop (Suc (Suc n)) tps)", simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   642
apply(rule_tac concat_drop_suc_iff, simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   643
apply(rule_tac concat_take_suc_iff, simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   644
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   645
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   646
declare append_assoc[simp]
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   647
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   648
lemma map_of:  "n < length xs \<Longrightarrow> (map f xs) ! n = f (xs ! n)"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   649
by(auto)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   650
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   651
lemma [simp]: "length (tms_of aprog) = length aprog"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   652
apply(auto simp: tms_of.simps tpairs_of.simps)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   653
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   654
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   655
lemma ci_nth: "\<lbrakk>ly = layout_of aprog; as < length aprog; 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   656
                abc_fetch as aprog = Some ins\<rbrakk>
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   657
    \<Longrightarrow> ci ly (start_of ly as) ins = tms_of aprog ! as"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   658
apply(simp add: tms_of.simps tpairs_of.simps 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   659
      abc_fetch.simps  map_of del: map_append)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   660
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   661
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   662
lemma t_split:"\<lbrakk>
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   663
        ly = layout_of aprog;
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   664
        as < length aprog; abc_fetch as aprog = Some ins\<rbrakk>
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   665
      \<Longrightarrow> \<exists> tp1 tp2. concat (tms_of aprog) = 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   666
            tp1 @ (ci ly (start_of ly as) ins) @ tp2
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   667
            \<and> tp1 = concat (take as (tms_of aprog)) \<and> 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   668
              tp2 = concat (drop (Suc as) (tms_of aprog))"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   669
apply(insert tm_append[of "as" "tms_of aprog" 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   670
                             "ci ly (start_of ly as) ins"], simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   671
apply(subgoal_tac "ci ly (start_of ly as) ins = (tms_of aprog) ! as")
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   672
apply(subgoal_tac "length (tms_of aprog) = length aprog", simp, simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   673
apply(rule_tac ci_nth, auto)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   674
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   675
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   676
lemma math_sub: "\<lbrakk>x >= Suc 0; x - 1 = z\<rbrakk> \<Longrightarrow> x + y - Suc 0 = z + y"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   677
by auto
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   678
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   679
lemma start_more_one: "as \<noteq> 0 \<Longrightarrow> start_of ly as >= Suc 0"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   680
apply(induct as, simp add: start_of.simps)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   681
apply(case_tac as, auto simp: start_of.simps)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   682
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   683
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   684
lemma tm_ct: "\<lbrakk>abc2t_correct aprog; tp \<in> set (tms_of aprog)\<rbrakk> \<Longrightarrow> 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   685
                           t_ncorrect tp"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   686
apply(simp add: abc2t_correct.simps tms_of.simps)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   687
apply(auto)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   688
apply(simp add:list_all_iff, auto)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   689
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   690
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   691
lemma div_apart: "\<lbrakk>x mod (2::nat) = 0; y mod 2 = 0\<rbrakk> 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   692
          \<Longrightarrow> (x + y) div 2 = x div 2 + y div 2"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   693
apply(drule mod_eqD)+
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   694
apply(auto)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   695
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   696
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   697
lemma div_apart_iff: "\<lbrakk>x mod (2::nat) = 0; y mod 2 = 0\<rbrakk> \<Longrightarrow> 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   698
           (x + y) mod 2 = 0"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   699
apply(auto)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   700
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   701
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   702
lemma tms_ct: "\<lbrakk>abc2t_correct aprog; n < length aprog\<rbrakk> \<Longrightarrow> 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   703
         t_ncorrect (concat (take n (tms_of aprog)))"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   704
apply(induct n, simp add: t_ncorrect.simps, simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   705
apply(subgoal_tac "concat (take (Suc n) (tms_of aprog)) = 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   706
        concat (take n (tms_of aprog)) @ (tms_of aprog ! n)", simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   707
apply(simp add: t_ncorrect.simps)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   708
apply(rule_tac div_apart_iff, simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   709
apply(subgoal_tac "t_ncorrect (tms_of aprog ! n)", 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   710
            simp add: t_ncorrect.simps)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   711
apply(rule_tac tm_ct, simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   712
apply(rule_tac nth_mem, simp add: tms_of.simps tpairs_of.simps)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   713
apply(rule_tac concat_suc, simp add: tms_of.simps tpairs_of.simps)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   714
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   715
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   716
lemma tcorrect_div2: "\<lbrakk>abc2t_correct aprog; Suc as < length aprog\<rbrakk>
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   717
  \<Longrightarrow> (length (concat (take as (tms_of aprog))) + length (tms_of aprog
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   718
 ! as)) div 2 = length (concat (take as (tms_of aprog))) div 2 + 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   719
                 length (tms_of aprog ! as) div 2"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   720
apply(subgoal_tac "t_ncorrect (tms_of aprog ! as)")
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   721
apply(subgoal_tac "t_ncorrect (concat (take as (tms_of aprog)))")
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   722
apply(rule_tac div_apart)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   723
apply(rule tct_div2, simp)+
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   724
apply(erule_tac tms_ct, simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   725
apply(rule_tac tm_ct, simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   726
apply(rule_tac nth_mem)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   727
apply(simp add: tms_of.simps tpairs_of.simps)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   728
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   729
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   730
lemma [simp]: "length (layout_of aprog) = length aprog"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   731
apply(auto simp: layout_of.simps)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   732
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   733
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   734
lemma start_of_ind: "\<lbrakk>as < length aprog; ly = layout_of aprog\<rbrakk> \<Longrightarrow> 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   735
       start_of ly (Suc as) = start_of ly as + 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   736
                          length ((tms_of aprog) ! as) div 2"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   737
apply(simp only: start_of.simps, simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   738
apply(auto simp: start_of.simps tms_of.simps layout_of.simps 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   739
                 tpairs_of.simps)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   740
apply(simp add: ci_length)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   741
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   742
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   743
lemma concat_take_suc: "Suc n \<le> length xs \<Longrightarrow>
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   744
  concat (take (Suc n) xs) = concat (take n xs) @ (xs ! n)"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   745
apply(subgoal_tac "take (Suc n) xs =
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   746
                   take n xs @ [xs ! n]")
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   747
apply(auto)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   748
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   749
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   750
lemma ci_length_not0: "Suc 0 <= length (ci ly as i) div 2"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   751
apply(subgoal_tac "length (ci ly as i) div 2 = length_of i")
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   752
apply(simp add: length_of.simps split: abc_inst.splits)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   753
apply(rule ci_length)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   754
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   755
 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   756
lemma findnth_length2: "length (findnth n) = 4 * n"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   757
apply(induct n, simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   758
apply(simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   759
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   760
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   761
lemma ci_length2: "length (ci ly as i) = 2 * (length_of i)"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   762
apply(simp add: ci.simps length_of.simps tinc_b_def tdec_b_def
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   763
              split: abc_inst.splits, auto)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   764
apply(simp add: findnth_length2)+
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   765
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   766
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   767
lemma tm_mod2: "as < length aprog \<Longrightarrow> 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   768
             length (tms_of aprog ! as) mod 2 = 0"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   769
apply(simp add: tms_of.simps)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   770
apply(subgoal_tac "map (\<lambda>(x, y). ci (layout_of aprog) x y) 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   771
              (tpairs_of aprog) ! as
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   772
                = (\<lambda>(x, y). ci (layout_of aprog) x y) 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   773
              ((tpairs_of aprog) ! as)", simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   774
apply(case_tac "(tpairs_of aprog ! as)", simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   775
apply(subgoal_tac "length (ci (layout_of aprog) a b) =
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   776
                 2 * (length_of b)", simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   777
apply(rule ci_length2)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   778
apply(rule map_of, simp add: tms_of.simps tpairs_of.simps)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   779
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   780
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   781
lemma tms_mod2: "as \<le> length aprog \<Longrightarrow> 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   782
        length (concat (take as (tms_of aprog))) mod 2 = 0"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   783
apply(induct as, simp, simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   784
apply(subgoal_tac "concat (take (Suc as) (tms_of aprog))
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   785
                  = concat (take as (tms_of aprog)) @ 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   786
                       (tms_of aprog ! as)", auto)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   787
apply(rule div_apart_iff, simp, rule tm_mod2, simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   788
apply(rule concat_take_suc, simp add: tms_of.simps tpairs_of.simps)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   789
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   790
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   791
lemma [simp]: "\<lbrakk>as < length aprog; (abc_fetch as aprog) = Some ins\<rbrakk>
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   792
       \<Longrightarrow> ci (layout_of aprog) 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   793
          (start_of (layout_of aprog) as) (ins) \<in> set (tms_of aprog)"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   794
apply(insert ci_nth[of "layout_of aprog" aprog as], simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   795
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   796
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   797
lemma startof_not0: "start_of ly as > 0"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   798
apply(induct as, simp add: start_of.simps)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   799
apply(case_tac as, auto simp: start_of.simps)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   800
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   801
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   802
declare abc_step_l.simps[simp del]
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   803
lemma pre_lheq: "\<lbrakk>tp = concat (take as (tms_of aprog));
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   804
   abc2t_correct aprog; as \<le> length aprog\<rbrakk> \<Longrightarrow> 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   805
         start_of (layout_of aprog) as - Suc 0 = length tp div 2"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   806
apply(induct as arbitrary: tp, simp add: start_of.simps, simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   807
proof - 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   808
  fix as tp
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   809
  assume h1: "\<And>tp. tp = concat (take as (tms_of aprog)) \<Longrightarrow> 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   810
     start_of (layout_of aprog) as - Suc 0 = 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   811
            length (concat (take as (tms_of aprog))) div 2"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   812
  and h2: " abc2t_correct aprog" "Suc as \<le> length aprog" 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   813
  from h2 show "start_of (layout_of aprog) (Suc as) - Suc 0 = 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   814
          length (concat (take (Suc as) (tms_of aprog))) div 2"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   815
    apply(insert h1[of "concat (take as (tms_of aprog))"], simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   816
    apply(insert start_of_ind[of as aprog "layout_of aprog"], simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   817
    apply(subgoal_tac "(take (Suc as) (tms_of aprog)) = 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   818
            take as (tms_of aprog) @ [(tms_of aprog) ! as]", simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   819
    apply(subgoal_tac "(length (concat (take as (tms_of aprog))) + 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   820
                       length (tms_of aprog ! as)) div 2
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   821
            = length (concat (take as (tms_of aprog))) div 2 + 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   822
              length (tms_of aprog ! as) div 2", simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   823
    apply(subgoal_tac "start_of (layout_of aprog) as = 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   824
       length (concat (take as (tms_of aprog))) div 2 + Suc 0", simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   825
    apply(subgoal_tac "start_of (layout_of aprog) as > 0", simp, 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   826
           rule_tac startof_not0)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   827
    apply(insert tm_mod2[of as aprog], simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   828
    apply(insert tms_mod2[of as aprog], simp, arith)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   829
    apply(rule take_Suc_last, simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   830
    done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   831
qed
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   832
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   833
lemma crsp2stateq: 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   834
  "\<lbrakk>as < length aprog; abc2t_correct aprog;
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   835
       crsp_l (layout_of aprog) (as, am) (a, aa, ba) inres\<rbrakk> \<Longrightarrow> 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   836
        a = length (concat (take as (tms_of aprog))) div 2 + 1"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   837
apply(simp add: crsp_l.simps)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   838
apply(insert pre_lheq[of "(concat (take as (tms_of aprog)))" as aprog]
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   839
, simp)   
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   840
apply(subgoal_tac "start_of (layout_of aprog) as > 0", 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   841
      auto intro: startof_not0)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   842
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   843
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   844
lemma turing_shift_outside: 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   845
     "\<lbrakk>t_steps (s0, l0, r0) (tp, length tp1 div 2) stp = (s, l, r); 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   846
       s \<noteq> 0; stp > 0;
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   847
       length tp1 div 2 < s0 \<and> 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   848
       s0 \<le> length tp1 div 2 + length tp div 2; 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   849
       t_ncorrect tp1; t_ncorrect tp;
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   850
       \<not> (length tp1 div 2 < s \<and> 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   851
      s \<le> length tp1 div 2 + length tp div 2)\<rbrakk>
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   852
    \<Longrightarrow> \<exists>stp' > 0. t_steps (s0, l0, r0) (tp1 @ tp @ tp2, 0) stp' 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   853
                = (s, l, r)"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   854
apply(rule_tac x = stp in exI)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   855
apply(case_tac stp, simp add: t_steps.simps)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   856
apply(simp only: stepn)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   857
apply(case_tac "t_steps (s0, l0, r0) (tp, length tp1 div 2) nat")
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   858
apply(subgoal_tac "length tp1 div 2 < a \<and> 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   859
                   a \<le> length tp1 div 2 + length tp div 2")
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   860
apply(subgoal_tac "t_steps (s0, l0, r0) (tp1 @ tp @ tp2, 0) nat 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   861
                   = (a, b, c)", simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   862
apply(rule_tac t_shift_in_step, simp+)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   863
apply(rule_tac turing_shift_inside, simp+)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   864
apply(rule classical)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   865
apply(subgoal_tac "t_step (a,b,c) 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   866
            (tp, length tp1 div 2) = (0, b, c)", simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   867
apply(rule_tac conf_keep_step, simp+)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   868
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   869
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   870
lemma turing_shift: 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   871
  "\<lbrakk>t_steps (s0, (l0, r0)) (tp, (length tp1 div 2)) stp
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   872
   = (s, (l, r)); s \<noteq> 0; stp > 0;
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   873
  (length tp1 div 2 < s0 \<and> s0 <= length tp1 div 2 + length tp div 2);
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   874
  t_ncorrect tp1; t_ncorrect tp\<rbrakk> \<Longrightarrow> 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   875
         \<exists> stp' > 0. t_steps (s0, (l0, r0)) (tp1 @ tp @ tp2, 0) stp' =
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   876
                    (s, (l, r))"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   877
apply(case_tac "s > length tp1 div 2 \<and> 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   878
              s <= length tp1 div 2 + length tp div 2")
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   879
apply(subgoal_tac " t_steps (s0, l0, r0) (tp1 @ tp @ tp2, 0) stp = 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   880
                   (s, l, r)")
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   881
apply(rule_tac x = stp in exI, simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   882
apply(rule_tac turing_shift_inside, simp+)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   883
apply(rule_tac turing_shift_outside, simp+)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   884
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   885
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   886
lemma inc_startof_not0:  "start_of ly as \<ge> Suc 0"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   887
apply(induct as, simp add: start_of.simps)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   888
apply(simp add: start_of.simps)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   889
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   890
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   891
lemma s_crsp:
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   892
  "\<lbrakk>as < length aprog; abc_fetch as aprog = Some ins;
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   893
  abc2t_correct aprog;
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   894
  crsp_l (layout_of aprog) (as, am) (a, aa, ba) inres\<rbrakk> \<Longrightarrow>  
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   895
  length (concat (take as (tms_of aprog))) div 2 < a 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   896
      \<and> a \<le> length (concat (take as (tms_of aprog))) div 2 + 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   897
         length (ci (layout_of aprog) (start_of (layout_of aprog) as)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   898
         ins) div 2"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   899
apply(subgoal_tac "a = length (concat (take as (tms_of aprog))) div 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   900
                   2 + 1", simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   901
apply(rule_tac ci_length_not0)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   902
apply(rule crsp2stateq, simp+)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   903
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   904
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   905
lemma tms_out_ex:
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   906
  "\<lbrakk>ly = layout_of aprog; tprog = tm_of aprog;
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   907
  abc2t_correct aprog;
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   908
  crsp_l ly (as, am) tc inres; as < length aprog;
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   909
  abc_fetch as aprog = Some ins;
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   910
  t_steps tc (ci ly (start_of ly as) ins, 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   911
  (start_of ly as) - 1) n = (s, l, r);
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   912
  n > 0; 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   913
  abc_step_l (as, am) (abc_fetch as aprog) = (as', am');
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   914
  s = start_of ly as'
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   915
  \<rbrakk>
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   916
  \<Longrightarrow> \<exists> stp > 0. (t_steps tc (tprog, 0) stp = (s, (l, r)))"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   917
apply(simp only: tm_of.simps)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   918
apply(subgoal_tac "\<exists> tp1 tp2. concat (tms_of aprog) = 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   919
      tp1 @ (ci ly (start_of ly as) ins) @ tp2
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   920
    \<and> tp1 = concat (take as (tms_of aprog)) \<and> 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   921
      tp2 = concat (drop (Suc as) (tms_of aprog))")
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   922
apply(erule exE, erule exE, erule conjE, erule conjE,
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   923
      case_tac tc, simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   924
apply(rule turing_shift)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   925
apply(subgoal_tac "start_of (layout_of aprog) as - Suc 0 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   926
                = length tp1 div 2", simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   927
apply(rule_tac pre_lheq, simp, simp, simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   928
apply(simp add: startof_not0, simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   929
apply(rule_tac s_crsp, simp, simp, simp, simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   930
apply(rule tms_ct, simp, simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   931
apply(rule tm_ct, simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   932
apply(subgoal_tac "ci (layout_of aprog) 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   933
                 (start_of (layout_of aprog) as) ins
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   934
                = (tms_of aprog ! as)", simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   935
apply(simp add: tms_of.simps tpairs_of.simps)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   936
apply(simp add: tms_of.simps tpairs_of.simps abc_fetch.simps)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   937
apply(erule_tac t_split, auto simp: tm_of.simps)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   938
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   939
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   940
(*
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   941
subsection {* The compilation of @{text "Inc n"} *}
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   942
*)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   943
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   944
text {*
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   945
  The lemmas in this section lead to the correctness of 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   946
  the compilation of @{text "Inc n"} instruction.
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   947
*}
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   948
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   949
fun at_begin_fst_bwtn :: "inc_inv_t"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   950
  where
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   951
  "at_begin_fst_bwtn (as, lm) (s, l, r) ires = 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   952
      (\<exists> lm1 tn rn. lm1 = (lm @ (0\<^bsup>tn\<^esup>)) \<and> length lm1 = s \<and> 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   953
          (if lm1 = [] then l = Bk # Bk # ires
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   954
           else l = [Bk]@<rev lm1>@Bk#Bk#ires) \<and> r = (Bk\<^bsup>rn\<^esup>))" 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   955
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   956
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   957
fun at_begin_fst_awtn :: "inc_inv_t"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   958
  where
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   959
  "at_begin_fst_awtn (as, lm) (s, l, r) ires = 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   960
      (\<exists> lm1 tn rn. lm1 = (lm @ (0\<^bsup>tn\<^esup>)) \<and> length lm1 = s \<and>
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   961
         (if lm1 = []  then l = Bk # Bk # ires
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   962
          else l = [Bk]@<rev lm1>@Bk#Bk#ires) \<and> r = [Oc]@Bk\<^bsup>rn\<^esup>
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   963
  )"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   964
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   965
fun at_begin_norm :: "inc_inv_t"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   966
  where
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   967
  "at_begin_norm (as, lm) (s, l, r) ires= 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   968
      (\<exists> lm1 lm2 rn. lm = lm1 @ lm2 \<and> length lm1 = s \<and> 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   969
        (if lm1 = [] then l = Bk # Bk # ires
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   970
         else l = Bk # <rev lm1> @ Bk# Bk # ires ) \<and> r = <lm2> @ (Bk\<^bsup>rn\<^esup>))"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   971
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   972
fun in_middle :: "inc_inv_t"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   973
  where
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   974
  "in_middle (as, lm) (s, l, r) ires = 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   975
      (\<exists> lm1 lm2 tn m ml mr rn. lm @ 0\<^bsup>tn\<^esup> = lm1 @ [m] @ lm2
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   976
       \<and> length lm1 = s \<and> m + 1 = ml + mr \<and>  
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   977
         ml \<noteq> 0 \<and> tn = s + 1 - length lm \<and> 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   978
       (if lm1 = [] then l = Oc\<^bsup>ml\<^esup> @ Bk # Bk # ires 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   979
        else l = (Oc\<^bsup>ml\<^esup>)@[Bk]@<rev lm1>@
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   980
                 Bk # Bk # ires) \<and> (r = (Oc\<^bsup>mr\<^esup>) @ [Bk] @ <lm2>@ (Bk\<^bsup>rn\<^esup>) \<or> 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   981
      (lm2 = [] \<and> r = (Oc\<^bsup>mr\<^esup>)))
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   982
      )"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   983
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   984
fun inv_locate_a :: "inc_inv_t"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   985
  where "inv_locate_a (as, lm) (s, l, r) ires = 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   986
     (at_begin_norm (as, lm) (s, l, r) ires \<or>
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   987
      at_begin_fst_bwtn (as, lm) (s, l, r) ires \<or>
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   988
      at_begin_fst_awtn (as, lm) (s, l, r) ires
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   989
      )"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   990
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   991
fun inv_locate_b :: "inc_inv_t"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   992
  where "inv_locate_b (as, lm) (s, l, r) ires = 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   993
        (in_middle (as, lm) (s, l, r)) ires "
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   994
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   995
fun inv_after_write :: "inc_inv_t"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   996
  where "inv_after_write (as, lm) (s, l, r) ires = 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   997
           (\<exists> rn m lm1 lm2. lm = lm1 @ m # lm2 \<and>
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   998
             (if lm1 = [] then l = Oc\<^bsup>m\<^esup> @ Bk # Bk # ires
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   999
              else Oc # l = Oc\<^bsup>Suc m \<^esup>@ Bk # <rev lm1> @ 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1000
                      Bk # Bk # ires) \<and> r = [Oc] @ <lm2> @ (Bk\<^bsup>rn\<^esup>))"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1001
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1002
fun inv_after_move :: "inc_inv_t"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1003
  where "inv_after_move (as, lm) (s, l, r) ires = 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1004
      (\<exists> rn m lm1 lm2. lm = lm1 @ m # lm2 \<and>
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1005
        (if lm1 = [] then l = Oc\<^bsup>Suc m\<^esup> @ Bk # Bk # ires
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1006
         else l = Oc\<^bsup>Suc m\<^esup>@ Bk # <rev lm1> @ Bk # Bk # ires) \<and> 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1007
        r = <lm2> @ (Bk\<^bsup>rn\<^esup>))"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1008
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1009
fun inv_after_clear :: "inc_inv_t"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1010
  where "inv_after_clear (as, lm) (s, l, r) ires =
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1011
       (\<exists> rn m lm1 lm2 r'. lm = lm1 @ m # lm2 \<and> 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1012
        (if lm1 = [] then l = Oc\<^bsup>Suc m\<^esup> @ Bk # Bk # ires
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1013
         else l = Oc\<^bsup>Suc m\<^esup>@ Bk # <rev lm1> @ Bk # Bk # ires) \<and> 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1014
          r = Bk # r' \<and> Oc # r' = <lm2> @ (Bk\<^bsup>rn\<^esup>))"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1015
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1016
fun inv_on_right_moving :: "inc_inv_t"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1017
  where "inv_on_right_moving (as, lm) (s, l, r) ires = 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1018
       (\<exists> lm1 lm2 m ml mr rn. lm = lm1 @ [m] @ lm2 \<and> 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1019
            ml + mr = m \<and> 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1020
          (if lm1 = [] then l = Oc\<^bsup>ml\<^esup> @ Bk # Bk # ires
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1021
          else l = (Oc\<^bsup>ml\<^esup>) @ [Bk] @ <rev lm1> @ Bk # Bk # ires) \<and> 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1022
         ((r = (Oc\<^bsup>mr\<^esup>) @ [Bk] @ <lm2> @ (Bk\<^bsup>rn\<^esup>)) \<or> 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1023
          (r = (Oc\<^bsup>mr\<^esup>) \<and> lm2 = [])))"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1024
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1025
fun inv_on_left_moving_norm :: "inc_inv_t"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1026
  where "inv_on_left_moving_norm (as, lm) (s, l, r) ires =
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1027
      (\<exists> lm1 lm2 m ml mr rn. lm = lm1 @ [m] @ lm2 \<and>  
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1028
             ml + mr = Suc m \<and> mr > 0 \<and> (if lm1 = [] then l = Oc\<^bsup>ml\<^esup> @ Bk # Bk # ires
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1029
                                         else l = (Oc\<^bsup>ml\<^esup>) @ Bk # <rev lm1> @ Bk # Bk # ires)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1030
        \<and> (r = (Oc\<^bsup>mr\<^esup>) @ Bk # <lm2> @ (Bk\<^bsup>rn\<^esup>) \<or> 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1031
           (lm2 = [] \<and> r = Oc\<^bsup>mr\<^esup>)))"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1032
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1033
fun inv_on_left_moving_in_middle_B:: "inc_inv_t"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1034
  where "inv_on_left_moving_in_middle_B (as, lm) (s, l, r) ires =
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1035
                (\<exists> lm1 lm2 rn. lm = lm1 @ lm2 \<and>  
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1036
                     (if lm1 = [] then l = Bk # ires
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1037
                      else l = <rev lm1> @ Bk # Bk # ires) \<and> 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1038
                      r = Bk # <lm2> @ (Bk\<^bsup>rn\<^esup>))"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1039
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1040
fun inv_on_left_moving :: "inc_inv_t"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1041
  where "inv_on_left_moving (as, lm) (s, l, r) ires = 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1042
       (inv_on_left_moving_norm  (as, lm) (s, l, r) ires \<or>
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1043
        inv_on_left_moving_in_middle_B (as, lm) (s, l, r) ires)"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1044
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1045
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1046
fun inv_check_left_moving_on_leftmost :: "inc_inv_t"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1047
  where "inv_check_left_moving_on_leftmost (as, lm) (s, l, r) ires = 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1048
                (\<exists> rn. l = ires \<and> r = [Bk, Bk] @ <lm> @ (Bk\<^bsup>rn\<^esup>))"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1049
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1050
fun inv_check_left_moving_in_middle :: "inc_inv_t"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1051
  where "inv_check_left_moving_in_middle (as, lm) (s, l, r) ires = 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1052
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1053
              (\<exists> lm1 lm2 r' rn. lm = lm1 @ lm2 \<and>
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1054
                 (Oc # l = <rev lm1> @ Bk # Bk # ires) \<and> r = Oc # Bk # r' \<and> 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1055
                           r' = <lm2> @ (Bk\<^bsup>rn\<^esup>))"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1056
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1057
fun inv_check_left_moving :: "inc_inv_t"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1058
  where "inv_check_left_moving (as, lm) (s, l, r) ires = 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1059
             (inv_check_left_moving_on_leftmost (as, lm) (s, l, r) ires \<or>
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1060
             inv_check_left_moving_in_middle (as, lm) (s, l, r) ires)"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1061
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1062
fun inv_after_left_moving :: "inc_inv_t"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1063
  where "inv_after_left_moving (as, lm) (s, l, r) ires= 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1064
              (\<exists> rn. l = Bk # ires \<and> r = Bk # <lm> @ (Bk\<^bsup>rn\<^esup>))"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1065
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1066
fun inv_stop :: "inc_inv_t"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1067
  where "inv_stop (as, lm) (s, l, r) ires= 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1068
              (\<exists> rn. l = Bk # Bk # ires \<and> r = <lm> @ (Bk\<^bsup>rn\<^esup>))"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1069
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1070
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1071
fun inc_inv :: "layout \<Rightarrow> nat \<Rightarrow> inc_inv_t"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1072
  where
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1073
  "inc_inv ly n (as, lm) (s, l, r) ires =
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1074
              (let ss = start_of ly as in
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1075
               let lm' = abc_lm_s lm n ((abc_lm_v lm n)+1) in
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1076
                if s = 0 then False
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1077
                else if s < ss then False
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1078
                else if s < ss + 2 * n then 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1079
                   if (s - ss) mod 2 = 0 then 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1080
                       inv_locate_a (as, lm) ((s - ss) div 2, l, r) ires
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1081
                   else inv_locate_b (as, lm) ((s - ss) div 2, l, r) ires
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1082
                else if s = ss + 2 * n then 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1083
                        inv_locate_a (as, lm) (n, l, r) ires
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1084
                else if s = ss + 2 * n + 1 then 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1085
                   inv_locate_b (as, lm) (n, l, r) ires
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1086
                else if s = ss + 2 * n + 2 then 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1087
                   inv_after_write (as, lm') (s - ss, l, r) ires
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1088
                else if s = ss + 2 * n + 3 then 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1089
                   inv_after_move (as, lm') (s - ss, l, r) ires
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1090
                else if s = ss + 2 * n + 4 then 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1091
                   inv_after_clear (as, lm') (s - ss, l, r) ires
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1092
                else if s = ss + 2 * n + 5 then 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1093
                   inv_on_right_moving (as, lm') (s - ss, l, r) ires
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1094
                else if s = ss + 2 * n + 6 then 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1095
                   inv_on_left_moving (as, lm') (s - ss, l, r) ires
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1096
                else if s = ss + 2 * n + 7 then 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1097
                   inv_check_left_moving (as, lm') (s - ss, l, r) ires
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1098
                else if s = ss + 2 * n + 8 then 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1099
                   inv_after_left_moving (as, lm') (s - ss, l, r) ires
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1100
                else if s = ss + 2 * n + 9 then 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1101
                   inv_stop (as, lm') (s - ss, l, r) ires
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1102
                else False) "
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1103
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1104
lemma fetch_intro: 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1105
  "\<lbrakk>\<And>xs.\<lbrakk>ba = Oc # xs\<rbrakk> \<Longrightarrow> P (fetch prog i Oc);
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1106
   \<And>xs.\<lbrakk>ba = Bk # xs\<rbrakk> \<Longrightarrow> P (fetch prog i Bk);
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1107
   ba = [] \<Longrightarrow> P (fetch prog i Bk)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1108
   \<rbrakk> \<Longrightarrow> P (fetch prog i 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1109
             (case ba of [] \<Rightarrow> Bk | Bk # xs \<Rightarrow> Bk | Oc # xs \<Rightarrow> Oc))"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1110
by (auto split:list.splits block.splits)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1111
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1112
lemma length_findnth[simp]: "length (findnth n) = 4 * n"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1113
apply(induct n, simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1114
apply(simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1115
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1116
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1117
declare tshift.simps[simp del]
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1118
declare findnth.simps[simp del]
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1119
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1120
lemma findnth_nth: 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1121
 "\<lbrakk>n > q; x < 4\<rbrakk> \<Longrightarrow> 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1122
        (findnth n) ! (4 * q + x) = (findnth (Suc q) ! (4 * q + x))"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1123
apply(induct n, simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1124
apply(case_tac "q < n", simp add: findnth.simps, auto)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1125
apply(simp add: nth_append)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1126
apply(subgoal_tac "q = n", simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1127
apply(arith)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1128
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1129
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1130
lemma Suc_pre[simp]: "\<not> a < start_of ly as \<Longrightarrow> 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1131
          (Suc a - start_of ly as) = Suc (a - start_of ly as)"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1132
apply(arith)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1133
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1134
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1135
lemma fetch_locate_a_o: "
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1136
\<And>a  q xs.
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1137
    \<lbrakk>\<not> a < start_of (layout_of aprog) as; 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1138
      a < start_of (layout_of aprog) as + 2 * n; 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1139
      a - start_of (layout_of aprog) as = 2 * q; 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1140
      start_of (layout_of aprog) as > 0\<rbrakk>
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1141
    \<Longrightarrow> (fetch (ci (layout_of aprog) (start_of (layout_of aprog) as)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1142
         (Inc n)) (Suc (2 * q)) Oc) = (R, a+1)"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1143
apply(auto simp: ci.simps findnth.simps fetch.simps
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1144
                  nth_of.simps tshift.simps nth_append Suc_pre)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1145
apply(subgoal_tac "(findnth n ! Suc (4 * q)) = 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1146
                 findnth (Suc q) ! (4 * q + 1)")
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1147
apply(simp add: findnth.simps nth_append)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1148
apply(subgoal_tac " findnth n !(4 * q + 1) = 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1149
                 findnth (Suc q) ! (4 * q + 1)", simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1150
apply(rule_tac findnth_nth, auto)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1151
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1152
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1153
lemma fetch_locate_a_b: "
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1154
\<And>a  q xs.
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1155
    \<lbrakk>abc_fetch as aprog = Some (Inc n);  
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1156
     \<not> a < start_of (layout_of aprog) as; 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1157
     a < start_of (layout_of aprog) as + 2 * n; 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1158
     a - start_of (layout_of aprog) as = 2 * q; 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1159
     start_of (layout_of aprog) as > 0\<rbrakk>
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1160
    \<Longrightarrow> (fetch (ci (layout_of aprog) 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1161
      (start_of (layout_of aprog) as) (Inc n)) (Suc (2 * q)) Bk)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1162
       = (W1, a)"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1163
apply(auto simp: ci.simps findnth.simps fetch.simps
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1164
                 tshift.simps nth_append)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1165
apply(subgoal_tac "(findnth n ! (4 * q)) = 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1166
                           findnth (Suc q) ! (4 * q )")
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1167
apply(simp add: findnth.simps nth_append)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1168
apply(subgoal_tac " findnth n !(4 * q + 0) =
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1169
                            findnth (Suc q) ! (4 * q + 0)", simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1170
apply(rule_tac findnth_nth, auto)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1171
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1172
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1173
lemma [intro]: "x mod 2 = Suc 0 \<Longrightarrow> \<exists> q. x = Suc (2 * q)"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1174
apply(drule mod_eqD, auto)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1175
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1176
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1177
lemma  add3_Suc: "x + 3 = Suc (Suc (Suc x))"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1178
apply(arith)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1179
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1180
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1181
declare start_of.simps[simp]
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1182
(*
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1183
lemma layout_not0: "start_of ly as > 0"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1184
by(induct as, auto)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1185
*)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1186
lemma [simp]: 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1187
 "\<lbrakk>\<not> a < start_of (layout_of aprog) as; 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1188
   a - start_of (layout_of aprog) as = Suc (2 * q); 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1189
   abc_fetch as aprog = Some (Inc n); 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1190
   start_of (layout_of aprog) as > 0\<rbrakk>
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1191
    \<Longrightarrow> Suc (Suc (2 * q + start_of (layout_of aprog) as - Suc 0)) = a"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1192
apply(subgoal_tac 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1193
"Suc (Suc (2 * q + start_of (layout_of aprog) as - Suc 0)) 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1194
              = 2 + 2 * q + start_of (layout_of aprog) as - Suc 0", 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1195
  simp, simp add: inc_startof_not0)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1196
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1197
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1198
lemma fetch_locate_b_o: "
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1199
\<And>a  xs.
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1200
    \<lbrakk>0 < a; \<not> a < start_of (layout_of aprog) as; 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1201
  a < start_of (layout_of aprog) as + 2 * n; 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1202
 (a - start_of (layout_of aprog) as) mod 2 = Suc 0; 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1203
 start_of (layout_of aprog) as > 0\<rbrakk>
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1204
    \<Longrightarrow> (fetch (ci (layout_of aprog) (start_of (layout_of aprog) as) 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1205
      (Inc n)) (Suc (a - start_of (layout_of aprog) as)) Oc) = (R, a)"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1206
apply(auto simp: ci.simps findnth.simps fetch.simps
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1207
                 nth_of.simps tshift.simps nth_append)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1208
apply(subgoal_tac "\<exists> q. (a - start_of (layout_of aprog) as) = 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1209
                         2 * q + 1", auto)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1210
apply(subgoal_tac "(findnth n ! Suc (Suc (Suc (4 * q)))) 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1211
                  = findnth (Suc q) ! (4 * q + 3)")
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1212
apply(simp add: findnth.simps nth_append)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1213
apply(subgoal_tac " findnth n ! (4 * q + 3) = 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1214
                 findnth (Suc q) ! (4 * q + 3)", simp add: add3_Suc)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1215
apply(rule_tac findnth_nth, auto)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1216
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1217
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1218
lemma fetch_locate_b_b: "
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1219
\<And>a  xs.
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1220
    \<lbrakk>0 < a;  \<not> a < start_of (layout_of aprog) as; 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1221
     a < start_of (layout_of aprog) as + 2 * n; 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1222
     (a - start_of (layout_of aprog) as) mod 2 = Suc 0; 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1223
     start_of (layout_of aprog) as > 0\<rbrakk>
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1224
    \<Longrightarrow> (fetch (ci (layout_of aprog) (start_of (layout_of aprog) as)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1225
        (Inc n)) (Suc (a - start_of (layout_of aprog) as)) Bk) 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1226
        = (R, a + 1)"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1227
apply(auto simp: ci.simps findnth.simps fetch.simps
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1228
                  nth_of.simps tshift.simps nth_append)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1229
apply(subgoal_tac "\<exists> q. (a - start_of (layout_of aprog) as) = 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1230
                  2 * q + 1", auto)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1231
apply(subgoal_tac "(findnth n ! Suc ((Suc (4 * q)))) = 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1232
                    findnth (Suc q) ! (4 * q + 2)")
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1233
apply(simp add: findnth.simps nth_append)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1234
apply(subgoal_tac " findnth n ! (4 * q + 2) = 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1235
                    findnth (Suc q) ! (4 * q + 2)", simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1236
apply(rule_tac findnth_nth, auto)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1237
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1238
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1239
lemma fetch_locate_n_a_o: 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1240
       "start_of (layout_of aprog) as > 0
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1241
       \<Longrightarrow> (fetch (ci (layout_of aprog) 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1242
      (start_of (layout_of aprog) as) (Inc n)) (Suc (2 * n)) Oc) = 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1243
             (R, start_of (layout_of aprog) as + 2 * n + 1)"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1244
apply(auto simp: ci.simps findnth.simps fetch.simps
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1245
                  nth_of.simps tshift.simps nth_append tinc_b_def)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1246
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1247
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1248
lemma fetch_locate_n_a_b: "
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1249
       start_of (layout_of aprog) as > 0
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1250
      \<Longrightarrow> (fetch (ci (layout_of aprog) 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1251
    (start_of (layout_of aprog) as) (Inc n)) (Suc (2 * n)) Bk) 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1252
   = (W1, start_of (layout_of aprog) as + 2 * n)"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1253
apply(auto simp: ci.simps findnth.simps fetch.simps
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1254
                  nth_of.simps tshift.simps nth_append tinc_b_def)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1255
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1256
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1257
lemma fetch_locate_n_b_o: "
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1258
    start_of (layout_of aprog) as > 0
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1259
    \<Longrightarrow> (fetch (ci (layout_of aprog) (start_of (layout_of aprog) as) 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1260
     (Inc n)) (Suc (Suc (2 * n))) Oc) = 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1261
                      (R, start_of (layout_of aprog) as + 2 * n + 1)"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1262
apply(auto simp: ci.simps findnth.simps fetch.simps
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1263
                  nth_of.simps tshift.simps nth_append tinc_b_def)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1264
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1265
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1266
lemma fetch_locate_n_b_b: "
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1267
    start_of (layout_of aprog) as > 0
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1268
   \<Longrightarrow> (fetch (ci (layout_of aprog) (start_of (layout_of aprog) as) 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1269
   (Inc n)) (Suc (Suc (2 * n))) Bk) = 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1270
       (W1, start_of (layout_of aprog) as + 2 * n + 2)"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1271
apply(auto simp: ci.simps findnth.simps fetch.simps
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1272
                  nth_of.simps tshift.simps nth_append tinc_b_def)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1273
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1274
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1275
lemma fetch_after_write_o: "
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1276
    start_of (layout_of aprog) as > 0
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1277
    \<Longrightarrow> (fetch (ci (layout_of aprog) (start_of (layout_of aprog) as) 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1278
            (Inc n)) (Suc (Suc (Suc (2 * n)))) Oc) = 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1279
        (R, start_of (layout_of aprog) as + 2*n + 3)"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1280
apply(auto simp: ci.simps findnth.simps fetch.simps
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1281
                  nth_of.simps tshift.simps nth_append tinc_b_def)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1282
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1283
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1284
lemma fetch_after_move_o: "
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1285
      start_of (layout_of aprog) as > 0
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1286
      \<Longrightarrow> (fetch (ci (layout_of aprog) 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1287
              (start_of (layout_of aprog) as) (Inc n)) (4 + 2 * n) Oc)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1288
        = (W0, start_of (layout_of aprog) as + 2 * n + 4)"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1289
apply(auto simp: ci.simps findnth.simps tshift.simps 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1290
                 tinc_b_def add3_Suc)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1291
apply(subgoal_tac "4 + 2*n = Suc (2*n + 3)", simp only: fetch.simps)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1292
apply(auto simp: nth_of.simps nth_append)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1293
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1294
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1295
lemma fetch_after_move_b: "
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1296
      start_of (layout_of aprog) as > 0
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1297
      \<Longrightarrow>(fetch (ci (layout_of aprog) 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1298
            (start_of (layout_of aprog) as) (Inc n)) (4 + 2 * n) Bk)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1299
       = (L, start_of (layout_of aprog) as + 2 * n + 6)"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1300
apply(auto simp: ci.simps findnth.simps tshift.simps 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1301
                 tinc_b_def add3_Suc)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1302
apply(subgoal_tac "4 + 2*n = Suc (2*n + 3)", simp only: fetch.simps)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1303
apply(auto simp: nth_of.simps nth_append)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1304
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1305
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1306
lemma fetch_clear_b: "
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1307
     start_of (layout_of aprog) as > 0
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1308
      \<Longrightarrow> (fetch (ci (layout_of aprog) 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1309
              (start_of (layout_of aprog) as) (Inc n)) (5 + 2 * n) Bk)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1310
      = (R, start_of (layout_of aprog) as + 2 * n + 5)"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1311
apply(auto simp: ci.simps findnth.simps 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1312
                     tshift.simps tinc_b_def add3_Suc)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1313
apply(subgoal_tac "5 + 2*n = Suc (2*n + 4)", simp only: fetch.simps)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1314
apply(auto simp: nth_of.simps nth_append)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1315
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1316
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1317
lemma fetch_right_move_o: "
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1318
      start_of (layout_of aprog) as > 0
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1319
      \<Longrightarrow> (fetch (ci (layout_of aprog) 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1320
                (start_of (layout_of aprog) as) (Inc n)) (6 + 2*n) Oc)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1321
      = (R, start_of (layout_of aprog) as + 2 * n + 5)"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1322
apply(auto simp: ci.simps findnth.simps tshift.simps 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1323
                 tinc_b_def add3_Suc)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1324
apply(subgoal_tac "6 + 2*n = Suc (2*n + 5)", simp only: fetch.simps)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1325
apply(auto simp: nth_of.simps nth_append)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1326
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1327
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1328
lemma fetch_right_move_b: "
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1329
      start_of (layout_of aprog) as > 0
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1330
      \<Longrightarrow> (fetch (ci (layout_of aprog) 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1331
                (start_of (layout_of aprog) as) (Inc n)) (6 + 2*n) Bk)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1332
      = (W1, start_of (layout_of aprog) as + 2 * n + 2)"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1333
apply(auto simp: ci.simps findnth.simps 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1334
                 tshift.simps tinc_b_def add3_Suc)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1335
apply(subgoal_tac "6 + 2*n = Suc (2*n + 5)", simp only: fetch.simps)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1336
apply(auto simp: nth_of.simps nth_append)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1337
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1338
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1339
lemma fetch_left_move_o: "
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1340
      start_of (layout_of aprog) as > 0
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1341
      \<Longrightarrow> (fetch (ci (layout_of aprog) 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1342
               (start_of (layout_of aprog) as) (Inc n)) (7 + 2*n) Oc)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1343
      = (L, start_of (layout_of aprog) as + 2 * n + 6)"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1344
apply(auto simp: ci.simps findnth.simps tshift.simps 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1345
                 tinc_b_def add3_Suc)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1346
apply(subgoal_tac "7 + 2*n = Suc (2*n + 6)", simp only: fetch.simps)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1347
apply(auto simp: nth_of.simps nth_append)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1348
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1349
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1350
lemma fetch_left_move_b: "
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1351
      start_of (layout_of aprog) as > 0
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1352
      \<Longrightarrow> (fetch (ci (layout_of aprog) 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1353
               (start_of (layout_of aprog) as) (Inc n)) (7 + 2*n) Bk)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1354
      = (L, start_of (layout_of aprog) as + 2 * n + 7)"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1355
apply(auto simp: ci.simps findnth.simps 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1356
                 tshift.simps tinc_b_def add3_Suc)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1357
apply(subgoal_tac "7 + 2*n = Suc (2*n + 6)", simp only: fetch.simps)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1358
apply(auto simp: nth_of.simps nth_append)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1359
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1360
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1361
lemma fetch_check_left_move_o: "
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1362
      start_of (layout_of aprog) as > 0
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1363
      \<Longrightarrow> (fetch (ci (layout_of aprog) 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1364
               (start_of (layout_of aprog) as) (Inc n)) (8 + 2*n) Oc)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1365
      = (L, start_of (layout_of aprog) as + 2 * n + 6)"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1366
apply(auto simp: ci.simps findnth.simps tshift.simps tinc_b_def)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1367
apply(subgoal_tac "8 + 2 * n = Suc (2 * n + 7)", 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1368
                                  simp only: fetch.simps)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1369
apply(auto simp: nth_of.simps nth_append)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1370
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1371
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1372
lemma fetch_check_left_move_b: "
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1373
      start_of (layout_of aprog) as > 0
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1374
      \<Longrightarrow> (fetch (ci (layout_of aprog) 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1375
              (start_of (layout_of aprog) as) (Inc n)) (8 + 2*n) Bk)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1376
      = (R, start_of (layout_of aprog) as + 2 * n + 8)  "
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1377
apply(auto simp: ci.simps findnth.simps 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1378
                 tshift.simps tinc_b_def add3_Suc)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1379
apply(subgoal_tac "8 + 2*n= Suc (2*n + 7)", simp only: fetch.simps)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1380
apply(auto simp: nth_of.simps nth_append)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1381
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1382
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1383
lemma fetch_after_left_move: "
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1384
      start_of (layout_of aprog) as > 0
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1385
      \<Longrightarrow> (fetch (ci (layout_of aprog) 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1386
              (start_of (layout_of aprog) as) (Inc n)) (9 + 2*n) Bk)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1387
     = (R, start_of (layout_of aprog) as + 2 * n + 9)"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1388
apply(auto simp: ci.simps findnth.simps fetch.simps
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1389
                  nth_of.simps tshift.simps nth_append tinc_b_def)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1390
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1391
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1392
lemma fetch_stop: "
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1393
       start_of (layout_of aprog) as > 0
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1394
      \<Longrightarrow> (fetch (ci (layout_of aprog) 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1395
             (start_of (layout_of aprog) as) (Inc n)) (10 + 2 *n)  b)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1396
     = (Nop, 0)"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1397
apply(auto simp: ci.simps findnth.simps fetch.simps
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1398
                  nth_of.simps tshift.simps nth_append tinc_b_def
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1399
            split: block.splits)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1400
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1401
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1402
lemma fetch_state0: "
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1403
       (fetch (ci (layout_of aprog) 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1404
               (start_of (layout_of aprog) as) (Inc n)) 0 b)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1405
     = (Nop, 0)"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1406
apply(auto simp: ci.simps findnth.simps fetch.simps
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1407
                  nth_of.simps tshift.simps nth_append tinc_b_def)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1408
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1409
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1410
lemmas fetch_simps = 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1411
  fetch_locate_a_o fetch_locate_a_b fetch_locate_b_o fetch_locate_b_b 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1412
  fetch_locate_n_a_b fetch_locate_n_a_o fetch_locate_n_b_o 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1413
  fetch_locate_n_b_b fetch_after_write_o fetch_after_move_o 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1414
  fetch_after_move_b fetch_clear_b fetch_right_move_o 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1415
  fetch_right_move_b fetch_left_move_o fetch_left_move_b
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1416
  fetch_after_left_move fetch_check_left_move_o fetch_stop 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1417
  fetch_state0 fetch_check_left_move_b
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1418
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1419
text {* *}
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1420
declare exponent_def[simp del] tape_of_nat_list.simps[simp del] 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1421
   at_begin_norm.simps[simp del] at_begin_fst_bwtn.simps[simp del] 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1422
   at_begin_fst_awtn.simps[simp del] in_middle.simps[simp del] 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1423
   abc_lm_s.simps[simp del] abc_lm_v.simps[simp del]  
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1424
   ci.simps[simp del] t_step.simps[simp del]
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1425
   inv_after_move.simps[simp del] 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1426
   inv_on_left_moving_norm.simps[simp del] 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1427
   inv_on_left_moving_in_middle_B.simps[simp del]
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1428
   inv_after_clear.simps[simp del] 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1429
   inv_after_write.simps[simp del] inv_on_left_moving.simps[simp del]
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1430
   inv_on_right_moving.simps[simp del] 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1431
   inv_check_left_moving.simps[simp del] 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1432
   inv_check_left_moving_in_middle.simps[simp del]
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1433
   inv_check_left_moving_on_leftmost.simps[simp del] 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1434
   inv_after_left_moving.simps[simp del]
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1435
   inv_stop.simps[simp del] inv_locate_a.simps[simp del] 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1436
   inv_locate_b.simps[simp del]
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1437
declare tms_of.simps[simp del] tm_of.simps[simp del]
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1438
        layout_of.simps[simp del] abc_fetch.simps [simp del] 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1439
        t_step.simps[simp del] t_steps.simps[simp del] 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1440
        tpairs_of.simps[simp del] start_of.simps[simp del]
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1441
        fetch.simps [simp del] new_tape.simps [simp del] 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1442
        nth_of.simps [simp del] ci.simps [simp del]
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1443
        length_of.simps[simp del]
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1444
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1445
(*! Start point *)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1446
lemma [simp]: "Suc (2 * q) mod 2 = Suc 0"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1447
by arith
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1448
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1449
lemma [simp]: "Suc (2 * q) div 2 = q"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1450
by arith
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1451
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1452
lemma [simp]: "\<lbrakk> \<not> a < start_of ly as; 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1453
          a < start_of ly as + 2 * n; a - start_of ly as = 2 * q\<rbrakk>
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1454
             \<Longrightarrow> Suc a < start_of ly as + 2 * n"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1455
apply(arith)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1456
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1457
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1458
lemma [simp]: "x mod 2 = Suc 0 \<Longrightarrow> (Suc x) mod 2 = 0"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1459
by arith
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1460
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1461
lemma [simp]: "x mod 2 = Suc 0 \<Longrightarrow> (Suc x) div 2 = Suc (x div 2)"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1462
by arith
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1463
lemma exp_def[simp]: "a\<^bsup>Suc n \<^esup>= a # a\<^bsup>n\<^esup>"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1464
by(simp add: exponent_def)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1465
lemma [intro]: "Bk # r = Oc\<^bsup>mr\<^esup> @ r' \<Longrightarrow> mr = 0"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1466
by(case_tac mr, auto simp: exponent_def)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1467
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1468
lemma [intro]: "Bk # r = replicate mr Oc \<Longrightarrow> mr = 0"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1469
by(case_tac mr, auto)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1470
lemma tape_of_nl_abv_cons[simp]: "xs \<noteq> [] \<Longrightarrow> 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1471
                   <x # xs> = Oc\<^bsup>Suc x\<^esup>@ Bk # <xs>"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1472
apply(simp add: tape_of_nl_abv tape_of_nat_list.simps)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1473
apply(case_tac xs, simp, simp add: tape_of_nat_list.simps)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1474
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1475
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1476
lemma [simp]: "<[]::nat list> = []"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1477
by(auto simp: tape_of_nl_abv tape_of_nat_list.simps)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1478
lemma [simp]: "Oc # r = <(lm::nat list)> @ Bk\<^bsup>rn\<^esup>\<Longrightarrow> lm \<noteq> []"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1479
apply(auto simp: tape_of_nl_abv tape_of_nat_list.simps)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1480
apply(case_tac rn, auto simp: exponent_def)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1481
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1482
lemma BkCons_nil: "Bk # xs = <lm::nat list> @ Bk\<^bsup>rn\<^esup>\<Longrightarrow> lm = []"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1483
apply(case_tac lm, simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1484
apply(case_tac list, auto simp: tape_of_nl_abv tape_of_nat_list.simps)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1485
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1486
lemma BkCons_nil': "Bk # xs = <lm::nat list> @ Bk\<^bsup>ln\<^esup>\<Longrightarrow> lm = []"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1487
by(auto intro: BkCons_nil)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1488
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1489
lemma hd_tl_tape_of_nat_list:  
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1490
   "tl (lm::nat list) \<noteq> [] \<Longrightarrow> <lm> = <hd lm> @ Bk # <tl lm>"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1491
apply(frule tape_of_nl_abv_cons[of "tl lm" "hd lm"])
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1492
apply(simp add: tape_of_nat_abv Bk_def del: tape_of_nl_abv_cons)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1493
apply(subgoal_tac "lm = hd lm # tl lm", auto)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1494
apply(case_tac lm, auto)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1495
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1496
lemma [simp]: "Oc # xs = Oc\<^bsup>mr\<^esup> @ Bk # <lm2> @ Bk\<^bsup>rn\<^esup>\<Longrightarrow> mr > 0"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1497
apply(case_tac mr, auto simp: exponent_def)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1498
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1499
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1500
lemma tape_of_nat_list_cons: "xs \<noteq> [] \<Longrightarrow> tape_of_nat_list (x # xs) =
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1501
              replicate (Suc x) Oc @ Bk # tape_of_nat_list xs"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1502
apply(drule tape_of_nl_abv_cons[of xs x])
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1503
apply(auto simp: tape_of_nl_abv tape_of_nat_abv Oc_def Bk_def exponent_def)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1504
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1505
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1506
lemma rev_eq: "rev xs = rev ys \<Longrightarrow> xs = ys"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1507
by simp
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1508
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1509
lemma tape_of_nat_list_eq: " xs = ys \<Longrightarrow> 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1510
        tape_of_nat_list xs = tape_of_nat_list ys"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1511
by simp
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1512
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1513
lemma tape_of_nl_nil_eq: "<(lm::nat list)> = [] = (lm = [])"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1514
apply(simp add: tape_of_nl_abv tape_of_nat_list.simps)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1515
apply(case_tac lm, simp add: tape_of_nat_list.simps)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1516
apply(case_tac "list")
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1517
apply(auto simp: tape_of_nat_list.simps)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1518
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1519
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1520
lemma rep_ind: "replicate (Suc n) a = replicate n a @ [a]"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1521
apply(induct n, simp, simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1522
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1523
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1524
lemma [simp]: "Oc # r = <lm::nat list> @ replicate rn Bk \<Longrightarrow> Suc 0 \<le> length lm"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1525
apply(rule_tac classical, auto)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1526
apply(case_tac lm, simp, case_tac rn, auto)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1527
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1528
lemma Oc_Bk_Cons: "Oc # Bk # list = <lm::nat list> @ Bk\<^bsup>ln\<^esup> \<Longrightarrow> 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1529
                   lm \<noteq> [] \<and> hd lm = 0"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1530
apply(case_tac lm, simp, case_tac ln, simp add: exponent_def, simp add: exponent_def, simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1531
apply(case_tac lista, auto simp: tape_of_nl_abv tape_of_nat_list.simps)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1532
done 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1533
(*lemma Oc_Oc_Cons: "Oc # Oc # list = <lm::nat list> @ Bk\<^bsup>ln\<^esup> \<Longrightarrow> 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1534
                  lm \<noteq> [] \<and> hd lm > 0"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1535
apply(case_tac lm, simp add: exponent_def, case_tac ln, simp, simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1536
apply(case_tac lista, 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1537
        auto simp: tape_of_nl_abv tape_of_nat_list.simps exponent_def)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1538
apply(case_tac [!] a, auto)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1539
apply(case_tac ln, auto)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1540
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1541
*)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1542
lemma Oc_nil_zero[simp]: "[Oc] = <lm::nat list> @ Bk\<^bsup>ln\<^esup> 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1543
                 \<Longrightarrow> lm = [0] \<and> ln = 0"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1544
apply(case_tac lm, simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1545
apply(case_tac ln, auto simp: exponent_def)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1546
apply(case_tac [!] list, 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1547
        auto simp: tape_of_nl_abv tape_of_nat_list.simps)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1548
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1549
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1550
lemma  [simp]: "Oc # r = <lm2> @ replicate rn Bk \<Longrightarrow> 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1551
       (\<exists>rn. r = replicate (hd lm2) Oc @ Bk # <tl lm2> @ 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1552
                      replicate rn Bk) \<or> 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1553
          tl lm2 = [] \<and> r = replicate (hd lm2) Oc"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1554
apply(rule_tac disjCI, simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1555
apply(case_tac "tl lm2 = []", simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1556
apply(case_tac lm2, simp add: tape_of_nl_abv tape_of_nat_list.simps)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1557
apply(case_tac rn, simp, simp, simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1558
apply(simp add: tape_of_nl_abv tape_of_nat_list.simps exponent_def)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1559
apply(case_tac rn, simp, simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1560
apply(rule_tac x = rn in exI)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1561
apply(simp add: hd_tl_tape_of_nat_list)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1562
apply(simp add: tape_of_nat_abv Oc_def exponent_def)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1563
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1564
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1565
(*inv: from locate_a to locate_b*)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1566
lemma [simp]: 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1567
      "inv_locate_a (as, lm) (q, l, Oc # r) ires
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1568
       \<Longrightarrow> inv_locate_b (as, lm) (q, Oc # l, r) ires"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1569
apply(simp only: inv_locate_a.simps inv_locate_b.simps in_middle.simps
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1570
          at_begin_norm.simps at_begin_fst_bwtn.simps
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1571
          at_begin_fst_awtn.simps)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1572
apply(erule disjE, erule exE, erule exE, erule exE)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1573
apply(rule_tac x = lm1 in exI, rule_tac x = "tl lm2" in exI, simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1574
apply(rule_tac x = "0" in exI, rule_tac x = "hd lm2" in exI, 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1575
                auto simp: exponent_def)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1576
apply(rule_tac x = "Suc 0" in exI, simp add:exponent_def)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1577
apply(rule_tac x = "lm @ replicate tn 0" in exI, 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1578
      rule_tac x = "[]" in exI,    
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1579
      rule_tac x = "Suc tn" in exI, rule_tac x = 0 in exI)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1580
apply(simp only: rep_ind, simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1581
apply(rule_tac x = "Suc 0" in exI, auto)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1582
apply(case_tac [1-3] rn, simp_all )
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1583
apply(rule_tac x = "lm @ replicate tn 0" in exI, 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1584
      rule_tac x = "[]" in exI, 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1585
      rule_tac x = "Suc tn" in exI, 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1586
      rule_tac x = 0 in exI, simp add: rep_ind del: replicate_Suc split:if_splits)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1587
apply(rule_tac x = "Suc 0" in exI, auto)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1588
apply(case_tac rn, simp, simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1589
apply(rule_tac [!] x = "Suc 0" in exI, auto)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1590
apply(case_tac [!] rn, simp_all)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1591
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1592
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1593
(*inv: from locate_a to _locate_a*)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1594
lemma locate_a_2_locate_a[simp]: "inv_locate_a (as, am) (q, aaa, Bk # xs) ires
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1595
       \<Longrightarrow> inv_locate_a (as, am) (q, aaa, Oc # xs) ires"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1596
apply(simp only: inv_locate_a.simps at_begin_norm.simps 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1597
                 at_begin_fst_bwtn.simps at_begin_fst_awtn.simps)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1598
apply(erule_tac disjE, erule exE, erule exE, erule exE, 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1599
      rule disjI2, rule disjI2)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1600
defer
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1601
apply(erule_tac disjE, erule exE, erule exE, 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1602
      erule exE, rule disjI2, rule disjI2)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1603
prefer 2
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1604
apply(simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1605
proof-
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1606
  fix lm1 tn rn
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1607
  assume k: "lm1 = am @ 0\<^bsup>tn\<^esup> \<and> length lm1 = q \<and> (if lm1 = [] then aaa = Bk # Bk # 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1608
    ires else aaa = [Bk] @ <rev lm1> @ Bk # Bk # ires) \<and> Bk # xs = Bk\<^bsup>rn\<^esup>"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1609
  thus "\<exists>lm1 tn rn. lm1 = am @ 0\<^bsup>tn\<^esup> \<and> length lm1 = q \<and> (if lm1 = [] then 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1610
    aaa = Bk # Bk # ires else aaa = [Bk] @ <rev lm1> @ Bk # Bk # ires) \<and> Oc # xs = [Oc] @ Bk\<^bsup>rn\<^esup>"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1611
    (is "\<exists>lm1 tn rn. ?P lm1 tn rn")
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1612
  proof -
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1613
    from k have "?P lm1 tn (rn - 1)"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1614
      apply(auto simp: Oc_def)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1615
      by(case_tac [!] "rn::nat", auto simp: exponent_def)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1616
    thus ?thesis by blast
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1617
  qed
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1618
next
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1619
  fix lm1 lm2 rn
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1620
  assume h1: "am = lm1 @ lm2 \<and> length lm1 = q \<and> (if lm1 = [] 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1621
    then aaa = Bk # Bk # ires else aaa = Bk # <rev lm1> @ Bk # Bk # ires) \<and>
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1622
    Bk # xs = <lm2> @ Bk\<^bsup>rn\<^esup>"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1623
  from h1 have h2: "lm2 = []"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1624
  proof(rule_tac xs = xs and rn = rn in BkCons_nil, simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1625
  qed
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1626
  from h1 and h2 show "\<exists>lm1 tn rn. lm1 = am @ 0\<^bsup>tn\<^esup> \<and> length lm1 = q \<and> 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1627
    (if lm1 = [] then aaa = Bk # Bk # ires else aaa = [Bk] @ <rev lm1> @ Bk # Bk # ires) \<and>
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1628
    Oc # xs = [Oc] @ Bk\<^bsup>rn\<^esup>" 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1629
    (is "\<exists>lm1 tn rn. ?P lm1 tn rn")
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1630
  proof -
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1631
    from h1 and h2  have "?P lm1 0 (rn - 1)"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1632
      apply(auto simp: Oc_def exponent_def 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1633
                      tape_of_nl_abv tape_of_nat_list.simps)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1634
      by(case_tac "rn::nat", simp, simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1635
    thus ?thesis by blast
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1636
  qed
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1637
qed
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1638
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1639
lemma [intro]: "\<exists>rn. [a] = a\<^bsup>rn\<^esup>"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1640
by(rule_tac x = "Suc 0" in exI, simp add: exponent_def)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1641
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1642
lemma [intro]: "\<exists>tn. [] = a\<^bsup>tn\<^esup>"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1643
apply(rule_tac x = 0 in exI, simp add: exponent_def)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1644
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1645
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1646
lemma [intro]:  "at_begin_norm (as, am) (q, aaa, []) ires
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1647
             \<Longrightarrow> at_begin_norm (as, am) (q, aaa, [Bk]) ires"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1648
apply(simp add: at_begin_norm.simps, erule_tac exE, erule_tac exE)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1649
apply(rule_tac x = lm1 in exI, simp, auto)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1650
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1651
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1652
lemma [intro]: "at_begin_fst_bwtn (as, am) (q, aaa, []) ires 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1653
            \<Longrightarrow> at_begin_fst_bwtn (as, am) (q, aaa, [Bk]) ires"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1654
apply(simp only: at_begin_fst_bwtn.simps, erule_tac exE, erule_tac exE, erule_tac exE)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1655
apply(rule_tac x = "am @ 0\<^bsup>tn\<^esup>" in exI, auto)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1656
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1657
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1658
lemma [intro]: "at_begin_fst_awtn (as, am) (q, aaa, []) ires
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1659
           \<Longrightarrow> at_begin_fst_awtn (as, am) (q, aaa, [Bk]) ires"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1660
apply(auto simp: at_begin_fst_awtn.simps)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1661
done 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1662
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1663
lemma [intro]: "inv_locate_a (as, am) (q, aaa, []) ires
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1664
            \<Longrightarrow> inv_locate_a (as, am) (q, aaa, [Bk]) ires"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1665
apply(simp only: inv_locate_a.simps)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1666
apply(erule disj_forward)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1667
defer
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1668
apply(erule disj_forward, auto)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1669
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1670
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1671
lemma [simp]: "inv_locate_a (as, am) (q, aaa, []) ires \<Longrightarrow> 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1672
               inv_locate_a (as, am) (q, aaa, [Oc]) ires"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1673
apply(insert locate_a_2_locate_a [of as am q aaa "[]"])
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1674
apply(subgoal_tac "inv_locate_a (as, am) (q, aaa, [Bk]) ires", auto)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1675
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1676
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1677
(*inv: from locate_b to locate_b*)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1678
lemma [simp]: "inv_locate_b (as, am) (q, aaa, Oc # xs) ires
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1679
         \<Longrightarrow> inv_locate_b (as, am) (q, Oc # aaa, xs) ires"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1680
apply(simp only: inv_locate_b.simps in_middle.simps)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1681
apply(erule exE)+
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1682
apply(rule_tac x = lm1 in exI, rule_tac x = lm2 in exI, 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1683
      rule_tac x = tn in exI, rule_tac x = m in exI)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1684
apply(rule_tac x = "Suc ml" in exI, rule_tac x = "mr - 1" in exI,
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1685
      rule_tac x = rn in exI)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1686
apply(case_tac mr, simp_all add: exponent_def, auto)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1687
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1688
lemma zero_and_nil[intro]: "(Bk # Bk\<^bsup>n\<^esup> = Oc\<^bsup>mr\<^esup> @ Bk # <lm::nat list> @ 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1689
                             Bk\<^bsup>rn \<^esup>) \<or> (lm2 = [] \<and> Bk # Bk\<^bsup>n\<^esup> = Oc\<^bsup>mr\<^esup>)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1690
       \<Longrightarrow> mr = 0 \<and> lm = []"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1691
apply(rule context_conjI)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1692
apply(case_tac mr, auto simp:exponent_def)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1693
apply(insert BkCons_nil[of "replicate (n - 1) Bk" lm rn])
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1694
apply(case_tac n, auto simp: exponent_def Bk_def  tape_of_nl_nil_eq)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1695
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1696
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1697
lemma tape_of_nat_def: "<[m::nat]> =  Oc # Oc\<^bsup>m\<^esup>"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1698
apply(simp add: tape_of_nl_abv tape_of_nat_list.simps)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1699
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1700
lemma [simp]: "\<lbrakk>inv_locate_b (as, am) (q, aaa, Bk # xs) ires; \<exists>n. xs = Bk\<^bsup>n\<^esup>\<rbrakk>
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1701
            \<Longrightarrow> inv_locate_a (as, am) (Suc q, Bk # aaa, xs) ires"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1702
apply(simp add: inv_locate_b.simps inv_locate_a.simps)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1703
apply(rule_tac disjI2, rule_tac disjI1)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1704
apply(simp only: in_middle.simps at_begin_fst_bwtn.simps)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1705
apply(erule_tac exE)+
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1706
apply(rule_tac x = "lm1 @ [m]" in exI, rule_tac x = tn in exI, simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1707
apply(subgoal_tac "mr = 0 \<and> lm2 = []")
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1708
defer
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1709
apply(rule_tac n = n and mr = mr and lm = "lm2" 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1710
               and rn = rn and n = n in zero_and_nil)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1711
apply(auto simp: exponent_def)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1712
apply(case_tac "lm1 = []", auto simp: tape_of_nat_def)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1713
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1714
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1715
lemma length_equal: "xs = ys \<Longrightarrow> length xs = length ys"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1716
by auto
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1717
lemma [simp]: "a\<^bsup>0\<^esup> = []" 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1718
by(simp add: exp_zero)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1719
(*inv: from locate_b to locate_a*)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1720
lemma [simp]: "length (a\<^bsup>b\<^esup>) = b"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1721
apply(simp add: exponent_def)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1722
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1723
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1724
lemma [simp]: "\<lbrakk>inv_locate_b (as, am) (q, aaa, Bk # xs) ires; 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1725
                \<not> (\<exists>n. xs = Bk\<^bsup>n\<^esup>)\<rbrakk> 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1726
       \<Longrightarrow> inv_locate_a (as, am) (Suc q, Bk # aaa, xs) ires"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1727
apply(simp add: inv_locate_b.simps inv_locate_a.simps)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1728
apply(rule_tac disjI1)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1729
apply(simp only: in_middle.simps at_begin_norm.simps)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1730
apply(erule_tac exE)+
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1731
apply(rule_tac x = "lm1 @ [m]" in exI, rule_tac x = lm2 in exI, simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1732
apply(subgoal_tac "tn = 0", simp add: exponent_def , auto split: if_splits)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1733
apply(case_tac [!] mr, simp_all add: tape_of_nat_def, auto)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1734
apply(case_tac lm2, simp, erule_tac x = rn in allE, simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1735
apply(case_tac am, simp, simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1736
apply(case_tac lm2, simp, erule_tac x = rn in allE, simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1737
apply(drule_tac length_equal, simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1738
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1739
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1740
lemma locate_b_2_a[intro]: 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1741
       "inv_locate_b (as, am) (q, aaa, Bk # xs) ires
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1742
    \<Longrightarrow> inv_locate_a (as, am) (Suc q, Bk # aaa, xs) ires"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1743
apply(case_tac "\<exists> n. xs = Bk\<^bsup>n\<^esup>", simp, simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1744
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1745
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1746
lemma locate_b_2_locate_a[simp]: 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1747
    "\<lbrakk>\<not> a < start_of ly as; 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1748
      a < start_of ly as + 2 * n; 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1749
      (a - start_of ly as) mod 2 = Suc 0; 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1750
     inv_locate_b (as, am) ((a - start_of ly as) div 2, aaa, Bk # xs) ires\<rbrakk>
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1751
   \<Longrightarrow> (Suc a < start_of ly as + 2 * n \<longrightarrow> inv_locate_a (as, am)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1752
       (Suc ((a - start_of ly as) div 2), Bk # aaa, xs) ires) \<and>
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1753
       (\<not> Suc a < start_of ly as + 2 * n \<longrightarrow> 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1754
                inv_locate_a (as, am) (n, Bk # aaa, xs) ires)"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1755
apply(auto)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1756
apply(subgoal_tac "n > 0")
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1757
apply(subgoal_tac "(a - start_of ly as) div 2 = n - 1")
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1758
apply(insert locate_b_2_a [of as am "n - 1" aaa xs], simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1759
apply(arith)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1760
apply(case_tac n, simp, simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1761
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1762
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1763
lemma [simp]:  "inv_locate_b (as, am) (q, l, []) ires 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1764
           \<Longrightarrow>  inv_locate_b (as, am) (q, l, [Bk]) ires"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1765
apply(simp only: inv_locate_b.simps in_middle.simps)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1766
apply(erule exE)+
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1767
apply(rule_tac x = lm1 in exI, rule_tac x = lm2 in exI, 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1768
      rule_tac x = tn in exI, rule_tac x = m in exI, 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1769
      rule_tac x = ml in exI, rule_tac x = mr in exI)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1770
apply(auto)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1771
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1772
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1773
lemma locate_b_2_locate_a_B[simp]: 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1774
 "\<lbrakk>\<not> a < start_of ly as; 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1775
   a < start_of ly as + 2 * n; 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1776
   (a - start_of ly as) mod 2 = Suc 0; 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1777
   inv_locate_b (as, am) ((a - start_of ly as) div 2, aaa, []) ires\<rbrakk>
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1778
   \<Longrightarrow> (Suc a < start_of ly as + 2 * n \<longrightarrow> 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1779
     inv_locate_a (as, am) 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1780
            (Suc ((a - start_of ly as) div 2), Bk # aaa, []) ires) 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1781
    \<and> (\<not> Suc a < start_of ly as + 2 * n \<longrightarrow> 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1782
                  inv_locate_a (as, am) (n, Bk # aaa, []) ires)"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1783
apply(insert locate_b_2_locate_a [of a ly as n am aaa "[]"], simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1784
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1785
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1786
(*inv: from locate_b to after_write*)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1787
lemma inv_locate_b_2_after_write[simp]: 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1788
      "inv_locate_b (as, am) (n, aaa, Bk # xs) ires
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1789
      \<Longrightarrow> inv_after_write (as, abc_lm_s am n (Suc (abc_lm_v am n)))
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1790
          (Suc (Suc (2 * n)), aaa, Oc # xs) ires"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1791
apply(auto simp: in_middle.simps inv_after_write.simps 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1792
                 abc_lm_v.simps abc_lm_s.simps  inv_locate_b.simps)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1793
apply(subgoal_tac [!] "mr = 0", auto simp: exponent_def split: if_splits)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1794
apply(subgoal_tac "lm2 = []", simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1795
apply(rule_tac x = rn in exI, rule_tac x = "Suc m" in exI,
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1796
      rule_tac x = "lm1" in exI, simp, rule_tac x = "[]" in exI, simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1797
apply(case_tac "Suc (length lm1) - length am", simp, simp only: rep_ind, simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1798
apply(subgoal_tac "length lm1 - length am = nat", simp, arith)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1799
apply(drule_tac length_equal, simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1800
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1801
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1802
lemma [simp]: "inv_locate_b (as, am) (n, aaa, []) ires \<Longrightarrow> 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1803
     inv_after_write (as, abc_lm_s am n (Suc (abc_lm_v am n))) 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1804
                     (Suc (Suc (2 * n)), aaa, [Oc]) ires"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1805
apply(insert inv_locate_b_2_after_write [of as am n aaa "[]"])
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1806
by(simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1807
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1808
(*inv: from after_write to after_move*)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1809
lemma [simp]: "inv_after_write (as, lm) (Suc (Suc (2 * n)), l, Oc # r) ires
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1810
                \<Longrightarrow> inv_after_move (as, lm) (2 * n + 3, Oc # l, r) ires"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1811
apply(auto simp:inv_after_move.simps inv_after_write.simps split: if_splits)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1812
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1813
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1814
lemma [simp]: "inv_after_write (as, abc_lm_s am n (Suc (abc_lm_v am n)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1815
                )) (Suc (Suc (2 * n)), aaa, Bk # xs) ires = False"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1816
apply(simp add: inv_after_write.simps )
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1817
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1818
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1819
lemma [simp]: 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1820
 "inv_after_write (as, abc_lm_s am n (Suc (abc_lm_v am n))) 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1821
                        (Suc (Suc (2 * n)), aaa, []) ires = False"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1822
apply(simp add: inv_after_write.simps )
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1823
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1824
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1825
(*inv: from after_move to after_clear*)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1826
lemma [simp]: "inv_after_move (as, lm) (s, l, Oc # r) ires
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1827
                \<Longrightarrow> inv_after_clear (as, lm) (s', l, Bk # r) ires"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1828
apply(auto simp: inv_after_move.simps inv_after_clear.simps split: if_splits)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1829
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1830
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1831
(*inv: from after_move to on_leftmoving*)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1832
lemma inv_after_move_2_inv_on_left_moving[simp]:  
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1833
   "inv_after_move (as, lm) (s, l, Bk # r) ires
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1834
   \<Longrightarrow> (l = [] \<longrightarrow> 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1835
         inv_on_left_moving (as, lm) (s', [], Bk # Bk # r) ires) \<and>
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1836
      (l \<noteq> [] \<longrightarrow> 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1837
         inv_on_left_moving (as, lm) (s', tl l, hd l # Bk # r) ires)"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1838
apply(simp only: inv_after_move.simps inv_on_left_moving.simps)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1839
apply(subgoal_tac "l \<noteq> []", rule conjI, simp, rule impI, 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1840
                rule disjI1, simp only: inv_on_left_moving_norm.simps)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1841
apply(erule exE)+
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1842
apply(subgoal_tac "lm2 = []")
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1843
apply(rule_tac x = lm1 in exI, rule_tac x = lm2 in exI,  
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1844
    rule_tac x = m in exI, rule_tac x = m in exI, 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1845
    rule_tac x = 1 in exI,  
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1846
    rule_tac x = "rn - 1" in exI, simp, case_tac rn)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1847
apply(auto simp: exponent_def  intro: BkCons_nil split: if_splits)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1848
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1849
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1850
lemma [elim]: "[] = <lm::nat list> \<Longrightarrow> lm = []"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1851
using tape_of_nl_nil_eq[of lm]
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1852
by simp
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1853
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1854
lemma inv_after_move_2_inv_on_left_moving_B[simp]: 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1855
    "inv_after_move (as, lm) (s, l, []) ires
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1856
      \<Longrightarrow> (l = [] \<longrightarrow> inv_on_left_moving (as, lm) (s', [], [Bk]) ires) \<and>
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1857
          (l \<noteq> [] \<longrightarrow> inv_on_left_moving (as, lm) (s', tl l, [hd l]) ires)"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1858
apply(simp only: inv_after_move.simps inv_on_left_moving.simps)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1859
apply(subgoal_tac "l \<noteq> []", rule conjI, simp, rule impI, rule disjI1,
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1860
        simp only: inv_on_left_moving_norm.simps)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1861
apply(erule exE)+
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1862
apply(subgoal_tac "lm2 = []")
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1863
apply(rule_tac x = lm1 in exI, rule_tac x = lm2 in exI,  
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1864
      rule_tac x = m in exI, rule_tac x = m in exI, 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1865
      rule_tac x = 1 in exI, rule_tac x = "rn - 1" in exI, simp, case_tac rn)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1866
apply(auto simp: exponent_def  tape_of_nl_nil_eq  intro: BkCons_nil  split: if_splits)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1867
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1868
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1869
(*inv: from after_clear to on_right_moving*)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1870
lemma [simp]: "Oc # r = replicate rn Bk = False"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1871
apply(case_tac rn, simp, simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1872
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1873
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1874
lemma inv_after_clear_2_inv_on_right_moving[simp]: 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1875
     "inv_after_clear (as, lm) (2 * n + 4, l, Bk # r) ires
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1876
      \<Longrightarrow> inv_on_right_moving (as, lm) (2 * n + 5, Bk # l, r) ires"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1877
apply(auto simp: inv_after_clear.simps inv_on_right_moving.simps )
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1878
apply(subgoal_tac "lm2 \<noteq> []")
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1879
apply(rule_tac x = "lm1 @ [m]" in exI, rule_tac x = "tl lm2" in exI, 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1880
      rule_tac x = "hd lm2" in exI, simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1881
apply(rule_tac x = 0 in exI, rule_tac x = "hd lm2" in exI)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1882
apply(simp add: exponent_def, rule conjI)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1883
apply(case_tac [!] "lm2::nat list", auto simp: exponent_def)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1884
apply(case_tac rn, auto split: if_splits simp: tape_of_nat_def)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1885
apply(case_tac list, 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1886
     simp add:  tape_of_nl_abv tape_of_nat_list.simps exponent_def)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1887
apply(erule_tac x = "rn - 1" in allE, 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1888
      case_tac rn, auto simp: exponent_def)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1889
apply(case_tac list, 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1890
     simp add:  tape_of_nl_abv tape_of_nat_list.simps exponent_def)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1891
apply(erule_tac x = "rn - 1" in allE, 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1892
      case_tac rn, auto simp: exponent_def)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1893
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1894
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1895
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1896
lemma [simp]: "inv_after_clear (as, lm) (2 * n + 4, l, []) ires\<Longrightarrow> 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1897
               inv_after_clear (as, lm) (2 * n + 4, l, [Bk]) ires" 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1898
by(auto simp: inv_after_clear.simps)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1899
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1900
lemma [simp]: "inv_after_clear (as, lm) (2 * n + 4, l, []) ires
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1901
             \<Longrightarrow> inv_on_right_moving (as, lm) (2 * n + 5, Bk # l, []) ires"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1902
by(insert 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1903
    inv_after_clear_2_inv_on_right_moving[of as lm n l "[]"], simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1904
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1905
(*inv: from on_right_moving to on_right_movign*)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1906
lemma [simp]: "inv_on_right_moving (as, lm) (2 * n + 5, l, Oc # r) ires
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1907
      \<Longrightarrow> inv_on_right_moving (as, lm) (2 * n + 5, Oc # l, r) ires"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1908
apply(auto simp: inv_on_right_moving.simps)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1909
apply(rule_tac x = lm1 in exI, rule_tac x = lm2 in exI, 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1910
           rule_tac x = "ml + mr" in exI, simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1911
apply(rule_tac x = "Suc ml" in exI, 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1912
           rule_tac x = "mr - 1" in exI, simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1913
apply(case_tac mr, auto simp: exponent_def )
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1914
apply(rule_tac x = lm1 in exI, rule_tac x = "[]" in exI, 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1915
      rule_tac x = "ml + mr" in exI, simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1916
apply(rule_tac x = "Suc ml" in exI, 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1917
      rule_tac x = "mr - 1" in exI, simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1918
apply(case_tac mr, auto split: if_splits simp: exponent_def)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1919
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1920
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1921
lemma inv_on_right_moving_2_inv_on_right_moving[simp]: 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1922
     "inv_on_right_moving (as, lm) (2 * n + 5, l, Bk # r) ires
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1923
     \<Longrightarrow> inv_after_write (as, lm) (Suc (Suc (2 * n)), l, Oc # r) ires"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1924
apply(auto simp: inv_on_right_moving.simps inv_after_write.simps )
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1925
apply(case_tac mr, auto simp: exponent_def split: if_splits)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1926
apply(case_tac [!] mr, simp_all)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1927
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1928
      
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1929
lemma [simp]: "inv_on_right_moving (as, lm) (2 * n + 5, l, []) ires\<Longrightarrow> 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1930
             inv_on_right_moving (as, lm) (2 * n + 5, l, [Bk]) ires"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1931
apply(auto simp: inv_on_right_moving.simps exponent_def)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1932
apply(rule_tac x = lm1 in exI, rule_tac x = "[]" in exI, simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1933
apply (rule_tac x = m in exI, auto split: if_splits simp: exponent_def)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1934
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1935
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1936
(*inv: from on_right_moving to after_write*)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1937
lemma [simp]: "inv_on_right_moving (as, lm) (2 * n + 5, l, []) ires
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1938
       \<Longrightarrow> inv_after_write (as, lm) (Suc (Suc (2 * n)), l, [Oc]) ires"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1939
apply(rule_tac inv_on_right_moving_2_inv_on_right_moving, simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1940
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1941
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1942
(*inv: from on_left_moving to on_left_moving*)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1943
lemma [simp]: "inv_on_left_moving_in_middle_B (as, lm) 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1944
               (s, l, Oc # r) ires = False"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1945
apply(auto simp: inv_on_left_moving_in_middle_B.simps )
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1946
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1947
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1948
lemma [simp]: "inv_on_left_moving_norm (as, lm) (s, l, Bk # r) ires 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1949
             = False"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1950
apply(auto simp: inv_on_left_moving_norm.simps)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1951
apply(case_tac [!] mr, auto simp: )
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1952
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1953
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1954
lemma [intro]: "\<exists>rna. Oc # Oc\<^bsup>m\<^esup> @ Bk # <lm> @ Bk\<^bsup>rn\<^esup> = <m # lm> @ Bk\<^bsup>rna\<^esup>"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1955
apply(case_tac lm, simp add: tape_of_nl_abv tape_of_nat_list.simps)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1956
apply(rule_tac x = "Suc rn" in exI, simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1957
apply(case_tac list, simp_all add: tape_of_nl_abv tape_of_nat_list.simps, auto)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1958
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1959
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1960
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1961
lemma [simp]: 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1962
  "\<lbrakk>inv_on_left_moving_norm (as, lm) (s, l, Oc # r) ires;
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1963
    hd l = Bk; l \<noteq> []\<rbrakk> \<Longrightarrow> 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1964
     inv_on_left_moving_in_middle_B (as, lm) (s, tl l, Bk # Oc # r) ires"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1965
apply(case_tac l, simp, simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1966
apply(simp only: inv_on_left_moving_norm.simps 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1967
                 inv_on_left_moving_in_middle_B.simps)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1968
apply(erule_tac exE)+
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1969
apply(rule_tac x = lm1 in exI, rule_tac x = "m # lm2" in exI, auto)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1970
apply(case_tac [!] ml, auto)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1971
apply(rule_tac [!] x = 0 in exI, simp_all add: tape_of_nl_abv tape_of_nat_list.simps)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1972
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1973
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1974
lemma [simp]: "\<lbrakk>inv_on_left_moving_norm (as, lm) (s, l, Oc # r) ires; 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1975
                hd l = Oc; l \<noteq> []\<rbrakk>
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1976
            \<Longrightarrow> inv_on_left_moving_norm (as, lm) 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1977
                                        (s, tl l, Oc # Oc # r) ires"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1978
apply(simp only: inv_on_left_moving_norm.simps)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1979
apply(erule exE)+
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1980
apply(rule_tac x = lm1 in exI, rule_tac x = lm2 in exI, 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1981
      rule_tac x = m in exI, rule_tac x = "ml - 1" in exI,
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1982
      rule_tac x = "Suc mr" in exI, rule_tac x = rn in exI, simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1983
apply(case_tac ml, auto simp: exponent_def split: if_splits)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1984
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1985
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1986
lemma [simp]: "inv_on_left_moving_norm (as, lm) (s, [], Oc # r) ires
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1987
     \<Longrightarrow> inv_on_left_moving_in_middle_B (as, lm) (s, [], Bk # Oc # r) ires"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1988
apply(auto simp: inv_on_left_moving_norm.simps 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1989
                 inv_on_left_moving_in_middle_B.simps split: if_splits)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1990
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1991
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1992
lemma [simp]:"inv_on_left_moving (as, lm) (s, l, Oc # r) ires
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1993
    \<Longrightarrow> (l = [] \<longrightarrow> inv_on_left_moving (as, lm) (s, [], Bk # Oc # r) ires)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1994
 \<and>  (l \<noteq> [] \<longrightarrow> inv_on_left_moving (as, lm) (s, tl l, hd l # Oc # r) ires)"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1995
apply(simp add: inv_on_left_moving.simps)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1996
apply(case_tac "l \<noteq> []", rule conjI, simp, simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1997
apply(case_tac "hd l", simp, simp, simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1998
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1999
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2000
(*inv: from on_left_moving to check_left_moving*)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2001
lemma [simp]: "inv_on_left_moving_in_middle_B (as, lm) 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2002
                                      (s, Bk # list, Bk # r) ires
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2003
          \<Longrightarrow> inv_check_left_moving_on_leftmost (as, lm) 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2004
                                      (s', list, Bk # Bk # r) ires"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2005
apply(auto simp: inv_on_left_moving_in_middle_B.simps 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2006
                 inv_check_left_moving_on_leftmost.simps split: if_splits)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2007
apply(case_tac [!] "rev lm1", simp_all)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2008
apply(case_tac [!] lista, simp_all add: tape_of_nl_abv tape_of_nat_list.simps)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2009
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2010
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2011
lemma [simp]:
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2012
    "inv_check_left_moving_in_middle (as, lm) (s, l, Bk # r) ires= False"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2013
by(auto simp: inv_check_left_moving_in_middle.simps )
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2014
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2015
lemma [simp]: 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2016
 "inv_on_left_moving_in_middle_B (as, lm) (s, [], Bk # r) ires\<Longrightarrow> 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2017
  inv_check_left_moving_on_leftmost (as, lm) (s', [], Bk # Bk # r) ires"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2018
apply(auto simp: inv_on_left_moving_in_middle_B.simps 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2019
                 inv_check_left_moving_on_leftmost.simps split: if_splits)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2020
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2021
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2022
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2023
lemma [simp]: "inv_check_left_moving_on_leftmost (as, lm) 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2024
                                       (s, list, Oc # r) ires= False"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2025
by(auto simp: inv_check_left_moving_on_leftmost.simps split: if_splits)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2026
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2027
lemma [simp]: "inv_on_left_moving_in_middle_B (as, lm) 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2028
                                         (s, Oc # list, Bk # r) ires
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2029
 \<Longrightarrow> inv_check_left_moving_in_middle (as, lm) (s', list, Oc # Bk # r) ires"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2030
apply(auto simp: inv_on_left_moving_in_middle_B.simps 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2031
                 inv_check_left_moving_in_middle.simps  split: if_splits)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2032
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2033
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2034
lemma inv_on_left_moving_2_check_left_moving[simp]:
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2035
 "inv_on_left_moving (as, lm) (s, l, Bk # r) ires
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2036
 \<Longrightarrow> (l = [] \<longrightarrow> inv_check_left_moving (as, lm) (s', [], Bk # Bk # r) ires)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2037
 \<and> (l \<noteq> [] \<longrightarrow> 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2038
      inv_check_left_moving (as, lm) (s', tl l, hd l # Bk # r) ires)"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2039
apply(simp add: inv_on_left_moving.simps inv_check_left_moving.simps)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2040
apply(case_tac l, simp, simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2041
apply(case_tac a, simp, simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2042
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2043
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2044
lemma [simp]: "inv_on_left_moving_norm (as, lm) (s, l, []) ires = False"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2045
apply(auto simp: inv_on_left_moving_norm.simps)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2046
by(case_tac [!] mr, auto)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2047
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2048
lemma [simp]: "inv_on_left_moving (as, lm) (s, l, []) ires\<Longrightarrow> 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2049
     inv_on_left_moving (as, lm) (6 + 2 * n, l, [Bk]) ires"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2050
apply(simp add: inv_on_left_moving.simps)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2051
apply(auto simp: inv_on_left_moving_in_middle_B.simps)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2052
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2053
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2054
lemma [simp]: "inv_on_left_moving (as, lm) (s, l, []) ires = False"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2055
apply(simp add: inv_on_left_moving.simps)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2056
apply(simp add: inv_on_left_moving_in_middle_B.simps)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2057
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2058
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2059
lemma [simp]: "inv_on_left_moving (as, lm) (s, l, []) ires
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2060
 \<Longrightarrow> (l = [] \<longrightarrow> inv_check_left_moving (as, lm) (s', [], [Bk]) ires) \<and>
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2061
    (l \<noteq> [] \<longrightarrow> inv_check_left_moving (as, lm) (s', tl l, [hd l]) ires)"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2062
by simp
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2063
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2064
lemma Oc_Bk_Cons_ex[simp]: 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2065
 "Oc # Bk # list = <lm::nat list> @ Bk\<^bsup>ln\<^esup> \<Longrightarrow> 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2066
                             \<exists>ln. list = <tl (lm)> @ Bk\<^bsup>ln\<^esup>"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2067
apply(case_tac "lm", simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2068
apply(case_tac ln, simp_all add: exponent_def)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2069
apply(case_tac lista, 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2070
      auto simp: tape_of_nl_abv tape_of_nat_list.simps exponent_def)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2071
apply(case_tac [!] a, auto simp: )
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2072
apply(case_tac ln, simp, rule_tac x = nat in exI, simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2073
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2074
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2075
lemma [simp]:
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2076
  "Oc # Bk # list = <rev lm1::nat list> @ Bk\<^bsup>ln\<^esup> \<Longrightarrow> 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2077
      \<exists>rna. Oc # Bk # <lm2> @ Bk\<^bsup>rn\<^esup> = <hd (rev lm1) # lm2> @ Bk\<^bsup>rna\<^esup>"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2078
apply(frule Oc_Bk_Cons, simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2079
apply(case_tac lm2, 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2080
     auto simp: tape_of_nl_abv tape_of_nat_list.simps  exponent_def )
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2081
apply(rule_tac x = "Suc rn" in exI, simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2082
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2083
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2084
(*inv: from check_left_moving to on_left_moving*)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2085
lemma [intro]: "\<exists>rna. a # a\<^bsup>rn\<^esup> = a\<^bsup>rna\<^esup>"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2086
apply(rule_tac x = "Suc rn" in exI, simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2087
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2088
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2089
lemma 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2090
inv_check_left_moving_in_middle_2_on_left_moving_in_middle_B[simp]:
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2091
"inv_check_left_moving_in_middle (as, lm) (s, Bk # list, Oc # r) ires
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2092
  \<Longrightarrow> inv_on_left_moving_in_middle_B (as, lm) (s', list, Bk # Oc # r) ires"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2093
apply(simp only: inv_check_left_moving_in_middle.simps 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2094
                 inv_on_left_moving_in_middle_B.simps)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2095
apply(erule_tac exE)+
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2096
apply(rule_tac x = "rev (tl (rev lm1))" in exI, 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2097
      rule_tac x = "[hd (rev lm1)] @ lm2" in exI, auto)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2098
apply(case_tac [!] "rev lm1",simp_all add: tape_of_nl_abv tape_of_nat_list.simps)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2099
apply(case_tac [!] a, simp_all)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2100
apply(case_tac [1] lm2, simp_all add: tape_of_nat_list.simps, auto)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2101
apply(case_tac [3] lm2, simp_all add: tape_of_nat_list.simps, auto)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2102
apply(case_tac [!] lista, simp_all add: tape_of_nat_list.simps)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2103
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2104
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2105
lemma [simp]: 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2106
 "inv_check_left_moving_in_middle (as, lm) (s, [], Oc # r) ires\<Longrightarrow>
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2107
     inv_check_left_moving_in_middle (as, lm) (s', [Bk], Oc # r) ires"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2108
apply(auto simp: inv_check_left_moving_in_middle.simps )
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2109
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2110
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2111
lemma [simp]: 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2112
 "inv_check_left_moving_in_middle (as, lm) (s, [], Oc # r) ires
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2113
   \<Longrightarrow> inv_on_left_moving_in_middle_B (as, lm) (s', [], Bk # Oc # r) ires"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2114
apply(insert 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2115
inv_check_left_moving_in_middle_2_on_left_moving_in_middle_B[of 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2116
                  as lm n "[]" r], simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2117
done 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2118
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2119
lemma [simp]: "a\<^bsup>0\<^esup> = []"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2120
apply(simp add: exponent_def)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2121
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2122
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2123
lemma [simp]: "inv_check_left_moving_in_middle (as, lm) 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2124
                       (s, Oc # list, Oc # r) ires
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2125
   \<Longrightarrow> inv_on_left_moving_norm (as, lm) (s', list, Oc # Oc # r) ires"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2126
apply(auto simp: inv_check_left_moving_in_middle.simps 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2127
                 inv_on_left_moving_norm.simps)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2128
apply(rule_tac x = "rev (tl (rev lm1))" in exI, 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2129
      rule_tac x = lm2 in exI, rule_tac x = "hd (rev lm1)" in exI)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2130
apply(rule_tac conjI)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2131
apply(case_tac "rev lm1", simp, simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2132
apply(rule_tac x = "hd (rev lm1) - 1" in exI, auto)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2133
apply(rule_tac [!] x = "Suc (Suc 0)" in exI, simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2134
apply(case_tac [!] "rev lm1", simp_all)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2135
apply(case_tac [!] a, simp_all add: tape_of_nl_abv tape_of_nat_list.simps, auto)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2136
done 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2137
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2138
lemma [simp]: "inv_check_left_moving (as, lm) (s, l, Oc # r) ires
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2139
\<Longrightarrow> (l = [] \<longrightarrow> inv_on_left_moving (as, lm) (s', [], Bk # Oc # r) ires) \<and>
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2140
   (l \<noteq> [] \<longrightarrow> inv_on_left_moving (as, lm) (s', tl l, hd l # Oc # r) ires)"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2141
apply(case_tac l, 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2142
      auto simp: inv_check_left_moving.simps inv_on_left_moving.simps)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2143
apply(case_tac a, simp, simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2144
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2145
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2146
(*inv: check_left_moving to after_left_moving*)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2147
lemma [simp]: "inv_check_left_moving (as, lm) (s, l, Bk # r) ires
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2148
                \<Longrightarrow> inv_after_left_moving (as, lm) (s', Bk # l, r) ires"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2149
apply(auto simp: inv_check_left_moving.simps 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2150
 inv_check_left_moving_on_leftmost.simps inv_after_left_moving.simps)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2151
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2152
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2153
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2154
lemma [simp]:"inv_check_left_moving (as, lm) (s, l, []) ires
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2155
      \<Longrightarrow> inv_after_left_moving (as, lm) (s', Bk # l, []) ires"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2156
by(simp add: inv_check_left_moving.simps  
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2157
inv_check_left_moving_in_middle.simps 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2158
inv_check_left_moving_on_leftmost.simps)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2159
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2160
(*inv: after_left_moving to inv_stop*)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2161
lemma [simp]: "inv_after_left_moving (as, lm) (s, l, Bk # r) ires
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2162
       \<Longrightarrow> inv_stop (as, lm) (s', Bk # l, r) ires"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2163
apply(auto simp: inv_after_left_moving.simps inv_stop.simps)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2164
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2165
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2166
lemma [simp]: "inv_after_left_moving (as, lm) (s, l, []) ires
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2167
             \<Longrightarrow> inv_stop (as, lm) (s', Bk # l, []) ires"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2168
by(auto simp: inv_after_left_moving.simps)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2169
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2170
(*inv: stop to stop*)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2171
lemma [simp]: "inv_stop (as, lm) (x, l, r) ires \<Longrightarrow> 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2172
               inv_stop (as, lm) (y, l, r) ires"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2173
apply(simp add: inv_stop.simps)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2174
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2175
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2176
lemma [simp]: "inv_after_clear (as, lm) (s, aaa, Oc # xs) ires= False"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2177
apply(auto simp: inv_after_clear.simps )
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2178
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2179
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2180
lemma [simp]: 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2181
  "inv_after_left_moving (as, lm) (s, aaa, Oc # xs) ires = False"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2182
by(auto simp: inv_after_left_moving.simps  )
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2183
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2184
lemma start_of_not0: "as \<noteq> 0 \<Longrightarrow> start_of ly as > 0"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2185
apply(rule startof_not0)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2186
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2187
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2188
text {*
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2189
  The single step currectness of the TM complied from Abacus instruction @{text "Inc n"}.
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2190
  It shows every single step execution of this TM keeps the invariant.
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2191
*}
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2192
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2193
lemma inc_inv_step: 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2194
  assumes 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2195
  -- {* Invariant holds on the start *}
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2196
      h11: "inc_inv ly n (as, am) tc ires" 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2197
  -- {* The layout of Abacus program @{text "aprog"} is @{text "ly"} *}
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2198
  and h12: "ly = layout_of aprog" 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2199
  -- {* The instruction at position @{text "as"} is @{text "Inc n"} *}
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2200
  and h21: "abc_fetch as aprog = Some (Inc n)" 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2201
  -- {* TM not yet reach the final state, where @{text "start_of ly as + 2*n + 9"} is the state
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2202
        where the current TM stops and the next TM starts. *}
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2203
  and h22: "(\<lambda> (s, l, r). s \<noteq> start_of ly as + 2*n + 9) tc"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2204
  shows 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2205
  -- {* 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2206
  Single step execution of the TM keeps the invaraint, where 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2207
  the TM compiled from @{text "Inc n"} is @{text "(ci ly (start_of ly as) (Inc n))"}
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2208
  @{text "start_of ly as - Suc 0)"} is the offset used to execute this {\em shifted}
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2209
  TM.
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2210
  *}
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2211
  "inc_inv ly n (as, am) (t_step tc (ci ly (start_of ly as) (Inc n), start_of ly as - Suc 0)) ires"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2212
proof -
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2213
  from h21 h22  have h3 : "start_of (layout_of aprog) as > 0"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2214
    apply(case_tac as, simp add: start_of.simps abc_fetch.simps)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2215
    apply(insert start_of_not0[of as "layout_of aprog"], simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2216
    done    
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2217
  from h11 h12 and h21 h22 and this show ?thesis 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2218
    apply(case_tac tc, simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2219
    apply(case_tac "a = 0", 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2220
      auto split:if_splits simp add:t_step.simps,
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2221
      tactic {* ALLGOALS (resolve_tac [@{thm fetch_intro}]) *})
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2222
    apply (simp_all add:fetch_simps new_tape.simps)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2223
    done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2224
qed
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2225
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2226
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2227
lemma t_steps_ind: "t_steps tc (p, off) (Suc n)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2228
                 = t_step (t_steps tc (p, off) n) (p, off)"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2229
apply(induct n arbitrary: tc)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2230
apply(simp add: t_steps.simps)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2231
apply(simp add: t_steps.simps)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2232
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2233
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2234
definition lex_pair :: "((nat \<times> nat) \<times> (nat \<times> nat)) set"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2235
  where 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2236
  "lex_pair \<equiv> less_than <*lex*> less_than"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2237
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2238
definition lex_triple :: 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2239
   "((nat \<times> (nat \<times> nat)) \<times> (nat \<times> (nat \<times> nat))) set"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2240
  where "lex_triple \<equiv> less_than <*lex*> lex_pair"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2241
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2242
definition lex_square :: 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2243
    "((nat \<times> nat \<times> nat \<times> nat) \<times> (nat \<times> nat \<times> nat \<times> nat)) set"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2244
  where "lex_square \<equiv> less_than <*lex*> lex_triple"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2245
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2246
fun abc_inc_stage1 :: "t_conf \<Rightarrow> nat \<Rightarrow> nat \<Rightarrow> nat"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2247
  where
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2248
  "abc_inc_stage1 (s, l, r) ss n = 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2249
            (if s = 0 then 0
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2250
             else if s \<le> ss+2*n+1 then 5
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2251
             else if s\<le> ss+2*n+5 then 4
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2252
             else if s \<le> ss+2*n+7 then 3
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2253
             else if s = ss+2*n+8 then 2
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2254
             else 1)"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2255
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2256
fun abc_inc_stage2 :: "t_conf \<Rightarrow> nat \<Rightarrow> nat \<Rightarrow> nat"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2257
  where
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2258
  "abc_inc_stage2 (s, l, r) ss n =
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2259
                (if s \<le> ss + 2*n + 1 then 0
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2260
                 else if s = ss + 2*n + 2 then length r
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2261
                 else if s = ss + 2*n + 3 then length r
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2262
                 else if s = ss + 2*n + 4 then length r
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2263
                 else if s = ss + 2*n + 5 then 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2264
                                  if r \<noteq> [] then length r
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2265
                                  else 1
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2266
                 else if s = ss+2*n+6 then length l
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2267
                 else if s = ss+2*n+7 then length l
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2268
                 else 0)"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2269
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2270
fun abc_inc_stage3 :: "t_conf \<Rightarrow> nat \<Rightarrow> nat \<Rightarrow> block list \<Rightarrow>  nat"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2271
  where
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2272
  "abc_inc_stage3 (s, l, r) ss n ires = (
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2273
              if s = ss + 2*n + 3 then 4
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2274
              else if s = ss + 2*n + 4 then 3
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2275
              else if s = ss + 2*n + 5 then 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2276
                   if r \<noteq> [] \<and> hd r = Oc then 2
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2277
                   else 1
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2278
              else if s = ss + 2*n + 2 then 0
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2279
              else if s = ss + 2*n + 6 then 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2280
                      if l = Bk # ires \<and> r \<noteq> [] \<and>  hd r = Oc then 2
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2281
                      else 1
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2282
              else if s = ss + 2*n + 7 then 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2283
                      if r \<noteq> [] \<and> hd r = Oc then 3
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2284
                      else 0
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2285
              else ss+2*n+9 - s)"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2286
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2287
fun abc_inc_stage4 :: "t_conf \<Rightarrow> nat \<Rightarrow> nat \<Rightarrow> block list \<Rightarrow> nat"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2288
  where
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2289
  "abc_inc_stage4 (s, l, r) ss n ires = 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2290
            (if s \<le> ss+2*n+1 \<and> (s - ss) mod 2 = 0 then 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2291
                if (r\<noteq>[] \<and> hd r = Oc) then 0
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2292
                else 1
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2293
             else if (s \<le> ss+2*n+1 \<and> (s - ss) mod 2 = Suc 0) 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2294
                                                 then length r
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2295
             else if s = ss + 2*n + 6 then 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2296
                  if l = Bk # ires \<and> hd r = Bk then 0
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2297
                  else Suc (length l)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2298
             else 0)"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2299
 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2300
fun abc_inc_measure :: "(t_conf \<times> nat \<times> nat \<times> block list) \<Rightarrow> 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2301
                        (nat \<times> nat \<times> nat \<times> nat)"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2302
  where
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2303
  "abc_inc_measure (c, ss, n, ires) = 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2304
     (abc_inc_stage1 c ss n, abc_inc_stage2 c ss n, 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2305
      abc_inc_stage3 c ss n ires, abc_inc_stage4 c ss n ires)"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2306
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2307
definition abc_inc_LE :: "(((nat \<times> block list \<times> block list) \<times> nat \<times> 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2308
       nat \<times> block list) \<times> ((nat \<times> block list \<times> block list) \<times> nat \<times> nat \<times> block list)) set"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2309
  where "abc_inc_LE \<equiv> (inv_image lex_square abc_inc_measure)"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2310
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2311
lemma wf_lex_triple: "wf lex_triple"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2312
by (auto intro:wf_lex_prod simp:lex_triple_def lex_pair_def)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2313
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2314
lemma wf_lex_square: "wf lex_square"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2315
by (auto intro:wf_lex_triple simp:lex_triple_def lex_square_def lex_pair_def)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2316
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2317
lemma wf_abc_inc_le[intro]: "wf abc_inc_LE"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2318
by(auto intro:wf_inv_image wf_lex_square simp:abc_inc_LE_def)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2319
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2320
(********************************************************************)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2321
declare inc_inv.simps[simp del]
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2322
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2323
lemma halt_lemma2': 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2324
  "\<lbrakk>wf LE;  \<forall> n. ((\<not> P (f n) \<and> Q (f n)) \<longrightarrow> 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2325
    (Q (f (Suc n)) \<and> (f (Suc n), (f n)) \<in> LE)); Q (f 0)\<rbrakk> 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2326
      \<Longrightarrow> \<exists> n. P (f n)"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2327
apply(intro exCI, simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2328
apply(subgoal_tac "\<forall> n. Q (f n)", simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2329
apply(drule_tac f = f in wf_inv_image)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2330
apply(simp add: inv_image_def)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2331
apply(erule wf_induct, simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2332
apply(erule_tac x = x in allE)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2333
apply(erule_tac x = n in allE, erule_tac x = n in allE)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2334
apply(erule_tac x = "Suc x" in allE, simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2335
apply(rule_tac allI)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2336
apply(induct_tac n, simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2337
apply(erule_tac x = na in allE, simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2338
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2339
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2340
lemma halt_lemma2'': 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2341
  "\<lbrakk>P (f n); \<not> P (f (0::nat))\<rbrakk> \<Longrightarrow> 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2342
         \<exists> n. (P (f n) \<and> (\<forall> i < n. \<not> P (f i)))"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2343
apply(induct n rule: nat_less_induct, auto)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2344
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2345
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2346
lemma halt_lemma2''':
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2347
 "\<lbrakk>\<forall>n. \<not> P (f n) \<and> Q (f n) \<longrightarrow> Q (f (Suc n)) \<and> (f (Suc n), f n) \<in> LE;
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2348
                 Q (f 0);  \<forall>i<na. \<not> P (f i)\<rbrakk> \<Longrightarrow> Q (f na)"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2349
apply(induct na, simp, simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2350
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2351
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2352
lemma halt_lemma2: 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2353
  "\<lbrakk>wf LE;  
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2354
    \<forall> n. ((\<not> P (f n) \<and> Q (f n)) \<longrightarrow> (Q (f (Suc n)) \<and> (f (Suc n), (f n)) \<in> LE)); 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2355
    Q (f 0); \<not> P (f 0)\<rbrakk> 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2356
  \<Longrightarrow> \<exists> n. P (f n) \<and> Q (f n)"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2357
apply(insert halt_lemma2' [of LE P f Q], simp, erule_tac exE)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2358
apply(subgoal_tac "\<exists> n. (P (f n) \<and> (\<forall> i < n. \<not> P (f i)))")
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2359
apply(erule_tac exE)+
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2360
apply(rule_tac x = na in exI, auto)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2361
apply(rule halt_lemma2''', simp, simp, simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2362
apply(erule_tac halt_lemma2'', simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2363
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2364
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2365
lemma [simp]: 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2366
  "\<lbrakk>ly = layout_of aprog; abc_fetch as aprog = Some (Inc n)\<rbrakk>
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2367
    \<Longrightarrow> start_of ly (Suc as) = start_of ly as + 2*n +9"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2368
apply(case_tac as, auto simp: abc_fetch.simps start_of.simps 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2369
          layout_of.simps length_of.simps split: if_splits)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2370
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2371
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2372
lemma inc_inv_init: 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2373
 "\<lbrakk>abc_fetch as aprog = Some (Inc n); 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2374
   crsp_l ly (as, am) (start_of ly as, l, r) ires; ly = layout_of aprog\<rbrakk>
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2375
  \<Longrightarrow> inc_inv ly n (as, am) (start_of ly as, l, r) ires"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2376
apply(auto simp: crsp_l.simps inc_inv.simps 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2377
      inv_locate_a.simps at_begin_fst_bwtn.simps 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2378
      at_begin_fst_awtn.simps at_begin_norm.simps )
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2379
apply(auto intro: startof_not0)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2380
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2381
     
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2382
lemma inc_inv_stop_pre[simp]: 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2383
   "\<lbrakk>ly = layout_of aprog; inc_inv ly n (as, am) (s, l, r) ires; 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2384
     s = start_of ly as; abc_fetch as aprog = Some (Inc n)\<rbrakk>
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2385
    \<Longrightarrow>  (\<forall>na. \<not> (\<lambda>((s, l, r), ss, n', ires'). s = start_of ly (Suc as)) 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2386
         (t_steps (s, l, r) (ci ly (start_of ly as) 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2387
          (Inc n), start_of ly as - Suc 0) na, s, n, ires) \<and>
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2388
       (\<lambda>((s, l, r), ss, n', ires'). inc_inv ly n (as, am) (s, l, r) ires')
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2389
         (t_steps (s, l, r) (ci ly (start_of ly as) 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2390
             (Inc n), start_of ly as - Suc 0) na, s, n, ires) \<longrightarrow>
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2391
       (\<lambda>((s, l, r), ss, n', ires'). inc_inv ly n (as, am) (s, l, r) ires') 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2392
      (t_steps (s, l, r) (ci ly (start_of ly as) 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2393
              (Inc n), start_of ly as - Suc 0) (Suc na), s, n, ires) \<and>
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2394
     ((t_steps (s, l, r) (ci ly (start_of ly as) (Inc n), 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2395
        start_of ly as - Suc 0) (Suc na), s, n, ires), 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2396
      t_steps (s, l, r) (ci ly (start_of ly as) 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2397
        (Inc n), start_of ly as - Suc 0) na, s, n, ires) \<in> abc_inc_LE)"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2398
apply(rule allI, rule impI, simp add: t_steps_ind,
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2399
       rule conjI, erule_tac conjE)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2400
apply(rule_tac inc_inv_step, simp, simp, simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2401
apply(case_tac "t_steps (start_of (layout_of aprog) as, l, r) (ci (layout_of aprog) 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2402
  (start_of (layout_of aprog) as) (Inc n), start_of (layout_of aprog) as - Suc 0) na", simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2403
proof -
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2404
  fix na
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2405
  assume h1: "abc_fetch as aprog = Some (Inc n)"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2406
    "\<not> (\<lambda>(s, l, r) (ss, n', ires'). s = start_of (layout_of aprog) as + 2 * n + 9)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2407
    (t_steps (start_of (layout_of aprog) as, l, r) (ci (layout_of aprog) 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2408
    (start_of (layout_of aprog) as) (Inc n), start_of (layout_of aprog) as - Suc 0) na) 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2409
    (start_of (layout_of aprog) as, n, ires) \<and>
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2410
    inc_inv (layout_of aprog) n (as, am) (t_steps (start_of (layout_of aprog) as, l, r)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2411
    (ci (layout_of aprog) (start_of (layout_of aprog) as) (Inc n), start_of (layout_of aprog) as - Suc 0) na) ires"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2412
  from h1 have h2: "start_of (layout_of aprog) as > 0"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2413
    apply(rule_tac startof_not0)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2414
    done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2415
  from h1 and h2 show "((t_step (t_steps (start_of (layout_of aprog) as, l, r) (ci (layout_of aprog)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2416
    (start_of (layout_of aprog) as) (Inc n), start_of (layout_of aprog) as - Suc 0) na)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2417
    (ci (layout_of aprog) (start_of (layout_of aprog) as) (Inc n), start_of (layout_of aprog) as - Suc 0),
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2418
    start_of (layout_of aprog) as, n, ires),
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2419
    t_steps (start_of (layout_of aprog) as, l, r) 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2420
    (ci (layout_of aprog) (start_of (layout_of aprog) as) (Inc n), start_of (layout_of aprog) as - Suc 0) na, 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2421
    start_of (layout_of aprog) as, n, ires)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2422
            \<in> abc_inc_LE"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2423
    apply(case_tac "(t_steps (start_of (layout_of aprog) as, l, r) 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2424
               (ci (layout_of aprog)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2425
         (start_of (layout_of aprog) as) (Inc n), 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2426
           start_of (layout_of aprog) as - Suc 0) na)", simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2427
    apply(case_tac "a = 0", 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2428
     auto split:if_splits simp add:t_step.simps inc_inv.simps, 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2429
       tactic {* ALLGOALS (resolve_tac [@{thm fetch_intro}]) *})
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2430
    apply(simp_all add:fetch_simps new_tape.simps)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2431
    apply(auto simp add: abc_inc_LE_def  
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2432
    lex_square_def lex_triple_def lex_pair_def
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2433
      inv_after_write.simps inv_after_move.simps inv_after_clear.simps
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2434
      inv_on_left_moving.simps inv_on_left_moving_norm.simps split: if_splits)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2435
    done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2436
qed
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2437
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2438
lemma inc_inv_stop_pre1: 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2439
  "\<lbrakk>
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2440
  ly = layout_of aprog; 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2441
  abc_fetch as aprog = Some (Inc n);
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2442
  s = start_of ly as; 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2443
  inc_inv ly n (as, am) (s, l, r) ires
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2444
  \<rbrakk> \<Longrightarrow> 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2445
  (\<exists> stp > 0. (\<lambda> (s', l', r').
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2446
           s' = start_of ly (Suc as) \<and> 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2447
           inc_inv ly n (as, am) (s', l', r') ires) 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2448
               (t_steps (s, l, r) (ci ly (start_of ly as) (Inc n), 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2449
                        start_of ly as - Suc 0) stp))"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2450
apply(insert halt_lemma2[of abc_inc_LE 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2451
    "\<lambda> ((s, l, r), ss, n', ires'). s = start_of ly (Suc as)" 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2452
    "(\<lambda> stp. (t_steps (s, l, r) 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2453
     (ci ly (start_of ly as) (Inc n), 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2454
     start_of ly as - Suc 0) stp, s, n, ires))" 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2455
    "\<lambda> ((s, l, r), ss, n'). inc_inv ly n (as, am) (s, l, r) ires"])
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2456
apply(insert  wf_abc_inc_le)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2457
apply(insert inc_inv_stop_pre[of ly aprog n as am s l r ires], simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2458
apply(simp only: t_steps.simps, auto)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2459
apply(rule_tac x = na in exI)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2460
apply(case_tac "(t_steps (start_of (layout_of aprog) as, l, r) 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2461
   (ci (layout_of aprog) (start_of (layout_of aprog) as) 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2462
   (Inc n), start_of (layout_of aprog) as - Suc 0) na)", simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2463
apply(case_tac na, simp add: t_steps.simps, simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2464
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2465
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2466
lemma inc_inv_stop: 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2467
  assumes program_and_layout: 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2468
  -- {* There is an Abacus program @{text "aprog"} and its layout is @{text "ly"}: *}
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2469
  "ly = layout_of aprog"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2470
  and an_instruction:
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2471
  -- {* There is an instruction @{text "Inc n"} at postion @{text "as"} of @{text "aprog"} *}
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2472
  "abc_fetch as aprog = Some (Inc n)"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2473
  and the_start_state:
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2474
  -- {* According to @{text "ly"} and @{text "as"}, 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2475
        the start state of the TM compiled from this
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2476
        @{text "Inc n"} instruction should be @{text "s"}:
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2477
     *}
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2478
  "s = start_of ly as"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2479
  and inv:
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2480
  -- {* Invariant holds on configuration @{text "(s, l, r)"} *}
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2481
  "inc_inv ly n (as, am) (s, l, r) ires"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2482
  shows  -- {* After @{text "stp"} steps of execution, the compiled 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2483
            TM reaches the start state of next compiled TM and the invariant 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2484
            still holds.
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2485
            *}
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2486
      "(\<exists> stp > 0. (\<lambda> (s', l', r').
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2487
           s' = start_of ly (Suc as) \<and> 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2488
           inc_inv ly n (as, am) (s', l', r') ires) 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2489
               (t_steps (s, l, r) (ci ly (start_of ly as) (Inc n), 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2490
                        start_of ly as - Suc 0) stp))"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2491
proof -
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2492
  from inc_inv_stop_pre1 [OF  program_and_layout an_instruction the_start_state inv] 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2493
  show ?thesis .
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2494
qed
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2495
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2496
lemma inc_inv_stop_cond: 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2497
  "\<lbrakk>ly = layout_of aprog; 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2498
    s' = start_of ly (as + 1); 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2499
    inc_inv ly n (as, lm) (s', (l', r')) ires; 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2500
    abc_fetch as aprog = Some (Inc n)\<rbrakk> \<Longrightarrow>
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2501
    crsp_l ly (Suc as, abc_lm_s lm n (Suc (abc_lm_v lm n))) 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2502
                                                (s', l', r') ires"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2503
apply(subgoal_tac "s' = start_of ly as + 2*n + 9", simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2504
apply(auto simp: inc_inv.simps inv_stop.simps crsp_l.simps )
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2505
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2506
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2507
lemma inc_crsp_ex_pre:
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2508
  "\<lbrakk>ly = layout_of aprog; 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2509
    crsp_l ly (as, am) tc ires;  
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2510
    abc_fetch as aprog = Some (Inc n)\<rbrakk>
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2511
 \<Longrightarrow> \<exists>stp > 0. crsp_l ly (abc_step_l (as, am) (Some (Inc n))) 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2512
                (t_steps tc (ci ly (start_of ly as) (Inc n), 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2513
                                start_of ly as - Suc 0) stp) ires"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2514
proof(case_tac tc, simp add: abc_step_l.simps)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2515
  fix a b c
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2516
  assume h1: "ly = layout_of aprog" 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2517
         "crsp_l (layout_of aprog) (as, am) (a, b, c) ires"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2518
         "abc_fetch as aprog = Some (Inc n)"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2519
  hence h2: "a = start_of ly as"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2520
    by(auto simp: crsp_l.simps)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2521
  from h1 and h2 have h3: 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2522
       "inc_inv ly n (as, am) (start_of ly as, b, c) ires"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2523
    by(rule_tac inc_inv_init, simp, simp, simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2524
  from h1 and h2 and h3 have h4:
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2525
       "(\<exists> stp > 0. (\<lambda> (s', l', r'). s' = 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2526
           start_of ly (Suc as) \<and> inc_inv ly n (as, am) (s', l', r') ires)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2527
         (t_steps (a, b, c) (ci ly (start_of ly as) 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2528
                 (Inc n), start_of ly as - Suc 0) stp))"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2529
    apply(rule_tac inc_inv_stop, auto)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2530
    done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2531
  from h1 and h2 and h3 and h4 show 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2532
     "\<exists>stp > 0. crsp_l (layout_of aprog) 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2533
        (Suc as, abc_lm_s am n (Suc (abc_lm_v am n)))
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2534
       (t_steps (a, b, c) (ci (layout_of aprog) 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2535
          (start_of (layout_of aprog) as) (Inc n), 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2536
              start_of (layout_of aprog) as - Suc 0) stp) ires"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2537
    apply(erule_tac exE)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2538
    apply(rule_tac x = stp in exI)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2539
    apply(case_tac "(t_steps (a, b, c) (ci (layout_of aprog) 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2540
         (start_of (layout_of aprog) as) (Inc n), 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2541
             start_of (layout_of aprog) as - Suc 0) stp)", simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2542
    apply(rule_tac inc_inv_stop_cond, auto)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2543
    done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2544
qed
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2545
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2546
text {*
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2547
  The total correctness of the compilaton of @{text "Inc n"} instruction.
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2548
*}
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2549
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2550
lemma inc_crsp_ex:
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2551
  assumes layout: 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2552
  -- {* For any Abacus program @{text "aprog"}, assuming its layout is @{text "ly"} *}
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2553
  "ly = layout_of aprog"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2554
  and corresponds: 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2555
  -- {* Abacus configuration @{text "(as, am)"} is in correspondence with 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2556
        TM configuration @{text "tc"} *}
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2557
  "crsp_l ly (as, am) tc ires"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2558
  and inc:
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2559
  -- {* There is an instruction @{text "Inc n"} at postion @{text "as"} of @{text "aprog"} *}
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2560
  "abc_fetch as aprog = Some (Inc n)"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2561
  shows
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2562
  -- {* 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2563
  After @{text "stp"} steps of execution, the TM compiled from this @{text "Inc n"}
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2564
  stops with a configuration which corresponds to the Abacus configuration obtained
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2565
  from the execution of this @{text "Inc n"} instruction.
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2566
  *} 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2567
  "\<exists>stp > 0. crsp_l ly (abc_step_l (as, am) (Some (Inc n))) 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2568
                       (t_steps tc (ci ly (start_of ly as) (Inc n), 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2569
                                start_of ly as - Suc 0) stp) ires"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2570
proof -
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2571
  from inc_crsp_ex_pre [OF layout corresponds inc] show ?thesis .
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2572
qed
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2573
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2574
(*
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2575
subsection {* The compilation of @{text "Dec n e"} *}
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2576
*)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2577
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2578
text {*
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2579
  The lemmas in this section lead to the correctness of the compilation 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2580
  of @{text "Dec n e"} instruction using the same techniques as 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2581
  @{text "Inc n"}.
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2582
*}
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2583
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2584
type_synonym dec_inv_t = "(nat * nat list) \<Rightarrow> t_conf \<Rightarrow> block list \<Rightarrow>  bool"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2585
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2586
fun dec_first_on_right_moving :: "nat \<Rightarrow> dec_inv_t"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2587
  where
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2588
  "dec_first_on_right_moving n (as, lm) (s, l, r) ires = 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2589
               (\<exists> lm1 lm2 m ml mr rn. lm = lm1 @ [m] @ lm2 \<and> 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2590
         ml + mr = Suc m \<and> length lm1 = n \<and> ml > 0 \<and> m > 0 \<and>
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2591
             (if lm1 = [] then l = Oc\<^bsup>ml\<^esup> @ Bk # Bk # ires
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2592
                          else  l = (Oc\<^bsup>ml\<^esup>) @ [Bk] @ <rev lm1> @ Bk # Bk # ires) \<and> 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2593
    ((r = (Oc\<^bsup>mr\<^esup>) @ [Bk] @ <lm2> @ (Bk\<^bsup>rn\<^esup>)) \<or> (r = (Oc\<^bsup>mr\<^esup>) \<and> lm2 = [])))"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2594
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2595
fun dec_on_right_moving :: "dec_inv_t"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2596
  where
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2597
  "dec_on_right_moving (as, lm) (s, l, r) ires =  
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2598
   (\<exists> lm1 lm2 m ml mr rn. lm = lm1 @ [m] @ lm2 \<and> 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2599
                             ml + mr = Suc (Suc m) \<and>
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2600
   (if lm1 = [] then l = Oc\<^bsup>ml\<^esup> @ Bk # Bk # ires
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2601
                else  l = (Oc\<^bsup>ml\<^esup>) @ [Bk] @ <rev lm1> @ Bk # Bk # ires) \<and> 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2602
   ((r = (Oc\<^bsup>mr\<^esup>) @ [Bk] @ <lm2> @ (Bk\<^bsup>rn\<^esup>)) \<or> (r = (Oc\<^bsup>mr\<^esup>) \<and> lm2 = [])))"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2603
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2604
fun dec_after_clear :: "dec_inv_t"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2605
  where
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2606
  "dec_after_clear (as, lm) (s, l, r) ires = 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2607
              (\<exists> lm1 lm2 m ml mr rn. lm = lm1 @ [m] @ lm2 \<and> 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2608
                ml + mr = Suc m \<and> ml = Suc m \<and> r \<noteq> [] \<and> r \<noteq> [] \<and>
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2609
               (if lm1 = [] then l = Oc\<^bsup>ml\<^esup> @ Bk # Bk # ires
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2610
                            else l = (Oc\<^bsup>ml \<^esup>) @ [Bk] @ <rev lm1> @ Bk # Bk # ires) \<and> 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2611
               (tl r = Bk # <lm2> @ (Bk\<^bsup>rn\<^esup>) \<or> tl r = [] \<and> lm2 = []))"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2612
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2613
fun dec_after_write :: "dec_inv_t"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2614
  where
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2615
  "dec_after_write (as, lm) (s, l, r) ires = 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2616
         (\<exists> lm1 lm2 m ml mr rn. lm = lm1 @ [m] @ lm2 \<and> 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2617
       ml + mr = Suc m \<and> ml = Suc m \<and> lm2 \<noteq> [] \<and>
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2618
       (if lm1 = [] then l = Bk # Oc\<^bsup>ml\<^esup> @ Bk # Bk # ires
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2619
                    else l = Bk # (Oc\<^bsup>ml \<^esup>) @ [Bk] @ <rev lm1> @ Bk # Bk # ires) \<and> 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2620
       tl r = <lm2> @ (Bk\<^bsup>rn\<^esup>))"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2621
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2622
fun dec_right_move :: "dec_inv_t"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2623
  where
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2624
  "dec_right_move (as, lm) (s, l, r) ires = 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2625
        (\<exists> lm1 lm2 m ml mr rn. lm = lm1 @ [m] @ lm2 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2626
            \<and> ml = Suc m \<and> mr = (0::nat) \<and> 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2627
              (if lm1 = [] then l = Bk # Oc\<^bsup>ml\<^esup> @ Bk # Bk # ires
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2628
                          else l = Bk # Oc\<^bsup>ml\<^esup>@ [Bk] @ <rev lm1> @ Bk # Bk # ires) 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2629
           \<and> (r = Bk # <lm2> @ Bk\<^bsup>rn\<^esup>\<or> r = [] \<and> lm2 = []))"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2630
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2631
fun dec_check_right_move :: "dec_inv_t"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2632
  where
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2633
  "dec_check_right_move (as, lm) (s, l, r) ires = 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2634
        (\<exists> lm1 lm2 m ml mr rn. lm = lm1 @ [m] @ lm2 \<and> 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2635
           ml = Suc m \<and> mr = (0::nat) \<and> 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2636
           (if lm1 = [] then l = Bk # Bk # Oc\<^bsup>ml\<^esup> @ Bk # Bk # ires
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2637
                       else l = Bk # Bk # Oc\<^bsup>ml \<^esup>@ [Bk] @ <rev lm1> @ Bk # Bk # ires) \<and> 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2638
           r = <lm2> @ Bk\<^bsup>rn\<^esup>)"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2639
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2640
fun dec_left_move :: "dec_inv_t"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2641
  where
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2642
  "dec_left_move (as, lm) (s, l, r) ires = 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2643
    (\<exists> lm1 m rn. (lm::nat list) = lm1 @ [m::nat] \<and>   
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2644
    rn > 0 \<and> 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2645
   (if lm1 = [] then l = Bk # Oc\<^bsup>Suc m\<^esup> @ Bk # Bk # ires
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2646
    else l = Bk # Oc\<^bsup>Suc m\<^esup> @ Bk # <rev lm1> @ Bk # Bk # ires) \<and> r = Bk\<^bsup>rn\<^esup>)"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2647
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2648
declare
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2649
  dec_on_right_moving.simps[simp del] dec_after_clear.simps[simp del] 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2650
  dec_after_write.simps[simp del] dec_left_move.simps[simp del] 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2651
  dec_check_right_move.simps[simp del] dec_right_move.simps[simp del] 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2652
  dec_first_on_right_moving.simps[simp del]
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2653
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2654
fun inv_locate_n_b :: "inc_inv_t"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2655
  where
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2656
  "inv_locate_n_b (as, lm) (s, l, r) ires= 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2657
    (\<exists> lm1 lm2 tn m ml mr rn. lm @ 0\<^bsup>tn\<^esup> = lm1 @ [m] @ lm2 \<and> 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2658
     length lm1 = s \<and> m + 1 = ml + mr \<and> 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2659
     ml = 1 \<and> tn = s + 1 - length lm \<and>
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2660
     (if lm1 = [] then l = Oc\<^bsup>ml\<^esup> @ Bk # Bk # ires
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2661
      else l = Oc\<^bsup>ml\<^esup>@Bk#<rev lm1>@Bk#Bk#ires) \<and> 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2662
     (r = (Oc\<^bsup>mr\<^esup>) @ [Bk] @ <lm2>@ (Bk\<^bsup>rn\<^esup>) \<or> (lm2 = [] \<and> r = (Oc\<^bsup>mr\<^esup>)))
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2663
  )"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2664
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2665
fun dec_inv_1 :: "layout \<Rightarrow> nat \<Rightarrow> nat \<Rightarrow> dec_inv_t"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2666
  where
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2667
  "dec_inv_1 ly n e (as, am) (s, l, r) ires = 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2668
           (let ss = start_of ly as in
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2669
            let am' = abc_lm_s am n (abc_lm_v am n - Suc 0) in
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2670
            let am'' = abc_lm_s am n (abc_lm_v am n) in
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2671
              if s = start_of ly e then  inv_stop (as, am'') (s, l, r) ires
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2672
              else if s = ss then False
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2673
              else if ss \<le> s \<and> s < ss + 2*n then
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2674
                   if (s - ss) mod 2 = 0 then 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2675
                        inv_locate_a (as, am) ((s - ss) div 2, l, r) ires
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2676
                    \<or> inv_locate_a (as, am'') ((s - ss) div 2, l, r) ires
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2677
                   else 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2678
                     inv_locate_b (as, am) ((s - ss) div 2, l, r) ires
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2679
                  \<or> inv_locate_b (as, am'') ((s - ss) div 2, l, r) ires
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2680
              else if s = ss + 2 * n then 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2681
                  inv_locate_a (as, am) (n, l, r) ires
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2682
                \<or> inv_locate_a (as, am'') (n, l, r) ires
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2683
              else if s = ss + 2 * n + 1 then 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2684
                  inv_locate_b (as, am) (n, l, r) ires
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2685
              else if s = ss + 2 * n + 13 then 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2686
                  inv_on_left_moving (as, am'') (s, l, r) ires
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2687
              else if s = ss + 2 * n + 14 then 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2688
                  inv_check_left_moving (as, am'') (s, l, r) ires
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2689
              else if s = ss + 2 * n + 15 then 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2690
                  inv_after_left_moving (as, am'') (s, l, r) ires
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2691
              else False)"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2692
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2693
fun dec_inv_2 :: "layout \<Rightarrow> nat \<Rightarrow> nat \<Rightarrow> dec_inv_t"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2694
  where
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2695
  "dec_inv_2 ly n e (as, am) (s, l, r) ires =
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2696
           (let ss = start_of ly as in
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2697
            let am' = abc_lm_s am n (abc_lm_v am n - Suc 0) in
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2698
            let am'' = abc_lm_s am n (abc_lm_v am n) in
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2699
              if s = 0 then False
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2700
              else if s = ss then False
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2701
              else if ss \<le> s \<and> s < ss + 2*n then
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2702
                   if (s - ss) mod 2 = 0 then 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2703
                      inv_locate_a (as, am) ((s - ss) div 2, l, r) ires
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2704
                   else inv_locate_b (as, am) ((s - ss) div 2, l, r) ires
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2705
              else if s = ss + 2 * n then 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2706
                      inv_locate_a (as, am) (n, l, r) ires
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2707
              else if s = ss + 2 * n + 1 then 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2708
                      inv_locate_n_b (as, am) (n, l, r) ires
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2709
              else if s = ss + 2 * n + 2 then 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2710
                      dec_first_on_right_moving n (as, am'') (s, l, r) ires
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2711
              else if s = ss + 2 * n + 3 then 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2712
                      dec_after_clear (as, am') (s, l, r) ires
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2713
              else if s = ss + 2 * n + 4 then 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2714
                      dec_right_move (as, am') (s, l, r) ires
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2715
              else if s = ss + 2 * n + 5 then 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2716
                      dec_check_right_move (as, am') (s, l, r) ires
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2717
              else if s = ss + 2 * n + 6 then 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2718
                      dec_left_move (as, am') (s, l, r) ires
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2719
              else if s = ss + 2 * n + 7 then 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2720
                      dec_after_write (as, am') (s, l, r) ires
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2721
              else if s = ss + 2 * n + 8 then 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2722
                      dec_on_right_moving (as, am') (s, l, r) ires
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2723
              else if s = ss + 2 * n + 9 then 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2724
                      dec_after_clear (as, am') (s, l, r) ires
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2725
              else if s = ss + 2 * n + 10 then 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2726
                      inv_on_left_moving (as, am') (s, l, r) ires
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2727
              else if s = ss + 2 * n + 11 then 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2728
                      inv_check_left_moving (as, am') (s, l, r) ires
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2729
              else if s = ss + 2 * n + 12 then 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2730
                      inv_after_left_moving (as, am') (s, l, r) ires
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2731
              else if s = ss + 2 * n + 16 then 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2732
                      inv_stop (as, am') (s, l, r) ires
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2733
              else False)"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2734
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2735
(*begin: dec_fetch lemmas*)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2736
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2737
lemma dec_fetch_locate_a_o: 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2738
      "\<lbrakk>start_of ly as \<le> a;
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2739
        a < start_of ly as + 2 * n; start_of ly as > 0;
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2740
        a - start_of ly as = 2 * q\<rbrakk>
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2741
       \<Longrightarrow> fetch (ci (layout_of aprog) 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2742
         (start_of ly as) (Dec n e)) (Suc (2 * q))  Oc = (R, a + 1)"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2743
apply(auto simp: ci.simps findnth.simps fetch.simps
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2744
                  nth_of.simps tshift.simps nth_append Suc_pre)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2745
apply(subgoal_tac "(findnth n ! Suc (4 * q)) = 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2746
                          findnth (Suc q) ! (4 * q + 1)")
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2747
apply(simp add: findnth.simps nth_append)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2748
apply(subgoal_tac " findnth n !(4 * q + 1) = 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2749
                          findnth (Suc q) ! (4 * q + 1)", simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2750
apply(rule_tac findnth_nth, auto)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2751
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2752
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2753
lemma  dec_fetch_locate_a_b:
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2754
       "\<lbrakk>start_of ly as \<le> a; 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2755
         a < start_of ly as + 2 * n; 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2756
         start_of ly as > 0;
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2757
         a - start_of ly as = 2 * q\<rbrakk>
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2758
       \<Longrightarrow> fetch (ci (layout_of aprog) (start_of ly as) (Dec n e)) 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2759
              (Suc (2 * q))  Bk = (W1, a)"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2760
apply(auto simp: ci.simps findnth.simps fetch.simps
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2761
                  nth_of.simps tshift.simps nth_append)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2762
apply(subgoal_tac "(findnth n ! (4 * q)) = 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2763
                       findnth (Suc q) ! (4 * q )")
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2764
apply(simp add: findnth.simps nth_append)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2765
apply(subgoal_tac " findnth n !(4 * q + 0) = 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2766
                       findnth (Suc q) ! (4 * q + 0)", simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2767
apply(rule_tac findnth_nth, auto)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2768
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2769
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2770
lemma dec_fetch_locate_b_o:
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2771
      "\<lbrakk>start_of ly as \<le> a; 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2772
        a < start_of ly as + 2 * n; 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2773
        (a - start_of ly as) mod 2 = Suc 0; 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2774
        start_of ly as> 0\<rbrakk>
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2775
       \<Longrightarrow> fetch (ci (layout_of aprog) (start_of ly as) (Dec n e)) 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2776
                       (Suc (a - start_of ly as)) Oc = (R, a)"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2777
apply(auto simp: ci.simps findnth.simps fetch.simps
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2778
                  nth_of.simps tshift.simps nth_append)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2779
apply(subgoal_tac "\<exists> q. (a - start_of ly as) = 2 * q + 1", auto)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2780
apply(subgoal_tac "(findnth n ! Suc (Suc (Suc (4 * q)))) = 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2781
                                findnth (Suc q) ! (4 * q + 3)")
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2782
apply(simp add: findnth.simps nth_append)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2783
apply(subgoal_tac " findnth n ! (4 * q + 3) = 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2784
                 findnth (Suc q) ! (4 * q + 3)", simp add: add3_Suc)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2785
apply(rule_tac findnth_nth, auto)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2786
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2787
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2788
lemma dec_fetch_locate_b_b: 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2789
      "\<lbrakk>\<not> a < start_of ly as; 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2790
        a < start_of ly as + 2 * n; 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2791
       (a - start_of ly as) mod 2 = Suc 0; 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2792
        start_of ly as > 0\<rbrakk>
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2793
       \<Longrightarrow> fetch (ci (layout_of aprog) (start_of ly as) (Dec n e)) 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2794
              (Suc (a - start_of ly as))  Bk = (R, a + 1)"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2795
apply(auto simp: ci.simps findnth.simps fetch.simps
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2796
                  nth_of.simps tshift.simps nth_append)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2797
apply(subgoal_tac "\<exists> q. (a - start_of ly as) = 2 * q + 1", auto)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2798
apply(subgoal_tac "(findnth n ! Suc ((Suc (4 * q)))) = 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2799
                          findnth (Suc q) ! (4 * q + 2)")
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2800
apply(simp add: findnth.simps nth_append)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2801
apply(subgoal_tac " findnth n ! (4 * q + 2) = 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2802
                          findnth (Suc q) ! (4 * q + 2)", simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2803
apply(rule_tac findnth_nth, auto)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2804
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2805
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2806
lemma dec_fetch_locate_n_a_o: 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2807
       "start_of ly as > 0 \<Longrightarrow> fetch (ci (layout_of aprog) 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2808
                       (start_of ly as) (Dec n e)) (Suc (2 * n))  Oc
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2809
       = (R, start_of ly as + 2*n + 1)"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2810
apply(auto simp: ci.simps findnth.simps fetch.simps
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2811
                  nth_of.simps tshift.simps nth_append tdec_b_def)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2812
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2813
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2814
lemma dec_fetch_locate_n_a_b: 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2815
       "start_of ly as > 0 \<Longrightarrow> fetch (ci (layout_of aprog) 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2816
                       (start_of ly as) (Dec n e)) (Suc (2 * n))  Bk
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2817
       = (W1, start_of ly as + 2*n)"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2818
apply(auto simp: ci.simps findnth.simps fetch.simps
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2819
                  nth_of.simps tshift.simps nth_append tdec_b_def)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2820
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2821
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2822
lemma dec_fetch_locate_n_b_o: 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2823
       "start_of ly as > 0 \<Longrightarrow> 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2824
            fetch (ci (layout_of aprog) 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2825
                (start_of ly as) (Dec n e)) (Suc (Suc (2 * n)))  Oc
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2826
      = (R, start_of ly as + 2*n + 2)"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2827
apply(auto simp: ci.simps findnth.simps fetch.simps
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2828
                  nth_of.simps tshift.simps nth_append tdec_b_def)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2829
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2830
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2831
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2832
lemma dec_fetch_locate_n_b_b: 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2833
       "start_of ly as > 0 \<Longrightarrow> 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2834
       fetch (ci (layout_of aprog) 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2835
                  (start_of ly as) (Dec n e)) (Suc (Suc (2 * n))) Bk
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2836
      = (L, start_of ly as + 2*n + 13)"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2837
apply(auto simp: ci.simps findnth.simps fetch.simps
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2838
                  nth_of.simps tshift.simps nth_append tdec_b_def)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2839
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2840
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2841
lemma dec_fetch_first_on_right_move_o: 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2842
      "start_of ly as > 0 \<Longrightarrow> 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2843
       fetch (ci (layout_of aprog) 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2844
             (start_of ly as) (Dec n e)) (Suc (Suc (Suc (2 * n))))  Oc
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2845
     = (R, start_of ly as + 2*n + 2)"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2846
apply(auto simp: ci.simps findnth.simps fetch.simps
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2847
                  nth_of.simps tshift.simps nth_append tdec_b_def)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2848
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2849
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2850
lemma dec_fetch_first_on_right_move_b: 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2851
      "start_of ly as > 0 \<Longrightarrow> 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2852
      fetch (ci (layout_of aprog) (start_of ly as) (Dec n e)) 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2853
                             (Suc (Suc (Suc (2 * n))))  Bk
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2854
     = (L, start_of ly as + 2*n + 3)"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2855
apply(auto simp: ci.simps findnth.simps fetch.simps
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2856
                  nth_of.simps tshift.simps nth_append tdec_b_def)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2857
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2858
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2859
lemma [simp]: "fetch x (a + 2 * n) b = fetch x (2 * n + a) b"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2860
thm arg_cong
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2861
apply(rule_tac x = "a + 2*n" and y = "2*n + a" in arg_cong, simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2862
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2863
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2864
lemma dec_fetch_first_after_clear_o: 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2865
     "start_of ly as > 0 \<Longrightarrow> fetch (ci (layout_of aprog) 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2866
                      (start_of ly as) (Dec n e)) (2 * n + 4) Oc
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2867
    = (W0, start_of ly as + 2*n + 3)"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2868
apply(auto simp: ci.simps findnth.simps tshift.simps 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2869
                          tdec_b_def add3_Suc)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2870
apply(subgoal_tac "2*n + 4 = Suc (2*n + 3)", simp only: fetch.simps)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2871
apply(auto simp: nth_of.simps nth_append)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2872
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2873
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2874
lemma dec_fetch_first_after_clear_b: 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2875
     "start_of ly as > 0 \<Longrightarrow> 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2876
     fetch (ci (layout_of aprog) 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2877
                   (start_of ly as) (Dec n e)) (2 * n + 4) Bk
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2878
    = (R, start_of ly as + 2*n + 4)"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2879
apply(auto simp: ci.simps findnth.simps 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2880
               tshift.simps tdec_b_def add3_Suc)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2881
apply(subgoal_tac "2*n + 4= Suc (2*n + 3)", simp only: fetch.simps)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2882
apply(auto simp: nth_of.simps nth_append)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2883
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2884
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2885
lemma dec_fetch_right_move_b: 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2886
     "start_of ly as > 0 \<Longrightarrow> fetch (ci (layout_of aprog) 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2887
                          (start_of ly as) (Dec n e)) (2 * n + 5) Bk
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2888
    = (R, start_of ly as + 2*n + 5)"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2889
apply(auto simp: ci.simps findnth.simps 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2890
                 tshift.simps tdec_b_def add3_Suc)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2891
apply(subgoal_tac "2*n + 5= Suc (2*n + 4)", simp only: fetch.simps)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2892
apply(auto simp: nth_of.simps nth_append)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2893
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2894
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2895
lemma dec_fetch_check_right_move_b: 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2896
     "start_of ly as > 0 \<Longrightarrow> 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2897
      fetch (ci (layout_of aprog)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2898
                (start_of ly as) (Dec n e)) (2 * n + 6) Bk
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2899
    = (L, start_of ly as + 2*n + 6)"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2900
apply(auto simp: ci.simps findnth.simps 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2901
               tshift.simps tdec_b_def add3_Suc)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2902
apply(subgoal_tac "2*n + 6 = Suc (2*n + 5)", simp only: fetch.simps)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2903
apply(auto simp: nth_of.simps nth_append)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2904
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2905
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2906
lemma dec_fetch_check_right_move_o: 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2907
     "start_of ly as > 0 \<Longrightarrow> 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2908
    fetch (ci (layout_of aprog) (start_of ly as) 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2909
                      (Dec n e)) (2 * n + 6) Oc
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2910
    = (L, start_of ly as + 2*n + 7)"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2911
apply(auto simp: ci.simps findnth.simps 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2912
                 tshift.simps tdec_b_def add3_Suc)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2913
apply(subgoal_tac "2*n + 6 = Suc (2*n + 5)", simp only: fetch.simps)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2914
apply(auto simp: nth_of.simps nth_append)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2915
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2916
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2917
lemma dec_fetch_left_move_b: 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2918
     "start_of ly as > 0 \<Longrightarrow> 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2919
     fetch (ci (layout_of aprog) 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2920
             (start_of ly as) (Dec n e)) (2 * n + 7) Bk
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2921
    = (L, start_of ly as + 2*n + 10)"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2922
apply(auto simp: ci.simps findnth.simps 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2923
                 tshift.simps tdec_b_def add3_Suc)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2924
apply(subgoal_tac "2*n + 7 = Suc (2*n + 6)", simp only: fetch.simps)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2925
apply(auto simp: nth_of.simps nth_append)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2926
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2927
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2928
lemma dec_fetch_after_write_b: 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2929
     "start_of ly as > 0 \<Longrightarrow> 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2930
    fetch (ci (layout_of aprog) 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2931
                   (start_of ly as) (Dec n e)) (2 * n + 8) Bk
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2932
    = (W1, start_of ly as + 2*n + 7)"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2933
apply(auto simp: ci.simps findnth.simps 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2934
                 tshift.simps tdec_b_def add3_Suc)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2935
apply(subgoal_tac "2*n + 8 = Suc (2*n + 7)", simp only: fetch.simps)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2936
apply(auto simp: nth_of.simps nth_append)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2937
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2938
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2939
lemma dec_fetch_after_write_o: 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2940
     "start_of ly as > 0 \<Longrightarrow> 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2941
     fetch (ci (layout_of aprog) 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2942
                   (start_of ly as) (Dec n e)) (2 * n + 8) Oc
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2943
    = (R, start_of ly as + 2*n + 8)"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2944
apply(auto simp: ci.simps findnth.simps 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2945
                 tshift.simps tdec_b_def add3_Suc)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2946
apply(subgoal_tac "2*n + 8 = Suc (2*n + 7)", simp only: fetch.simps)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2947
apply(auto simp: nth_of.simps nth_append)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2948
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2949
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2950
lemma dec_fetch_on_right_move_b: 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2951
     "start_of ly as > 0 \<Longrightarrow> 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2952
     fetch (ci (layout_of aprog) 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2953
                   (start_of ly as) (Dec n e)) (2 * n + 9) Bk
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2954
    = (L, start_of ly as + 2*n + 9)"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2955
apply(auto simp: ci.simps findnth.simps 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2956
                 tshift.simps tdec_b_def add3_Suc)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2957
apply(subgoal_tac "2*n + 9 = Suc (2*n + 8)", simp only: fetch.simps)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2958
apply(auto simp: nth_of.simps nth_append)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2959
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2960
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2961
lemma dec_fetch_on_right_move_o: 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2962
     "start_of ly as > 0 \<Longrightarrow> 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2963
     fetch (ci (layout_of aprog) 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2964
             (start_of ly as) (Dec n e)) (2 * n + 9) Oc
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2965
    = (R, start_of ly as + 2*n + 8)"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2966
apply(auto simp: ci.simps findnth.simps 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2967
                 tshift.simps tdec_b_def add3_Suc)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2968
apply(subgoal_tac "2*n + 9 = Suc (2*n + 8)", simp only: fetch.simps)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2969
apply(auto simp: nth_of.simps nth_append)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2970
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2971
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2972
lemma dec_fetch_after_clear_b: 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2973
     "start_of ly as > 0 \<Longrightarrow> 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2974
     fetch (ci (layout_of aprog) 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2975
            (start_of ly as) (Dec n e)) (2 * n + 10) Bk
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2976
    = (R, start_of ly as + 2*n + 4)" 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2977
apply(auto simp: ci.simps findnth.simps 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2978
                 tshift.simps tdec_b_def add3_Suc)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2979
apply(subgoal_tac "2*n + 10 = Suc (2*n + 9)", simp only: fetch.simps)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2980
apply(auto simp: nth_of.simps nth_append)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2981
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2982
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2983
lemma dec_fetch_after_clear_o: 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2984
     "start_of ly as > 0 \<Longrightarrow> 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2985
    fetch (ci (layout_of aprog) 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2986
             (start_of ly as) (Dec n e)) (2 * n + 10) Oc
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2987
    = (W0, start_of ly as + 2*n + 9)"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2988
apply(auto simp: ci.simps findnth.simps 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2989
                 tshift.simps tdec_b_def add3_Suc)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2990
apply(subgoal_tac "2*n + 10= Suc (2*n + 9)", simp only: fetch.simps)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2991
apply(auto simp: nth_of.simps nth_append)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2992
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2993
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2994
lemma dec_fetch_on_left_move1_o:
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2995
      "start_of ly as > 0 \<Longrightarrow> 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2996
    fetch (ci (layout_of aprog) 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2997
           (start_of ly as) (Dec n e)) (2 * n + 11) Oc
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2998
    = (L, start_of ly as + 2*n + 10)"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2999
apply(auto simp: ci.simps findnth.simps 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3000
                 tshift.simps tdec_b_def add3_Suc)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3001
apply(subgoal_tac "2*n + 11= Suc (2*n + 10)", simp only: fetch.simps)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3002
apply(auto simp: nth_of.simps nth_append)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3003
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3004
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3005
lemma dec_fetch_on_left_move1_b:
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3006
     "start_of ly as > 0 \<Longrightarrow> 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3007
    fetch (ci (layout_of aprog) 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3008
             (start_of ly as) (Dec n e)) (2 * n + 11) Bk
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3009
    = (L, start_of ly as + 2*n + 11)"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3010
apply(auto simp: ci.simps findnth.simps 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3011
                 tshift.simps tdec_b_def add3_Suc)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3012
apply(subgoal_tac "2*n + 11 = Suc (2*n + 10)", 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3013
      simp only: fetch.simps)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3014
apply(auto simp: nth_of.simps nth_append)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3015
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3016
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3017
lemma dec_fetch_check_left_move1_o: 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3018
    "start_of ly as > 0 \<Longrightarrow> 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3019
  fetch (ci (layout_of aprog) 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3020
             (start_of ly as) (Dec n e)) (2 * n + 12) Oc
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3021
    = (L, start_of ly as + 2*n + 10)"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3022
apply(auto simp: ci.simps findnth.simps 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3023
                 tshift.simps tdec_b_def add3_Suc)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3024
apply(subgoal_tac "2*n + 12= Suc (2*n + 11)", simp only: fetch.simps)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3025
apply(auto simp: nth_of.simps nth_append)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3026
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3027
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3028
lemma dec_fetch_check_left_move1_b: 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3029
    "start_of ly as > 0 \<Longrightarrow> 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3030
   fetch (ci (layout_of aprog) 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3031
                  (start_of ly as) (Dec n e)) (2 * n + 12) Bk
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3032
    = (R, start_of ly as + 2*n + 12)"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3033
apply(auto simp: ci.simps findnth.simps 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3034
                 tshift.simps tdec_b_def add3_Suc)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3035
apply(subgoal_tac "2*n + 12 = Suc (2*n + 11)", 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3036
      simp only: fetch.simps)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3037
apply(auto simp: nth_of.simps nth_append)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3038
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3039
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3040
lemma dec_fetch_after_left_move1_b: 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3041
  "start_of ly as > 0 \<Longrightarrow> 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3042
  fetch (ci (layout_of aprog) 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3043
                (start_of ly as) (Dec n e)) (2 * n + 13) Bk
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3044
    = (R, start_of ly as + 2*n + 16)"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3045
apply(auto simp: ci.simps findnth.simps 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3046
                 tshift.simps tdec_b_def add3_Suc)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3047
apply(subgoal_tac "2*n + 13 = Suc (2*n + 12)", 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3048
      simp only: fetch.simps)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3049
apply(auto simp: nth_of.simps nth_append)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3050
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3051
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3052
lemma dec_fetch_on_left_move2_o:
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3053
  "start_of ly as > 0 \<Longrightarrow> 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3054
  fetch (ci (layout_of aprog) 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3055
           (start_of ly as) (Dec n e)) (2 * n + 14) Oc
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3056
   = (L, start_of ly as + 2*n + 13)"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3057
apply(auto simp: ci.simps findnth.simps 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3058
                 tshift.simps tdec_b_def add3_Suc)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3059
apply(subgoal_tac "2*n + 14 = Suc (2*n + 13)", 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3060
      simp only: fetch.simps)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3061
apply(auto simp: nth_of.simps nth_append)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3062
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3063
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3064
lemma dec_fetch_on_left_move2_b:
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3065
  "start_of ly as > 0 \<Longrightarrow> 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3066
  fetch (ci (layout_of aprog) 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3067
              (start_of ly as) (Dec n e)) (2 * n + 14) Bk
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3068
 = (L, start_of ly as + 2*n + 14)"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3069
apply(auto simp: ci.simps findnth.simps 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3070
                 tshift.simps tdec_b_def add3_Suc)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3071
apply(subgoal_tac "2*n + 14 = Suc (2*n + 13)", 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3072
      simp only: fetch.simps)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3073
apply(auto simp: nth_of.simps nth_append)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3074
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3075
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3076
lemma dec_fetch_check_left_move2_o:
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3077
  "start_of ly as > 0 \<Longrightarrow> 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3078
  fetch (ci (layout_of aprog) 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3079
                (start_of ly as) (Dec n e)) (2 * n + 15)  Oc
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3080
 = (L, start_of ly as + 2*n + 13)"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3081
apply(auto simp: ci.simps findnth.simps 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3082
                 tshift.simps tdec_b_def add3_Suc)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3083
apply(subgoal_tac "2*n + 15 = Suc (2*n + 14)", 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3084
      simp only: fetch.simps)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3085
apply(auto simp: nth_of.simps nth_append)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3086
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3087
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3088
lemma dec_fetch_check_left_move2_b:
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3089
  "start_of ly as > 0 \<Longrightarrow> 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3090
  fetch (ci (layout_of aprog) 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3091
                (start_of ly as) (Dec n e)) (2 * n + 15)  Bk
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3092
 = (R, start_of ly as + 2*n + 15)"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3093
apply(auto simp: ci.simps findnth.simps 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3094
                 tshift.simps tdec_b_def add3_Suc)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3095
apply(subgoal_tac "2*n + 15= Suc (2*n + 14)", simp only: fetch.simps)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3096
apply(auto simp: nth_of.simps nth_append)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3097
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3098
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3099
lemma dec_fetch_after_left_move2_b: 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3100
  "\<lbrakk>ly = layout_of aprog; 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3101
    abc_fetch as aprog = Some (Dec n e); 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3102
    start_of ly as > 0\<rbrakk> \<Longrightarrow> 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3103
     fetch (ci (layout_of aprog) (start_of ly as) 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3104
              (Dec n e)) (2 * n + 16)  Bk
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3105
 = (R, start_of ly e)" 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3106
apply(auto simp: ci.simps findnth.simps 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3107
                 tshift.simps tdec_b_def add3_Suc)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3108
apply(subgoal_tac "2*n + 16 = Suc (2*n + 15)",
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3109
      simp only: fetch.simps)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3110
apply(auto simp: nth_of.simps nth_append)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3111
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3112
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3113
lemma dec_fetch_next_state: 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3114
    "start_of ly as > 0 \<Longrightarrow> 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3115
    fetch (ci (layout_of aprog) 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3116
           (start_of ly as) (Dec n e)) (2* n + 17)  b
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3117
    = (Nop, 0)"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3118
apply(case_tac b)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3119
apply(auto simp: ci.simps findnth.simps 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3120
                 tshift.simps tdec_b_def add3_Suc)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3121
apply(subgoal_tac [!] "2*n + 17 = Suc (2*n + 16)", 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3122
      simp_all only: fetch.simps)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3123
apply(auto simp: nth_of.simps nth_append)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3124
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3125
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3126
(*End: dec_fetch lemmas*)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3127
lemmas dec_fetch_simps = 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3128
 dec_fetch_locate_a_o dec_fetch_locate_a_b dec_fetch_locate_b_o 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3129
 dec_fetch_locate_b_b dec_fetch_locate_n_a_o 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3130
 dec_fetch_locate_n_a_b dec_fetch_locate_n_b_o 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3131
 dec_fetch_locate_n_b_b dec_fetch_first_on_right_move_o 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3132
 dec_fetch_first_on_right_move_b dec_fetch_first_after_clear_b
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3133
 dec_fetch_first_after_clear_o dec_fetch_right_move_b 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3134
 dec_fetch_on_right_move_b dec_fetch_on_right_move_o 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3135
 dec_fetch_after_clear_b dec_fetch_after_clear_o
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3136
 dec_fetch_check_right_move_b dec_fetch_check_right_move_o 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3137
 dec_fetch_left_move_b dec_fetch_on_left_move1_b 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3138
 dec_fetch_on_left_move1_o dec_fetch_check_left_move1_b 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3139
 dec_fetch_check_left_move1_o dec_fetch_after_left_move1_b 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3140
 dec_fetch_on_left_move2_b dec_fetch_on_left_move2_o
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3141
 dec_fetch_check_left_move2_o dec_fetch_check_left_move2_b 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3142
 dec_fetch_after_left_move2_b dec_fetch_after_write_b 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3143
 dec_fetch_after_write_o dec_fetch_next_state
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3144
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3145
lemma [simp]:
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3146
  "\<lbrakk>start_of ly as \<le> a; 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3147
    a < start_of ly as + 2 * n; 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3148
    (a - start_of ly as) mod 2 = Suc 0; 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3149
    inv_locate_b (as, am) ((a - start_of ly as) div 2, aaa, Bk # xs) ires\<rbrakk>
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3150
     \<Longrightarrow> \<not> Suc a < start_of ly as + 2 * n \<longrightarrow> 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3151
                inv_locate_a (as, am) (n, Bk # aaa, xs) ires"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3152
apply(insert locate_b_2_locate_a[of a ly as n am aaa xs], simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3153
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3154
 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3155
lemma [simp]: 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3156
  "\<lbrakk>start_of ly as \<le> a; 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3157
    a < start_of ly as + 2 * n; 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3158
    (a - start_of ly as) mod 2 = Suc 0; 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3159
    inv_locate_b (as, am) ((a - start_of ly as) div 2, aaa, []) ires\<rbrakk>
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3160
   \<Longrightarrow> \<not> Suc a < start_of ly as + 2 * n \<longrightarrow> 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3161
                  inv_locate_a (as, am) (n, Bk # aaa, []) ires"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3162
apply(insert locate_b_2_locate_a_B[of a ly as n am aaa], simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3163
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3164
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3165
(*
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3166
lemma [simp]: "a\<^bsup>0\<^esup>=[]"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3167
apply(simp add: exponent_def)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3168
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3169
*)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3170
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3171
lemma exp_ind: "a\<^bsup>Suc b\<^esup> =  a\<^bsup>b\<^esup> @ [a]"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3172
apply(simp only: exponent_def rep_ind)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3173
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3174
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3175
lemma [simp]:
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3176
  "inv_locate_b (as, am) (n, l, Oc # r) ires
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3177
  \<Longrightarrow> dec_first_on_right_moving n (as,  abc_lm_s am n (abc_lm_v am n))
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3178
                      (Suc (Suc (start_of ly as + 2 * n)), Oc # l, r) ires"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3179
apply(simp only: inv_locate_b.simps 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3180
     dec_first_on_right_moving.simps in_middle.simps 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3181
     abc_lm_s.simps abc_lm_v.simps)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3182
apply(erule_tac exE)+
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3183
apply(erule conjE)+
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3184
apply(case_tac "n < length am", simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3185
apply(rule_tac x = lm1 in exI, rule_tac x = lm2 in exI, 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3186
      rule_tac x = m in exI, simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3187
apply(rule_tac x = "Suc ml" in exI, rule_tac conjI, rule_tac [1-2] impI)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3188
prefer 3
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3189
apply(rule_tac x = lm1 in exI, rule_tac x = lm2 in exI, 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3190
      rule_tac x = m in exI, simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3191
apply(subgoal_tac "Suc n - length am = Suc (n - length am)",
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3192
      simp only:exponent_def rep_ind, simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3193
apply(rule_tac x = "Suc ml" in exI, simp_all)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3194
apply(rule_tac [!] x = "mr - 1" in exI, simp_all)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3195
apply(case_tac [!] mr, auto)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3196
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3197
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3198
lemma [simp]: 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3199
  "\<lbrakk>inv_locate_b (as, am) (n, l, r) ires; l \<noteq> []\<rbrakk> \<Longrightarrow> 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3200
  \<not> inv_on_left_moving_in_middle_B (as, abc_lm_s am n (abc_lm_v am n)) 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3201
    (s, tl l, hd l # r) ires"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3202
apply(auto simp: inv_locate_b.simps 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3203
                 inv_on_left_moving_in_middle_B.simps in_middle.simps)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3204
apply(case_tac [!] ml, auto split: if_splits)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3205
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3206
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3207
lemma [simp]: "inv_locate_b (as, am) (n, l, r) ires \<Longrightarrow> l \<noteq> []"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3208
apply(auto simp: inv_locate_b.simps in_middle.simps split: if_splits)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3209
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3210
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3211
lemma [simp]: "\<lbrakk>inv_locate_b (as, am) (n, l, Bk # r) ires; n < length am\<rbrakk>
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3212
     \<Longrightarrow> inv_on_left_moving_norm (as, am) (s, tl l, hd l # Bk # r) ires"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3213
apply(simp only: inv_locate_b.simps inv_on_left_moving_norm.simps 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3214
                 in_middle.simps)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3215
apply(erule_tac exE)+
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3216
apply(erule_tac conjE)+
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3217
apply(rule_tac x = lm1 in exI, rule_tac x = lm2 in exI, 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3218
      rule_tac x = m in exI, simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3219
apply(rule_tac x = "ml - 1" in exI, auto)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3220
apply(rule_tac [!] x = "Suc mr" in exI)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3221
apply(case_tac [!] mr, auto)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3222
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3223
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3224
lemma [simp]: "\<lbrakk>inv_locate_b (as, am) (n, l, Bk # r) ires; \<not> n < length am\<rbrakk>
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3225
    \<Longrightarrow> inv_on_left_moving_norm (as, am @ 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3226
        replicate (n - length am) 0 @ [0]) (s, tl l, hd l # Bk # r) ires"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3227
apply(simp only: inv_locate_b.simps inv_on_left_moving_norm.simps 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3228
                 in_middle.simps)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3229
apply(erule_tac exE)+
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3230
apply(erule_tac conjE)+
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3231
apply(rule_tac x = lm1 in exI, rule_tac x = lm2 in exI, 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3232
      rule_tac x = m in exI, simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3233
apply(subgoal_tac "Suc n - length am = Suc (n - length am)", simp only: rep_ind exponent_def, simp_all)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3234
apply(rule_tac x = "Suc mr" in exI, auto)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3235
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3236
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3237
lemma inv_locate_b_2_on_left_moving[simp]: 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3238
  "\<lbrakk>inv_locate_b (as, am) (n, l, Bk # r) ires\<rbrakk>
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3239
   \<Longrightarrow> (l = [] \<longrightarrow> inv_on_left_moving (as,  
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3240
            abc_lm_s am n (abc_lm_v am n)) (s, [], Bk # Bk # r) ires) \<and>
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3241
       (l \<noteq> [] \<longrightarrow> inv_on_left_moving (as,  
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3242
            abc_lm_s am n (abc_lm_v am n)) (s, tl l, hd l # Bk # r) ires)"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3243
apply(subgoal_tac "l\<noteq>[]")
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3244
apply(subgoal_tac "\<not> inv_on_left_moving_in_middle_B 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3245
      (as,  abc_lm_s am n (abc_lm_v am n)) (s, tl l, hd l # Bk # r) ires")
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3246
apply(simp add:inv_on_left_moving.simps 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3247
          abc_lm_s.simps abc_lm_v.simps split: if_splits, auto)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3248
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3249
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3250
lemma [simp]: 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3251
  "inv_locate_b (as, am) (n, l, []) ires \<Longrightarrow> 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3252
                   inv_locate_b (as, am) (n, l, [Bk]) ires" 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3253
apply(auto simp: inv_locate_b.simps in_middle.simps)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3254
apply(rule_tac x = lm1 in exI, rule_tac x = "[]" in exI,
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3255
      rule_tac x = "Suc (length lm1) - length am" in exI, 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3256
      rule_tac x = m in exI, simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3257
apply(rule_tac x = ml in exI, rule_tac x = mr in exI)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3258
apply(auto)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3259
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3260
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3261
lemma nil_2_nil: "<lm::nat list> = [] \<Longrightarrow> lm = []"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3262
apply(auto simp: tape_of_nl_abv)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3263
apply(case_tac lm, simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3264
apply(case_tac list, auto simp: tape_of_nat_list.simps)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3265
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3266
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3267
lemma  inv_locate_b_2_on_left_moving_b[simp]: 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3268
   "inv_locate_b (as, am) (n, l, []) ires
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3269
     \<Longrightarrow> (l = [] \<longrightarrow> inv_on_left_moving (as, 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3270
                  abc_lm_s am n (abc_lm_v am n)) (s, [], [Bk]) ires) \<and>
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3271
         (l \<noteq> [] \<longrightarrow> inv_on_left_moving (as, abc_lm_s am n 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3272
                  (abc_lm_v am n)) (s, tl l, [hd l]) ires)"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3273
apply(insert inv_locate_b_2_on_left_moving[of as am n l "[]" ires s])
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3274
apply(simp only: inv_on_left_moving.simps, simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3275
apply(subgoal_tac "\<not> inv_on_left_moving_in_middle_B 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3276
         (as, abc_lm_s am n (abc_lm_v am n)) (s, tl l, [hd l]) ires", simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3277
apply(simp only: inv_on_left_moving_norm.simps)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3278
apply(erule_tac exE)+
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3279
apply(erule_tac conjE)+
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3280
apply(rule_tac x = lm1 in exI, rule_tac x = lm2 in exI, 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3281
      rule_tac x = m in exI, rule_tac x = ml in exI, 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3282
      rule_tac x = mr in exI, simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3283
apply(case_tac mr, simp, simp, case_tac nat, auto intro: nil_2_nil)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3284
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3285
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3286
lemma [simp]: 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3287
 "\<lbrakk>dec_first_on_right_moving n (as, am) (s, aaa, Oc # xs) ires\<rbrakk>
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3288
   \<Longrightarrow> dec_first_on_right_moving n (as, am) (s', Oc # aaa, xs) ires"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3289
apply(simp only: dec_first_on_right_moving.simps)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3290
apply(erule exE)+
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3291
apply(rule_tac x = lm1 in exI, rule_tac x = lm2 in exI, 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3292
      rule_tac x = m in exI, simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3293
apply(rule_tac x = "Suc ml" in exI, 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3294
      rule_tac x = "mr - 1" in exI, auto)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3295
apply(case_tac [!] mr, auto)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3296
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3297
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3298
lemma [simp]: 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3299
  "dec_first_on_right_moving n (as, am) (s, l, Bk # xs) ires \<Longrightarrow> l \<noteq> []"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3300
apply(auto simp: dec_first_on_right_moving.simps split: if_splits)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3301
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3302
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3303
lemma [elim]: 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3304
  "\<lbrakk>\<not> length lm1 < length am; 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3305
    am @ replicate (length lm1 - length am) 0 @ [0::nat] = 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3306
                                                lm1 @ m # lm2;
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3307
    0 < m\<rbrakk>
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3308
   \<Longrightarrow> RR"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3309
apply(subgoal_tac "lm2 = []", simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3310
apply(drule_tac length_equal, simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3311
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3312
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3313
lemma [simp]: 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3314
 "\<lbrakk>dec_first_on_right_moving n (as, 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3315
                   abc_lm_s am n (abc_lm_v am n)) (s, l, Bk # xs) ires\<rbrakk>
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3316
\<Longrightarrow> dec_after_clear (as, abc_lm_s am n 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3317
                 (abc_lm_v am n - Suc 0)) (s', tl l, hd l # Bk # xs) ires"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3318
apply(simp only: dec_first_on_right_moving.simps 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3319
                 dec_after_clear.simps abc_lm_s.simps abc_lm_v.simps)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3320
apply(erule_tac exE)+
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3321
apply(case_tac "n < length am")
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3322
apply(rule_tac x = lm1 in exI, rule_tac x = lm2 in exI, 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3323
      rule_tac x = "m - 1" in exI, auto simp: )
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3324
apply(case_tac [!] mr, auto)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3325
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3326
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3327
lemma [simp]: 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3328
 "\<lbrakk>dec_first_on_right_moving n (as, 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3329
                   abc_lm_s am n (abc_lm_v am n)) (s, l, []) ires\<rbrakk>
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3330
\<Longrightarrow> (l = [] \<longrightarrow> dec_after_clear (as, 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3331
             abc_lm_s am n (abc_lm_v am n - Suc 0)) (s', [], [Bk]) ires) \<and>
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3332
    (l \<noteq> [] \<longrightarrow> dec_after_clear (as, abc_lm_s am n 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3333
                      (abc_lm_v am n - Suc 0)) (s', tl l, [hd l]) ires)"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3334
apply(subgoal_tac "l \<noteq> []", 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3335
      simp only: dec_first_on_right_moving.simps 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3336
                 dec_after_clear.simps abc_lm_s.simps abc_lm_v.simps)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3337
apply(erule_tac exE)+
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3338
apply(case_tac "n < length am", simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3339
apply(rule_tac x = lm1 in exI, rule_tac x = "m - 1" in exI, auto)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3340
apply(case_tac [1-2] mr, auto)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3341
apply(case_tac [1-2] m, auto simp: dec_first_on_right_moving.simps split: if_splits)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3342
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3343
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3344
lemma [simp]: "\<lbrakk>dec_after_clear (as, am) (s, l, Oc # r) ires\<rbrakk>
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3345
                \<Longrightarrow> dec_after_clear (as, am) (s', l, Bk # r) ires"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3346
apply(auto simp: dec_after_clear.simps)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3347
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3348
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3349
lemma [simp]: "\<lbrakk>dec_after_clear (as, am) (s, l, Bk # r) ires\<rbrakk>
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3350
                \<Longrightarrow> dec_right_move (as, am) (s', Bk # l, r) ires"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3351
apply(auto simp: dec_after_clear.simps dec_right_move.simps split: if_splits)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3352
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3353
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3354
lemma [simp]: "\<lbrakk>dec_after_clear (as, am) (s, l, []) ires\<rbrakk>
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3355
             \<Longrightarrow> dec_right_move (as, am) (s', Bk # l, []) ires"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3356
apply(auto simp: dec_after_clear.simps dec_right_move.simps )
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3357
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3358
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3359
lemma [simp]: "\<exists>rn. a::block\<^bsup>rn\<^esup> = []"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3360
apply(rule_tac x = 0 in exI, simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3361
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3362
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3363
lemma [simp]: "\<lbrakk>dec_after_clear (as, am) (s, l, []) ires\<rbrakk>
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3364
             \<Longrightarrow> dec_right_move (as, am) (s', Bk # l, [Bk]) ires"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3365
apply(auto simp: dec_after_clear.simps dec_right_move.simps split: if_splits)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3366
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3367
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3368
lemma [simp]:"dec_right_move (as, am) (s, l, Oc # r) ires = False"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3369
apply(auto simp: dec_right_move.simps)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3370
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3371
              
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3372
lemma dec_right_move_2_check_right_move[simp]:
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3373
     "\<lbrakk>dec_right_move (as, am) (s, l, Bk # r) ires\<rbrakk>
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3374
      \<Longrightarrow> dec_check_right_move (as, am) (s', Bk # l, r) ires"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3375
apply(auto simp: dec_right_move.simps dec_check_right_move.simps split: if_splits)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3376
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3377
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3378
lemma [simp]: 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3379
 "dec_right_move (as, am) (s, l, []) ires= 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3380
  dec_right_move (as, am) (s, l, [Bk]) ires"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3381
apply(simp add: dec_right_move.simps)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3382
apply(rule_tac iffI)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3383
apply(erule_tac [!] exE)+
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3384
apply(erule_tac [2] exE)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3385
apply(rule_tac [!] x = lm1 in exI, rule_tac x = "[]" in exI, 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3386
      rule_tac [!] x = m in exI, auto)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3387
apply(auto intro: nil_2_nil)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3388
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3389
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3390
lemma [simp]: "\<lbrakk>dec_right_move (as, am) (s, l, []) ires\<rbrakk>
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3391
             \<Longrightarrow> dec_check_right_move (as, am) (s, Bk # l, []) ires"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3392
apply(insert dec_right_move_2_check_right_move[of as am s l "[]" s'], 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3393
      simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3394
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3395
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3396
lemma [simp]: "dec_check_right_move (as, am) (s, l, r) ires\<Longrightarrow> l \<noteq> []"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3397
apply(auto simp: dec_check_right_move.simps split: if_splits)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3398
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3399
 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3400
lemma [simp]: "\<lbrakk>dec_check_right_move (as, am) (s, l, Oc # r) ires\<rbrakk>
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3401
             \<Longrightarrow> dec_after_write (as, am) (s', tl l, hd l # Oc # r) ires"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3402
apply(auto simp: dec_check_right_move.simps dec_after_write.simps)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3403
apply(rule_tac x = lm1 in exI, rule_tac x = lm2 in exI, 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3404
      rule_tac x = m in exI, auto)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3405
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3406
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3407
lemma [simp]: "\<lbrakk>dec_check_right_move (as, am) (s, l, Bk # r) ires\<rbrakk>
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3408
                \<Longrightarrow> dec_left_move (as, am) (s', tl l, hd l # Bk # r) ires"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3409
apply(auto simp: dec_check_right_move.simps 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3410
                 dec_left_move.simps inv_after_move.simps)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3411
apply(rule_tac x = lm1 in exI, rule_tac x = m in exI, auto)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3412
apply(auto intro: BkCons_nil nil_2_nil dest: BkCons_nil)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3413
apply(rule_tac x = "Suc rn" in exI)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3414
apply(auto intro: BkCons_nil nil_2_nil dest: BkCons_nil)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3415
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3416
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3417
lemma [simp]: "\<lbrakk>dec_check_right_move (as, am) (s, l, []) ires\<rbrakk>
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3418
             \<Longrightarrow> dec_left_move (as, am) (s', tl l, [hd l]) ires"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3419
apply(auto simp: dec_check_right_move.simps 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3420
                 dec_left_move.simps inv_after_move.simps)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3421
apply(rule_tac x = lm1 in exI, rule_tac x = m in exI, auto)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3422
apply(auto intro: BkCons_nil nil_2_nil dest: BkCons_nil)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3423
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3424
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3425
lemma [simp]: "dec_left_move (as, am) (s, aaa, Oc # xs) ires = False"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3426
apply(auto simp: dec_left_move.simps inv_after_move.simps)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3427
apply(case_tac [!] rn, auto)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3428
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3429
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3430
lemma [simp]: "dec_left_move (as, am) (s, l, r) ires
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3431
             \<Longrightarrow> l \<noteq> []"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3432
apply(auto simp: dec_left_move.simps split: if_splits)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3433
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3434
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3435
lemma tape_of_nl_abv_cons_ex[simp]: 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3436
   "\<exists>lna. Oc # Oc\<^bsup>m\<^esup> @ Bk # <rev lm1> @ Bk\<^bsup>ln\<^esup> = <m # rev lm1> @ Bk\<^bsup>lna\<^esup>"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3437
apply(case_tac "lm1=[]", auto simp: tape_of_nl_abv 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3438
                                    tape_of_nat_list.simps)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3439
apply(rule_tac x = "ln" in exI, simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3440
apply(simp add:  tape_of_nat_list_cons exponent_def)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3441
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3442
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3443
(*
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3444
lemma [simp]: "inv_on_left_moving_in_middle_B (as, lm1 @ [m])
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3445
                 (s', Oc # Oc\<^bsup>m\<^esup> @ Bk # <rev lm1> @ Bk\<^bsup>ln\<^esup>, Bk # Bk\<^bsup>rn\<^esup>) ires"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3446
apply(simp only: inv_on_left_moving_in_middle_B.simps)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3447
apply(rule_tac x = "lm1 @ [m]" in exI, rule_tac x = "[]" in exI, auto)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3448
done    
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3449
*)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3450
lemma [simp]: "inv_on_left_moving_in_middle_B (as, [m])
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3451
  (s', Oc # Oc\<^bsup>m\<^esup> @ Bk # Bk # ires, Bk # Bk\<^bsup>rn\<^esup>) ires"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3452
apply(simp add: inv_on_left_moving_in_middle_B.simps)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3453
apply(rule_tac x = "[m]" in exI, simp, auto simp: tape_of_nat_def)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3454
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3455
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3456
lemma [simp]: "inv_on_left_moving_in_middle_B (as, [m])
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3457
  (s', Oc # Oc\<^bsup>m\<^esup> @ Bk # Bk # ires, [Bk]) ires"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3458
apply(simp add: inv_on_left_moving_in_middle_B.simps)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3459
apply(rule_tac x = "[m]" in exI, simp, auto simp: tape_of_nat_def)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3460
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3461
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3462
lemma [simp]: "lm1 \<noteq> [] \<Longrightarrow> 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3463
  inv_on_left_moving_in_middle_B (as, lm1 @ [m]) (s', 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3464
  Oc # Oc\<^bsup>m\<^esup> @ Bk # <rev lm1> @ Bk # Bk # ires, Bk # Bk\<^bsup>rn\<^esup>) ires"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3465
apply(simp only: inv_on_left_moving_in_middle_B.simps)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3466
apply(rule_tac x = "lm1 @ [m ]" in exI, rule_tac x = "[]" in exI, simp, auto)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3467
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3468
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3469
lemma [simp]: "lm1 \<noteq> [] \<Longrightarrow> 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3470
  inv_on_left_moving_in_middle_B (as, lm1 @ [m]) (s', 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3471
  Oc # Oc\<^bsup>m\<^esup> @ Bk # <rev lm1> @ Bk # Bk # ires, [Bk]) ires"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3472
apply(simp only: inv_on_left_moving_in_middle_B.simps)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3473
apply(rule_tac x = "lm1 @ [m ]" in exI, rule_tac x = "[]" in exI, simp, auto)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3474
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3475
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3476
lemma [simp]: "dec_left_move (as, am) (s, l, Bk # r) ires
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3477
       \<Longrightarrow> inv_on_left_moving (as, am) (s', tl l, hd l # Bk # r) ires"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3478
apply(auto simp: dec_left_move.simps inv_on_left_moving.simps split: if_splits)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3479
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3480
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3481
(*
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3482
lemma [simp]: "inv_on_left_moving_in_middle_B (as, lm1 @ [m]) 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3483
                        (s', Oc # Oc\<^bsup>m\<^esup> @ Bk # <rev lm1> @ Bk\<^bsup>ln\<^esup>, [Bk])  ires"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3484
apply(auto simp: inv_on_left_moving_in_middle_B.simps)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3485
apply(rule_tac x = "lm1 @ [m]" in exI, rule_tac x = "[]" in exI, auto)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3486
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3487
*)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3488
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3489
lemma [simp]: "dec_left_move (as, am) (s, l, []) ires
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3490
             \<Longrightarrow> inv_on_left_moving (as, am) (s', tl l, [hd l]) ires"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3491
apply(auto simp: dec_left_move.simps inv_on_left_moving.simps split: if_splits)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3492
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3493
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3494
lemma [simp]: "dec_after_write (as, am) (s, l, Oc # r) ires
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3495
       \<Longrightarrow> dec_on_right_moving (as, am) (s', Oc # l, r) ires"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3496
apply(auto simp: dec_after_write.simps dec_on_right_moving.simps)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3497
apply(rule_tac x = "lm1 @ [m]" in exI, rule_tac x = "tl lm2" in exI, 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3498
      rule_tac x = "hd lm2" in exI, simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3499
apply(rule_tac x = "Suc 0" in exI,rule_tac x =  "Suc (hd lm2)" in exI)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3500
apply(case_tac lm2, simp, simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3501
apply(case_tac "list = []", 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3502
      auto simp: tape_of_nl_abv tape_of_nat_list.simps split: if_splits )
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3503
apply(case_tac rn, auto)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3504
apply(case_tac "rev lm1", simp, simp add: tape_of_nat_list.simps)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3505
apply(case_tac rn, auto)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3506
apply(case_tac list, simp_all add: tape_of_nat_list.simps, auto)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3507
apply(case_tac "rev lm1", simp, simp add: tape_of_nat_list.simps)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3508
apply(case_tac list, simp_all add: tape_of_nat_list.simps, auto)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3509
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3510
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3511
lemma [simp]: "dec_after_write (as, am) (s, l, Bk # r) ires
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3512
       \<Longrightarrow> dec_after_write (as, am) (s', l, Oc # r) ires"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3513
apply(auto simp: dec_after_write.simps)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3514
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3515
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3516
lemma [simp]: "dec_after_write (as, am) (s, aaa, []) ires
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3517
             \<Longrightarrow> dec_after_write (as, am) (s', aaa, [Oc]) ires"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3518
apply(auto simp: dec_after_write.simps)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3519
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3520
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3521
lemma [simp]: "dec_on_right_moving (as, am) (s, l, Oc # r) ires
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3522
       \<Longrightarrow> dec_on_right_moving (as, am) (s', Oc # l, r) ires"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3523
apply(simp only: dec_on_right_moving.simps)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3524
apply(erule_tac exE)+
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3525
apply(erule conjE)+
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3526
apply(rule_tac x = lm1 in exI, rule_tac x = lm2 in exI,
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3527
      rule_tac x = "m" in exI, rule_tac x = "Suc ml" in exI, 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3528
      rule_tac x = "mr - 1" in exI, simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3529
apply(case_tac mr, auto)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3530
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3531
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3532
lemma [simp]: "dec_on_right_moving (as, am) (s, l, r) ires\<Longrightarrow>  l \<noteq> []"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3533
apply(auto simp: dec_on_right_moving.simps split: if_splits)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3534
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3535
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3536
lemma [simp]: "dec_on_right_moving (as, am) (s, l, Bk # r) ires
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3537
      \<Longrightarrow>  dec_after_clear (as, am) (s', tl l, hd l # Bk # r) ires"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3538
apply(auto simp: dec_on_right_moving.simps dec_after_clear.simps)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3539
apply(case_tac [!] mr, auto split: if_splits)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3540
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3541
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3542
lemma [simp]: "dec_on_right_moving (as, am) (s, l, []) ires
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3543
             \<Longrightarrow> dec_after_clear (as, am) (s', tl l, [hd l]) ires"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3544
apply(auto simp: dec_on_right_moving.simps dec_after_clear.simps)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3545
apply(case_tac mr, simp_all split: if_splits)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3546
apply(rule_tac x = lm1 in exI, simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3547
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3548
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3549
lemma start_of_le: "a < b \<Longrightarrow> start_of ly a \<le> start_of ly b"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3550
proof(induct b arbitrary: a, simp, case_tac "a = b", simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3551
  fix b a
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3552
  show "start_of ly b \<le> start_of ly (Suc b)"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3553
    apply(case_tac "b::nat", 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3554
          simp add: start_of.simps, simp add: start_of.simps)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3555
    done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3556
next
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3557
  fix b a
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3558
  assume h1: "\<And>a. a < b \<Longrightarrow> start_of ly a \<le> start_of ly b" 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3559
             "a < Suc b" "a \<noteq> b"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3560
  hence "a < b"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3561
    by(simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3562
  from h1 and this have h2: "start_of ly a \<le> start_of ly b"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3563
    by(drule_tac h1, simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3564
  from h2 show "start_of ly a \<le> start_of ly (Suc b)"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3565
  proof -
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3566
    have "start_of ly b \<le> start_of ly (Suc b)"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3567
      apply(case_tac "b::nat", 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3568
            simp add: start_of.simps, simp add: start_of.simps)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3569
      done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3570
    from h2 and this show "start_of ly a \<le> start_of ly (Suc b)"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3571
      by simp
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3572
  qed
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3573
qed
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3574
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3575
lemma start_of_dec_length[simp]: 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3576
  "\<lbrakk>abc_fetch a aprog = Some (Dec n e)\<rbrakk> \<Longrightarrow> 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3577
    start_of (layout_of aprog) (Suc a)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3578
          = start_of (layout_of aprog) a + 2*n + 16"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3579
apply(case_tac a, auto simp: abc_fetch.simps start_of.simps 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3580
                             layout_of.simps length_of.simps 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3581
                       split: if_splits)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3582
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3583
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3584
lemma start_of_ge: 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3585
 "\<lbrakk>abc_fetch a aprog = Some (Dec n e); a < e\<rbrakk> \<Longrightarrow>
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3586
  start_of (layout_of aprog) e > 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3587
              start_of (layout_of aprog) a + 2*n + 15"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3588
apply(case_tac "e = Suc a", 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3589
      simp add: start_of.simps abc_fetch.simps layout_of.simps 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3590
                length_of.simps split: if_splits)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3591
apply(subgoal_tac "Suc a < e", drule_tac a = "Suc a" 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3592
             and ly = "layout_of aprog" in start_of_le)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3593
apply(subgoal_tac "start_of (layout_of aprog) (Suc a)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3594
         = start_of (layout_of aprog) a + 2*n + 16", simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3595
apply(rule_tac start_of_dec_length, simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3596
apply(arith)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3597
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3598
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3599
lemma starte_not_equal[simp]: 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3600
 "\<lbrakk>abc_fetch as aprog = Some (Dec n e); ly = layout_of aprog\<rbrakk>
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3601
   \<Longrightarrow> (start_of ly e \<noteq> Suc (Suc (start_of ly as + 2 * n)) \<and>  
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3602
        start_of ly e \<noteq> start_of ly as + 2 * n + 3 \<and> 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3603
        start_of ly e \<noteq> start_of ly as + 2 * n + 4 \<and>
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3604
        start_of ly e \<noteq> start_of ly as + 2 * n + 5 \<and> 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3605
        start_of ly e \<noteq> start_of ly as + 2 * n + 6 \<and> 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3606
        start_of ly e \<noteq> start_of ly as + 2 * n + 7 \<and>
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3607
        start_of ly e \<noteq> start_of ly as + 2 * n + 8 \<and> 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3608
        start_of ly e \<noteq> start_of ly as + 2 * n + 9 \<and> 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3609
        start_of ly e \<noteq> start_of ly as + 2 * n + 10 \<and>
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3610
        start_of ly e \<noteq> start_of ly as + 2 * n + 11 \<and> 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3611
        start_of ly e \<noteq> start_of ly as + 2 * n + 12 \<and> 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3612
        start_of ly e \<noteq> start_of ly as + 2 * n + 13 \<and>
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3613
        start_of ly e \<noteq> start_of ly as + 2 * n + 14 \<and> 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3614
        start_of ly e \<noteq> start_of ly as + 2 * n + 15)" 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3615
apply(case_tac "e = as", simp) 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3616
apply(case_tac "e < as")
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3617
apply(drule_tac a = e and b = as and ly = ly in start_of_le, simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3618
apply(drule_tac a = as and e = e in start_of_ge, simp, simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3619
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3620
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3621
lemma [simp]: "\<lbrakk>abc_fetch as aprog = Some (Dec n e); ly = layout_of aprog\<rbrakk>
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3622
      \<Longrightarrow> (Suc (Suc (start_of ly as + 2 * n)) \<noteq> start_of ly e \<and> 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3623
          start_of ly as + 2 * n + 3 \<noteq> start_of ly e \<and> 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3624
          start_of ly as + 2 * n + 4 \<noteq> start_of ly e \<and>
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3625
          start_of ly as + 2 * n + 5 \<noteq>start_of ly e \<and> 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3626
          start_of ly as + 2 * n + 6 \<noteq> start_of ly e \<and>
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3627
          start_of ly as + 2 * n + 7 \<noteq> start_of ly e \<and> 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3628
          start_of ly as + 2 * n + 8 \<noteq> start_of ly e \<and> 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3629
          start_of ly as + 2 * n + 9 \<noteq> start_of ly e \<and> 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3630
          start_of ly as + 2 * n + 10 \<noteq> start_of ly e \<and>
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3631
          start_of ly as + 2 * n + 11 \<noteq> start_of ly e \<and> 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3632
          start_of ly as + 2 * n + 12 \<noteq> start_of ly e \<and> 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3633
          start_of ly as + 2 * n + 13 \<noteq> start_of ly e \<and> 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3634
          start_of ly as + 2 * n + 14 \<noteq> start_of ly e \<and> 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3635
          start_of ly as + 2 * n + 15 \<noteq> start_of ly e)"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3636
apply(insert starte_not_equal[of as aprog n e ly], 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3637
                            simp del: starte_not_equal)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3638
apply(erule_tac conjE)+
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3639
apply(rule_tac conjI, simp del: starte_not_equal)+
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3640
apply(rule not_sym, simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3641
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3642
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3643
lemma [simp]: "start_of (layout_of aprog) as > 0 \<Longrightarrow> 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3644
  fetch (ci (layout_of aprog) (start_of (layout_of aprog) as)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3645
                       (Dec n as)) (Suc 0) Oc =
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3646
 (R, Suc (start_of (layout_of aprog) as))"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3647
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3648
apply(auto simp: ci.simps findnth.simps fetch.simps
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3649
                 nth_of.simps tshift.simps nth_append 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3650
                 Suc_pre tdec_b_def)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3651
apply(insert findnth_nth[of 0 n "Suc 0"], simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3652
apply(simp add: findnth.simps)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3653
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3654
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3655
lemma start_of_inj[simp]: 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3656
  "\<lbrakk>abc_fetch as aprog = Some (Dec n e); e \<noteq> as; ly = layout_of aprog\<rbrakk>
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3657
   \<Longrightarrow> start_of ly as \<noteq> start_of ly e"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3658
apply(case_tac "e < as")
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3659
apply(case_tac "as", simp, simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3660
apply(case_tac "e = nat", simp add: start_of.simps 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3661
                                    layout_of.simps length_of.simps)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3662
apply(subgoal_tac "e < length aprog", simp add: length_of.simps 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3663
                                         split: abc_inst.splits)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3664
apply(simp add: abc_fetch.simps split: if_splits)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3665
apply(subgoal_tac "e < nat", drule_tac a = e and b = nat 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3666
                                   and ly =ly in start_of_le, simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3667
apply(subgoal_tac "start_of ly nat < start_of ly (Suc nat)", 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3668
          simp, simp add: start_of.simps layout_of.simps)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3669
apply(subgoal_tac "nat < length aprog", simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3670
apply(case_tac "aprog ! nat", auto simp: length_of.simps)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3671
apply(simp add: abc_fetch.simps split: if_splits)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3672
apply(subgoal_tac "e > as", drule_tac start_of_ge, auto)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3673
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3674
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3675
lemma [simp]: "\<lbrakk>abc_fetch as aprog = Some (Dec n e); e < as\<rbrakk>
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3676
    \<Longrightarrow> Suc (start_of (layout_of aprog) e) - 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3677
                               start_of (layout_of aprog) as = 0"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3678
apply(frule_tac ly = "layout_of aprog" in start_of_le, simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3679
apply(subgoal_tac "start_of (layout_of aprog) as \<noteq> 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3680
                            start_of (layout_of aprog) e", arith)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3681
apply(rule start_of_inj, auto)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3682
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3683
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3684
lemma [simp]:
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3685
   "\<lbrakk>abc_fetch as aprog = Some (Dec n e); 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3686
     0 < start_of (layout_of aprog) as\<rbrakk>
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3687
 \<Longrightarrow> (fetch (ci (layout_of aprog) (start_of (layout_of aprog) as) 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3688
     (Dec n e)) (Suc (start_of (layout_of aprog) e) - 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3689
                 start_of (layout_of aprog) as) Oc)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3690
    = (if e = as then (R, start_of (layout_of aprog) as + 1)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3691
                 else (Nop, 0))"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3692
apply(auto split: if_splits)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3693
apply(case_tac "e < as", simp add: fetch.simps)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3694
apply(subgoal_tac " e > as")
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3695
apply(drule start_of_ge, simp,
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3696
      auto simp: fetch.simps ci_length nth_of.simps)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3697
apply(subgoal_tac 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3698
 "length (ci (layout_of aprog) (start_of (layout_of aprog) as) 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3699
                        (Dec n e)) div 2= length_of (Dec n e)")
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3700
defer
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3701
apply(simp add: ci_length)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3702
apply(subgoal_tac 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3703
 "length (ci (layout_of aprog) (start_of (layout_of aprog) as)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3704
                  (Dec n e)) mod 2 = 0", auto simp: length_of.simps)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3705
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3706
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3707
lemma [simp]:
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3708
    "start_of (layout_of aprog) as > 0 \<Longrightarrow> 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3709
 fetch (ci (layout_of aprog) (start_of (layout_of aprog) as) 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3710
                                          (Dec n as)) (Suc 0)  Bk 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3711
      = (W1, start_of (layout_of aprog) as)"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3712
apply(auto simp: ci.simps findnth.simps fetch.simps nth_of.simps 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3713
                 tshift.simps nth_append Suc_pre tdec_b_def)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3714
apply(insert findnth_nth[of 0 n "0"], simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3715
apply(simp add: findnth.simps)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3716
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3717
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3718
lemma [simp]: 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3719
 "\<lbrakk>abc_fetch as aprog = Some (Dec n e); 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3720
   0 < start_of (layout_of aprog) as\<rbrakk>
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3721
\<Longrightarrow> (fetch (ci (layout_of aprog) (start_of (layout_of aprog) as)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3722
         (Dec n e)) (Suc (start_of (layout_of aprog) e) - 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3723
              start_of (layout_of aprog) as)  Bk)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3724
   = (if e = as then (W1, start_of (layout_of aprog) as)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3725
                  else (Nop, 0))"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3726
apply(auto split: if_splits)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3727
apply(case_tac "e < as", simp add: fetch.simps)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3728
apply(subgoal_tac " e > as")
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3729
apply(drule start_of_ge, simp, auto simp: fetch.simps 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3730
                                          ci_length nth_of.simps)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3731
apply(subgoal_tac 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3732
 "length (ci (layout_of aprog) (start_of (layout_of aprog) as) 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3733
                            (Dec n e)) div 2= length_of (Dec n e)")
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3734
defer
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3735
apply(simp add: ci_length)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3736
apply(subgoal_tac 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3737
 "length (ci (layout_of aprog) (start_of (layout_of aprog) as) 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3738
                   (Dec n e)) mod 2 = 0", auto simp: length_of.simps)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3739
apply(simp add: ci.simps tshift.simps tdec_b_def)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3740
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3741
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3742
lemma [simp]: 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3743
 "inv_stop (as, abc_lm_s am n (abc_lm_v am n)) (s, l, r) ires \<Longrightarrow> l \<noteq> []"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3744
apply(auto simp: inv_stop.simps)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3745
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3746
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3747
lemma [simp]: 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3748
 "\<lbrakk>abc_fetch as aprog = Some (Dec n e); e \<noteq> as; ly = layout_of aprog\<rbrakk>
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3749
  \<Longrightarrow> (\<not> (start_of ly as \<le> start_of ly e \<and> 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3750
      start_of ly e < start_of ly as + 2 * n))
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3751
    \<and> start_of ly e \<noteq> start_of ly as + 2*n \<and> 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3752
      start_of ly e \<noteq> Suc (start_of ly as + 2*n) "
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3753
apply(case_tac "e < as")
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3754
apply(drule_tac ly = ly in start_of_le, simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3755
apply(case_tac n, simp, drule start_of_inj, simp, simp, simp, simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3756
apply(drule_tac start_of_ge, simp, simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3757
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3758
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3759
lemma [simp]: 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3760
   "\<lbrakk>abc_fetch as aprog = Some (Dec n e); start_of ly as \<le> s; 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3761
     s < start_of ly as + 2 * n; ly = layout_of aprog\<rbrakk>
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3762
     \<Longrightarrow> Suc s \<noteq> start_of ly e "
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3763
apply(case_tac "e = as", simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3764
apply(case_tac "e < as")
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3765
apply(drule_tac a = e and b = as and ly = ly in start_of_le, simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3766
apply(drule_tac start_of_ge, auto)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3767
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3768
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3769
lemma [simp]: "\<lbrakk>abc_fetch as aprog = Some (Dec n e); 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3770
                ly = layout_of aprog\<rbrakk>
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3771
         \<Longrightarrow> Suc (start_of ly as + 2 * n) \<noteq> start_of ly e"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3772
apply(case_tac "e = as", simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3773
apply(case_tac "e < as")
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3774
apply(drule_tac a = e and b = as and ly = ly in start_of_le, simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3775
apply(drule_tac start_of_ge, auto)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3776
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3777
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3778
lemma dec_false_1[simp]:
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3779
 "\<lbrakk>abc_lm_v am n = 0; inv_locate_b (as, am) (n, aaa, Oc # xs) ires\<rbrakk>
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3780
  \<Longrightarrow> False"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3781
apply(auto simp: inv_locate_b.simps in_middle.simps exponent_def)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3782
apply(case_tac "length lm1 \<ge> length am", auto)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3783
apply(subgoal_tac "lm2 = []", simp, subgoal_tac "m = 0", simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3784
apply(case_tac mr, auto simp: )
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3785
apply(subgoal_tac "Suc (length lm1) - length am = 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3786
                   Suc (length lm1 - length am)", 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3787
      simp add: rep_ind del: replicate.simps, simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3788
apply(drule_tac xs = "am @ replicate (Suc (length lm1) - length am) 0"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3789
                and ys = "lm1 @ m # lm2" in length_equal, simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3790
apply(case_tac mr, auto simp: abc_lm_v.simps)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3791
apply(case_tac "mr = 0", simp_all add:  exponent_def split: if_splits)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3792
apply(subgoal_tac "Suc (length lm1) - length am = 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3793
                       Suc (length lm1 - length am)", 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3794
      simp add: rep_ind del: replicate.simps, simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3795
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3796
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3797
lemma [simp]: 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3798
 "\<lbrakk>inv_locate_b (as, am) (n, aaa, Bk # xs) ires; 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3799
   abc_lm_v am n = 0\<rbrakk>
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3800
   \<Longrightarrow> inv_on_left_moving (as, abc_lm_s am n 0) 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3801
                         (s, tl aaa, hd aaa # Bk # xs) ires" 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3802
apply(insert inv_locate_b_2_on_left_moving[of as am n aaa xs ires s], simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3803
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3804
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3805
lemma [simp]:
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3806
 "\<lbrakk>abc_lm_v am n = 0; inv_locate_b (as, am) (n, aaa, []) ires\<rbrakk>
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3807
   \<Longrightarrow> inv_on_left_moving (as, abc_lm_s am n 0) (s, tl aaa, [hd aaa]) ires"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3808
apply(insert inv_locate_b_2_on_left_moving_b[of as am n aaa ires s], simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3809
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3810
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3811
lemma [simp]: "\<lbrakk>am ! n = (0::nat); n < length am\<rbrakk> \<Longrightarrow> am[n := 0] = am"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3812
apply(simp add: list_update_same_conv)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3813
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3814
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3815
lemma [simp]: "\<lbrakk>abc_lm_v am n = 0; 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3816
                inv_locate_b (as, abc_lm_s am n 0) (n, Oc # aaa, xs) ires\<rbrakk>
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3817
     \<Longrightarrow> inv_locate_b (as, am) (n, Oc # aaa, xs) ires"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3818
apply(simp only: inv_locate_b.simps in_middle.simps abc_lm_s.simps 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3819
                 abc_lm_v.simps)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3820
apply(erule_tac exE)+
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3821
apply(rule_tac x = lm1 in exI, rule_tac x = lm2 in exI, simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3822
apply(case_tac "n < length am", simp_all)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3823
apply(erule_tac conjE)+
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3824
apply(rule_tac x = tn in exI, rule_tac x = m in exI, simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3825
apply(rule_tac x = ml in exI, rule_tac x = mr in exI, simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3826
defer
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3827
apply(rule_tac x = "Suc n - length am" in exI, rule_tac x = m in exI)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3828
apply(subgoal_tac "Suc n - length am = Suc (n - length am)")
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3829
apply(simp add: exponent_def rep_ind del: replicate.simps, auto)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3830
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3831
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3832
lemma  [intro]: "\<lbrakk>abc_lm_v (a # list) 0 = 0\<rbrakk> \<Longrightarrow> a = 0"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3833
apply(simp add: abc_lm_v.simps split: if_splits)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3834
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3835
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3836
lemma [simp]: 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3837
 "inv_stop (as, abc_lm_s am n 0) 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3838
          (start_of (layout_of aprog) e, aaa, Oc # xs) ires
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3839
  \<Longrightarrow> inv_locate_a (as, abc_lm_s am n 0) (0, aaa, Oc # xs) ires"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3840
apply(simp add: inv_locate_a.simps)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3841
apply(rule disjI1)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3842
apply(auto simp: inv_stop.simps at_begin_norm.simps)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3843
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3844
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3845
lemma [simp]: 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3846
 "\<lbrakk>abc_lm_v am 0 = 0; 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3847
  inv_stop (as, abc_lm_s am 0 0) 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3848
      (start_of (layout_of aprog) e, aaa, Oc # xs) ires\<rbrakk> \<Longrightarrow> 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3849
  inv_locate_b (as, am) (0, Oc # aaa, xs) ires"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3850
apply(auto simp: inv_stop.simps inv_locate_b.simps 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3851
                 in_middle.simps abc_lm_s.simps)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3852
apply(case_tac "am = []", simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3853
apply(rule_tac x = "[]" in exI, rule_tac x = "Suc 0" in exI, 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3854
      rule_tac x = 0 in exI, simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3855
apply(rule_tac x = "Suc 0" in exI, rule_tac x = 0 in exI, 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3856
  simp add: tape_of_nl_abv tape_of_nat_list.simps, auto)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3857
apply(case_tac rn, auto)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3858
apply(rule_tac x = "tl am" in exI, rule_tac x = 0 in exI, 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3859
      rule_tac x = "hd am" in exI, simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3860
apply(rule_tac x = "Suc 0" in exI, rule_tac x = "hd am" in exI, simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3861
apply(case_tac am, simp, simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3862
apply(subgoal_tac "a = 0", case_tac list, 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3863
      auto simp: tape_of_nat_list.simps tape_of_nl_abv)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3864
apply(case_tac rn, auto)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3865
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3866
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3867
lemma [simp]: 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3868
 "\<lbrakk>inv_stop (as, abc_lm_s am n 0) 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3869
          (start_of (layout_of aprog) e, aaa, Oc # xs) ires\<rbrakk>
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3870
  \<Longrightarrow> inv_locate_b (as, am) (0, Oc # aaa, xs) ires \<or> 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3871
      inv_locate_b (as, abc_lm_s am n 0) (0, Oc # aaa, xs) ires"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3872
apply(simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3873
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3874
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3875
lemma [simp]: 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3876
"\<lbrakk>abc_lm_v am n = 0; 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3877
  inv_stop (as, abc_lm_s am n 0) 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3878
          (start_of (layout_of aprog) e, aaa, Oc # xs) ires\<rbrakk>
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3879
 \<Longrightarrow> \<not> Suc 0 < 2 * n \<longrightarrow> e = as \<longrightarrow> 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3880
            inv_locate_b (as, am) (n, Oc # aaa, xs) ires"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3881
apply(case_tac n, simp, simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3882
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3883
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3884
lemma dec_false2: 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3885
 "inv_stop (as, abc_lm_s am n 0) 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3886
  (start_of (layout_of aprog) e, aaa, Bk # xs) ires = False"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3887
apply(auto simp: inv_stop.simps abc_lm_s.simps)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3888
apply(case_tac "am", simp, case_tac n, simp add: tape_of_nl_abv)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3889
apply(case_tac list, simp add: tape_of_nat_list.simps )
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3890
apply(simp add: tape_of_nat_list.simps , simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3891
apply(case_tac "list[nat := 0]", 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3892
      simp add: tape_of_nat_list.simps  tape_of_nl_abv)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3893
apply(simp add: tape_of_nat_list.simps )
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3894
apply(case_tac "am @ replicate (n - length am) 0 @ [0]", simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3895
apply(case_tac list, auto simp: tape_of_nl_abv 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3896
                                tape_of_nat_list.simps )
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3897
done	
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3898
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3899
lemma dec_false3:
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3900
   "inv_stop (as, abc_lm_s am n 0) 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3901
              (start_of (layout_of aprog) e, aaa, []) ires = False"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3902
apply(auto simp: inv_stop.simps abc_lm_s.simps)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3903
apply(case_tac "am", case_tac n, auto)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3904
apply(case_tac n, auto simp: tape_of_nl_abv)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3905
apply(case_tac "list::nat list",
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3906
            simp add: tape_of_nat_list.simps tape_of_nat_list.simps)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3907
apply(simp add: tape_of_nat_list.simps)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3908
apply(case_tac "list[nat := 0]", 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3909
            simp add: tape_of_nat_list.simps tape_of_nat_list.simps)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3910
apply(simp add: tape_of_nat_list.simps)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3911
apply(case_tac "(am @ replicate (n - length am) 0 @ [0])", simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3912
apply(case_tac list, auto simp: tape_of_nat_list.simps)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3913
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3914
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3915
lemma [simp]:
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3916
  "fetch (ci (layout_of aprog) 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3917
       (start_of (layout_of aprog) as) (Dec n e)) 0 b = (Nop, 0)"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3918
by(simp add: fetch.simps)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3919
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3920
declare dec_inv_1.simps[simp del]
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3921
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3922
declare inv_locate_n_b.simps [simp del]
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3923
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3924
lemma [simp]:
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3925
"\<lbrakk>0 < abc_lm_v am n; 0 < n; 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3926
  at_begin_norm (as, am) (n, aaa, Oc # xs) ires\<rbrakk>
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3927
  \<Longrightarrow> inv_locate_n_b (as, am) (n, Oc # aaa, xs) ires"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3928
apply(simp only: at_begin_norm.simps inv_locate_n_b.simps)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3929
apply(erule_tac exE)+
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3930
apply(rule_tac x = lm1 in exI, simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3931
apply(case_tac "length lm2", simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3932
apply(case_tac rn, simp, simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3933
apply(rule_tac x = "tl lm2" in exI, rule_tac x = "hd lm2" in exI, simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3934
apply(rule conjI)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3935
apply(case_tac "lm2", simp, simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3936
apply(case_tac "lm2", auto simp: tape_of_nl_abv tape_of_nat_list.simps)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3937
apply(case_tac [!] "list", auto simp: tape_of_nl_abv tape_of_nat_list.simps)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3938
apply(case_tac rn, auto)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3939
done 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3940
lemma [simp]: "(\<exists>rn. Oc # xs = Bk\<^bsup>rn\<^esup>) = False"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3941
apply(auto)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3942
apply(case_tac rn, auto simp: )
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3943
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3944
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3945
lemma [simp]:
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3946
  "\<lbrakk>0 < abc_lm_v am n; 0 < n; 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3947
    at_begin_fst_bwtn (as, am) (n, aaa, Oc # xs) ires\<rbrakk>
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3948
 \<Longrightarrow> inv_locate_n_b (as, am) (n, Oc # aaa, xs) ires"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3949
apply(simp add: at_begin_fst_bwtn.simps inv_locate_n_b.simps )
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3950
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3951
 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3952
lemma Suc_minus:"length am + tn = n
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3953
       \<Longrightarrow> Suc tn = Suc n - length am "
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3954
apply(arith)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3955
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3956
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3957
lemma [simp]: 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3958
 "\<lbrakk>0 < abc_lm_v am n; 0 < n; 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3959
   at_begin_fst_awtn (as, am) (n, aaa, Oc # xs) ires\<rbrakk>
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3960
 \<Longrightarrow> inv_locate_n_b (as, am) (n, Oc # aaa, xs) ires"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3961
apply(simp only: at_begin_fst_awtn.simps inv_locate_n_b.simps )
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3962
apply(erule exE)+
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3963
apply(erule conjE)+
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3964
apply(rule_tac x = lm1 in exI, rule_tac x = "[]" in exI, 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3965
      rule_tac x = "Suc tn" in exI, rule_tac x = 0 in exI)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3966
apply(simp add: exponent_def rep_ind del: replicate.simps)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3967
apply(rule conjI)+
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3968
apply(auto)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3969
apply(case_tac [!] rn, auto)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3970
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3971
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3972
lemma [simp]: 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3973
 "\<lbrakk>0 < abc_lm_v am n; 0 < n; inv_locate_a (as, am) (n, aaa, Oc # xs) ires\<rbrakk>
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3974
 \<Longrightarrow> inv_locate_n_b (as, am) (n, Oc#aaa, xs) ires"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3975
apply(auto simp: inv_locate_a.simps)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3976
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3977
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3978
lemma [simp]:
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3979
 "\<lbrakk>inv_locate_n_b (as, am) (n, aaa, Oc # xs) ires\<rbrakk>
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3980
 \<Longrightarrow> dec_first_on_right_moving n (as, abc_lm_s am n (abc_lm_v am n))  
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3981
                                      (s, Oc # aaa, xs) ires"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3982
apply(auto simp: inv_locate_n_b.simps dec_first_on_right_moving.simps 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3983
                 abc_lm_s.simps abc_lm_v.simps)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3984
apply(rule_tac x = lm1 in exI, rule_tac x = lm2 in exI, 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3985
      rule_tac x = m in exI, simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3986
apply(rule_tac x = "Suc (Suc 0)" in exI, 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3987
      rule_tac x = "m - 1" in exI, simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3988
apply(case_tac m, auto simp:  exponent_def)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3989
apply(rule_tac x = lm1 in exI, rule_tac x = lm2 in exI, 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3990
      rule_tac x = m in exI, 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3991
      simp add: Suc_diff_le rep_ind del: replicate.simps)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3992
apply(rule_tac x = "Suc (Suc 0)" in exI, 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3993
      rule_tac x = "m - 1" in exI, simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3994
apply(case_tac m, auto simp:  exponent_def)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3995
apply(rule_tac x = lm1 in exI, rule_tac x = "[]" in exI, 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3996
      rule_tac x = m in exI, simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3997
apply(rule_tac x = "Suc (Suc 0)" in exI, 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3998
      rule_tac x = "m - 1" in exI, simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3999
apply(case_tac m, auto)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4000
apply(rule_tac x = lm1 in exI, rule_tac x = lm2 in exI, 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4001
      rule_tac x = m in exI, 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4002
      simp add: Suc_diff_le rep_ind del: replicate.simps, simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4003
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4004
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4005
lemma dec_false_2: 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4006
 "\<lbrakk>0 < abc_lm_v am n; inv_locate_n_b (as, am) (n, aaa, Bk # xs) ires\<rbrakk> 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4007
 \<Longrightarrow> False"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4008
apply(auto simp: inv_locate_n_b.simps abc_lm_v.simps split: if_splits)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4009
apply(case_tac [!] m, auto)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4010
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4011
 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4012
lemma dec_false_2_b:
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4013
 "\<lbrakk>0 < abc_lm_v am n; inv_locate_n_b (as, am) 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4014
                                (n, aaa, []) ires\<rbrakk> \<Longrightarrow> False"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4015
apply(auto simp: inv_locate_n_b.simps abc_lm_v.simps split: if_splits)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4016
apply(case_tac [!] m, auto simp: )
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4017
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4018
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4019
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4020
(*begin: dec halt1 lemmas*)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4021
thm abc_inc_stage1.simps
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4022
fun abc_dec_1_stage1:: "t_conf \<Rightarrow> nat \<Rightarrow> nat \<Rightarrow> nat"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4023
  where
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4024
  "abc_dec_1_stage1 (s, l, r) ss n = 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4025
       (if s > ss \<and> s \<le> ss + 2*n + 1 then 4
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4026
        else if s = ss + 2 * n + 13 \<or> s = ss + 2*n + 14 then 3
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4027
        else if s = ss + 2*n + 15 then 2
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4028
        else 0)"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4029
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4030
fun abc_dec_1_stage2:: "t_conf \<Rightarrow> nat \<Rightarrow> nat \<Rightarrow> nat"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4031
  where
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4032
  "abc_dec_1_stage2 (s, l, r) ss n = 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4033
       (if s \<le> ss + 2 * n + 1 then (ss + 2 * n + 16 - s)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4034
        else if s = ss + 2*n + 13 then length l
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4035
        else if s = ss + 2*n + 14 then length l
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4036
        else 0)"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4037
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4038
fun abc_dec_1_stage3 :: "t_conf \<Rightarrow> nat \<Rightarrow> nat \<Rightarrow> block list \<Rightarrow> nat"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4039
  where
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4040
  "abc_dec_1_stage3 (s, l, r) ss n ires = 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4041
        (if s \<le> ss + 2*n + 1 then 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4042
             if (s - ss) mod 2 = 0 then 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4043
                         if r \<noteq> [] \<and> hd r = Oc then 0 else 1  
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4044
                         else length r
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4045
         else if s = ss + 2 * n + 13 then 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4046
             if l = Bk # ires \<and> r \<noteq> [] \<and> hd r = Oc then 2 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4047
             else 1
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4048
         else if s = ss + 2 * n + 14 then 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4049
             if r \<noteq> [] \<and> hd r = Oc then 3 else 0 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4050
         else 0)"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4051
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4052
fun abc_dec_1_measure :: "(t_conf \<times> nat \<times> nat \<times> block list) \<Rightarrow> (nat \<times> nat \<times> nat)"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4053
  where
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4054
  "abc_dec_1_measure (c, ss, n, ires) = (abc_dec_1_stage1 c ss n, 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4055
                   abc_dec_1_stage2 c ss n, abc_dec_1_stage3 c ss n ires)"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4056
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4057
definition abc_dec_1_LE ::
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4058
  "(((nat \<times> block list \<times> block list) \<times> nat \<times>
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4059
  nat \<times> block list) \<times> ((nat \<times> block list \<times> block list) \<times> nat \<times> nat \<times> block list)) set"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4060
  where "abc_dec_1_LE \<equiv> (inv_image lex_triple abc_dec_1_measure)"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4061
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4062
lemma wf_dec_le: "wf abc_dec_1_LE"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4063
by(auto intro:wf_inv_image wf_lex_triple simp:abc_dec_1_LE_def)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4064
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4065
declare dec_inv_1.simps[simp del] dec_inv_2.simps[simp del]
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4066
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4067
lemma [elim]: 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4068
 "\<lbrakk>abc_fetch as aprog = Some (Dec n e); 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4069
   start_of (layout_of aprog) as < start_of (layout_of aprog) e;
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4070
   start_of (layout_of aprog) e \<le> 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4071
         Suc (start_of (layout_of aprog) as + 2 * n)\<rbrakk> \<Longrightarrow> False"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4072
apply(case_tac "e = as", simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4073
apply(case_tac "e < as")
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4074
apply(drule_tac a = e and b = as and ly = "layout_of aprog" in 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4075
                                                 start_of_le, simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4076
apply(drule_tac start_of_ge, auto)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4077
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4078
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4079
lemma [elim]: "\<lbrakk>abc_fetch as aprog = Some (Dec n e); 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4080
                                start_of (layout_of aprog) e 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4081
    = start_of (layout_of aprog) as + 2 * n + 13\<rbrakk>
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4082
         \<Longrightarrow> False"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4083
apply(insert starte_not_equal[of as aprog n e "layout_of aprog"], 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4084
      simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4085
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4086
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4087
lemma [elim]: "\<lbrakk>abc_fetch as aprog = Some (Dec n e);
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4088
                 start_of (layout_of aprog) e = 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4089
               start_of (layout_of aprog) as + 2 * n + 14\<rbrakk>
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4090
        \<Longrightarrow> False"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4091
apply(insert starte_not_equal[of as aprog n e "layout_of aprog"],
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4092
      simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4093
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4094
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4095
lemma [elim]: 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4096
 "\<lbrakk>abc_fetch as aprog = Some (Dec n e);
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4097
   start_of (layout_of aprog) as < start_of (layout_of aprog) e;
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4098
   start_of (layout_of aprog) e \<le> 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4099
              Suc (start_of (layout_of aprog) as + 2 * n)\<rbrakk>
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4100
   \<Longrightarrow> False"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4101
apply(case_tac "e = as", simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4102
apply(case_tac "e < as")
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4103
apply(drule_tac a = e and b = as and ly = "layout_of aprog" in 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4104
                                                    start_of_le, simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4105
apply(drule_tac start_of_ge, auto)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4106
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4107
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4108
lemma [elim]: 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4109
 "\<lbrakk>abc_fetch as aprog = Some (Dec n e); 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4110
   start_of (layout_of aprog) e = 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4111
               start_of (layout_of aprog) as + 2 * n + 13\<rbrakk>
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4112
    \<Longrightarrow> False"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4113
apply(insert starte_not_equal[of as aprog n e "layout_of aprog"], 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4114
      simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4115
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4116
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4117
lemma [simp]: 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4118
 "abc_fetch as aprog = Some (Dec n e) \<Longrightarrow> 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4119
   Suc (start_of (layout_of aprog) as) \<noteq> start_of (layout_of aprog) e"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4120
apply(case_tac "e = as", simp) 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4121
apply(case_tac "e < as")
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4122
apply(drule_tac a = e and b = as and ly = "(layout_of aprog)" in 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4123
                                                 start_of_le, simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4124
apply(drule_tac a = as and e = e in start_of_ge, simp, simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4125
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4126
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4127
lemma [simp]: "inv_on_left_moving (as, am) (s, [], r) ires 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4128
  = False"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4129
apply(simp add: inv_on_left_moving.simps inv_on_left_moving_norm.simps
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4130
                inv_on_left_moving_in_middle_B.simps)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4131
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4132
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4133
lemma [simp]: 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4134
  "inv_check_left_moving (as, abc_lm_s am n 0)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4135
  (start_of (layout_of aprog) as + 2 * n + 14, [], Oc # xs) ires
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4136
 = False"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4137
apply(simp add: inv_check_left_moving.simps inv_check_left_moving_in_middle.simps)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4138
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4139
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4140
lemma dec_inv_stop1_pre: 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4141
    "\<lbrakk>abc_fetch as aprog = Some (Dec n e); abc_lm_v am n = 0;
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4142
      start_of (layout_of aprog) as > 0\<rbrakk>
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4143
 \<Longrightarrow> \<forall>na. \<not> (\<lambda>(s, l, r) (ss, n', ires'). s = start_of (layout_of aprog) e)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4144
            (t_steps (Suc (start_of (layout_of aprog) as), l, r) 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4145
              (ci (layout_of aprog) (start_of (layout_of aprog) as) 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4146
                 (Dec n e), start_of (layout_of aprog) as - Suc 0) na)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4147
                      (start_of (layout_of aprog) as, n, ires) \<and>
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4148
           dec_inv_1 (layout_of aprog) n e (as, am)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4149
            (t_steps (Suc (start_of (layout_of aprog) as), l, r) 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4150
              (ci (layout_of aprog) (start_of (layout_of aprog) as) 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4151
                (Dec n e), start_of (layout_of aprog) as - Suc 0) na) ires
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4152
       \<longrightarrow> dec_inv_1 (layout_of aprog) n e (as, am)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4153
            (t_steps (Suc (start_of (layout_of aprog) as), l, r) 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4154
              (ci (layout_of aprog) (start_of (layout_of aprog) as)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4155
                 (Dec n e), start_of (layout_of aprog) as - Suc 0) 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4156
                    (Suc na)) ires \<and>
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4157
            ((t_steps (Suc (start_of (layout_of aprog) as), l, r) 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4158
            (ci (layout_of aprog) (start_of (layout_of aprog) as) 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4159
           (Dec n e), start_of (layout_of aprog) as - Suc 0) (Suc na),
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4160
             start_of (layout_of aprog) as, n, ires),
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4161
         t_steps (Suc (start_of (layout_of aprog) as), l, r) 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4162
            (ci (layout_of aprog) (start_of (layout_of aprog) as) 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4163
               (Dec n e), start_of (layout_of aprog) as - Suc 0) na,
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4164
            start_of (layout_of aprog) as, n, ires)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4165
           \<in> abc_dec_1_LE"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4166
apply(rule allI, rule impI, simp add: t_steps_ind)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4167
apply(case_tac "(t_steps (Suc (start_of (layout_of aprog) as), l, r) 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4168
(ci (layout_of aprog) (start_of (layout_of aprog) as) (Dec n e), 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4169
start_of (layout_of aprog) as - Suc 0) na)", simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4170
apply(auto split:if_splits simp add:t_step.simps dec_inv_1.simps, 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4171
          tactic {* ALLGOALS (resolve_tac [@{thm fetch_intro}]) *})
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4172
apply(simp_all add:dec_fetch_simps new_tape.simps dec_inv_1.simps)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4173
apply(auto simp add: abc_dec_1_LE_def lex_square_def 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4174
                     lex_triple_def lex_pair_def  
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4175
                split: if_splits)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4176
apply(rule dec_false_1, simp, simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4177
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4178
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4179
lemma dec_inv_stop1: 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4180
  "\<lbrakk>ly = layout_of aprog; 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4181
    dec_inv_1 ly n e (as, am) (start_of ly as + 1, l, r) ires; 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4182
    abc_fetch as aprog = Some (Dec n e); abc_lm_v am n = 0\<rbrakk> \<Longrightarrow> 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4183
  (\<exists> stp. (\<lambda> (s', l', r'). s' = start_of ly e \<and> 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4184
           dec_inv_1 ly n e (as, am) (s', l' , r') ires) 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4185
  (t_steps (start_of ly as + 1, l, r)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4186
     (ci ly (start_of ly as) (Dec n e), start_of ly as - Suc 0) stp))"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4187
apply(insert halt_lemma2[of abc_dec_1_LE 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4188
    "\<lambda> ((s, l, r), ss, n', ires'). s = start_of ly e" 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4189
     "(\<lambda> stp. (t_steps (start_of ly as + 1, l, r) 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4190
          (ci ly (start_of ly as) (Dec n e), start_of ly as - Suc 0) 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4191
               stp, start_of ly as, n, ires))"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4192
     "\<lambda> ((s, l, r), ss, n, ires'). dec_inv_1 ly n e (as, am) (s, l, r) ires'"],
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4193
     simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4194
apply(insert wf_dec_le, simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4195
apply(insert dec_inv_stop1_pre[of as aprog n e am l r], simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4196
apply(subgoal_tac "start_of (layout_of aprog) as > 0", 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4197
                                      simp add: t_steps.simps)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4198
apply(erule_tac exE, rule_tac x = na in exI)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4199
apply(case_tac
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4200
     "(t_steps (Suc (start_of (layout_of aprog) as), l, r) 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4201
         (ci (layout_of aprog) (start_of (layout_of aprog) as)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4202
           (Dec n e), start_of (layout_of aprog) as - Suc 0) na)",
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4203
      case_tac b, auto)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4204
apply(rule startof_not0)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4205
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4206
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4207
(*begin: dec halt2 lemmas*)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4208
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4209
lemma [simp]:
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4210
  "\<lbrakk>abc_fetch as aprog = Some (Dec n e); 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4211
    ly = layout_of aprog\<rbrakk> \<Longrightarrow> 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4212
              start_of ly (Suc as) = start_of ly as + 2*n + 16"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4213
by simp
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4214
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4215
fun abc_dec_2_stage1 :: "t_conf \<Rightarrow> nat \<Rightarrow> nat \<Rightarrow> nat"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4216
  where
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4217
  "abc_dec_2_stage1 (s, l, r) ss n = 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4218
              (if s \<le> ss + 2*n + 1 then 7
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4219
               else if s = ss + 2*n + 2 then 6 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4220
               else if s = ss + 2*n + 3 then 5
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4221
               else if s \<ge> ss + 2*n + 4 \<and> s \<le> ss + 2*n + 9 then 4
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4222
               else if s = ss + 2*n + 6 then 3
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4223
               else if s = ss + 2*n + 10 \<or> s = ss + 2*n + 11 then 2
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4224
               else if s = ss + 2*n + 12 then 1
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4225
               else 0)"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4226
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4227
thm new_tape.simps
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4228
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4229
fun abc_dec_2_stage2 :: "t_conf \<Rightarrow> nat \<Rightarrow> nat \<Rightarrow> nat"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4230
  where
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4231
  "abc_dec_2_stage2 (s, l, r) ss n = 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4232
       (if s \<le> ss + 2 * n + 1 then (ss + 2 * n + 16 - s)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4233
        else if s = ss + 2*n + 10 then length l
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4234
        else if s = ss + 2*n + 11 then length l
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4235
        else if s = ss + 2*n + 4 then length r - 1
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4236
        else if s = ss + 2*n + 5 then length r 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4237
        else if s = ss + 2*n + 7 then length r - 1
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4238
        else if s = ss + 2*n + 8 then  
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4239
              length r + length (takeWhile (\<lambda> a. a = Oc) l) - 1
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4240
        else if s = ss + 2*n + 9 then 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4241
              length r + length (takeWhile (\<lambda> a. a = Oc) l) - 1
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4242
        else 0)"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4243
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4244
fun abc_dec_2_stage3 :: "t_conf \<Rightarrow> nat \<Rightarrow> nat \<Rightarrow> block list \<Rightarrow> nat"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4245
  where
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4246
  "abc_dec_2_stage3 (s, l, r) ss n ires =
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4247
        (if s \<le> ss + 2*n + 1 then 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4248
            if (s - ss) mod 2 = 0 then if r \<noteq> [] \<and> 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4249
                                          hd r = Oc then 0 else 1  
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4250
            else length r
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4251
         else if s = ss + 2 * n + 10 then 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4252
             if l = Bk # ires \<and> r \<noteq> [] \<and> hd r = Oc then 2
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4253
             else 1
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4254
         else if s = ss + 2 * n + 11 then 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4255
             if r \<noteq> [] \<and> hd r = Oc then 3 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4256
             else 0 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4257
         else (ss + 2 * n + 16 - s))"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4258
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4259
fun abc_dec_2_stage4 :: "t_conf \<Rightarrow> nat \<Rightarrow> nat \<Rightarrow> nat"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4260
  where
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4261
  "abc_dec_2_stage4 (s, l, r) ss n = 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4262
          (if s = ss + 2*n + 2 then length r
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4263
           else if s = ss + 2*n + 8 then length r
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4264
           else if s = ss + 2*n + 3 then 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4265
               if r \<noteq> [] \<and> hd r = Oc then 1
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4266
               else 0
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4267
           else if s = ss + 2*n + 7 then 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4268
               if r \<noteq> [] \<and> hd r = Oc then 0 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4269
               else 1
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4270
           else if s = ss + 2*n + 9 then 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4271
               if r \<noteq> [] \<and> hd r = Oc then 1
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4272
               else 0 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4273
           else 0)"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4274
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4275
fun abc_dec_2_measure :: "(t_conf \<times> nat \<times> nat \<times> block list) \<Rightarrow> 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4276
                                    (nat \<times> nat \<times> nat \<times> nat)"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4277
  where
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4278
  "abc_dec_2_measure (c, ss, n, ires) = 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4279
       (abc_dec_2_stage1 c ss n, abc_dec_2_stage2 c ss n,
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4280
        abc_dec_2_stage3 c ss n ires, abc_dec_2_stage4 c ss n)"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4281
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4282
definition abc_dec_2_LE :: 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4283
       "(((nat \<times> block list \<times> block list) \<times> nat \<times> nat \<times> block list) \<times> 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4284
        ((nat \<times> block list \<times> block list) \<times> nat \<times> nat \<times> block list)) set"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4285
  where "abc_dec_2_LE \<equiv> (inv_image lex_square abc_dec_2_measure)"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4286
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4287
lemma wf_dec_2_le: "wf abc_dec_2_LE"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4288
by(auto intro:wf_inv_image wf_lex_triple wf_lex_square 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4289
   simp:abc_dec_2_LE_def)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4290
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4291
lemma [simp]: "dec_after_write (as, am) (s, aa, r) ires
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4292
           \<Longrightarrow> takeWhile (\<lambda>a. a = Oc) aa = []"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4293
apply(simp only : dec_after_write.simps)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4294
apply(erule exE)+
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4295
apply(erule_tac conjE)+
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4296
apply(case_tac aa, simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4297
apply(case_tac a, simp only: takeWhile.simps , simp, simp split: if_splits)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4298
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4299
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4300
lemma [simp]: 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4301
     "\<lbrakk>dec_on_right_moving (as, lm) (s, aa, []) ires; 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4302
       length (takeWhile (\<lambda>a. a = Oc) (tl aa)) 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4303
           \<noteq> length (takeWhile (\<lambda>a. a = Oc) aa) - Suc 0\<rbrakk>
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4304
    \<Longrightarrow> length (takeWhile (\<lambda>a. a = Oc) (tl aa)) < 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4305
                       length (takeWhile (\<lambda>a. a = Oc) aa) - Suc 0"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4306
apply(simp only: dec_on_right_moving.simps)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4307
apply(erule_tac exE)+
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4308
apply(erule_tac conjE)+
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4309
apply(case_tac mr, auto split: if_splits)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4310
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4311
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4312
lemma [simp]: 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4313
  "dec_after_clear (as, abc_lm_s am n (abc_lm_v am n - Suc 0)) 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4314
             (start_of (layout_of aprog) as + 2 * n + 9, aa, Bk # xs) ires
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4315
 \<Longrightarrow> length xs - Suc 0 < length xs + 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4316
                             length (takeWhile (\<lambda>a. a = Oc) aa)"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4317
apply(simp only: dec_after_clear.simps)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4318
apply(erule_tac exE)+
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4319
apply(erule conjE)+
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4320
apply(simp split: if_splits )
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4321
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4322
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4323
lemma [simp]: 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4324
 "\<lbrakk>dec_after_clear (as, abc_lm_s am n (abc_lm_v am n - Suc 0))
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4325
       (start_of (layout_of aprog) as + 2 * n + 9, aa, []) ires\<rbrakk>
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4326
    \<Longrightarrow> Suc 0 < length (takeWhile (\<lambda>a. a = Oc) aa)"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4327
apply(simp add: dec_after_clear.simps split: if_splits)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4328
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4329
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4330
lemma [simp]: 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4331
 "\<lbrakk>dec_on_right_moving (as, am) (s, aa, Bk # xs) ires; 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4332
   Suc (length (takeWhile (\<lambda>a. a = Oc) (tl aa)))
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4333
   \<noteq> length (takeWhile (\<lambda>a. a = Oc) aa)\<rbrakk>
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4334
  \<Longrightarrow> Suc (length (takeWhile (\<lambda>a. a = Oc) (tl aa))) 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4335
    < length (takeWhile (\<lambda>a. a = Oc) aa)"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4336
apply(simp only: dec_on_right_moving.simps)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4337
apply(erule exE)+
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4338
apply(erule conjE)+
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4339
apply(case_tac ml, auto split: if_splits )
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4340
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4341
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4342
(*
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4343
lemma abc_dec_2_wf: 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4344
     "\<lbrakk>ly = layout_of aprog; dec_inv_2 ly n e (as, am) (start_of ly as + 1, l, r);  abc_fetch as aprog = Dec n e; abc_lm_v am n > 0\<rbrakk>
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4345
       \<Longrightarrow> \<forall>na. \<not> (\<lambda>(s, l, r) (ss, n'). s = start_of (layout_of aprog) as + 2*n + 16)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4346
        (t_steps (Suc (start_of (layout_of aprog) as), l, r) (ci (layout_of aprog) (start_of (layout_of aprog) as) (Dec n e), start_of (layout_of aprog) as - Suc 0) na)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4347
           (start_of (layout_of aprog) as, n) \<longrightarrow>
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4348
        ((t_steps (Suc (start_of (layout_of aprog) as), l, r) (ci (layout_of aprog) (start_of (layout_of aprog) as) (Dec n e), start_of (layout_of aprog) as - Suc 0) (Suc na),
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4349
            start_of (layout_of aprog) as, n),
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4350
          t_steps (Suc (start_of (layout_of aprog) as), l, r) (ci (layout_of aprog) (start_of (layout_of aprog) as) (Dec n e), start_of (layout_of aprog) as - Suc 0) na,
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4351
           start_of (layout_of aprog) as, n)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4352
        \<in> abc_dec_2_LE"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4353
proof(rule allI, rule impI, simp add: t_steps_ind)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4354
  fix na
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4355
  assume h1 :"ly = layout_of aprog" "dec_inv_2 (layout_of aprog) n e (as, am) (Suc (start_of (layout_of aprog) as), l, r)" 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4356
          "abc_fetch as aprog = Dec n e" "abc_lm_v am n > 0"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4357
         "\<not> (\<lambda>(s, l, r) (ss, n'). s = start_of (layout_of aprog) as + 2*n + 16)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4358
             (t_steps (Suc (start_of (layout_of aprog) as), l, r) (ci (layout_of aprog) (start_of (layout_of aprog) as) (Dec n e), start_of (layout_of aprog) as - Suc 0) na)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4359
             (start_of (layout_of aprog) as, n)"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4360
  thus "((t_step (t_steps (Suc (start_of (layout_of aprog) as), l, r) (ci (layout_of aprog) (start_of (layout_of aprog) as) (Dec n e), start_of (layout_of aprog) as - Suc 0) na)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4361
               (ci (layout_of aprog) (start_of (layout_of aprog) as) (Dec n e), start_of (layout_of aprog) as - Suc 0),
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4362
              start_of (layout_of aprog) as, n),
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4363
             t_steps (Suc (start_of (layout_of aprog) as), l, r) (ci (layout_of aprog) (start_of (layout_of aprog) as) (Dec n e), start_of (layout_of aprog) as - Suc 0) na,
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4364
             start_of (layout_of aprog) as, n)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4365
            \<in> abc_dec_2_LE"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4366
  proof(insert dec_inv_2_steps[of "layout_of aprog" n e as am "(start_of (layout_of aprog) as + 1, l, r)" aprog na], 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4367
        case_tac "(t_steps (start_of (layout_of aprog) as + 1, l, r) (ci (layout_of aprog) (start_of (layout_of aprog) as) (Dec n e), start_of (layout_of aprog) as - Suc 0) na)", case_tac b, simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4368
    fix a b aa ba
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4369
    assume "dec_inv_2 (layout_of aprog) n e (as, am) (a, aa, ba)" " a \<noteq> start_of (layout_of aprog) as + 2*n + 16" "abc_lm_v am n > 0" "abc_fetch as aprog = Dec n e "
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4370
    thus "((t_step (a, aa, ba) (ci (layout_of aprog) (start_of (layout_of aprog) as) (Dec n e), start_of (layout_of aprog) as - Suc 0), start_of (layout_of aprog) as, n), (a, aa, ba),
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4371
                    start_of (layout_of aprog) as, n)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4372
                   \<in> abc_dec_2_LE"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4373
      apply(case_tac "a = 0", auto split:if_splits simp add:t_step.simps dec_inv_2.simps, 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4374
                tactic {* ALLGOALS (resolve_tac (thms "fetch_intro")) *})
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4375
      apply(simp_all add:dec_fetch_simps new_tape.simps)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4376
      apply(auto simp add: abc_dec_2_LE_def  lex_square_def lex_triple_def lex_pair_def  
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4377
                           split: if_splits)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4378
      
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4379
      done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4380
  qed
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4381
qed
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4382
*)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4383
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4384
lemma [simp]: "inv_check_left_moving (as, abc_lm_s am n (abc_lm_v am n - Suc 0)) 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4385
  (start_of (layout_of aprog) as + 2 * n + 11, [], Oc # xs) ires = False"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4386
apply(simp add: inv_check_left_moving.simps inv_check_left_moving_in_middle.simps)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4387
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4388
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4389
lemma dec_inv_stop2_pre: 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4390
  "\<lbrakk>abc_fetch as aprog = Some (Dec n e); abc_lm_v am n > 0\<rbrakk> \<Longrightarrow> 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4391
    \<forall>na. \<not> (\<lambda>(s, l, r) (ss, n', ires'). 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4392
                     s = start_of (layout_of aprog) as + 2 * n + 16)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4393
   (t_steps (Suc (start_of (layout_of aprog) as), l, r) 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4394
      (ci (layout_of aprog) (start_of (layout_of aprog) as) (Dec n e),
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4395
            start_of (layout_of aprog) as - Suc 0) na)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4396
    (start_of (layout_of aprog) as, n, ires) \<and>
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4397
 dec_inv_2 (layout_of aprog) n e (as, am)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4398
     (t_steps (Suc (start_of (layout_of aprog) as), l, r) 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4399
      (ci (layout_of aprog) (start_of (layout_of aprog) as) (Dec n e),
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4400
          start_of (layout_of aprog) as - Suc 0) na) ires
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4401
 \<longrightarrow>
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4402
 dec_inv_2 (layout_of aprog) n e (as, am)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4403
     (t_steps (Suc (start_of (layout_of aprog) as), l, r) 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4404
      (ci (layout_of aprog) (start_of (layout_of aprog) as) (Dec n e),
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4405
              start_of (layout_of aprog) as - Suc 0) (Suc na)) ires \<and>
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4406
 ((t_steps (Suc (start_of (layout_of aprog) as), l, r) 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4407
      (ci (layout_of aprog) (start_of (layout_of aprog) as) (Dec n e),
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4408
            start_of (layout_of aprog) as - Suc 0) (Suc na),  
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4409
              start_of (layout_of aprog) as, n, ires),
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4410
  t_steps (Suc (start_of (layout_of aprog) as), l, r) 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4411
      (ci (layout_of aprog) (start_of (layout_of aprog) as) (Dec n e),
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4412
             start_of (layout_of aprog) as - Suc 0) na,
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4413
                          start_of (layout_of aprog) as, n, ires)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4414
   \<in> abc_dec_2_LE"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4415
apply(subgoal_tac "start_of (layout_of aprog) as > 0")
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4416
apply(rule allI, rule impI, simp add: t_steps_ind)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4417
apply(case_tac "(t_steps (Suc (start_of (layout_of aprog) as), l, r)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4418
     (ci (layout_of aprog) (start_of (layout_of aprog) as) (Dec n e), 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4419
             start_of (layout_of aprog) as - Suc 0) na)", simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4420
apply(auto split:if_splits simp add:t_step.simps dec_inv_2.simps, 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4421
           tactic {* ALLGOALS (resolve_tac [@{thm fetch_intro}]) *})
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4422
apply(simp_all add:dec_fetch_simps new_tape.simps dec_inv_2.simps)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4423
apply(auto simp add: abc_dec_2_LE_def lex_square_def lex_triple_def 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4424
                     lex_pair_def split: if_splits)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4425
apply(auto intro: dec_false_2_b dec_false_2)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4426
apply(rule startof_not0)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4427
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4428
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4429
lemma dec_stop2: 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4430
 "\<lbrakk>ly = layout_of aprog; 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4431
   dec_inv_2 ly n e (as, am) (start_of ly as + 1, l, r) ires; 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4432
   abc_fetch as aprog = Some (Dec n e); 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4433
   abc_lm_v am n > 0\<rbrakk> \<Longrightarrow> 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4434
  (\<exists> stp. (\<lambda> (s', l', r'). s' = start_of ly (Suc as) \<and> 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4435
   dec_inv_2 ly n e (as, am) (s', l', r') ires)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4436
       (t_steps (start_of ly as+1, l, r) (ci ly (start_of ly as)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4437
                           (Dec n e), start_of ly as - Suc 0) stp))"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4438
apply(insert halt_lemma2[of abc_dec_2_LE 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4439
      "\<lambda> ((s, l, r), ss, n', ires'). s = start_of ly (Suc as)"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4440
      "(\<lambda> stp. (t_steps (start_of ly as + 1, l, r) 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4441
       (ci ly (start_of ly as) (Dec n e), start_of ly as - Suc 0) stp,
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4442
                 start_of ly as, n, ires))"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4443
      "(\<lambda> ((s, l, r), ss, n, ires'). dec_inv_2 ly n e (as, am) (s, l, r) ires')"])
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4444
apply(insert wf_dec_2_le, simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4445
apply(insert dec_inv_stop2_pre[of as aprog n e am l r], 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4446
      simp add: t_steps.simps)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4447
apply(erule_tac exE)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4448
apply(rule_tac x = na in exI)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4449
apply(case_tac "(t_steps (Suc (start_of (layout_of aprog) as), l, r) 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4450
(ci (layout_of aprog) (start_of (layout_of aprog) as) (Dec n e), 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4451
            start_of (layout_of aprog) as - Suc 0) na)",
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4452
      case_tac b, auto)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4453
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4454
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4455
lemma dec_inv_stop_cond1: 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4456
  "\<lbrakk>ly = layout_of aprog; 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4457
    dec_inv_1 ly n e (as, lm) (s, (l, r)) ires; s = start_of ly e;
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4458
    abc_fetch as aprog = Some (Dec n e); abc_lm_v lm n = 0\<rbrakk> 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4459
   \<Longrightarrow> crsp_l ly (e, abc_lm_s lm n 0) (s, l, r) ires"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4460
apply(simp add: dec_inv_1.simps split: if_splits)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4461
apply(auto simp: crsp_l.simps inv_stop.simps )
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4462
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4463
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4464
lemma dec_inv_stop_cond2: 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4465
   "\<lbrakk>ly = layout_of aprog; s = start_of ly (Suc as); 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4466
     dec_inv_2 ly n e (as, lm) (s, (l, r)) ires;
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4467
     abc_fetch as aprog = Some (Dec n e); 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4468
     abc_lm_v lm n > 0\<rbrakk>
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4469
   \<Longrightarrow> crsp_l ly (Suc as,
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4470
                  abc_lm_s lm n (abc_lm_v lm n - Suc 0)) (s, l, r) ires"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4471
apply(simp add: dec_inv_2.simps split: if_splits)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4472
apply(auto simp: crsp_l.simps inv_stop.simps )
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4473
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4474
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4475
lemma [simp]: "(case Bk\<^bsup>rn\<^esup> of [] \<Rightarrow> Bk |
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4476
                 Bk # xs \<Rightarrow> Bk | Oc # xs \<Rightarrow> Oc) = Bk"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4477
apply(case_tac rn, auto)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4478
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4479
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4480
lemma [simp]: "t_steps tc (p,off) (m + n) = 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4481
                   t_steps (t_steps tc (p, off) m) (p, off) n"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4482
apply(induct m arbitrary: n)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4483
apply(simp add: t_steps.simps)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4484
proof -
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4485
  fix m n
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4486
  assume h1: "\<And>n. t_steps tc (p, off) (m + n) =
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4487
                     t_steps (t_steps tc (p, off) m) (p, off) n"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4488
  hence h2: "t_steps tc (p, off) (Suc m + n) = 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4489
                     t_steps tc (p, off) (m + Suc n)"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4490
    by simp
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4491
  from h1 and this show 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4492
    "t_steps tc (p, off) (Suc m + n) = 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4493
         t_steps (t_steps tc (p, off) (Suc m)) (p, off) n"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4494
  proof(simp only: h2, simp add: t_steps.simps)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4495
    have h3: "(t_step (t_steps tc (p, off) m) (p, off)) = 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4496
                      (t_steps (t_step tc (p, off)) (p, off) m)"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4497
      apply(simp add: t_steps.simps[THEN sym] t_steps_ind[THEN sym])
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4498
      done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4499
    from h3 show 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4500
      "t_steps (t_step (t_steps tc (p, off) m) (p, off)) (p, off) n =          t_steps (t_steps (t_step tc (p, off)) (p, off) m) (p, off) n"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4501
      by simp
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4502
  qed
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4503
qed
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4504
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4505
lemma [simp]: " abc_fetch as aprog = Some (Dec n e) \<Longrightarrow> 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4506
          Suc (start_of (layout_of aprog) as) \<noteq> 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4507
                           start_of (layout_of aprog) e"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4508
apply(case_tac "e = as", simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4509
apply(case_tac "e < as")
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4510
apply(drule_tac a = e and b = as and ly = "layout_of aprog" 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4511
                                           in start_of_le, simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4512
apply(drule_tac start_of_ge, auto)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4513
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4514
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4515
lemma [simp]: "inv_locate_b (as, []) (0, Oc # Bk # Bk # ires, Bk\<^bsup>rn - Suc 0\<^esup>) ires"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4516
apply(auto simp: inv_locate_b.simps in_middle.simps)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4517
apply(rule_tac x = "[]" in exI, rule_tac x = "Suc 0" in exI, 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4518
      rule_tac x = 0 in exI, simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4519
apply(rule_tac x = "Suc 0" in exI, rule_tac x = 0 in exI, auto)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4520
apply(case_tac rn, simp, case_tac nat, auto)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4521
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4522
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4523
lemma [simp]: 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4524
       "inv_locate_n_b (as, []) (0, Oc # Bk # Bk # ires, Bk\<^bsup>rn - Suc 0\<^esup>) ires"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4525
apply(auto simp: inv_locate_n_b.simps in_middle.simps)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4526
apply(case_tac rn, simp, case_tac nat, auto)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4527
done 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4528
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4529
lemma [simp]:
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4530
"abc_fetch as aprog = Some (Dec n e) \<Longrightarrow>
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4531
   dec_inv_1 (layout_of aprog) n e (as, []) 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4532
    (Suc (start_of (layout_of aprog) as), Oc # Bk # Bk # ires, Bk\<^bsup>rn - Suc 0\<^esup>) ires
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4533
\<and>
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4534
   dec_inv_2 (layout_of aprog) n e (as, []) 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4535
    (Suc (start_of (layout_of aprog) as), Oc # Bk # Bk # ires, Bk\<^bsup>rn - Suc 0\<^esup>) ires"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4536
apply(simp add: dec_inv_1.simps dec_inv_2.simps)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4537
apply(case_tac n, auto)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4538
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4539
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4540
lemma [simp]: 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4541
 "\<lbrakk>am \<noteq> []; <am> = Oc # r'; 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4542
   abc_fetch as aprog = Some (Dec n e)\<rbrakk> 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4543
 \<Longrightarrow> inv_locate_b (as, am) (0, Oc # Bk # Bk # ires, r' @ Bk\<^bsup>rn\<^esup>) ires"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4544
apply(auto simp: inv_locate_b.simps in_middle.simps)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4545
apply(rule_tac x = "tl am" in exI, rule_tac x = 0 in exI,
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4546
      rule_tac x = "hd am" in exI, simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4547
apply(rule_tac x = "Suc 0" in exI)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4548
apply(rule_tac x = "hd am" in exI, simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4549
apply(case_tac am, simp, case_tac list, auto simp: tape_of_nl_abv tape_of_nat_list.simps)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4550
apply(case_tac rn, auto)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4551
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4552
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4553
lemma [simp]: 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4554
  "\<lbrakk><am> = Oc # r'; abc_fetch as aprog = Some (Dec n e)\<rbrakk> \<Longrightarrow> 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4555
  inv_locate_n_b (as, am) (0, Oc # Bk # Bk # ires, r' @ Bk\<^bsup>rn\<^esup>) ires"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4556
apply(auto simp: inv_locate_n_b.simps)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4557
apply(rule_tac x = "tl am" in exI, rule_tac x = "hd am" in exI, auto)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4558
apply(case_tac [!] am, auto simp: tape_of_nl_abv tape_of_nat_list.simps )
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4559
apply(case_tac [!]list, auto simp: tape_of_nl_abv tape_of_nat_list.simps)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4560
apply(case_tac rn, simp, simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4561
apply(erule_tac x = nat in allE, simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4562
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4563
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4564
lemma [simp]:
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4565
   "\<lbrakk>am \<noteq> [];  
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4566
     <am> = Oc # r'; 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4567
     abc_fetch as aprog = Some (Dec n e)\<rbrakk> \<Longrightarrow>
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4568
    dec_inv_1 (layout_of aprog) n e (as, am) 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4569
      (Suc (start_of (layout_of aprog) as), 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4570
           Oc # Bk # Bk # ires, r' @ Bk\<^bsup>rn\<^esup>) ires \<and>
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4571
    dec_inv_2 (layout_of aprog) n e (as, am) 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4572
      (Suc (start_of (layout_of aprog) as), 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4573
           Oc # Bk # Bk # ires, r' @ Bk\<^bsup>rn\<^esup>) ires"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4574
apply(simp add: dec_inv_1.simps dec_inv_2.simps)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4575
apply(case_tac n, auto)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4576
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4577
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4578
lemma [simp]: "am \<noteq> [] \<Longrightarrow>  \<exists>r'. <am::nat list> = Oc # r'"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4579
apply(case_tac am, simp, case_tac list)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4580
apply(auto simp: tape_of_nl_abv tape_of_nat_list.simps )
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4581
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4582
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4583
lemma [simp]: "start_of (layout_of aprog) as > 0 \<Longrightarrow> 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4584
      (fetch (ci (layout_of aprog) 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4585
           (start_of (layout_of aprog) as) (Dec n e)) (Suc 0)  Bk)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4586
    = (W1, start_of (layout_of aprog) as)"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4587
apply(auto simp: ci.simps findnth.simps fetch.simps
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4588
             nth_of.simps tshift.simps nth_append Suc_pre tdec_b_def)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4589
thm findnth_nth
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4590
apply(insert findnth_nth[of 0 n 0], simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4591
apply(simp add: findnth.simps)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4592
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4593
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4594
lemma [simp]:
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4595
    "start_of (layout_of aprog) as > 0
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4596
   \<Longrightarrow> (t_step (start_of (layout_of aprog) as, Bk # Bk # ires, Bk\<^bsup>rn\<^esup>)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4597
    (ci (layout_of aprog) (start_of (layout_of aprog) as) (Dec n e), 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4598
                             start_of (layout_of aprog) as - Suc 0))
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4599
   = (start_of (layout_of aprog) as, Bk # Bk # ires, Oc # Bk\<^bsup>rn- Suc 0\<^esup>)"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4600
apply(simp add: t_step.simps)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4601
apply(case_tac "start_of (layout_of aprog) as",
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4602
      auto simp: new_tape.simps)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4603
apply(case_tac rn, auto)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4604
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4605
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4606
lemma [simp]: "start_of (layout_of aprog) as > 0 \<Longrightarrow> 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4607
 (fetch (ci (layout_of aprog) (start_of (layout_of aprog) as) 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4608
         (Dec n e)) (Suc 0)  Oc)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4609
  = (R, Suc (start_of (layout_of aprog) as))"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4610
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4611
apply(auto simp: ci.simps findnth.simps fetch.simps
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4612
                 nth_of.simps tshift.simps nth_append 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4613
                 Suc_pre tdec_b_def)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4614
apply(insert findnth_nth[of 0 n "Suc 0"], simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4615
apply(simp add: findnth.simps)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4616
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4617
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4618
lemma [simp]: "start_of (layout_of aprog) as > 0 \<Longrightarrow> 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4619
 (t_step (start_of (layout_of aprog) as, Bk # Bk # ires, Oc # Bk\<^bsup>rn - Suc 0\<^esup>)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4620
     (ci (layout_of aprog) (start_of (layout_of aprog) as) (Dec n e), 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4621
        start_of (layout_of aprog) as - Suc 0)) =
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4622
  (Suc (start_of (layout_of aprog) as), Oc # Bk # Bk # ires, Bk\<^bsup>rn-Suc 0\<^esup>)"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4623
apply(simp add: t_step.simps)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4624
apply(case_tac "start_of (layout_of aprog) as", 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4625
      auto simp: new_tape.simps)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4626
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4627
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4628
lemma [simp]: "start_of (layout_of aprog) as > 0 \<Longrightarrow> 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4629
 t_step (start_of (layout_of aprog) as, Bk # Bk # ires, Oc # r' @ Bk\<^bsup>rn\<^esup>) 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4630
      (ci (layout_of aprog) (start_of (layout_of aprog) as) (Dec n e),
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4631
                 start_of (layout_of aprog) as - Suc 0) =
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4632
      (Suc (start_of (layout_of aprog) as), Oc # Bk # Bk # ires, r' @ Bk\<^bsup>rn\<^esup>)"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4633
apply(simp add: t_step.simps)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4634
apply(case_tac "start_of (layout_of aprog) as", 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4635
      auto simp: new_tape.simps)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4636
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4637
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4638
lemma crsp_next_state:
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4639
  "\<lbrakk>crsp_l (layout_of aprog) (as, am) tc ires; 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4640
    abc_fetch as aprog = Some (Dec n e)\<rbrakk>
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4641
  \<Longrightarrow> \<exists> stp' > 0. (\<lambda> (s, l, r). 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4642
           (s = Suc (start_of (layout_of aprog) as) 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4643
 \<and> (dec_inv_1 (layout_of aprog) n e (as, am) (s, l, r) ires) 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4644
 \<and> (dec_inv_2 (layout_of aprog) n e (as, am) (s, l, r)) ires)) 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4645
     (t_steps tc (ci (layout_of aprog) (start_of (layout_of aprog) as)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4646
             (Dec n e), start_of (layout_of aprog) as - Suc 0) stp')"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4647
apply(subgoal_tac "start_of (layout_of aprog) as > 0")
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4648
apply(case_tac tc, case_tac b, auto simp: crsp_l.simps)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4649
apply(case_tac "am = []", simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4650
apply(rule_tac x = "Suc (Suc 0)" in exI, simp add: t_steps.simps)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4651
proof-
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4652
  fix  rn
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4653
  assume h1: "am \<noteq> []" "abc_fetch as aprog = Some (Dec n e)" 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4654
             "start_of (layout_of aprog) as > 0"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4655
  hence h2: "\<exists> r'. <am> = Oc # r'"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4656
    by simp
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4657
  from h1 and h2 show 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4658
   "\<exists>stp'>0. case t_steps (start_of (layout_of aprog) as, Bk # Bk # ires, <am> @ Bk\<^bsup>rn\<^esup>)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4659
    (ci (layout_of aprog) (start_of (layout_of aprog) as) (Dec n e),
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4660
    start_of (layout_of aprog) as - Suc 0) stp' of
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4661
    (s, ab) \<Rightarrow> s = Suc (start_of (layout_of aprog) as) \<and>
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4662
    dec_inv_1 (layout_of aprog) n e (as, am) (s, ab) ires \<and> 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4663
    dec_inv_2 (layout_of aprog) n e (as, am) (s, ab) ires"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4664
  proof(erule_tac exE, simp, rule_tac x = "Suc 0" in exI, 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4665
        simp add: t_steps.simps)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4666
  qed
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4667
next
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4668
  assume "abc_fetch as aprog = Some (Dec n e)"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4669
  thus "0 < start_of (layout_of aprog) as"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4670
   apply(insert startof_not0[of "layout_of aprog" as], simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4671
   done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4672
qed
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4673
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4674
lemma dec_crsp_ex1: 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4675
  "\<lbrakk>crsp_l (layout_of aprog) (as, am) tc ires;
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4676
  abc_fetch as aprog = Some (Dec n e); 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4677
  abc_lm_v am n = 0\<rbrakk>
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4678
  \<Longrightarrow> \<exists>stp > 0. crsp_l (layout_of aprog) (e, abc_lm_s am n 0) 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4679
    (t_steps tc (ci (layout_of aprog) (start_of (layout_of aprog) as)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4680
 (Dec n e), start_of (layout_of aprog) as - Suc 0) stp) ires"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4681
proof -
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4682
  assume h1: "crsp_l (layout_of aprog) (as, am) tc ires" 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4683
       "abc_fetch as aprog = Some (Dec n e)" "abc_lm_v am n = 0"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4684
  hence h2: "\<exists> stp' > 0. (\<lambda> (s, l, r). 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4685
    (s = Suc (start_of (layout_of aprog) as) \<and> 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4686
 (dec_inv_1 (layout_of aprog) n e (as, am) (s, l, r)) ires)) 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4687
   (t_steps tc (ci (layout_of aprog) (start_of (layout_of aprog) as) 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4688
      (Dec n e), start_of (layout_of aprog) as - Suc 0) stp')"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4689
    apply(insert crsp_next_state[of aprog as am tc ires n e], auto)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4690
    done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4691
  from h1 and h2 show 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4692
 "\<exists>stp > 0. crsp_l (layout_of aprog) (e, abc_lm_s am n 0) 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4693
           (t_steps tc (ci (layout_of aprog) (start_of 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4694
                (layout_of aprog) as) (Dec n e), 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4695
                    start_of (layout_of aprog) as - Suc 0) stp) ires" 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4696
  proof(erule_tac exE, case_tac "(t_steps tc (ci (layout_of aprog)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4697
       (start_of (layout_of aprog) as) (Dec n e), start_of 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4698
          (layout_of aprog) as - Suc 0) stp')",  simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4699
    fix stp' a b c
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4700
    assume h3: "stp' > 0 \<and> a = Suc (start_of (layout_of aprog) as) \<and> 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4701
               dec_inv_1 (layout_of aprog) n e (as, am) (a, b, c) ires" 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4702
             "abc_fetch as aprog = Some (Dec n e)" "abc_lm_v am n = 0"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4703
     "t_steps tc (ci (layout_of aprog) (start_of (layout_of aprog) as)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4704
          (Dec n e), start_of (layout_of aprog) as - Suc 0) stp' 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4705
        = (Suc (start_of (layout_of aprog) as), b, c)" 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4706
    thus "\<exists>stp > 0. crsp_l (layout_of aprog) (e, abc_lm_s am n 0) 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4707
     (t_steps tc (ci (layout_of aprog) (start_of (layout_of aprog) as)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4708
           (Dec n e), start_of (layout_of aprog) as - Suc 0) stp) ires"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4709
    proof(erule_tac conjE, simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4710
      assume "dec_inv_1 (layout_of aprog) n e (as, am) 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4711
                    (Suc (start_of (layout_of aprog) as), b, c) ires"     
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4712
             "abc_fetch as aprog = Some (Dec n e)" 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4713
             "abc_lm_v am n = 0"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4714
             " t_steps tc (ci (layout_of aprog) 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4715
              (start_of (layout_of aprog) as) (Dec n e), 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4716
               start_of (layout_of aprog) as - Suc 0) stp' 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4717
             = (Suc (start_of (layout_of aprog) as), b, c)"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4718
      hence h4: "\<exists>stp. (\<lambda>(s', l', r'). s' = 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4719
                     start_of (layout_of aprog) e \<and> 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4720
                dec_inv_1 (layout_of aprog) n e (as, am) (s', l', r') ires)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4721
                 (t_steps (start_of (layout_of aprog) as + 1, b, c) 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4722
                  (ci (layout_of aprog) 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4723
                      (start_of (layout_of aprog) as) (Dec n e), 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4724
                         start_of (layout_of aprog) as - Suc 0) stp)"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4725
	apply(rule_tac dec_inv_stop1, auto)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4726
	done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4727
      from  h3 and h4 show ?thesis
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4728
	apply(erule_tac exE)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4729
	apply(rule_tac x = "stp' + stp" in exI, simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4730
	apply(case_tac "(t_steps (Suc (start_of (layout_of aprog) as),
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4731
                     b, c) (ci (layout_of aprog) 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4732
                     (start_of (layout_of aprog) as) (Dec n e), 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4733
                      start_of (layout_of aprog) as - Suc 0) stp)", 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4734
              simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4735
	apply(rule_tac dec_inv_stop_cond1, auto)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4736
	done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4737
    qed
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4738
  qed
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4739
qed
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4740
	  
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4741
lemma dec_crsp_ex2:
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4742
  "\<lbrakk>crsp_l (layout_of aprog) (as, am) tc ires; 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4743
    abc_fetch as aprog = Some (Dec n e);
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4744
    0 < abc_lm_v am n\<rbrakk>
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4745
 \<Longrightarrow> \<exists>stp > 0. crsp_l (layout_of aprog) 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4746
               (Suc as, abc_lm_s am n (abc_lm_v am n - Suc 0))
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4747
   (t_steps tc (ci (layout_of aprog) (start_of (layout_of aprog) as) 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4748
              (Dec n e), start_of (layout_of aprog) as - Suc 0) stp) ires"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4749
proof -
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4750
  assume h1: 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4751
 "crsp_l (layout_of aprog) (as, am) tc ires" 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4752
 "abc_fetch as aprog = Some (Dec n e)"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4753
  "abc_lm_v am n > 0"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4754
  hence h2: 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4755
 "\<exists> stp' > 0. (\<lambda> (s, l, r). (s = Suc (start_of (layout_of aprog) as)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4756
 \<and> (dec_inv_2 (layout_of aprog) n e (as, am) (s, l, r)) ires)) 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4757
(t_steps tc (ci (layout_of aprog) (start_of (layout_of aprog) as) 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4758
              (Dec n e), start_of (layout_of aprog) as - Suc 0) stp')"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4759
    apply(insert crsp_next_state[of aprog as am tc ires n e], auto)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4760
    done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4761
  from h1 and h2 show 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4762
 "\<exists>stp >0. crsp_l (layout_of aprog) 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4763
   (Suc as, abc_lm_s am n (abc_lm_v am n - Suc 0))
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4764
   (t_steps tc (ci (layout_of aprog) (start_of (layout_of aprog) as) 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4765
               (Dec n e), start_of (layout_of aprog) as - Suc 0) stp) ires"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4766
  proof(erule_tac exE, 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4767
        case_tac 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4768
 "(t_steps tc (ci (layout_of aprog) (start_of (layout_of aprog) as) 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4769
      (Dec n e), start_of (layout_of aprog) as - Suc 0) stp')",  simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4770
    fix stp' a b c
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4771
    assume h3: "0 < stp' \<and> a = Suc (start_of (layout_of aprog) as) \<and>
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4772
               dec_inv_2 (layout_of aprog) n e (as, am) (a, b, c) ires" 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4773
               "abc_fetch as aprog = Some (Dec n e)" 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4774
               "abc_lm_v am n > 0"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4775
               "t_steps tc (ci (layout_of aprog) 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4776
                   (start_of (layout_of aprog) as) (Dec n e), 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4777
                     start_of (layout_of aprog) as - Suc 0) stp' 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4778
                  = (Suc (start_of (layout_of aprog) as), b, c)"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4779
    thus "?thesis"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4780
    proof(erule_tac conjE, simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4781
      assume 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4782
    "dec_inv_2 (layout_of aprog) n e (as, am) 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4783
      (Suc (start_of (layout_of aprog) as), b, c) ires" 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4784
    "abc_fetch as aprog = Some (Dec n e)" "abc_lm_v am n > 0"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4785
    "t_steps tc (ci (layout_of aprog) (start_of (layout_of aprog) as)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4786
         (Dec n e), start_of (layout_of aprog) as - Suc 0) stp'
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4787
             = (Suc (start_of (layout_of aprog) as), b, c)"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4788
      hence h4: 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4789
   "\<exists>stp. (\<lambda>(s', l', r'). s' = start_of (layout_of aprog) (Suc as) \<and>
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4790
           dec_inv_2 (layout_of aprog) n e (as, am) (s', l', r') ires)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4791
             (t_steps (start_of (layout_of aprog) as + 1, b, c) 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4792
              (ci (layout_of aprog) (start_of (layout_of aprog) as) 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4793
               (Dec n e), start_of (layout_of aprog) as - Suc 0) stp)"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4794
	apply(rule_tac dec_stop2, auto)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4795
	done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4796
      from  h3 and h4 show ?thesis
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4797
	apply(erule_tac exE)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4798
	apply(rule_tac x = "stp' + stp" in exI, simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4799
	apply(case_tac 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4800
         "(t_steps (Suc (start_of (layout_of aprog) as), b, c) 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4801
           (ci (layout_of aprog) (start_of (layout_of aprog) as)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4802
             (Dec n e), start_of (layout_of aprog) as - Suc 0) stp)"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4803
              ,simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4804
	apply(rule_tac dec_inv_stop_cond2, auto)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4805
	done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4806
    qed
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4807
  qed
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4808
qed
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4809
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4810
lemma dec_crsp_ex_pre:
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4811
  "\<lbrakk>ly = layout_of aprog; crsp_l ly (as, am) tc ires; 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4812
     abc_fetch as aprog = Some (Dec n e)\<rbrakk>
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4813
 \<Longrightarrow> \<exists>stp > 0. crsp_l ly (abc_step_l (as, am) (Some (Dec n e))) 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4814
      (t_steps tc (ci (layout_of aprog) (start_of ly as) (Dec n e),
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4815
                                       start_of ly as - Suc 0) stp) ires"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4816
apply(auto simp: abc_step_l.simps intro: dec_crsp_ex2 dec_crsp_ex1)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4817
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4818
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4819
lemma dec_crsp_ex:
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4820
  assumes layout: -- {* There is an Abacus program @{text "aprog"} with layout @{text "ly"} *}
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4821
  "ly = layout_of aprog"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4822
  and dec: -- {* There is an @{text "Dec n e"} instruction at postion @{text "as"} of @{text "aprog"} *}
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4823
      "abc_fetch as aprog = Some (Dec n e)"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4824
  and correspond: 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4825
  -- {* Abacus configuration @{text "(as, am)"} is in correspondence with TM 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4826
         configuration @{text "tc"}
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4827
      *}
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4828
  "crsp_l ly (as, am) tc ires"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4829
shows 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4830
   "\<exists>stp > 0. crsp_l ly (abc_step_l (as, am) (Some (Dec n e))) 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4831
      (t_steps tc (ci (layout_of aprog) (start_of ly as) (Dec n e),
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4832
                                       start_of ly as - Suc 0) stp) ires"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4833
proof -
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4834
  from dec_crsp_ex_pre layout dec correspond  show ?thesis by blast
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4835
qed
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4836
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4837
(*
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4838
subsection {* Compilation of @{text "Goto n"}*}
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4839
*)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4840
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4841
lemma goto_fetch: 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4842
     "fetch (ci (layout_of aprog) 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4843
         (start_of (layout_of aprog) as) (Goto n)) (Suc 0)  b
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4844
     = (Nop, start_of (layout_of aprog) n)"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4845
apply(auto simp: ci.simps fetch.simps nth_of.simps 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4846
           split: block.splits)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4847
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4848
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4849
text {*
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4850
  Correctness of complied @{text "Goto n"}
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4851
  *}
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4852
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4853
lemma goto_crsp_ex_pre: 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4854
  "\<lbrakk>ly = layout_of aprog; 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4855
    crsp_l ly (as, am) tc ires;
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4856
    abc_fetch as aprog = Some (Goto n)\<rbrakk>
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4857
 \<Longrightarrow> \<exists>stp > 0. crsp_l ly (abc_step_l (as, am) (Some (Goto n))) 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4858
      (t_steps tc (ci (layout_of aprog) (start_of ly as) (Goto n), 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4859
                                        start_of ly as - Suc 0) stp) ires"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4860
apply(rule_tac x = 1 in exI)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4861
apply(simp add: abc_step_l.simps t_steps.simps t_step.simps)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4862
apply(case_tac tc, simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4863
apply(subgoal_tac "a = start_of (layout_of aprog) as", auto)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4864
apply(subgoal_tac "start_of (layout_of aprog) as > 0", simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4865
apply(auto simp: goto_fetch new_tape.simps crsp_l.simps)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4866
apply(rule startof_not0)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4867
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4868
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4869
lemma goto_crsp_ex:
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4870
  assumes layout: "ly = layout_of aprog"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4871
  and goto: "abc_fetch as aprog = Some (Goto n)"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4872
  and correspondence: "crsp_l ly (as, am) tc ires"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4873
  shows "\<exists>stp>0. crsp_l ly (abc_step_l (as, am) (Some (Goto n))) 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4874
              (t_steps tc (ci (layout_of aprog) (start_of ly as) (Goto n),
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4875
                                           start_of ly as - Suc 0) stp) ires"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4876
proof -
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4877
  from goto_crsp_ex_pre and layout goto correspondence show "?thesis" by blast
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4878
qed
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4879
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4880
subsection {*
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4881
  The correctness of the compiler
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4882
  *}
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4883
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4884
declare abc_step_l.simps[simp del]
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4885
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4886
lemma tm_crsp_ex: 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4887
         "\<lbrakk>ly = layout_of aprog;
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4888
           crsp_l ly (as, am) tc ires; 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4889
           as < length aprog;
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4890
           abc_fetch as aprog = Some ins\<rbrakk>
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4891
      \<Longrightarrow> \<exists> n > 0. crsp_l ly (abc_step_l (as,am) (Some ins))
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4892
               (t_steps tc (ci (layout_of aprog) (start_of ly as) 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4893
                  (ins), (start_of ly as) - (Suc 0)) n) ires"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4894
apply(case_tac "ins", simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4895
apply(auto intro: inc_crsp_ex_pre dec_crsp_ex goto_crsp_ex)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4896
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4897
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4898
lemma start_of_pre: 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4899
  "n < length aprog \<Longrightarrow> start_of (layout_of aprog) n
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4900
                     = start_of (layout_of (butlast aprog)) n"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4901
apply(induct n, simp add: start_of.simps, simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4902
apply(simp add: layout_of.simps start_of.simps)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4903
apply(subgoal_tac "n < length aprog - Suc 0", simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4904
apply(subgoal_tac "(aprog ! n) = (butlast aprog ! n)", simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4905
proof -
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4906
  fix n
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4907
  assume h1: "Suc n < length aprog"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4908
  thus "aprog ! n = butlast aprog ! n"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4909
    apply(case_tac "length aprog", simp, simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4910
    apply(insert nth_append[of "butlast aprog" "[last aprog]" n])
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4911
    apply(subgoal_tac "(butlast aprog @ [last aprog]) = aprog")
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4912
    apply(simp split: if_splits)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4913
    apply(rule append_butlast_last_id, case_tac aprog, simp, simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4914
    done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4915
next
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4916
  fix n
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4917
  assume "Suc n < length aprog"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4918
  thus "n < length aprog - Suc 0"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4919
    apply(case_tac aprog, simp, simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4920
    done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4921
qed
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4922
    
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4923
lemma zip_eq: "xs = ys \<Longrightarrow> zip xs zs = zip ys zs"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4924
by simp
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4925
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4926
lemma tpairs_of_append_iff: "length aprog = Suc n \<Longrightarrow> 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4927
         tpairs_of aprog = tpairs_of (butlast aprog) @ 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4928
                     [(start_of (layout_of aprog) n, aprog ! n)]"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4929
apply(simp add: tpairs_of.simps)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4930
apply(insert zip_append[of "map (start_of (layout_of aprog)) [0..<n]"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4931
     "butlast aprog" "[start_of (layout_of aprog) n]" "[last aprog]"])
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4932
apply(simp del: zip_append)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4933
apply(subgoal_tac "(butlast aprog @ [last aprog]) = aprog", auto)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4934
apply(rule_tac zip_eq, auto)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4935
apply(rule_tac start_of_pre, simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4936
apply(insert last_conv_nth[of aprog], case_tac aprog, simp, simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4937
apply(rule append_butlast_last_id, case_tac aprog, simp, simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4938
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4939
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4940
lemma [simp]: "list_all (\<lambda>(n, tm). abacus.t_ncorrect (ci layout n tm))
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4941
         (zip (map (start_of layout) [0..<length aprog]) aprog)"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4942
proof(induct "length aprog" arbitrary: aprog, simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4943
  fix x aprog
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4944
  assume ind: "\<And>aprog. x = length aprog \<Longrightarrow> 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4945
        list_all (\<lambda>(n, tm). abacus.t_ncorrect (ci layout n tm))
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4946
           (zip (map (start_of layout) [0..<length aprog]) aprog)"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4947
  and h: "Suc x = length (aprog::abc_inst list)"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4948
  have g1: "list_all (\<lambda>(n, tm). abacus.t_ncorrect (ci layout n tm)) 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4949
    (zip (map (start_of layout) [0..<length (butlast aprog)]) 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4950
                                                 (butlast aprog))"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4951
    using h
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4952
    apply(rule_tac ind, auto)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4953
    done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4954
  have g2: "(map (start_of layout) [0..<length aprog]) = 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4955
                     map (start_of layout) ([0..<length aprog - 1] 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4956
         @ [length aprog - 1])"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4957
    using h
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4958
    apply(case_tac aprog, simp, simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4959
    done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4960
  have "\<exists> xs a. aprog = xs @ [a]"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4961
    using h
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4962
    apply(rule_tac x = "butlast aprog" in exI, 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4963
          rule_tac x = "last aprog" in exI)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4964
    apply(case_tac "aprog = []", simp, simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4965
    done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4966
  from this obtain xs where "\<exists> a. aprog = xs @ [a]" ..
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4967
  from this obtain a where g3: "aprog = xs @ [a]" ..
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4968
  from g1 and g2 and g3 show "list_all (\<lambda>(n, tm). 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4969
                              abacus.t_ncorrect (ci layout n tm)) 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4970
              (zip (map (start_of layout) [0..<length aprog]) aprog)"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4971
    apply(simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4972
    apply(auto simp: t_ncorrect.simps ci.simps  tshift.simps 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4973
          tinc_b_def tdec_b_def split: abc_inst.splits)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4974
    apply arith+
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4975
    done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4976
qed
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4977
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4978
lemma [intro]: "abc2t_correct aprog"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4979
apply(simp add: abc2t_correct.simps tpairs_of.simps 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4980
          split: abc_inst.splits)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4981
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4982
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4983
lemma as_out: "\<lbrakk>ly = layout_of aprog; tprog = tm_of aprog; 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4984
                crsp_l ly (as, am) tc ires; length aprog \<le> as\<rbrakk> 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4985
            \<Longrightarrow> abc_step_l (as, am) (abc_fetch as aprog) = (as, am)"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4986
apply(simp add: abc_fetch.simps abc_step_l.simps)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4987
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4988
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4989
lemma tm_merge_ex: 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4990
  "\<lbrakk>crsp_l (layout_of aprog) (as, am) tc ires; 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4991
    as < length aprog; 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4992
    abc_fetch as aprog = Some a; 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4993
    abc2t_correct aprog;
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4994
    crsp_l (layout_of aprog) (abc_step_l (as, am) (Some a))
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4995
     (t_steps tc (ci (layout_of aprog) (start_of (layout_of aprog) as)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4996
         a, start_of (layout_of aprog) as - Suc 0) n) ires; 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4997
    n > 0\<rbrakk>
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4998
   \<Longrightarrow> \<exists>stp > 0. crsp_l (layout_of aprog) (abc_step_l (as, am) 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4999
                       (Some a)) (t_steps tc (tm_of aprog, 0) stp) ires"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5000
apply(case_tac "(t_steps tc (ci (layout_of aprog) 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5001
           (start_of (layout_of aprog) as) a, 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5002
            start_of (layout_of aprog) as - Suc 0) n)",  simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5003
apply(case_tac "(abc_step_l (as, am) (Some a))", simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5004
proof -
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5005
  fix aa b c aaa ba 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5006
  assume h: 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5007
  "crsp_l (layout_of aprog) (as, am) tc ires" 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5008
  "as < length aprog" 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5009
  "abc_fetch as aprog = Some a" 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5010
  "crsp_l (layout_of aprog) (aaa, ba) (aa, b, c) ires" 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5011
  "abc2t_correct aprog" 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5012
  "n>0"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5013
  "t_steps tc (ci (layout_of aprog) (start_of (layout_of aprog) as) a,
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5014
      start_of (layout_of aprog) as - Suc 0) n = (aa, b, c)" 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5015
   "abc_step_l (as, am) (Some a) = (aaa, ba)"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5016
  hence "aa = start_of (layout_of aprog) aaa"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5017
    apply(simp add: crsp_l.simps)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5018
    done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5019
  from this and h show 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5020
  "\<exists>stp > 0. crsp_l (layout_of aprog) (aaa, ba) 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5021
                          (t_steps tc (tm_of aprog, 0) stp) ires"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5022
    apply(insert tms_out_ex[of "layout_of aprog" aprog 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5023
                "tm_of aprog" as am tc ires a n aa b c aaa ba], auto)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5024
    done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5025
qed
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5026
 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5027
lemma crsp_inside: 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5028
  "\<lbrakk>ly = layout_of aprog; 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5029
    tprog = tm_of aprog;
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5030
    crsp_l ly (as, am) tc ires;
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5031
    as < length aprog\<rbrakk> \<Longrightarrow> 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5032
    (\<exists> stp > 0. crsp_l ly (abc_step_l (as,am) (abc_fetch as aprog)) 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5033
                                         (t_steps tc (tprog, 0) stp) ires)"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5034
apply(case_tac "abc_fetch as aprog", simp add: abc_fetch.simps)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5035
proof -
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5036
  fix a
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5037
  assume "ly = layout_of aprog" 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5038
     "tprog = tm_of aprog" 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5039
     "crsp_l ly (as, am) tc ires" 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5040
     "as < length aprog" 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5041
     "abc_fetch as aprog = Some a"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5042
  thus "\<exists>stp > 0. crsp_l ly (abc_step_l (as, am) 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5043
                 (abc_fetch as aprog)) (t_steps tc (tprog, 0) stp) ires"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5044
    proof(insert tm_crsp_ex[of ly aprog as am tc ires a], 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5045
          auto intro: tm_merge_ex)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5046
  qed
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5047
qed
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5048
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5049
lemma crsp_outside: 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5050
  "\<lbrakk>ly = layout_of aprog; tprog = tm_of aprog;
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5051
    crsp_l ly (as, am) tc ires; as \<ge> length aprog\<rbrakk>
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5052
    \<Longrightarrow> (\<exists> stp. crsp_l ly (abc_step_l (as,am) (abc_fetch as aprog)) 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5053
                                         (t_steps tc (tprog, 0) stp) ires)"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5054
apply(subgoal_tac "abc_step_l (as, am) (abc_fetch as aprog)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5055
                = (as, am)", simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5056
apply(rule_tac x = 0 in exI, simp add: t_steps.simps)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5057
apply(rule as_out, simp+)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5058
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5059
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5060
text {*
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5061
  Single-step correntess of the compiler.
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5062
*}
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5063
lemma astep_crsp_pre: 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5064
      "\<lbrakk>ly = layout_of aprog; 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5065
        tprog = tm_of aprog;
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5066
        crsp_l ly (as, am) tc ires\<rbrakk>
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5067
       \<Longrightarrow> (\<exists> stp. crsp_l ly (abc_step_l (as,am) 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5068
                  (abc_fetch as aprog)) (t_steps tc (tprog, 0) stp) ires)"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5069
apply(case_tac "as < length aprog")
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5070
apply(drule_tac crsp_inside, auto)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5071
apply(rule_tac crsp_outside, simp+)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5072
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5073
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5074
text {*
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5075
  Single-step correntess of the compiler.
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5076
*}
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5077
lemma astep_crsp_pre1: 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5078
      "\<lbrakk>ly = layout_of aprog;
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5079
        tprog = tm_of aprog;
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5080
        crsp_l ly (as, am) tc ires\<rbrakk>
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5081
       \<Longrightarrow> (\<exists> stp. crsp_l ly (abc_step_l (as,am) 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5082
                  (abc_fetch as aprog)) (t_steps tc (tprog, 0) stp) ires)"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5083
apply(case_tac "as < length aprog")
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5084
apply(drule_tac crsp_inside, auto)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5085
apply(rule_tac crsp_outside, simp+)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5086
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5087
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5088
lemma astep_crsp:
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5089
  assumes layout: 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5090
  -- {* There is a Abacus program @{text "aprog"} with layout @{text "ly"} *}
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5091
  "ly = layout_of aprog"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5092
  and compiled: 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5093
  -- {* @{text "tprog"} is the TM compiled from @{text "aprog"} *}
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5094
  "tprog = tm_of aprog"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5095
  and corresponds: 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5096
  -- {* Abacus configuration @{text "(as, am)"} is in correspondence with TM configuration
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5097
   @{text "tc"} *}
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5098
  "crsp_l ly (as, am) tc ires"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5099
  -- {* One step execution of @{text "aprog"} can be simulated by multi-step execution 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5100
  of @{text "tprog"} *}
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5101
  shows "(\<exists> stp. crsp_l ly (abc_step_l (as,am) 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5102
                  (abc_fetch as aprog)) (t_steps tc (tprog, 0) stp) ires)"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5103
proof -
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5104
  from astep_crsp_pre1 [OF layout compiled corresponds] show ?thesis .
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5105
qed
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5106
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5107
lemma steps_crsp_pre: 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5108
    "\<lbrakk>ly = layout_of aprog; tprog = tm_of aprog; 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5109
      crsp_l ly ac tc ires; ac' = abc_steps_l ac aprog n\<rbrakk> \<Longrightarrow> 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5110
        (\<exists> n'. crsp_l ly ac' (t_steps tc (tprog, 0) n') ires)"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5111
apply(induct n arbitrary: ac' ac tc, simp add: abc_steps_l.simps)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5112
apply(rule_tac x = 0 in exI)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5113
apply(case_tac ac, simp add: abc_steps_l.simps t_steps.simps)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5114
apply(case_tac ac, simp add: abc_steps_l.simps)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5115
apply(subgoal_tac 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5116
   "(\<exists> stp. crsp_l ly (abc_step_l (a, b)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5117
            (abc_fetch a aprog)) (t_steps tc (tprog, 0) stp) ires)")
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5118
apply(erule exE)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5119
apply(subgoal_tac 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5120
   "\<exists>n'. crsp_l (layout_of aprog) 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5121
    (abc_steps_l (abc_step_l (a, b) (abc_fetch a aprog)) aprog n)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5122
         (t_steps ((t_steps tc (tprog, 0) stp)) (tm_of aprog, 0) n') ires")
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5123
apply(erule exE)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5124
apply(subgoal_tac 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5125
    "t_steps (t_steps tc (tprog, 0) stp) (tm_of aprog, 0) n' =
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5126
     t_steps tc (tprog, 0) (stp + n')")
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5127
apply(rule_tac x = "stp + n'" in exI, simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5128
apply(auto intro: astep_crsp simp: t_step_add)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5129
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5130
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5131
text {*
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5132
  Multi-step correctess of the compiler.
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5133
*}
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5134
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5135
lemma steps_crsp: 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5136
  assumes layout: 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5137
  -- {* There is an Abacus program @{text "aprog"} with layout @{text "ly"} *}
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5138
    "ly = layout_of aprog"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5139
  and compiled: 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5140
  -- {* @{text "tprog"} is the TM compiled from @{text "aprog"} *}
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5141
  "tprog = tm_of aprog"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5142
  and correspond: 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5143
  -- {* Abacus configuration @{text "ac"} is in correspondence with TM configuration @{text "tc"} *}
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5144
      "crsp_l ly ac tc ires"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5145
  and execution: 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5146
  -- {* @{text "ac'"} is the configuration obtained from @{text "n"}-step execution 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5147
      of @{text "aprog"} starting from configuration @{text "ac"} *}
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5148
  "ac' = abc_steps_l ac aprog n" 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5149
  -- {* There exists steps @{text "n'"} steps, after these steps of execution, 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5150
  the Turing configuration such obtained is in correspondence with @{text "ac'"} *}
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5151
  shows "(\<exists> n'. crsp_l ly ac' (t_steps tc (tprog, 0) n') ires)"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5152
proof -
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5153
  from steps_crsp_pre [OF layout compiled correspond execution] show ?thesis .
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5154
qed
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5155
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5156
subsection {* The Mop-up machine *}
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5157
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5158
fun mop_bef :: "nat \<Rightarrow> tprog"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5159
  where
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5160
  "mop_bef 0 = []" |
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5161
  "mop_bef (Suc n) = mop_bef n @ 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5162
       [(R, 2*n + 3), (W0, 2*n + 2), (R, 2*n + 1), (W1, 2*n + 2)]"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5163
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5164
definition mp_up :: "tprog"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5165
  where
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5166
  "mp_up \<equiv> [(R, 2), (R, 1), (L, 5), (W0, 3), (R, 4), (W0, 3),
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5167
            (R, 2), (W0, 3), (L, 5), (L, 6), (R, 0), (L, 6)]"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5168
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5169
fun tMp :: "nat \<Rightarrow> nat \<Rightarrow> tprog"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5170
  where 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5171
  "tMp n off = tshift (mop_bef n @ tshift mp_up (2*n)) off"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5172
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5173
declare  mp_up_def[simp del]  tMp.simps[simp del] mop_bef.simps[simp del]
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5174
(**********Begin: equiv among aba and turing***********)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5175
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5176
lemma tm_append_step: 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5177
 "\<lbrakk>t_ncorrect tp1; t_step tc (tp1, 0) = (s, l, r); s \<noteq> 0\<rbrakk> 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5178
 \<Longrightarrow> t_step tc (tp1 @ tp2, 0) = (s, l, r)"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5179
apply(simp add: t_step.simps)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5180
apply(case_tac tc, simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5181
apply(case_tac 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5182
       "(fetch tp1 a (case c of [] \<Rightarrow> Bk |
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5183
               Bk # xs \<Rightarrow> Bk | Oc # xs \<Rightarrow> Oc))", simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5184
apply(case_tac a, simp add: fetch.simps)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5185
apply(simp add: fetch.simps)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5186
apply(case_tac c, simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5187
apply(case_tac [!] "ab::block")
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5188
apply(auto simp: nth_of.simps nth_append t_ncorrect.simps 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5189
           split: if_splits)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5190
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5191
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5192
lemma state0_ind: "t_steps (0, l, r) (tp, 0) stp = (0, l, r)"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5193
apply(induct stp, simp add: t_steps.simps)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5194
apply(simp add: t_steps.simps t_step.simps fetch.simps new_tape.simps)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5195
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5196
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5197
lemma tm_append_steps:  
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5198
 "\<lbrakk>t_ncorrect tp1; t_steps tc (tp1, 0) stp = (s, l ,r); s \<noteq> 0\<rbrakk>
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5199
  \<Longrightarrow> t_steps tc (tp1 @ tp2, 0) stp = (s, l, r)"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5200
apply(induct stp arbitrary: tc s l r)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5201
apply(case_tac tc,  simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5202
apply(simp add: t_steps.simps)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5203
proof -
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5204
  fix stp tc s l r
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5205
  assume h1: "\<And>tc s l r. \<lbrakk>t_ncorrect tp1; t_steps tc (tp1, 0) stp = 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5206
   (s, l, r); s \<noteq> 0\<rbrakk> \<Longrightarrow> t_steps tc (tp1 @ tp2, 0) stp = (s, l, r)"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5207
    and h2: "t_steps tc (tp1, 0) (Suc stp) = (s, l, r)" "s \<noteq> 0" 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5208
            "t_ncorrect tp1"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5209
  thus "t_steps tc (tp1 @ tp2, 0) (Suc stp) = (s, l, r)"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5210
    apply(simp add: t_steps.simps)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5211
    apply(case_tac "(t_step tc (tp1, 0))", simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5212
    proof-
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5213
      fix a b c 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5214
      assume g1: "\<And>tc s l r. \<lbrakk>t_steps tc (tp1, 0) stp = (s, l, r); 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5215
                0 < s\<rbrakk> \<Longrightarrow> t_steps tc (tp1 @ tp2, 0) stp = (s, l, r)"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5216
	and g2: "t_step tc (tp1, 0) = (a, b, c)" 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5217
                "t_steps (a, b, c) (tp1, 0) stp = (s, l, r)" 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5218
                "0 < s" 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5219
                "t_ncorrect tp1"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5220
      hence g3: "a > 0"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5221
	apply(case_tac "a::nat", auto simp: t_steps.simps)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5222
	apply(simp add: state0_ind)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5223
	done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5224
      from g1 and g2 and this have g4: 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5225
                    "(t_step tc (tp1 @ tp2, 0)) = (a, b, c)"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5226
	apply(rule_tac tm_append_step, simp, simp, simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5227
	done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5228
      from g1 and g2 and g3 and g4 show 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5229
          "t_steps (t_step tc (tp1 @ tp2, 0)) (tp1 @ tp2, 0) stp
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5230
                                                         = (s, l, r)"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5231
	apply(simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5232
	done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5233
    qed
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5234
qed
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5235
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5236
lemma shift_fetch: 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5237
 "\<lbrakk>n < length tp; 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5238
  (tp:: (taction \<times> nat) list) ! n = (aa, ba);
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5239
   ba \<noteq> 0\<rbrakk> 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5240
   \<Longrightarrow> (tshift tp (length tp div 2)) ! n = 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5241
                     (aa , ba + length tp div 2)"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5242
apply(simp add: tshift.simps)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5243
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5244
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5245
lemma tshift_length_equal: "length (tshift tp q) = length tp"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5246
apply(auto simp: tshift.simps)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5247
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5248
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5249
thm nth_of.simps
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5250
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5251
lemma [simp]: "t_ncorrect tp \<Longrightarrow> 2 * (length tp div 2) = length tp"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5252
apply(auto simp: t_ncorrect.simps)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5253
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5254
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5255
lemma  tm_append_step_equal': 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5256
   "\<lbrakk>t_ncorrect tp; t_ncorrect tp'; off = length tp div 2\<rbrakk> \<Longrightarrow> 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5257
    (\<lambda> (s, l, r). ((\<lambda> (s', l', r'). 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5258
      (s'\<noteq> 0 \<longrightarrow> (s = s' + off \<and> l = l' \<and> r = r'))) 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5259
         (t_step (a, b, c) (tp', 0))))
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5260
               (t_step (a + off, b, c) (tp @ tshift tp' off, 0))"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5261
apply(simp add: t_step.simps)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5262
apply(case_tac a, simp add: fetch.simps)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5263
apply(case_tac 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5264
"(fetch tp' a (case c of [] \<Rightarrow> Bk | Bk # xs \<Rightarrow> Bk | Oc # xs \<Rightarrow> Oc))",
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5265
 simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5266
apply(case_tac 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5267
"(fetch (tp @ tshift tp' (length tp div 2))
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5268
        (Suc (nat + length tp div 2)) 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5269
           (case c of [] \<Rightarrow> Bk | Bk # xs \<Rightarrow> Bk | Oc # xs \<Rightarrow> Oc))", 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5270
 simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5271
apply(case_tac "(new_tape aa (b, c))",
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5272
      case_tac "(new_tape aaa (b, c))", simp, 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5273
      rule impI, simp add: fetch.simps split: block.splits option.splits)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5274
apply (auto simp: nth_of.simps t_ncorrect.simps 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5275
                      nth_append tshift_length_equal tshift.simps split: if_splits)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5276
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5277
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5278
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5279
lemma  tm_append_step_equal: 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5280
 "\<lbrakk>t_ncorrect tp; t_ncorrect tp'; off = length tp div 2; 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5281
   t_step (a, b, c) (tp', 0) = (aa, ab, bb);  aa \<noteq> 0\<rbrakk>
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5282
 \<Longrightarrow> t_step (a + length tp div 2, b, c) 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5283
        (tp @ tshift tp' (length tp div 2), 0)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5284
                          = (aa + length tp div 2, ab, bb)"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5285
apply(insert tm_append_step_equal'[of tp tp' off a b c], simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5286
apply(case_tac "(t_step (a + length tp div 2, b, c) 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5287
                   (tp @ tshift tp' (length tp div 2), 0))", simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5288
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5289
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5290
lemma tm_append_steps_equal: 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5291
 "\<lbrakk>t_ncorrect tp; t_ncorrect tp'; off = length tp div 2\<rbrakk> \<Longrightarrow> 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5292
   (\<lambda> (s, l, r). ((\<lambda> (s', l', r'). ((s'\<noteq> 0 \<longrightarrow> s = s' + off \<and> l = l'
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5293
                     \<and> r = r'))) (t_steps (a, b, c) (tp', 0) stp)))
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5294
   (t_steps (a + off, b, c) (tp @ tshift tp' off, 0) stp)"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5295
apply(induct stp arbitrary : a b c, simp add: t_steps.simps)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5296
apply(simp add: t_steps.simps)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5297
apply(case_tac "(t_step (a, b, c) (tp', 0))", simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5298
apply(case_tac "aa = 0", simp add: state0_ind)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5299
apply(subgoal_tac "(t_step (a + length tp div 2, b, c) 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5300
                      (tp @ tshift tp' (length tp div 2), 0)) 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5301
  = (aa + length tp div 2, ba, ca)", simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5302
apply(rule tm_append_step_equal, auto)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5303
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5304
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5305
(*********Begin: mop_up***************)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5306
type_synonym mopup_type = "t_conf \<Rightarrow> nat list \<Rightarrow> nat \<Rightarrow> block list \<Rightarrow> bool"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5307
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5308
fun mopup_stop :: "mopup_type"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5309
  where
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5310
  "mopup_stop (s, l, r) lm n ires= 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5311
        (\<exists> ln rn. l = Bk\<^bsup>ln\<^esup> @ Bk # Bk # ires \<and> r = <abc_lm_v lm n> @ Bk\<^bsup>rn\<^esup>)"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5312
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5313
fun mopup_bef_erase_a :: "mopup_type"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5314
  where
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5315
  "mopup_bef_erase_a (s, l, r) lm n ires= 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5316
         (\<exists> ln m rn. l = Bk \<^bsup>ln\<^esup> @ Bk # Bk # ires \<and> 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5317
                  r = Oc\<^bsup>m \<^esup>@ Bk # <(drop ((s + 1) div 2) lm)> @ Bk\<^bsup>rn\<^esup>)"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5318
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5319
fun mopup_bef_erase_b :: "mopup_type"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5320
  where
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5321
  "mopup_bef_erase_b (s, l, r) lm n ires = 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5322
      (\<exists> ln m rn. l = Bk\<^bsup>ln\<^esup> @ Bk # Bk # ires \<and> r = Bk # Oc\<^bsup>m\<^esup> @ Bk # 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5323
                                      <(drop (s div 2) lm)> @ Bk\<^bsup>rn\<^esup>)"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5324
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5325
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5326
fun mopup_jump_over1 :: "mopup_type"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5327
  where
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5328
  "mopup_jump_over1 (s, l, r) lm n ires = 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5329
      (\<exists> ln m1 m2 rn. m1 + m2 = Suc (abc_lm_v lm n) \<and> 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5330
        l = Oc\<^bsup>m1\<^esup> @ Bk\<^bsup>ln\<^esup> @ Bk # Bk # ires \<and> 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5331
     (r = Oc\<^bsup>m2\<^esup> @ Bk # <(drop (Suc n) lm)> @ Bk\<^bsup>rn \<^esup>\<or> 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5332
     (r = Oc\<^bsup>m2\<^esup> \<and> (drop (Suc n) lm) = [])))"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5333
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5334
fun mopup_aft_erase_a :: "mopup_type"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5335
  where
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5336
  "mopup_aft_erase_a (s, l, r) lm n ires = 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5337
      (\<exists> lnl lnr rn (ml::nat list) m. 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5338
          m = Suc (abc_lm_v lm n) \<and> l = Bk\<^bsup>lnr \<^esup>@ Oc\<^bsup>m \<^esup>@ Bk\<^bsup>lnl\<^esup> @ Bk # Bk # ires \<and> 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5339
                                   (r = <ml> @ Bk\<^bsup>rn\<^esup>))"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5340
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5341
fun mopup_aft_erase_b :: "mopup_type"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5342
  where
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5343
  "mopup_aft_erase_b (s, l, r) lm n ires= 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5344
   (\<exists> lnl lnr rn (ml::nat list) m. 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5345
      m = Suc (abc_lm_v lm n) \<and> 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5346
      l = Bk\<^bsup>lnr \<^esup>@ Oc\<^bsup>m \<^esup>@ Bk\<^bsup>lnl\<^esup> @ Bk # Bk # ires \<and> 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5347
     (r = Bk # <ml> @ Bk\<^bsup>rn \<^esup>\<or>
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5348
      r = Bk # Bk # <ml> @ Bk\<^bsup>rn\<^esup>))"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5349
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5350
fun mopup_aft_erase_c :: "mopup_type"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5351
  where
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5352
  "mopup_aft_erase_c (s, l, r) lm n ires = 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5353
 (\<exists> lnl lnr rn (ml::nat list) m. 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5354
     m = Suc (abc_lm_v lm n) \<and> 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5355
     l = Bk\<^bsup>lnr \<^esup>@ Oc\<^bsup>m \<^esup>@ Bk\<^bsup>lnl\<^esup> @ Bk # Bk # ires \<and> 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5356
    (r = <ml> @ Bk\<^bsup>rn \<^esup>\<or> r = Bk # <ml> @ Bk\<^bsup>rn\<^esup>))"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5357
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5358
fun mopup_left_moving :: "mopup_type"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5359
  where
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5360
  "mopup_left_moving (s, l, r) lm n ires = 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5361
  (\<exists> lnl lnr rn m.
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5362
     m = Suc (abc_lm_v lm n) \<and> 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5363
   ((l = Bk\<^bsup>lnr \<^esup>@ Oc\<^bsup>m \<^esup>@ Bk\<^bsup>lnl\<^esup> @ Bk # Bk # ires \<and> r = Bk\<^bsup>rn\<^esup>) \<or>
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5364
    (l = Oc\<^bsup>m - 1\<^esup> @ Bk\<^bsup>lnl\<^esup> @ Bk # Bk # ires \<and> r = Oc # Bk\<^bsup>rn\<^esup>)))"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5365
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5366
fun mopup_jump_over2 :: "mopup_type"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5367
  where
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5368
  "mopup_jump_over2 (s, l, r) lm n ires = 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5369
     (\<exists> ln rn m1 m2.
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5370
          m1 + m2 = Suc (abc_lm_v lm n) 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5371
        \<and> r \<noteq> [] 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5372
        \<and> (hd r = Oc \<longrightarrow> (l = Oc\<^bsup>m1\<^esup> @ Bk\<^bsup>ln\<^esup> @ Bk # Bk # ires \<and> r = Oc\<^bsup>m2\<^esup> @ Bk\<^bsup>rn\<^esup>)) 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5373
        \<and> (hd r = Bk \<longrightarrow> (l = Bk\<^bsup>ln\<^esup> @ Bk # ires \<and> r = Bk # Oc\<^bsup>m1 + m2\<^esup> @ Bk\<^bsup>rn\<^esup>)))"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5374
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5375
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5376
fun mopup_inv :: "mopup_type"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5377
  where
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5378
  "mopup_inv (s, l, r) lm n ires = 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5379
      (if s = 0 then mopup_stop (s, l, r) lm n ires
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5380
       else if s \<le> 2*n then
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5381
               if s mod 2 = 1 then mopup_bef_erase_a (s, l, r) lm n ires
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5382
                   else mopup_bef_erase_b (s, l, r) lm n ires
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5383
            else if s = 2*n + 1 then 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5384
                mopup_jump_over1 (s, l, r) lm n ires
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5385
            else if s = 2*n + 2 then mopup_aft_erase_a (s, l, r) lm n ires
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5386
            else if s = 2*n + 3 then mopup_aft_erase_b (s, l, r) lm n ires
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5387
            else if s = 2*n + 4 then mopup_aft_erase_c (s, l, r) lm n ires
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5388
            else if s = 2*n + 5 then mopup_left_moving (s, l, r) lm n ires
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5389
            else if s = 2*n + 6 then mopup_jump_over2 (s, l, r) lm n ires
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5390
            else False)"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5391
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5392
declare 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5393
  mopup_jump_over2.simps[simp del] mopup_left_moving.simps[simp del]
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5394
  mopup_aft_erase_c.simps[simp del] mopup_aft_erase_b.simps[simp del] 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5395
  mopup_aft_erase_a.simps[simp del] mopup_jump_over1.simps[simp del]
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5396
  mopup_bef_erase_a.simps[simp del] mopup_bef_erase_b.simps[simp del]
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5397
  mopup_stop.simps[simp del]
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5398
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5399
lemma mopup_fetch_0[simp]: 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5400
     "(fetch (mop_bef n @ tshift mp_up (2 * n)) 0 b) = (Nop, 0)"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5401
by(simp add: fetch.simps)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5402
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5403
lemma mop_bef_length[simp]: "length (mop_bef n) = 4 * n"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5404
apply(induct n, simp add: mop_bef.simps, simp add: mop_bef.simps)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5405
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5406
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5407
thm findnth_nth
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5408
lemma mop_bef_nth: 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5409
  "\<lbrakk>q < n; x < 4\<rbrakk> \<Longrightarrow> mop_bef n ! (4 * q + x) = 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5410
                             mop_bef (Suc q) ! ((4 * q) + x)"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5411
apply(induct n, simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5412
apply(case_tac "q < n", simp add: mop_bef.simps, auto)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5413
apply(simp add: nth_append)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5414
apply(subgoal_tac "q = n", simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5415
apply(arith)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5416
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5417
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5418
lemma fetch_bef_erase_a_o[simp]: 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5419
 "\<lbrakk>0 < s; s \<le> 2 * n; s mod 2 = Suc 0\<rbrakk>
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5420
  \<Longrightarrow> (fetch (mop_bef n @ tshift mp_up (2 * n)) s Oc) = (W0, s + 1)"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5421
apply(subgoal_tac "\<exists> q. s = 2*q + 1", auto)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5422
apply(subgoal_tac "length (mop_bef n) = 4*n")
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5423
apply(auto simp: fetch.simps nth_of.simps nth_append)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5424
apply(subgoal_tac "mop_bef n ! (4 * q + 1) = 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5425
                      mop_bef (Suc q) ! ((4 * q) + 1)", 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5426
      simp add: mop_bef.simps nth_append)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5427
apply(rule mop_bef_nth, auto)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5428
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5429
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5430
lemma fetch_bef_erase_a_b[simp]:
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5431
  "\<lbrakk>n < length lm; 0 < s; s \<le> 2 * n; s mod 2 = Suc 0\<rbrakk>
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5432
   \<Longrightarrow>  (fetch (mop_bef n @ tshift mp_up (2 * n)) s Bk) = (R, s + 2)"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5433
apply(subgoal_tac "\<exists> q. s = 2*q + 1", auto)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5434
apply(subgoal_tac "length (mop_bef n) = 4*n")
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5435
apply(auto simp: fetch.simps nth_of.simps nth_append)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5436
apply(subgoal_tac "mop_bef n ! (4 * q + 0) = 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5437
                       mop_bef (Suc q) ! ((4 * q + 0))", 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5438
      simp add: mop_bef.simps nth_append)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5439
apply(rule mop_bef_nth, auto)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5440
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5441
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5442
lemma fetch_bef_erase_b_b: 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5443
  "\<lbrakk>n < length lm; 0 < s; s \<le> 2 * n; s mod 2 = 0\<rbrakk> \<Longrightarrow> 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5444
     (fetch (mop_bef n @ tshift mp_up (2 * n)) s Bk) = (R, s - 1)"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5445
apply(subgoal_tac "\<exists> q. s = 2 * q", auto)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5446
apply(case_tac qa, simp, simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5447
apply(auto simp: fetch.simps nth_of.simps nth_append)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5448
apply(subgoal_tac "mop_bef n ! (4 * nat + 2) = 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5449
                     mop_bef (Suc nat) ! ((4 * nat) + 2)", 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5450
      simp add: mop_bef.simps nth_append)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5451
apply(rule mop_bef_nth, auto)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5452
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5453
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5454
lemma fetch_jump_over1_o: 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5455
 "fetch (mop_bef n @ tshift mp_up (2 * n)) (Suc (2 * n)) Oc
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5456
  = (R, Suc (2 * n))"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5457
apply(subgoal_tac "length (mop_bef n) = 4 * n")
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5458
apply(auto simp: fetch.simps nth_of.simps mp_up_def nth_append 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5459
                 tshift.simps)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5460
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5461
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5462
lemma fetch_jump_over1_b: 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5463
 "fetch (mop_bef n @ tshift mp_up (2 * n)) (Suc (2 * n)) Bk 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5464
 = (R, Suc (Suc (2 * n)))"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5465
apply(subgoal_tac "length (mop_bef n) = 4 * n")
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5466
apply(auto simp: fetch.simps nth_of.simps mp_up_def 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5467
                 nth_append tshift.simps)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5468
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5469
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5470
lemma fetch_aft_erase_a_o: 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5471
 "fetch (mop_bef n @ tshift mp_up (2 * n)) (Suc (Suc (2 * n))) Oc 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5472
 = (W0, Suc (2 * n + 2))"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5473
apply(subgoal_tac "length (mop_bef n) = 4 * n")
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5474
apply(auto simp: fetch.simps nth_of.simps mp_up_def 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5475
                 nth_append tshift.simps)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5476
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5477
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5478
lemma fetch_aft_erase_a_b: 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5479
 "fetch (mop_bef n @ tshift mp_up (2 * n)) (Suc (Suc (2 * n))) Bk
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5480
  = (L, Suc (2 * n + 4))"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5481
apply(subgoal_tac "length (mop_bef n) = 4 * n")
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5482
apply(auto simp: fetch.simps nth_of.simps mp_up_def 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5483
                 nth_append tshift.simps)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5484
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5485
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5486
lemma fetch_aft_erase_b_b: 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5487
 "fetch (mop_bef n @ tshift mp_up (2 * n)) (2*n + 3) Bk
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5488
  = (R, Suc (2 * n + 3))"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5489
apply(subgoal_tac "length (mop_bef n) = 4 * n")
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5490
apply(subgoal_tac "2*n + 3 = Suc (2*n + 2)", simp only: fetch.simps)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5491
apply(auto simp: nth_of.simps mp_up_def nth_append tshift.simps)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5492
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5493
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5494
lemma fetch_aft_erase_c_o: 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5495
 "fetch (mop_bef n @ tshift mp_up (2 * n)) (2 * n + 4) Oc 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5496
 = (W0, Suc (2 * n + 2))"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5497
apply(subgoal_tac "length (mop_bef n) = 4 * n")
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5498
apply(subgoal_tac "2*n + 4 = Suc (2*n + 3)", simp only: fetch.simps)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5499
apply(auto simp: nth_of.simps mp_up_def nth_append tshift.simps)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5500
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5501
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5502
lemma fetch_aft_erase_c_b: 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5503
 "fetch (mop_bef n @ tshift mp_up (2 * n)) (2 * n + 4) Bk 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5504
 = (R, Suc (2 * n + 1))"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5505
apply(subgoal_tac "length (mop_bef n) = 4 * n")
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5506
apply(subgoal_tac "2*n + 4 = Suc (2*n + 3)", simp only: fetch.simps)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5507
apply(auto simp: nth_of.simps mp_up_def nth_append tshift.simps)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5508
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5509
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5510
lemma fetch_left_moving_o: 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5511
 "(fetch (mop_bef n @ tshift mp_up (2 * n)) (2 * n + 5) Oc) 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5512
 = (L, 2*n + 6)"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5513
apply(subgoal_tac "length (mop_bef n) = 4 * n")
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5514
apply(subgoal_tac "2*n + 5 = Suc (2*n + 4)", simp only: fetch.simps)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5515
apply(auto simp: nth_of.simps mp_up_def nth_append tshift.simps)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5516
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5517
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5518
lemma fetch_left_moving_b: 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5519
 "(fetch (mop_bef n @ tshift mp_up (2 * n)) (2 * n + 5) Bk)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5520
  = (L, 2*n + 5)"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5521
apply(subgoal_tac "length (mop_bef n) = 4 * n")
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5522
apply(subgoal_tac "2*n + 5 = Suc (2*n + 4)", simp only: fetch.simps)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5523
apply(auto simp: nth_of.simps mp_up_def nth_append tshift.simps)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5524
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5525
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5526
lemma fetch_jump_over2_b:
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5527
  "(fetch (mop_bef n @ tshift mp_up (2 * n)) (2 * n + 6) Bk) 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5528
 = (R, 0)"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5529
apply(subgoal_tac "length (mop_bef n) = 4 * n")
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5530
apply(subgoal_tac "2*n + 6 = Suc (2*n + 5)", simp only: fetch.simps)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5531
apply(auto simp: nth_of.simps mp_up_def nth_append tshift.simps)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5532
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5533
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5534
lemma fetch_jump_over2_o: 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5535
"(fetch (mop_bef n @ tshift mp_up (2 * n)) (2 * n + 6) Oc) 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5536
 = (L, 2*n + 6)"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5537
apply(subgoal_tac "length (mop_bef n) = 4 * n")
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5538
apply(subgoal_tac "2*n + 6 = Suc (2*n + 5)", simp only: fetch.simps)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5539
apply(auto simp: nth_of.simps mp_up_def nth_append tshift.simps)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5540
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5541
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5542
lemmas mopupfetchs = 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5543
fetch_bef_erase_a_o fetch_bef_erase_a_b fetch_bef_erase_b_b 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5544
fetch_jump_over1_o fetch_jump_over1_b fetch_aft_erase_a_o 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5545
fetch_aft_erase_a_b fetch_aft_erase_b_b fetch_aft_erase_c_o 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5546
fetch_aft_erase_c_b fetch_left_moving_o fetch_left_moving_b 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5547
fetch_jump_over2_b fetch_jump_over2_o
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5548
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5549
lemma [simp]: 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5550
"\<lbrakk>n < length lm; 0 < s; s mod 2 = Suc 0; 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5551
  mopup_bef_erase_a (s, l, Oc # xs) lm n ires; 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5552
  Suc s \<le> 2 * n\<rbrakk> \<Longrightarrow> 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5553
  mopup_bef_erase_b (Suc s, l, Bk # xs) lm n ires"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5554
apply(auto simp: mopup_bef_erase_a.simps mopup_bef_erase_b.simps )
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5555
apply(rule_tac x = "m - 1" in exI, rule_tac x = rn in exI)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5556
apply(case_tac m, simp, simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5557
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5558
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5559
lemma mopup_false1:
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5560
  "\<lbrakk>0 < s; s \<le> 2 * n; s mod 2 = Suc 0;  \<not> Suc s \<le> 2 * n\<rbrakk> 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5561
  \<Longrightarrow> RR"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5562
apply(arith)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5563
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5564
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5565
lemma [simp]: 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5566
 "\<lbrakk>n < length lm; 0 < s; s \<le> 2 * n; s mod 2 = Suc 0; 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5567
   mopup_bef_erase_a (s, l, Oc # xs) lm n ires; r = Oc # xs\<rbrakk>
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5568
 \<Longrightarrow> (Suc s \<le> 2 * n \<longrightarrow> mopup_bef_erase_b (Suc s, l, Bk # xs) lm n ires)  \<and>
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5569
     (\<not> Suc s \<le> 2 * n \<longrightarrow> mopup_jump_over1 (Suc s, l, Bk # xs) lm n ires) "
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5570
apply(auto elim: mopup_false1)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5571
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5572
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5573
lemma drop_abc_lm_v_simp[simp]: 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5574
   "n < length lm \<Longrightarrow> drop n lm = abc_lm_v lm n # drop (Suc n) lm"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5575
apply(auto simp: abc_lm_v.simps)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5576
apply(drule drop_Suc_conv_tl, simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5577
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5578
lemma [simp]: "(\<exists>rna. Bk\<^bsup>rn\<^esup> = Bk # Bk\<^bsup>rna\<^esup>) \<or> Bk\<^bsup>rn\<^esup> = []"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5579
apply(case_tac rn, simp, auto)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5580
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5581
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5582
lemma [simp]: "\<exists>lna. Bk # Bk\<^bsup>ln\<^esup> = Bk\<^bsup>lna\<^esup>"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5583
apply(rule_tac x = "Suc ln" in exI, auto)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5584
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5585
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5586
lemma mopup_bef_erase_a_2_jump_over[simp]: 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5587
 "\<lbrakk>n < length lm; 0 < s; s mod 2 = Suc 0; 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5588
   mopup_bef_erase_a (s, l, Bk # xs) lm n ires; Suc s = 2 * n\<rbrakk> 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5589
\<Longrightarrow> mopup_jump_over1 (Suc (2 * n), Bk # l, xs) lm n ires"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5590
apply(auto simp: mopup_bef_erase_a.simps mopup_jump_over1.simps)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5591
apply(case_tac m, simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5592
apply(rule_tac x = "Suc ln" in exI, rule_tac x = 0 in exI, 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5593
      simp add: tape_of_nl_abv)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5594
apply(case_tac "drop (Suc n) lm", auto simp: tape_of_nat_list.simps )
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5595
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5596
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5597
lemma Suc_Suc_div:  "\<lbrakk>0 < s; s mod 2 = Suc 0; Suc (Suc s) \<le> 2 * n\<rbrakk>
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5598
           \<Longrightarrow> (Suc (Suc (s div 2))) \<le> n"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5599
apply(arith)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5600
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5601
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5602
lemma mopup_bef_erase_a_2_a[simp]: 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5603
 "\<lbrakk>n < length lm; 0 < s; s mod 2 = Suc 0; 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5604
   mopup_bef_erase_a (s, l, Bk # xs) lm n ires; 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5605
   Suc (Suc s) \<le> 2 * n\<rbrakk> \<Longrightarrow> 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5606
   mopup_bef_erase_a (Suc (Suc s), Bk # l, xs) lm n ires"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5607
apply(auto simp: mopup_bef_erase_a.simps )
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5608
apply(subgoal_tac "drop (Suc (Suc (s div 2))) lm \<noteq> []")
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5609
apply(case_tac m, simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5610
apply(rule_tac x = "Suc (abc_lm_v lm (Suc (s div 2)))" in exI, 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5611
      rule_tac x = rn in exI, simp, simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5612
apply(subgoal_tac "(Suc (Suc (s div 2))) \<le> n", simp, 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5613
      rule_tac Suc_Suc_div, auto)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5614
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5615
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5616
lemma mopup_false2: 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5617
 "\<lbrakk>n < length lm; 0 < s; s \<le> 2 * n; 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5618
   s mod 2 = Suc 0; Suc s \<noteq> 2 * n;
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5619
   \<not> Suc (Suc s) \<le> 2 * n\<rbrakk> \<Longrightarrow> RR"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5620
apply(arith)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5621
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5622
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5623
lemma [simp]:
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5624
  "\<lbrakk>n < length lm; 0 < s; s \<le> 2 * n; 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5625
   s mod 2 = Suc 0; 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5626
   mopup_bef_erase_a (s, l, Bk # xs) lm n ires; 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5627
   r = Bk # xs\<rbrakk>
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5628
 \<Longrightarrow> (Suc s = 2 * n \<longrightarrow> 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5629
             mopup_jump_over1 (Suc (2 * n), Bk # l, xs) lm n ires) \<and>
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5630
     (Suc s \<noteq> 2 * n \<longrightarrow> 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5631
       (Suc (Suc s) \<le> 2 * n \<longrightarrow> 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5632
          mopup_bef_erase_a (Suc (Suc s), Bk # l, xs) lm n ires) \<and> 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5633
       (\<not> Suc (Suc s) \<le> 2 * n \<longrightarrow> 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5634
          mopup_aft_erase_a (Suc (Suc s), Bk # l, xs) lm n ires))"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5635
apply(auto elim: mopup_false2)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5636
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5637
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5638
lemma [simp]: "mopup_bef_erase_a (s, l, []) lm n ires \<Longrightarrow> 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5639
                        mopup_bef_erase_a (s, l, [Bk]) lm n ires"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5640
apply(auto simp: mopup_bef_erase_a.simps)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5641
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5642
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5643
lemma [simp]:
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5644
   "\<lbrakk>n < length lm; 0 < s; s \<le> 2 * n; s mod 2 = Suc 0;
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5645
     mopup_bef_erase_a (s, l, []) lm n ires; r = []\<rbrakk>
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5646
    \<Longrightarrow> (Suc s = 2 * n \<longrightarrow> 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5647
              mopup_jump_over1 (Suc (2 * n), Bk # l, []) lm n ires) \<and>
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5648
        (Suc s \<noteq> 2 * n \<longrightarrow> 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5649
             (Suc (Suc s) \<le> 2 * n \<longrightarrow> 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5650
                 mopup_bef_erase_a (Suc (Suc s), Bk # l, []) lm n ires) \<and>
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5651
             (\<not> Suc (Suc s) \<le> 2 * n \<longrightarrow> 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5652
                 mopup_aft_erase_a (Suc (Suc s), Bk # l, []) lm n ires))"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5653
apply(auto)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5654
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5655
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5656
lemma "mopup_bef_erase_b (s, l, Oc # xs) lm n ires \<Longrightarrow> l \<noteq> []"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5657
apply(auto simp: mopup_bef_erase_b.simps)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5658
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5659
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5660
lemma [simp]: "mopup_bef_erase_b (s, l, Oc # xs) lm n ires = False"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5661
apply(auto simp: mopup_bef_erase_b.simps )
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5662
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5663
 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5664
lemma [simp]: "\<lbrakk>0 < s; s \<le> 2 *n; s mod 2 \<noteq> Suc 0\<rbrakk> \<Longrightarrow> 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5665
                                      (s - Suc 0) mod 2 = Suc 0"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5666
apply(arith)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5667
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5668
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5669
lemma [simp]: "\<lbrakk>0 < s; s \<le> 2 *n; s mod 2 \<noteq> Suc 0\<rbrakk> \<Longrightarrow>
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5670
                                       s - Suc 0 \<le> 2 * n"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5671
apply(simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5672
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5673
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5674
lemma [simp]: "\<lbrakk>0 < s; s \<le> 2 *n; s mod 2 \<noteq> Suc 0\<rbrakk> \<Longrightarrow> \<not> s \<le> Suc 0"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5675
apply(arith)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5676
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5677
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5678
lemma [simp]: "\<lbrakk>n < length lm; 0 < s; s \<le> 2 * n; 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5679
               s mod 2 \<noteq> Suc 0; 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5680
               mopup_bef_erase_b (s, l, Bk # xs) lm n ires; r = Bk # xs\<rbrakk> 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5681
           \<Longrightarrow> mopup_bef_erase_a (s - Suc 0, Bk # l, xs) lm n ires"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5682
apply(auto simp: mopup_bef_erase_b.simps mopup_bef_erase_a.simps)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5683
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5684
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5685
lemma [simp]: "\<lbrakk>mopup_bef_erase_b (s, l, []) lm n ires\<rbrakk> \<Longrightarrow> 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5686
                   mopup_bef_erase_a (s - Suc 0, Bk # l, []) lm n ires"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5687
apply(auto simp: mopup_bef_erase_b.simps mopup_bef_erase_a.simps)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5688
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5689
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5690
lemma [simp]: 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5691
   "\<lbrakk>n < length lm;
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5692
    mopup_jump_over1 (Suc (2 * n), l, Oc # xs) lm n ires;
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5693
    r = Oc # xs\<rbrakk>
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5694
  \<Longrightarrow> mopup_jump_over1 (Suc (2 * n), Oc # l, xs) lm n ires"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5695
apply(auto simp: mopup_jump_over1.simps)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5696
apply(rule_tac x = ln in exI, rule_tac x = "Suc m1" in exI,
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5697
       rule_tac x = "m2 - 1" in exI)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5698
apply(case_tac "m2", simp, simp, rule_tac x = rn in exI, simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5699
apply(rule_tac x = ln in exI, rule_tac x = "Suc m1" in exI, 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5700
      rule_tac x = "m2 - 1" in exI)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5701
apply(case_tac m2, simp, simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5702
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5703
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5704
lemma mopup_jump_over1_2_aft_erase_a[simp]:  
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5705
 "\<lbrakk>n < length lm; mopup_jump_over1 (Suc (2 * n), l, Bk # xs) lm n ires\<rbrakk>
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5706
  \<Longrightarrow> mopup_aft_erase_a (Suc (Suc (2 * n)), Bk # l, xs) lm n ires"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5707
apply(simp only: mopup_jump_over1.simps mopup_aft_erase_a.simps)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5708
apply(erule_tac exE)+
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5709
apply(rule_tac x = ln in exI, rule_tac x = "Suc 0" in exI)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5710
apply(case_tac m2, simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5711
apply(rule_tac x = rn in exI, rule_tac x = "drop (Suc n) lm" in exI, 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5712
      simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5713
apply(simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5714
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5715
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5716
lemma [simp]: 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5717
 "\<lbrakk>n < length lm; mopup_jump_over1 (Suc (2 * n), l, []) lm n ires\<rbrakk> \<Longrightarrow> 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5718
    mopup_aft_erase_a (Suc (Suc (2 * n)), Bk # l, []) lm n ires"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5719
apply(rule mopup_jump_over1_2_aft_erase_a, simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5720
apply(auto simp: mopup_jump_over1.simps)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5721
apply(rule_tac x = ln in exI, rule_tac x = m1 in exI, 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5722
      rule_tac x = m2 in exI, simp add: )
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5723
apply(rule_tac x = 0 in exI, auto)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5724
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5725
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5726
lemma [simp]: 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5727
 "\<lbrakk>n < length lm; 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5728
   mopup_aft_erase_a (Suc (Suc (2 * n)), l, Oc # xs) lm n ires\<rbrakk> 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5729
 \<Longrightarrow> mopup_aft_erase_b (Suc (Suc (Suc (2 * n))), l, Bk # xs) lm n ires"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5730
apply(auto simp: mopup_aft_erase_a.simps mopup_aft_erase_b.simps )
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5731
apply(case_tac ml, simp, case_tac rn, simp, simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5732
apply(case_tac list, auto simp: tape_of_nl_abv 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5733
                                tape_of_nat_list.simps )
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5734
apply(case_tac a, simp, rule_tac x = rn in exI, 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5735
      rule_tac x = "[]" in exI,
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5736
       simp add: tape_of_nat_list.simps, simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5737
apply(rule_tac x = rn in exI, rule_tac x = "[nat]" in exI, 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5738
      simp add: tape_of_nat_list.simps )
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5739
apply(case_tac a, simp, rule_tac x = rn in exI, 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5740
       rule_tac x = "aa # lista" in exI, simp, simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5741
apply(rule_tac x = rn in exI, rule_tac x = "nat # aa # lista" in exI, 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5742
       simp add: tape_of_nat_list.simps )
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5743
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5744
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5745
lemma [simp]:
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5746
  "mopup_aft_erase_a (Suc (Suc (2 * n)), l, Bk # xs) lm n ires \<Longrightarrow> l \<noteq> []"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5747
apply(auto simp: mopup_aft_erase_a.simps)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5748
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5749
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5750
lemma [simp]:
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5751
  "\<lbrakk>n < length lm;
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5752
    mopup_aft_erase_a (Suc (Suc (2 * n)), l, Bk # xs) lm n ires\<rbrakk>
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5753
  \<Longrightarrow> mopup_left_moving (5 + 2 * n, tl l, hd l # Bk # xs) lm n ires"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5754
apply(simp only: mopup_aft_erase_a.simps mopup_left_moving.simps)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5755
apply(erule exE)+
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5756
apply(case_tac lnr, simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5757
apply(rule_tac x = lnl in exI, simp, rule_tac x = rn in exI, simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5758
apply(subgoal_tac "ml = []", simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5759
apply(rule_tac xs = xs and rn = rn in BkCons_nil, simp, auto)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5760
apply(subgoal_tac "ml = []", auto)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5761
apply(rule_tac xs = xs and rn = rn in BkCons_nil, simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5762
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5763
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5764
lemma [simp]:
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5765
  "mopup_aft_erase_a (Suc (Suc (2 * n)), l, []) lm n ires \<Longrightarrow> l \<noteq> []"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5766
apply(simp only: mopup_aft_erase_a.simps)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5767
apply(erule exE)+
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5768
apply(auto)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5769
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5770
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5771
lemma [simp]:
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5772
  "\<lbrakk>n < length lm; mopup_aft_erase_a (Suc (Suc (2 * n)), l, []) lm n ires\<rbrakk>
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5773
  \<Longrightarrow> mopup_left_moving (5 + 2 * n, tl l, [hd l]) lm n ires"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5774
apply(simp only: mopup_aft_erase_a.simps mopup_left_moving.simps)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5775
apply(erule exE)+
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5776
apply(subgoal_tac "ml = [] \<and> rn = 0", erule conjE, erule conjE, simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5777
apply(case_tac lnr, simp, rule_tac x = lnl in exI, simp, 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5778
      rule_tac x = 0 in exI, simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5779
apply(rule_tac x = lnl in exI, rule_tac x = nat in exI, 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5780
      rule_tac x = "Suc 0" in exI, simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5781
apply(case_tac ml, simp, case_tac rn, simp, simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5782
apply(case_tac list, auto simp: tape_of_nl_abv tape_of_nat_list.simps)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5783
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5784
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5785
lemma [simp]: "mopup_aft_erase_b (2 * n + 3, l, Oc # xs) lm n ires = False"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5786
apply(auto simp: mopup_aft_erase_b.simps )
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5787
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5788
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5789
lemma [simp]: 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5790
 "\<lbrakk>n < length lm; 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5791
   mopup_aft_erase_c (2 * n + 4, l, Oc # xs) lm n ires\<rbrakk>
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5792
  \<Longrightarrow> mopup_aft_erase_b (Suc (Suc (Suc (2 * n))), l, Bk # xs) lm n ires"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5793
apply(auto simp: mopup_aft_erase_c.simps mopup_aft_erase_b.simps )
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5794
apply(case_tac ml, simp, case_tac rn, simp, simp, simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5795
apply(case_tac list, auto simp: tape_of_nl_abv 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5796
                        tape_of_nat_list.simps tape_of_nat_abv )
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5797
apply(case_tac a, rule_tac x = rn in exI, 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5798
      rule_tac x = "[]" in exI, simp add: tape_of_nat_list.simps)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5799
apply(rule_tac x = rn in exI, rule_tac x = "[nat]" in exI, 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5800
      simp add: tape_of_nat_list.simps )
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5801
apply(case_tac a, simp, rule_tac x = rn in exI, 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5802
      rule_tac x = "aa # lista" in exI, simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5803
apply(rule_tac x = rn in exI, rule_tac x = "nat # aa # lista" in exI, 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5804
      simp add: tape_of_nat_list.simps )
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5805
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5806
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5807
lemma mopup_aft_erase_c_aft_erase_a[simp]: 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5808
 "\<lbrakk>n < length lm; mopup_aft_erase_c (2 * n + 4, l, Bk # xs) lm n ires\<rbrakk> 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5809
 \<Longrightarrow> mopup_aft_erase_a (Suc (Suc (2 * n)), Bk # l, xs) lm n ires"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5810
apply(simp only: mopup_aft_erase_c.simps mopup_aft_erase_a.simps )
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5811
apply(erule_tac exE)+
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5812
apply(erule conjE, erule conjE, erule disjE)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5813
apply(subgoal_tac "ml = []", simp, case_tac rn, 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5814
      simp, simp, rule conjI)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5815
apply(rule_tac x = lnl in exI, rule_tac x = "Suc lnr" in exI, simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5816
apply(rule_tac x = nat in exI, rule_tac x = "[]" in exI, simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5817
apply(rule_tac xs = xs and rn = rn in BkCons_nil, simp, simp, 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5818
      rule conjI)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5819
apply(rule_tac x = lnl in exI, rule_tac x = "Suc lnr" in exI, simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5820
apply(rule_tac x = rn in exI, rule_tac x = "ml" in exI, simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5821
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5822
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5823
lemma [simp]: 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5824
 "\<lbrakk>n < length lm; mopup_aft_erase_c (2 * n + 4, l, []) lm n ires\<rbrakk> 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5825
 \<Longrightarrow> mopup_aft_erase_a (Suc (Suc (2 * n)), Bk # l, []) lm n ires"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5826
apply(rule mopup_aft_erase_c_aft_erase_a, simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5827
apply(simp only: mopup_aft_erase_c.simps)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5828
apply(erule exE)+
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5829
apply(rule_tac x = lnl in exI, rule_tac x = lnr in exI, simp add: )
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5830
apply(rule_tac x = 0 in exI, rule_tac x = "[]" in exI, simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5831
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5832
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5833
lemma mopup_aft_erase_b_2_aft_erase_c[simp]:
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5834
  "\<lbrakk>n < length lm; mopup_aft_erase_b (2 * n + 3, l, Bk # xs) lm n ires\<rbrakk>  
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5835
 \<Longrightarrow> mopup_aft_erase_c (4 + 2 * n, Bk # l, xs) lm n ires"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5836
apply(auto simp: mopup_aft_erase_b.simps mopup_aft_erase_c.simps)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5837
apply(rule_tac x = "lnl" in exI, rule_tac x = "Suc lnr" in exI, simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5838
apply(rule_tac x = "lnl" in exI, rule_tac x = "Suc lnr" in exI, simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5839
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5840
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5841
lemma [simp]: 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5842
 "\<lbrakk>n < length lm; mopup_aft_erase_b (2 * n + 3, l, []) lm n ires\<rbrakk> 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5843
 \<Longrightarrow> mopup_aft_erase_c (4 + 2 * n, Bk # l, []) lm n ires"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5844
apply(rule_tac mopup_aft_erase_b_2_aft_erase_c, simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5845
apply(simp add: mopup_aft_erase_b.simps)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5846
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5847
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5848
lemma [simp]: 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5849
    "mopup_left_moving (2 * n + 5, l, Oc # xs) lm n ires \<Longrightarrow> l \<noteq> []"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5850
apply(auto simp: mopup_left_moving.simps)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5851
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5852
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5853
lemma [simp]:  
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5854
 "\<lbrakk>n < length lm; mopup_left_moving (2 * n + 5, l, Oc # xs) lm n ires\<rbrakk>
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5855
  \<Longrightarrow> mopup_jump_over2 (2 * n + 6, tl l, hd l # Oc # xs) lm n ires"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5856
apply(simp only: mopup_left_moving.simps mopup_jump_over2.simps)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5857
apply(erule_tac exE)+
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5858
apply(erule conjE, erule disjE, erule conjE)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5859
apply(case_tac rn, simp, simp add: )
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5860
apply(case_tac "hd l", simp add:  )
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5861
apply(case_tac "abc_lm_v lm n", simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5862
apply(rule_tac x = "lnl" in exI, rule_tac x = rn in exI, 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5863
      rule_tac x = "Suc 0" in exI, rule_tac x = 0 in exI)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5864
apply(case_tac lnl, simp, simp, simp add: exp_ind[THEN sym], simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5865
apply(case_tac "abc_lm_v lm n", simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5866
apply(case_tac lnl, simp, simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5867
apply(rule_tac x = lnl in exI, rule_tac x = rn in exI)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5868
apply(rule_tac x = nat in exI, rule_tac x = "Suc (Suc 0)" in exI, simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5869
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5870
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5871
lemma [simp]: "mopup_left_moving (2 * n + 5, l, xs) lm n ires \<Longrightarrow> l \<noteq> []"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5872
apply(auto simp: mopup_left_moving.simps)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5873
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5874
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5875
lemma [simp]:
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5876
  "\<lbrakk>n < length lm; mopup_left_moving (2 * n + 5, l, Bk # xs) lm n ires\<rbrakk> 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5877
 \<Longrightarrow> mopup_left_moving (2 * n + 5, tl l, hd l # Bk # xs) lm n ires"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5878
apply(simp only: mopup_left_moving.simps)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5879
apply(erule exE)+
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5880
apply(case_tac lnr, simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5881
apply(rule_tac x = lnl in exI, rule_tac x = 0 in exI, 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5882
      rule_tac x = rn in exI, simp, simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5883
apply(rule_tac x = lnl in exI, rule_tac x = nat in exI, simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5884
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5885
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5886
lemma [simp]: 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5887
"\<lbrakk>n < length lm; mopup_left_moving (2 * n + 5, l, []) lm n ires\<rbrakk>
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5888
    \<Longrightarrow> mopup_left_moving (2 * n + 5, tl l, [hd l]) lm n ires"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5889
apply(simp only: mopup_left_moving.simps)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5890
apply(erule exE)+
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5891
apply(case_tac lnr, simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5892
apply(rule_tac x = lnl in exI, rule_tac x = 0 in exI, 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5893
      rule_tac x = 0 in exI, simp, auto)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5894
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5895
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5896
lemma [simp]: 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5897
 "mopup_jump_over2 (2 * n + 6, l, Oc # xs) lm n ires \<Longrightarrow> l \<noteq> []"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5898
apply(auto simp: mopup_jump_over2.simps )
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5899
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5900
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5901
lemma [intro]: "\<exists>lna. Bk # Bk\<^bsup>ln\<^esup> = Bk\<^bsup>lna\<^esup> @ [Bk]"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5902
apply(simp only: exp_ind[THEN sym], auto)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5903
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5904
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5905
lemma [simp]: 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5906
"\<lbrakk>n < length lm; mopup_jump_over2 (2 * n + 6, l, Oc # xs) lm n ires\<rbrakk>
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5907
 \<Longrightarrow>  mopup_jump_over2 (2 * n + 6, tl l, hd l # Oc # xs) lm n ires"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5908
apply(simp only: mopup_jump_over2.simps)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5909
apply(erule_tac exE)+
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5910
apply(simp add:  , erule conjE, erule_tac conjE)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5911
apply(case_tac m1, simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5912
apply(rule_tac x = ln in exI, rule_tac x = rn in exI, 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5913
      rule_tac x = 0 in exI, simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5914
apply(case_tac ln, simp, simp, simp only: exp_ind[THEN sym], simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5915
apply(rule_tac x = ln in exI, rule_tac x = rn in exI, 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5916
      rule_tac x = nat in exI, rule_tac x = "Suc m2" in exI, simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5917
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5918
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5919
lemma [simp]: "\<exists>rna. Oc # Oc\<^bsup>a\<^esup> @ Bk\<^bsup>rn\<^esup> = <a> @ Bk\<^bsup>rna\<^esup>"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5920
apply(case_tac a, auto simp: tape_of_nat_abv )
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5921
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5922
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5923
lemma [simp]: 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5924
 "\<lbrakk>n < length lm; mopup_jump_over2 (2 * n + 6, l, Bk # xs) lm n ires\<rbrakk> 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5925
  \<Longrightarrow> mopup_stop (0, Bk # l, xs) lm n ires"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5926
apply(auto simp: mopup_jump_over2.simps mopup_stop.simps)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5927
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5928
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5929
lemma [simp]: "mopup_jump_over2 (2 * n + 6, l, []) lm n ires = False"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5930
apply(simp only: mopup_jump_over2.simps, simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5931
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5932
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5933
lemma mopup_inv_step:
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5934
  "\<lbrakk>n < length lm; mopup_inv (s, l, r) lm n ires\<rbrakk>
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5935
  \<Longrightarrow> mopup_inv (t_step (s, l, r) 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5936
       ((mop_bef n @ tshift mp_up (2 * n)), 0)) lm n ires"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5937
apply(auto split:if_splits simp add:t_step.simps,
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5938
      tactic {* ALLGOALS (resolve_tac [@{thm "fetch_intro"}]) *})
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5939
apply(simp_all add: mopupfetchs new_tape.simps)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5940
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5941
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5942
declare mopup_inv.simps[simp del]
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5943
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5944
lemma mopup_inv_steps: 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5945
"\<lbrakk>n < length lm; mopup_inv (s, l, r) lm n ires\<rbrakk> \<Longrightarrow> 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5946
     mopup_inv (t_steps (s, l, r) 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5947
                   ((mop_bef n @ tshift mp_up (2 * n)), 0) stp) lm n ires"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5948
apply(induct stp, simp add: t_steps.simps)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5949
apply(simp add: t_steps_ind)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5950
apply(case_tac "(t_steps (s, l, r) 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5951
                (mop_bef n @ tshift mp_up (2 * n), 0) stp)", simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5952
apply(rule_tac mopup_inv_step, simp, simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5953
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5954
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5955
lemma [simp]: 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5956
 "\<lbrakk>n < length lm; Suc 0 \<le> n\<rbrakk> \<Longrightarrow> 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5957
            mopup_bef_erase_a (Suc 0, Bk\<^bsup>ln\<^esup> @ Bk # Bk # ires, <lm> @ Bk\<^bsup>rn\<^esup>) lm n ires"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5958
apply(auto simp: mopup_bef_erase_a.simps  abc_lm_v.simps)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5959
apply(case_tac lm, simp, case_tac list, simp, simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5960
apply(rule_tac x = "Suc a" in exI, rule_tac x = rn in exI, simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5961
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5962
  
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5963
lemma [simp]:
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5964
  "lm \<noteq> [] \<Longrightarrow> mopup_jump_over1 (Suc 0, Bk\<^bsup>ln\<^esup> @ Bk # Bk # ires, <lm> @ Bk\<^bsup>rn\<^esup>) lm 0  ires"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5965
apply(auto simp: mopup_jump_over1.simps)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5966
apply(rule_tac x = ln in exI, rule_tac x = 0 in exI, simp add: )
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5967
apply(case_tac lm, simp, simp add: abc_lm_v.simps)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5968
apply(case_tac rn, simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5969
apply(case_tac list, rule_tac disjI2, 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5970
      simp add: tape_of_nl_abv tape_of_nat_list.simps)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5971
apply(rule_tac disjI1,
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5972
      simp add: tape_of_nl_abv tape_of_nat_list.simps )
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5973
apply(rule_tac disjI1, case_tac list, 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5974
      simp add: tape_of_nl_abv tape_of_nat_list.simps, 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5975
      rule_tac x = nat in exI, simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5976
apply(simp add: tape_of_nl_abv tape_of_nat_list.simps )
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5977
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5978
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5979
lemma mopup_init: 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5980
 "\<lbrakk>n < length lm; crsp_l ly (as, lm) (ac, l, r) ires\<rbrakk> \<Longrightarrow> 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5981
                               mopup_inv (Suc 0, l, r) lm n ires"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5982
apply(auto simp: crsp_l.simps mopup_inv.simps)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5983
apply(case_tac n, simp, auto simp: mopup_bef_erase_a.simps )
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5984
apply(rule_tac x = "Suc (hd lm)" in exI, rule_tac x = rn in exI, simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5985
apply(case_tac lm, simp, case_tac list, simp, case_tac lista, simp add: abc_lm_v.simps)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5986
apply(simp add: tape_of_nl_abv tape_of_nat_list.simps abc_lm_v.simps)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5987
apply(simp add: mopup_jump_over1.simps)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5988
apply(rule_tac x = 0 in exI, rule_tac x = 0 in exI, auto)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5989
apply(case_tac [!] n, simp_all)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5990
apply(case_tac [!] lm, simp, case_tac list, simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5991
apply(case_tac rn, simp add: tape_of_nl_abv tape_of_nat_list.simps abc_lm_v.simps)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5992
apply(erule_tac x = nat in allE, simp add: tape_of_nl_abv tape_of_nat_list.simps abc_lm_v.simps)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5993
apply(simp add: abc_lm_v.simps, auto)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5994
apply(case_tac list, simp_all add: tape_of_nl_abv tape_of_nat_list.simps abc_lm_v.simps) 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5995
apply(erule_tac x = rn in allE, simp_all)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5996
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5997
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5998
fun abc_mopup_stage1 :: "t_conf \<Rightarrow> nat \<Rightarrow> nat"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  5999
  where
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6000
  "abc_mopup_stage1 (s, l, r) n = 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6001
           (if s > 0 \<and> s \<le> 2*n then 6
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6002
            else if s = 2*n + 1 then 4
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6003
            else if s \<ge> 2*n + 2 \<and> s \<le> 2*n + 4 then 3
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6004
            else if s = 2*n + 5 then 2
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6005
            else if s = 2*n + 6 then 1
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6006
            else 0)"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6007
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6008
fun abc_mopup_stage2 :: "t_conf \<Rightarrow> nat \<Rightarrow> nat"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6009
  where
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6010
  "abc_mopup_stage2 (s, l, r) n = 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6011
           (if s > 0 \<and> s \<le> 2*n then length r
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6012
            else if s = 2*n + 1 then length r
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6013
            else if s = 2*n + 5 then length l
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6014
            else if s = 2*n + 6 then length l
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6015
            else if s \<ge> 2*n + 2 \<and> s \<le> 2*n + 4 then length r
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6016
            else 0)"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6017
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6018
fun abc_mopup_stage3 :: "t_conf \<Rightarrow> nat \<Rightarrow> nat"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6019
  where
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6020
  "abc_mopup_stage3 (s, l, r) n = 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6021
          (if s > 0 \<and> s \<le> 2*n then 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6022
              if hd r = Bk then 0
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6023
              else 1
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6024
           else if s = 2*n + 2 then 1 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6025
           else if s = 2*n + 3 then 0
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6026
           else if s = 2*n + 4 then 2
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6027
           else 0)"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6028
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6029
fun abc_mopup_measure :: "(t_conf \<times> nat) \<Rightarrow> (nat \<times> nat \<times> nat)"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6030
  where
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6031
  "abc_mopup_measure (c, n) = 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6032
    (abc_mopup_stage1 c n, abc_mopup_stage2 c n, 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6033
                                       abc_mopup_stage3 c n)"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6034
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6035
definition abc_mopup_LE ::
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6036
   "(((nat \<times> block list \<times> block list) \<times> nat) \<times> 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6037
    ((nat \<times> block list \<times> block list) \<times> nat)) set"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6038
  where
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6039
  "abc_mopup_LE \<equiv> (inv_image lex_triple abc_mopup_measure)"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6040
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6041
lemma wf_abc_mopup_le[intro]: "wf abc_mopup_LE"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6042
by(auto intro:wf_inv_image wf_lex_triple simp:abc_mopup_LE_def)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6043
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6044
lemma [simp]: "mopup_bef_erase_a (a, aa, []) lm n ires = False"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6045
apply(auto simp: mopup_bef_erase_a.simps)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6046
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6047
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6048
lemma [simp]: "mopup_bef_erase_b (a, aa, []) lm n ires = False"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6049
apply(auto simp: mopup_bef_erase_b.simps) 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6050
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6051
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6052
lemma [simp]: "mopup_aft_erase_b (2 * n + 3, aa, []) lm n ires = False"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6053
apply(auto simp: mopup_aft_erase_b.simps)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6054
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6055
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6056
lemma mopup_halt_pre: 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6057
 "\<lbrakk>n < length lm; mopup_inv (Suc 0, l, r) lm n ires; wf abc_mopup_LE\<rbrakk>
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6058
 \<Longrightarrow>  \<forall>na. \<not> (\<lambda>(s, l, r) n. s = 0) (t_steps (Suc 0, l, r)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6059
      (mop_bef n @ tshift mp_up (2 * n), 0) na) n \<longrightarrow>
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6060
       ((t_steps (Suc 0, l, r) (mop_bef n @ tshift mp_up (2 * n), 0) 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6061
        (Suc na), n),
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6062
       t_steps (Suc 0, l, r) (mop_bef n @ tshift mp_up (2 * n), 0)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6063
         na, n) \<in> abc_mopup_LE"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6064
apply(rule allI, rule impI, simp add: t_steps_ind)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6065
apply(subgoal_tac "mopup_inv (t_steps (Suc 0, l, r) 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6066
                     (mop_bef n @ tshift mp_up (2 * n), 0) na) lm n ires")
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6067
apply(case_tac "(t_steps (Suc 0, l, r) 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6068
               (mop_bef n @ tshift mp_up (2 * n), 0) na)",  simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6069
proof -
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6070
  fix na a b c
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6071
  assume  "n < length lm" "mopup_inv (a, b, c) lm n ires" "0 < a"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6072
  thus "((t_step (a, b, c) (mop_bef n @ tshift mp_up (2 * n), 0), n),
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6073
         (a, b, c), n) \<in> abc_mopup_LE"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6074
    apply(auto split:if_splits simp add:t_step.simps mopup_inv.simps,
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6075
      tactic {* ALLGOALS (resolve_tac [@{thm "fetch_intro"}]) *})
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6076
    apply(simp_all add: mopupfetchs new_tape.simps abc_mopup_LE_def 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6077
                   lex_triple_def lex_pair_def )
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6078
    done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6079
next
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6080
  fix na
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6081
  assume "n < length lm" "mopup_inv (Suc 0, l, r) lm n ires"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6082
  thus "mopup_inv (t_steps (Suc 0, l, r) 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6083
       (mop_bef n @ tshift mp_up (2 * n), 0) na) lm n ires"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6084
    apply(rule mopup_inv_steps)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6085
    done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6086
qed
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6087
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6088
lemma mopup_halt: "\<lbrakk>n < length lm; crsp_l ly (as, lm) (s, l, r) ires\<rbrakk> \<Longrightarrow> 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6089
  \<exists> stp. (\<lambda> (s, l, r). s = 0) (t_steps (Suc 0, l, r) 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6090
        ((mop_bef n @ tshift mp_up (2 * n)), 0) stp)"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6091
apply(subgoal_tac "mopup_inv (Suc 0, l, r) lm n ires")
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6092
apply(insert wf_abc_mopup_le)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6093
apply(insert halt_lemma[of abc_mopup_LE 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6094
    "\<lambda> ((s, l, r), n). s = 0" 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6095
    "\<lambda> stp. (t_steps (Suc 0, l, r) ((mop_bef n @ tshift mp_up (2 * n))
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6096
           , 0) stp, n)"], auto)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6097
apply(insert mopup_halt_pre[of n lm l r], simp, erule exE)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6098
apply(rule_tac x = na in exI, case_tac "(t_steps (Suc 0, l, r) 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6099
          (mop_bef n @ tshift mp_up (2 * n), 0) na)", simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6100
apply(rule_tac mopup_init, auto)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6101
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6102
(***End: mopup stop****)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6103
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6104
lemma mopup_halt_conf_pre: 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6105
 "\<lbrakk>n < length lm; crsp_l ly (as, lm) (s, l, r) ires\<rbrakk> 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6106
  \<Longrightarrow> \<exists> na. (\<lambda> (s', l', r').  s' = 0 \<and> mopup_stop (s', l', r') lm n ires)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6107
      (t_steps (Suc 0, l, r) 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6108
            ((mop_bef n @ tshift mp_up (2 * n)), 0) na)"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6109
apply(subgoal_tac "\<exists> stp. (\<lambda> (s, l, r). s = 0) 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6110
 (t_steps (Suc 0, l, r) ((mop_bef n @ tshift mp_up (2 * n)), 0) stp)",
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6111
       erule exE)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6112
apply(rule_tac x = stp in exI, 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6113
      case_tac "(t_steps (Suc 0, l, r) 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6114
          (mop_bef n @ tshift mp_up (2 * n), 0) stp)", simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6115
apply(subgoal_tac " mopup_inv (Suc 0, l, r) lm n ires")
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6116
apply(subgoal_tac "mopup_inv (t_steps (Suc 0, l, r) 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6117
            (mop_bef n @ tshift mp_up (2 * n), 0) stp) lm n ires", simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6118
apply(simp only: mopup_inv.simps)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6119
apply(rule_tac mopup_inv_steps, simp, simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6120
apply(rule_tac mopup_init, simp, simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6121
apply(rule_tac mopup_halt, simp, simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6122
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6123
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6124
lemma  mopup_halt_conf:
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6125
  assumes len: "n < length lm"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6126
  and correspond: "crsp_l ly (as, lm) (s, l, r) ires"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6127
  shows 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6128
  "\<exists> na. (\<lambda> (s', l', r'). ((\<exists>ln rn. s' = 0 \<and> l' = Bk\<^bsup>ln\<^esup> @ Bk # Bk # ires
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6129
                           \<and> r' = Oc\<^bsup>Suc (abc_lm_v lm n)\<^esup> @ Bk\<^bsup>rn\<^esup>)))
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6130
             (t_steps (Suc 0, l, r) 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6131
                  ((mop_bef n @ tshift mp_up (2 * n)), 0) na)"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6132
using len correspond mopup_halt_conf_pre[of n lm ly as s l r ires]
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6133
apply(simp add: mopup_stop.simps tape_of_nat_abv tape_of_nat_list.simps)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6134
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6135
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6136
subsection {* Final results about Abacus machine *}
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6137
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6138
lemma mopup_halt_bef: "\<lbrakk>n < length lm; crsp_l ly (as, lm) (s, l, r) ires\<rbrakk> 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6139
    \<Longrightarrow> \<exists>stp. (\<lambda>(s, l, r). s \<noteq> 0 \<and> ((\<lambda> (s', l', r'). s' = 0)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6140
   (t_step (s, l, r) (mop_bef n @ tshift mp_up (2 * n), 0))))
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6141
    (t_steps (Suc 0, l, r) (mop_bef n @ tshift mp_up (2 * n), 0) stp)"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6142
apply(insert mopup_halt[of n lm ly as s l r ires], simp, erule_tac exE)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6143
proof -
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6144
  fix stp
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6145
  assume "n < length lm" 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6146
         "crsp_l ly (as, lm) (s, l, r) ires" 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6147
         "(\<lambda>(s, l, r). s = 0) 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6148
            (t_steps (Suc 0, l, r) 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6149
              (mop_bef n @ tshift mp_up (2 * n), 0) stp)"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6150
  thus "\<exists>stp. (\<lambda>(s, ab). 0 < s \<and> (\<lambda>(s', l', r'). s' = 0) 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6151
   (t_step (s, ab) (mop_bef n @ tshift mp_up (2 * n), 0))) 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6152
    (t_steps (Suc 0, l, r) (mop_bef n @ tshift mp_up (2 * n), 0) stp)"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6153
  proof(induct stp, simp add: t_steps.simps, simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6154
    fix stpa
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6155
    assume h1: 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6156
      "(\<lambda>(s, l, r). s = 0) (t_steps (Suc 0, l, r) 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6157
           (mop_bef n @ tshift mp_up (2 * n), 0) stpa) \<Longrightarrow>
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6158
       \<exists>stp. (\<lambda>(s, ab). 0 < s \<and> (\<lambda>(s', l', r'). s' = 0) 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6159
         (t_step (s, ab) (mop_bef n @ tshift mp_up (2 * n), 0))) 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6160
            (t_steps (Suc 0, l, r) 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6161
              (mop_bef n @ tshift mp_up (2 * n), 0) stp)"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6162
      and h2: 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6163
        "(\<lambda>(s, l, r). s = 0) (t_steps (Suc 0, l, r) 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6164
                    (mop_bef n @ tshift mp_up (2 * n), 0) (Suc stpa))"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6165
         "n < length lm" 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6166
         "crsp_l ly (as, lm) (s, l, r) ires"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6167
    thus "\<exists>stp. (\<lambda>(s, ab). 0 < s \<and> (\<lambda>(s', l', r'). s' = 0) 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6168
             (t_step (s, ab) (mop_bef n @ tshift mp_up (2 * n), 0))) (
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6169
                t_steps (Suc 0, l, r) 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6170
                  (mop_bef n @ tshift mp_up (2 * n), 0) stp)"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6171
      apply(case_tac "(\<lambda>(s, l, r). s = 0) (t_steps (Suc 0, l, r) 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6172
                     (mop_bef n @ tshift mp_up (2 * n), 0) stpa)", 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6173
            simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6174
      apply(rule_tac x = "stpa" in exI)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6175
      apply(case_tac "(t_steps (Suc 0, l, r) 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6176
                         (mop_bef n @ tshift mp_up (2 * n), 0) stpa)",
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6177
            simp add: t_steps_ind)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6178
      done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6179
  qed
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6180
qed
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6181
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6182
lemma tshift_nth_state0: "\<lbrakk>n < length tp; tp ! n = (a, 0)\<rbrakk>
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6183
    \<Longrightarrow> tshift tp off ! n = (a, 0)"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6184
apply(induct n, case_tac tp, simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6185
apply(auto simp: tshift.simps)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6186
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6187
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6188
lemma shift_length: "length (tshift tp n) = length tp"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6189
apply(auto simp: tshift.simps)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6190
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6191
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6192
lemma even_Suc_le: "\<lbrakk>y mod 2 = 0; 2 * x < y\<rbrakk> \<Longrightarrow> Suc (2 * x) < y"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6193
by arith
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6194
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6195
lemma [simp]: "(4::nat) * n mod 2 = 0"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6196
by arith
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6197
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6198
lemma tm_append_fetch_equal: 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6199
  "\<lbrakk>t_ncorrect (tm_of aprog); s'> 0;
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6200
    fetch (mop_bef n @ tshift mp_up (2 * n)) s' b = (a, 0)\<rbrakk>
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6201
\<Longrightarrow> fetch (tm_of aprog @ tshift (mop_bef n @ tshift mp_up (2 * n)) 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6202
    (length (tm_of aprog) div 2)) (s' + length (tm_of aprog) div 2) b 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6203
   = (a, 0)"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6204
apply(case_tac s', simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6205
apply(auto simp: fetch.simps nth_of.simps t_ncorrect.simps shift_length nth_append
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6206
                 tshift.simps split: list.splits block.splits split: if_splits)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6207
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6208
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6209
lemma [simp]:
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6210
  "\<lbrakk>t_ncorrect (tm_of aprog);
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6211
    t_step (s', l', r') (mop_bef n @ tshift mp_up (2 * n), 0) = 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6212
                                               (0, l'', r''); s' > 0\<rbrakk>
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6213
  \<Longrightarrow> t_step (s' + length (tm_of aprog) div 2, l', r') 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6214
        (tm_of aprog @ tshift (mop_bef n @ tshift mp_up (2 * n))
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6215
           (length (tm_of aprog) div 2), 0) = (0, l'', r'')"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6216
apply(simp add: t_step.simps)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6217
apply(subgoal_tac 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6218
   "(fetch (mop_bef n @ tshift mp_up (2 * n)) s' 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6219
              (case r' of [] \<Rightarrow> Bk | Bk # xs \<Rightarrow> Bk | Oc # xs \<Rightarrow> Oc))
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6220
  = (fetch (tm_of aprog @ tshift (mop_bef n @ tshift mp_up (2 * n)) 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6221
       (length (tm_of aprog) div 2)) (s' + length (tm_of aprog) div 2)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6222
    (case r' of [] \<Rightarrow> Bk | Bk # xs \<Rightarrow> Bk | Oc # xs \<Rightarrow> Oc))", simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6223
apply(case_tac "(fetch (mop_bef n @ tshift mp_up (2 * n)) s' 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6224
       (case r' of [] \<Rightarrow> Bk | Bk # xs \<Rightarrow> Bk | Oc # xs \<Rightarrow> Oc))", simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6225
apply(drule_tac tm_append_fetch_equal, auto)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6226
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6227
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6228
lemma [intro]: 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6229
  "start_of (layout_of aprog) (length aprog) - Suc 0 = 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6230
                                      length (tm_of aprog) div 2"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6231
apply(subgoal_tac  "abc2t_correct aprog")
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6232
apply(insert pre_lheq[of "concat (take (length aprog) 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6233
       (tms_of aprog))" "length aprog" aprog], simp add: tm_of.simps)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6234
by auto
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6235
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6236
lemma tm_append_stop_step: 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6237
  "\<lbrakk>t_ncorrect (tm_of aprog); 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6238
    t_ncorrect (mop_bef n @ tshift mp_up (2 * n)); n < length lm; 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6239
   (t_steps (Suc 0, l, r) (mop_bef n @ tshift mp_up (2 * n), 0) stp) =
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6240
                         (s', l', r');
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6241
    s' \<noteq> 0;
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6242
    t_step (s', l', r') (mop_bef n @ tshift mp_up (2 * n), 0) 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6243
                                                     = (0, l'', r'')\<rbrakk>
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6244
     \<Longrightarrow>
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6245
(t_steps ((start_of (layout_of aprog) (length aprog), l, r)) 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6246
  (tm_of aprog @ tshift (mop_bef n @ tshift mp_up (2 * n))
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6247
   (start_of (layout_of aprog) (length aprog) - Suc 0), 0) (Suc stp))
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6248
  = (0, l'', r'')"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6249
apply(insert tm_append_steps_equal[of "tm_of aprog" 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6250
      "(mop_bef n @ tshift mp_up (2 * n))"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6251
      "(start_of (layout_of aprog) (length aprog) - Suc 0)" 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6252
      "Suc 0" l r stp], simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6253
apply(subgoal_tac "(start_of (layout_of aprog) (length aprog) - Suc 0)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6254
              = (length (tm_of aprog) div 2)", simp add: t_steps_ind)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6255
apply(case_tac 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6256
 "(t_steps (start_of (layout_of aprog) (length aprog), l, r) 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6257
      (tm_of aprog @ tshift (mop_bef n @ tshift mp_up (2 * n))
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6258
           (length (tm_of aprog) div 2), 0) stp)", simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6259
apply(subgoal_tac "start_of (layout_of aprog) (length aprog) > 0", 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6260
      case_tac "start_of (layout_of aprog) (length aprog)", 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6261
      simp, simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6262
apply(rule startof_not0, auto)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6263
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6264
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6265
lemma start_of_out_range: 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6266
"as \<ge> length aprog \<Longrightarrow> 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6267
   start_of (layout_of aprog) as = 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6268
             start_of (layout_of aprog) (length aprog)"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6269
apply(induct as, simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6270
apply(case_tac "length aprog = Suc as", simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6271
apply(simp add: start_of.simps)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6272
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6273
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6274
lemma [intro]: "t_ncorrect (tm_of aprog)"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6275
apply(simp add: tm_of.simps)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6276
apply(insert tms_mod2[of "length aprog" aprog], 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6277
                                simp add: t_ncorrect.simps)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6278
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6279
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6280
lemma abacus_turing_eq_halt_case_pre: 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6281
   "\<lbrakk>ly = layout_of aprog; 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6282
     tprog = tm_of aprog; 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6283
     crsp_l ly ac tc ires;
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6284
     n < length am;
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6285
     abc_steps_l ac aprog stp = (as, am); 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6286
     mop_ss = start_of ly (length aprog);
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6287
     as \<ge> length aprog\<rbrakk>
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6288
     \<Longrightarrow> \<exists> stp. (\<lambda> (s, l, r). s = 0 \<and> mopup_inv (0, l, r) am n ires)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6289
                (t_steps tc (tprog @ (tMp n (mop_ss - 1)), 0) stp)"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6290
apply(insert steps_crsp[of ly aprog tprog ac tc ires "(as, am)" stp], auto)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6291
apply(case_tac "(t_steps tc (tm_of aprog, 0) n')",  
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6292
      simp add: tMp.simps)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6293
apply(subgoal_tac "t_ncorrect (mop_bef n @ tshift mp_up (2 * n))")
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6294
proof -
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6295
  fix n' a b c
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6296
  assume h1: 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6297
    "crsp_l (layout_of aprog) ac tc ires" 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6298
    "abc_steps_l ac aprog stp = (as, am)" 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6299
    "length aprog \<le> as"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6300
    "crsp_l (layout_of aprog) (as, am) (a, b, c) ires"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6301
    "t_steps tc (tm_of aprog, 0) n' = (a, b, c)"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6302
    "n < length am"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6303
    "t_ncorrect (mop_bef n @ tshift mp_up (2 * n))"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6304
  hence h2:
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6305
  "t_steps tc (tm_of aprog @ tshift (mop_bef n @ tshift mp_up (2 * n))
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6306
    (start_of (layout_of aprog) (length aprog) - Suc 0), 0) n' 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6307
                                    = (a, b, c)" 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6308
    apply(rule_tac tm_append_steps, simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6309
    apply(simp add: crsp_l.simps, auto)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6310
    apply(simp add: crsp_l.simps)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6311
    apply(rule startof_not0)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6312
    done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6313
  from h1 have h3: 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6314
  "\<exists>stp. (\<lambda>(s, l, r). s \<noteq> 0 \<and> ((\<lambda> (s', l', r'). s' = 0) 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6315
           (t_step (s, l, r) (mop_bef n @ tshift mp_up (2 * n), 0))))
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6316
         (t_steps (Suc 0, b, c) 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6317
               (mop_bef n @ tshift mp_up (2 * n), 0) stp)"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6318
    apply(rule_tac mopup_halt_bef, auto)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6319
    done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6320
  from h1 and h2 and h3 show 
35
839e37b75d9a removed second definition of tshift in abacus.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 34
diff changeset
  6321
    "\<exists>stp. case t_steps tc (tm_of aprog @ tshift (mop_bef n @ tshift mp_up (2 * n))
0
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6322
    (start_of (layout_of aprog) (length aprog) - Suc 0), 0) stp of (s, ab)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6323
    \<Rightarrow> s = 0 \<and> mopup_inv (0, ab) am n ires"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6324
  proof(erule_tac exE, 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6325
    case_tac "(t_steps (Suc 0, b, c) 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6326
              (mop_bef n @ tshift mp_up (2 * n), 0) stpa)", simp,
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6327
    case_tac "(t_step (aa, ba, ca) 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6328
              (mop_bef n @ tshift mp_up (2 * n), 0))", simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6329
    fix stpa aa ba ca aaa baa caa
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6330
    assume g1: "0 < aa \<and> aaa = 0" 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6331
      "t_steps (Suc 0, b, c) 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6332
      (mop_bef n @ tshift mp_up (2 * n), 0) stpa = (aa, ba,ca)" 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6333
      "t_step (aa, ba, ca) (mop_bef n @ tshift mp_up (2 * n), 0)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6334
      = (0, baa, caa)"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6335
    from h1 and this have g2: 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6336
      "t_steps (start_of (layout_of aprog) (length aprog), b, c) 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6337
         (tm_of aprog @ tshift (mop_bef n @ tshift mp_up (2 * n)) 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6338
           (start_of (layout_of aprog) (length aprog) - Suc 0), 0) 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6339
                (Suc stpa) = (0, baa, caa)"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6340
      apply(rule_tac tm_append_stop_step, auto)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6341
      done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6342
    from h1 and h2 and g1 and this show "?thesis"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6343
      apply(rule_tac x = "n' + Suc stpa" in exI)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6344
      apply(simp add: t_steps_ind del: t_steps.simps)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6345
      apply(subgoal_tac "a = start_of (layout_of aprog) 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6346
                                          (length aprog)", simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6347
      apply(insert mopup_inv_steps[of n am "Suc 0" b c ires "Suc stpa"],
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6348
            simp add: t_steps_ind)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6349
      apply(subgoal_tac "mopup_inv (Suc 0, b, c) am n ires", simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6350
      apply(rule_tac mopup_init, simp, simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6351
      apply(simp add: crsp_l.simps)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6352
      apply(erule_tac start_of_out_range)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6353
      done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6354
  qed
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6355
next
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6356
  show " t_ncorrect (mop_bef n @ tshift mp_up (2 * n))"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6357
    apply(auto simp: t_ncorrect.simps tshift.simps mp_up_def)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6358
    done   
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6359
qed
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6360
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6361
text {*
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6362
  One of the main theorems about Abacus compilation.
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6363
*}
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6364
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6365
lemma abacus_turing_eq_halt_case: 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6366
  assumes layout: 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6367
  -- {* There is an Abacus program @{text "aprog"} with layout @{text "ly"}: *}
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6368
  "ly = layout_of aprog"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6369
  and complied: 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6370
  -- {* The TM compiled from @{text "aprog"} is @{text "tprog"}: *}
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6371
  "tprog = tm_of aprog"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6372
  and correspond: 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6373
  -- {* TM configuration @{text "tc"} and Abacus configuration @{text "ac"}
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6374
  are in correspondence: *}
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6375
  "crsp_l ly ac tc ires"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6376
  and halt_state: 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6377
  -- {* @{text "as"} is a program label outside the range of @{text "aprog"}. So 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6378
  if Abacus is in such a state, it is in halt state: *}
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6379
  "as \<ge> length aprog"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6380
  and abc_exec: 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6381
  -- {* Supposing after @{text "stp"} step of execution, Abacus program @{text "aprog"}
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6382
  reaches such a halt state: *}
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6383
  "abc_steps_l ac aprog stp = (as, am)"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6384
  and rs_len: 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6385
  -- {* @{text "n"} is a memory address in the range of Abacus memory @{text "am"}: *}
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6386
  "n < length am"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6387
  and mopup_start:
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6388
  -- {* The startling label for mopup mahines, according to the layout and Abacus program 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6389
   should be @{text "mop_ss"}: *}
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6390
  "mop_ss = start_of ly (length aprog)"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6391
  shows 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6392
  -- {* 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6393
  After @{text "stp"} steps of execution of the TM composed of @{text "tprog"} and the mopup 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6394
  TM @{text "(tMp n (mop_ss - 1))"} will halt and gives rise to a configuration which 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6395
  only hold the content of memory cell @{text "n"}:
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6396
  *}
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6397
  "\<exists> stp. (\<lambda> (s, l, r). \<exists> ln rn. s = 0 \<and>  l = Bk\<^bsup>ln\<^esup> @ Bk # Bk # ires
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6398
     \<and> r = Oc\<^bsup>Suc (abc_lm_v am n)\<^esup> @ Bk\<^bsup>rn\<^esup>)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6399
           (t_steps tc (tprog @ (tMp n (mop_ss - 1)), 0) stp)"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6400
proof -
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6401
  from layout complied correspond halt_state abc_exec rs_len mopup_start
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6402
       and abacus_turing_eq_halt_case_pre [of ly aprog tprog ac tc ires n am stp as mop_ss]
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6403
  show "?thesis" 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6404
    apply(simp add: mopup_inv.simps mopup_stop.simps tape_of_nat_abv)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6405
    done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6406
qed
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6407
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6408
lemma abc_unhalt_case_zero: 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6409
"\<lbrakk>crsp_l (layout_of aprog) ac tc ires;
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6410
  n < length am; 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6411
  \<forall>stp. (\<lambda>(as, am). as < length aprog) (abc_steps_l ac aprog stp)\<rbrakk>
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6412
 \<Longrightarrow> \<exists>astp bstp. 0 \<le> bstp \<and> 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6413
          crsp_l (layout_of aprog) (abc_steps_l ac aprog astp) 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6414
                (t_steps tc (tm_of aprog, 0) bstp) ires"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6415
apply(rule_tac x = "Suc 0" in exI)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6416
apply(case_tac " abc_steps_l ac aprog (Suc 0)", simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6417
proof -
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6418
  fix a b
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6419
  assume "crsp_l (layout_of aprog) ac tc ires" 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6420
         "abc_steps_l ac aprog (Suc 0) = (a, b)"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6421
  thus "\<exists>bstp. crsp_l (layout_of aprog) (a, b) 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6422
               (t_steps tc (tm_of aprog, 0) bstp) ires"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6423
    apply(insert steps_crsp[of "layout_of aprog" aprog 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6424
                  "tm_of aprog" ac tc ires "(a, b)" "Suc 0"], auto)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6425
    done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6426
qed
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6427
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6428
declare abc_steps_l.simps[simp del]
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6429
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6430
lemma abc_steps_ind: 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6431
 "let (as, am) = abc_steps_l ac aprog stp in 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6432
   abc_steps_l ac aprog (Suc stp) =
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6433
              abc_step_l (as, am) (abc_fetch as aprog) "
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6434
proof(simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6435
  show "(\<lambda>(as, am). abc_steps_l ac aprog (Suc stp) = 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6436
        abc_step_l (as, am) (abc_fetch as aprog)) 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6437
              (abc_steps_l ac aprog stp)"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6438
  proof(induct stp arbitrary: ac)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6439
    fix ac
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6440
    show "(\<lambda>(as, am). abc_steps_l ac aprog (Suc 0) = 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6441
            abc_step_l (as, am) (abc_fetch as aprog))  
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6442
                    (abc_steps_l ac aprog 0)"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6443
      apply(case_tac "ac:: nat \<times> nat list", 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6444
            simp add: abc_steps_l.simps)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6445
      apply(case_tac "(abc_step_l (a, b) (abc_fetch a aprog))",
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6446
            simp add: abc_steps_l.simps)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6447
      done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6448
  next
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6449
    fix stp ac
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6450
    assume h1:
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6451
      "(\<And>ac. (\<lambda>(as, am). abc_steps_l ac aprog (Suc stp) =
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6452
                            abc_step_l (as, am) (abc_fetch as aprog)) 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6453
             (abc_steps_l ac aprog stp))"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6454
    thus 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6455
      "(\<lambda>(as, am). abc_steps_l ac aprog (Suc (Suc stp)) =
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6456
              abc_step_l (as, am) (abc_fetch as aprog)) 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6457
                             (abc_steps_l ac aprog (Suc stp))"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6458
      apply(case_tac "ac::nat \<times> nat list", simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6459
      apply(subgoal_tac 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6460
           "abc_steps_l (a, b) aprog (Suc (Suc stp)) =
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6461
            abc_steps_l (abc_step_l (a, b) (abc_fetch a aprog)) 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6462
                                              aprog (Suc stp)", simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6463
      apply(case_tac "(abc_step_l (a, b) (abc_fetch a aprog))", simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6464
    proof -
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6465
      fix a b aa ba
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6466
      assume h2: "abc_step_l (a, b) (abc_fetch a aprog) = (aa, ba)"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6467
      from h1 and h2  show 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6468
      "(\<lambda>(as, am). abc_steps_l (aa, ba) aprog (Suc stp) = 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6469
          abc_step_l (as, am) (abc_fetch as aprog)) 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6470
                    (abc_steps_l (a, b) aprog (Suc stp))"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6471
	apply(insert h1[of "(aa, ba)"])
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6472
	apply(simp add: abc_steps_l.simps)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6473
	apply(insert h2, simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6474
	done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6475
    next
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6476
      fix a b
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6477
      show 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6478
        "abc_steps_l (a, b) aprog (Suc (Suc stp)) = 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6479
         abc_steps_l (abc_step_l (a, b) (abc_fetch a aprog)) 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6480
                                                   aprog (Suc stp)"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6481
	apply(simp only: abc_steps_l.simps)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6482
	done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6483
    qed
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6484
  qed
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6485
qed
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6486
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6487
lemma abc_unhalt_case_induct: 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6488
  "\<lbrakk>crsp_l (layout_of aprog) ac tc ires;
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6489
    n < length am; 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6490
    \<forall>stp. (\<lambda>(as, am). as < length aprog) (abc_steps_l ac aprog stp); 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6491
    stp \<le> bstp;
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6492
    crsp_l (layout_of aprog) (abc_steps_l ac aprog astp) 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6493
                           (t_steps tc (tm_of aprog, 0) bstp) ires\<rbrakk>
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6494
 \<Longrightarrow> \<exists>astp bstp. Suc stp \<le> bstp \<and> crsp_l (layout_of aprog) 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6495
       (abc_steps_l ac aprog astp) (t_steps tc (tm_of aprog, 0) bstp) ires"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6496
apply(rule_tac x = "Suc astp" in exI)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6497
apply(case_tac "abc_steps_l ac aprog astp")
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6498
proof -
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6499
  fix a b
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6500
  assume 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6501
    "\<forall>stp. (\<lambda>(as, am). as < length aprog)  
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6502
                 (abc_steps_l ac aprog stp)" 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6503
    "stp \<le> bstp"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6504
    "crsp_l (layout_of aprog) (abc_steps_l ac aprog astp) 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6505
      (t_steps tc (tm_of aprog, 0) bstp) ires" 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6506
    "abc_steps_l ac aprog astp = (a, b)"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6507
  thus 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6508
 "\<exists>bstp\<ge>Suc stp. crsp_l (layout_of aprog)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6509
       (abc_steps_l ac aprog (Suc astp)) 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6510
   (t_steps tc (tm_of aprog, 0) bstp) ires"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6511
    apply(insert crsp_inside[of "layout_of aprog" aprog 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6512
      "tm_of aprog" a b "(t_steps tc (tm_of aprog, 0) bstp)" "ires"], auto)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6513
    apply(erule_tac x = astp in allE, auto)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6514
    apply(rule_tac x = "bstp + stpa" in exI, simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6515
    apply(insert abc_steps_ind[of ac aprog "astp"], simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6516
    done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6517
qed   
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6518
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6519
lemma abc_unhalt_case: 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6520
  "\<lbrakk>crsp_l (layout_of aprog) ac tc ires;  
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6521
    \<forall>stp. (\<lambda>(as, am). as < length aprog) (abc_steps_l ac aprog stp)\<rbrakk>
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6522
 \<Longrightarrow> (\<exists> astp bstp. bstp \<ge> stp \<and> 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6523
         crsp_l (layout_of aprog) (abc_steps_l ac aprog astp) 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6524
                                (t_steps tc (tm_of aprog, 0) bstp) ires)"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6525
apply(induct stp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6526
apply(rule_tac abc_unhalt_case_zero, auto)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6527
apply(rule_tac abc_unhalt_case_induct, auto)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6528
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6529
  
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6530
lemma abacus_turing_eq_unhalt_case_pre: 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6531
  "\<lbrakk>ly = layout_of aprog; 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6532
    tprog = tm_of aprog;
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6533
    crsp_l ly ac tc ires;
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6534
    \<forall> stp. ((\<lambda> (as, am). as < length aprog)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6535
                       (abc_steps_l ac aprog stp));
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6536
    mop_ss = start_of ly (length aprog)\<rbrakk>
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6537
  \<Longrightarrow> (\<not> (\<exists> stp. (\<lambda> (s, l, r). s = 0)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6538
              (t_steps tc (tprog @ (tMp n (mop_ss - 1)), 0) stp)))"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6539
  apply(auto)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6540
proof -
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6541
  fix stp a b
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6542
  assume h1: 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6543
    "crsp_l (layout_of aprog) ac tc ires" 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6544
    "\<forall>stp. (\<lambda>(as, am). as < length aprog) (abc_steps_l ac aprog stp)"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6545
    "t_steps tc (tm_of aprog @ tMp n (start_of (layout_of aprog) 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6546
    (length aprog) - Suc 0), 0) stp = (0, a, b)"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6547
  thus "False"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6548
  proof(insert abc_unhalt_case[of aprog ac tc ires stp], auto, 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6549
        case_tac "(abc_steps_l ac aprog astp)", 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6550
        case_tac "(t_steps tc (tm_of aprog, 0) bstp)", simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6551
    fix astp bstp aa ba aaa baa c
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6552
    assume h2: 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6553
      "abc_steps_l ac aprog astp = (aa, ba)" "stp \<le> bstp"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6554
      "t_steps tc (tm_of aprog, 0) bstp = (aaa, baa, c)" 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6555
      "crsp_l (layout_of aprog) (aa, ba) (aaa, baa, c) ires"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6556
    hence h3: 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6557
      "t_steps tc (tm_of aprog @ tMp n 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6558
       (start_of (layout_of aprog) (length aprog) - Suc 0), 0) bstp 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6559
                    = (aaa, baa, c)"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6560
      apply(intro tm_append_steps, auto)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6561
      apply(simp add: crsp_l.simps, rule startof_not0)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6562
      done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6563
    from h2 have h4: "\<exists> diff. bstp = stp + diff"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6564
      apply(rule_tac x = "bstp - stp" in exI, simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6565
      done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6566
    from h4 and h3 and h2  and h1 show "?thesis"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6567
      apply(auto)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6568
      apply(simp add: state0_ind crsp_l.simps)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6569
      apply(subgoal_tac "start_of (layout_of aprog) aa > 0", simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6570
      apply(rule startof_not0)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6571
      done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6572
  qed
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6573
qed
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6574
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6575
lemma abacus_turing_eq_unhalt_case:
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6576
  assumes layout: 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6577
  -- {* There is an Abacus program @{text "aprog"} with layout @{text "ly"}: *}
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6578
  "ly = layout_of aprog"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6579
  and compiled: 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6580
  -- {* The TM compiled from @{text "aprog"} is @{text "tprog"}: *}
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6581
  "tprog = tm_of aprog"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6582
  and correspond: 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6583
  -- {* 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6584
  TM configuration @{text "tc"} and Abacus configuration @{text "ac"}
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6585
  are in correspondence: 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6586
  *}
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6587
  "crsp_l ly ac tc ires"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6588
  and abc_unhalt: 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6589
  -- {*
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6590
  If, no matter how many steps the Abacus program @{text "aprog"} executes, it
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6591
  may never reach a halt state. 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6592
  *}
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6593
  "\<forall> stp. ((\<lambda> (as, am). as < length aprog)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6594
                       (abc_steps_l ac aprog stp))"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6595
  and mopup_start: "mop_ss = start_of ly (length aprog)"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6596
  shows
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6597
  -- {*
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6598
  The the TM composed of TM @{text "tprog"} and the moupup TM may never reach a halt state as well.
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6599
  *}
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6600
  "\<not> (\<exists> stp. (\<lambda> (s, l, r). s = 0)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6601
              (t_steps tc (tprog @ (tMp n (mop_ss - 1)), 0) stp))"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6602
  using layout compiled correspond abc_unhalt mopup_start
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6603
  apply(rule_tac abacus_turing_eq_unhalt_case_pre, auto)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6604
  done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6605
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6606
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6607
definition abc_list_crsp:: "nat list \<Rightarrow> nat list \<Rightarrow> bool"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6608
  where
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6609
  "abc_list_crsp xs ys = (\<exists> n. xs = ys @ 0\<^bsup>n\<^esup> \<or> ys = xs @ 0\<^bsup>n\<^esup>)"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6610
lemma [intro]: "abc_list_crsp (lm @ 0\<^bsup>m\<^esup>) lm"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6611
apply(auto simp: abc_list_crsp_def)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6612
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6613
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6614
lemma abc_list_crsp_lm_v: 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6615
  "abc_list_crsp lma lmb \<Longrightarrow> abc_lm_v lma n = abc_lm_v lmb n"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6616
apply(auto simp: abc_list_crsp_def abc_lm_v.simps 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6617
                 nth_append exponent_def)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6618
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6619
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6620
lemma  rep_app_cons_iff: 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6621
  "k < n \<Longrightarrow> replicate n a[k:=b] = 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6622
          replicate k a @ b # replicate (n - k - 1) a"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6623
apply(induct n arbitrary: k, simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6624
apply(simp split:nat.splits)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6625
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6626
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6627
lemma abc_list_crsp_lm_s: 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6628
  "abc_list_crsp lma lmb \<Longrightarrow> 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6629
      abc_list_crsp (abc_lm_s lma m n) (abc_lm_s lmb m n)"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6630
apply(auto simp: abc_list_crsp_def abc_lm_v.simps abc_lm_s.simps)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6631
apply(simp_all add: list_update_append, auto simp: exponent_def)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6632
proof -
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6633
  fix na
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6634
  assume h: "m < length lmb + na" " \<not> m < length lmb"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6635
  hence "m - length lmb < na" by simp
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6636
  hence "replicate na 0[(m- length lmb):= n] = 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6637
           replicate (m - length lmb) 0 @ n # 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6638
              replicate (na - (m - length lmb) - 1) 0"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6639
    apply(erule_tac rep_app_cons_iff)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6640
    done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6641
  thus "\<exists>nb. replicate na 0[m - length lmb := n] =
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6642
                 replicate (m - length lmb) 0 @ n # replicate nb 0 \<or>
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6643
                 replicate (m - length lmb) 0 @ [n] =
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6644
                 replicate na 0[m - length lmb := n] @ replicate nb 0"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6645
    apply(auto)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6646
    done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6647
next
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6648
  fix na
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6649
  assume h: "\<not> m < length lmb + na"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6650
  show 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6651
    "\<exists>nb. replicate na 0 @ replicate (m - (length lmb + na)) 0 @ [n] =
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6652
           replicate (m - length lmb) 0 @ n # replicate nb 0 \<or>
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6653
          replicate (m - length lmb) 0 @ [n] =
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6654
            replicate na 0 @
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6655
            replicate (m - (length lmb + na)) 0 @ n # replicate nb 0"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6656
    apply(rule_tac x = 0 in exI, simp, auto)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6657
    using h
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6658
    apply(simp add: replicate_add[THEN sym])
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6659
    done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6660
next
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6661
  fix na
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6662
  assume h: "\<not> m < length lma" "m < length lma + na"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6663
  hence "m - length lma < na" by simp
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6664
  hence 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6665
    "replicate na 0[(m- length lma):= n] = replicate (m - length lma) 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6666
                  0 @ n # replicate (na - (m - length lma) - 1) 0"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6667
    apply(erule_tac rep_app_cons_iff)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6668
    done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6669
  thus "\<exists>nb. replicate (m - length lma) 0 @ [n] =
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6670
                 replicate na 0[m - length lma := n] @ replicate nb 0 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6671
           \<or> replicate na 0[m - length lma := n] =
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6672
                 replicate (m - length lma) 0 @ n # replicate nb 0"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6673
    apply(auto)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6674
    done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6675
next
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6676
  fix na
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6677
  assume "\<not> m < length lma + na"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6678
  thus " \<exists>nb. replicate (m - length lma) 0 @ [n] =
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6679
            replicate na 0 @
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6680
            replicate (m - (length lma + na)) 0 @ n # replicate nb 0 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6681
        \<or>   replicate na 0 @ 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6682
               replicate (m - (length lma + na)) 0 @ [n] =
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6683
            replicate (m - length lma) 0 @ n # replicate nb 0"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6684
    apply(rule_tac x = 0 in exI, simp, auto)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6685
    apply(simp add: replicate_add[THEN sym])
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6686
    done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6687
qed
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6688
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6689
lemma abc_list_crsp_step: 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6690
  "\<lbrakk>abc_list_crsp lma lmb; abc_step_l (aa, lma) i = (a, lma'); 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6691
    abc_step_l (aa, lmb) i = (a', lmb')\<rbrakk>
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6692
    \<Longrightarrow> a' = a \<and> abc_list_crsp lma' lmb'"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6693
apply(case_tac i, auto simp: abc_step_l.simps 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6694
       abc_list_crsp_lm_s abc_list_crsp_lm_v Let_def 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6695
                       split: abc_inst.splits if_splits)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6696
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6697
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6698
lemma abc_steps_red: 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6699
  "abc_steps_l ac aprog stp = (as, am) \<Longrightarrow>
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6700
     abc_steps_l ac aprog (Suc stp) = 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6701
           abc_step_l (as, am) (abc_fetch as aprog)"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6702
using abc_steps_ind[of ac aprog stp]
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6703
apply(simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6704
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6705
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6706
lemma abc_list_crsp_steps: 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6707
  "\<lbrakk>abc_steps_l (0, lm @ 0\<^bsup>m\<^esup>) aprog stp = (a, lm'); aprog \<noteq> []\<rbrakk> 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6708
      \<Longrightarrow> \<exists> lma. abc_steps_l (0, lm) aprog stp = (a, lma) \<and> 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6709
                                          abc_list_crsp lm' lma"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6710
apply(induct stp arbitrary: a lm', simp add: abc_steps_l.simps, auto)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6711
apply(case_tac "abc_steps_l (0, lm @ 0\<^bsup>m\<^esup>) aprog stp", 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6712
      simp add: abc_steps_ind)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6713
proof -
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6714
  fix stp a lm' aa b
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6715
  assume ind:
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6716
    "\<And>a lm'. aa = a \<and> b = lm' \<Longrightarrow> 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6717
     \<exists>lma. abc_steps_l (0, lm) aprog stp = (a, lma) \<and>
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6718
                                          abc_list_crsp lm' lma"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6719
    and h: "abc_steps_l (0, lm @ 0\<^bsup>m\<^esup>) aprog (Suc stp) = (a, lm')" 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6720
           "abc_steps_l (0, lm @ 0\<^bsup>m\<^esup>) aprog stp = (aa, b)" 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6721
           "aprog \<noteq> []"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6722
  hence g1: "abc_steps_l (0, lm @ 0\<^bsup>m\<^esup>) aprog (Suc stp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6723
          = abc_step_l (aa, b) (abc_fetch aa aprog)"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6724
    apply(rule_tac abc_steps_red, simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6725
    done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6726
  have "\<exists>lma. abc_steps_l (0, lm) aprog stp = (aa, lma) \<and> 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6727
              abc_list_crsp b lma"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6728
    apply(rule_tac ind, simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6729
    done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6730
  from this obtain lma where g2: 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6731
    "abc_steps_l (0, lm) aprog stp = (aa, lma) \<and> 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6732
     abc_list_crsp b lma"   ..
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6733
  hence g3: "abc_steps_l (0, lm) aprog (Suc stp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6734
          = abc_step_l (aa, lma) (abc_fetch aa aprog)"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6735
    apply(rule_tac abc_steps_red, simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6736
    done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6737
  show "\<exists>lma. abc_steps_l (0, lm) aprog (Suc stp) = (a, lma) \<and>  
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6738
              abc_list_crsp lm' lma"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6739
    using g1 g2 g3 h
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6740
    apply(auto)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6741
    apply(case_tac "abc_step_l (aa, b) (abc_fetch aa aprog)",
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6742
          case_tac "abc_step_l (aa, lma) (abc_fetch aa aprog)", simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6743
    apply(rule_tac abc_list_crsp_step, auto)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6744
    done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6745
qed
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6746
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6747
lemma [simp]: "(case ca of [] \<Rightarrow> Bk | Bk # xs \<Rightarrow> Bk | Oc # xs \<Rightarrow> Oc) =
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6748
                (case ca of [] \<Rightarrow> Bk | x # xs \<Rightarrow> x)"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6749
by(case_tac ca, simp_all, case_tac a, simp, simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6750
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6751
lemma steps_eq: "length t mod 2 = 0 \<Longrightarrow> 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6752
                    t_steps c (t, 0) stp = steps c t stp"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6753
apply(induct stp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6754
apply(simp add: steps.simps t_steps.simps)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6755
apply(simp add:tstep_red t_steps_ind)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6756
apply(case_tac "steps c t stp", simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6757
apply(auto simp: t_step.simps tstep.simps)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6758
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6759
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6760
lemma crsp_l_start: "crsp_l ly (0, lm) (Suc 0, Bk # Bk # ires, <lm> @ Bk\<^bsup>rn\<^esup>) ires"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6761
apply(simp add: crsp_l.simps, auto simp: start_of.simps)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6762
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6763
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6764
lemma t_ncorrect_app: "\<lbrakk>t_ncorrect t1; t_ncorrect t2\<rbrakk> \<Longrightarrow> 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6765
                                          t_ncorrect (t1 @ t2)"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6766
apply(simp add: t_ncorrect.simps, auto)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6767
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6768
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6769
lemma [simp]: 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6770
  "(length (tm_of aprog) + 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6771
    length (tMp n (start_of ly (length aprog) - Suc 0))) mod 2 = 0"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6772
apply(subgoal_tac 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6773
 "t_ncorrect (tm_of aprog @ tMp n 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6774
             (start_of ly (length aprog) - Suc 0))")
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6775
apply(simp add: t_ncorrect.simps)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6776
apply(rule_tac t_ncorrect_app, 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6777
      auto simp: tMp.simps t_ncorrect.simps tshift.simps mp_up_def)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6778
apply(subgoal_tac
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6779
       "t_ncorrect (tm_of aprog)", simp add: t_ncorrect.simps)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6780
apply(auto)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6781
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6782
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6783
lemma [simp]: "takeWhile (\<lambda>a. a = Oc) 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6784
              (replicate rs Oc @ replicate rn Bk) = replicate rs Oc"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6785
apply(induct rs, auto)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6786
apply(induct rn, auto)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6787
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6788
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6789
lemma abacus_turing_eq_halt': 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6790
  "\<lbrakk>ly = layout_of aprog; 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6791
    tprog = tm_of aprog; 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6792
    n < length am;
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6793
    abc_steps_l (0, lm) aprog stp = (as, am); 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6794
    mop_ss = start_of ly (length aprog);
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6795
    as \<ge> length aprog\<rbrakk>
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6796
    \<Longrightarrow> \<exists> stp m l. steps (Suc 0, Bk # Bk # ires, <lm> @ Bk\<^bsup>rn\<^esup>) 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6797
                (tprog @ (tMp n (mop_ss - 1))) stp
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6798
                  = (0, Bk\<^bsup>m\<^esup> @ Bk # Bk # ires, Oc\<^bsup>Suc (abc_lm_v am n)\<^esup> @ Bk\<^bsup>l\<^esup>)"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6799
apply(drule_tac tc = "(Suc 0, Bk # Bk # ires, <lm> @ Bk\<^bsup>rn\<^esup>)" in 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6800
               abacus_turing_eq_halt_case, auto intro: crsp_l_start)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6801
apply(subgoal_tac 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6802
         "length (tm_of aprog @ tMp n 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6803
                  (start_of ly (length aprog) - Suc 0)) mod 2 = 0")
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6804
apply(simp add: steps_eq)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6805
apply(rule_tac x = stpa in exI, 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6806
       simp add:  exponent_def, auto)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6807
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6808
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6809
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6810
lemma list_length: "xs = ys \<Longrightarrow> length xs = length ys"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6811
by simp
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6812
lemma [elim]: "tinres (Bk\<^bsup>m\<^esup>) b \<Longrightarrow> \<exists>m. b = Bk\<^bsup>m\<^esup>"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6813
apply(auto simp: tinres_def)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6814
apply(rule_tac x = "m-n" in exI, 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6815
             auto simp: exponent_def replicate_add[THEN sym]) 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6816
apply(case_tac "m < n", auto)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6817
apply(drule_tac list_length, auto)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6818
apply(subgoal_tac "\<exists> d. m = d + n", auto simp: replicate_add)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6819
apply(rule_tac x = "m - n" in exI, simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6820
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6821
lemma [intro]: "tinres [Bk] (Bk\<^bsup>k\<^esup>) "
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6822
apply(auto simp: tinres_def exponent_def)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6823
apply(case_tac k, auto)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6824
apply(rule_tac x = "Suc 0" in exI, simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6825
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6826
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6827
lemma abacus_turing_eq_halt_pre: 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6828
 "\<lbrakk>ly = layout_of aprog; 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6829
   tprog = tm_of aprog; 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6830
   n < length am;     
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6831
   abc_steps_l (0, lm) aprog stp = (as, am);  
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6832
   mop_ss = start_of ly (length aprog);
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6833
   as \<ge> length aprog\<rbrakk>
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6834
  \<Longrightarrow> \<exists> stp m l. steps  (Suc 0, Bk # Bk # ires, <lm> @ Bk\<^bsup>rn\<^esup>)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6835
               (tprog @ (tMp n (mop_ss - 1))) stp
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6836
                 = (0, Bk\<^bsup>m\<^esup> @ Bk # Bk # ires, Oc\<^bsup>Suc (abc_lm_v am n)\<^esup> @ Bk\<^bsup>l\<^esup>)"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6837
using abacus_turing_eq_halt'
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6838
apply(simp)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6839
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6840
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6841
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6842
text {*
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6843
  Main theorem for the case when the original Abacus program does halt.
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6844
*}
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6845
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6846
lemma abacus_turing_eq_halt: 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6847
  assumes layout:
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6848
  "ly = layout_of aprog"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6849
  -- {* There is an Abacus program @{text "aprog"} with layout @{text "ly"}: *}
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6850
  and compiled: "tprog = tm_of aprog"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6851
  -- {* The TM compiled from @{text "aprog"} is @{text "tprog"}: *}
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6852
  and halt_state: 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6853
   -- {* @{text "as"} is a program label outside the range of @{text "aprog"}. So 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6854
  if Abacus is in such a state, it is in halt state: *}
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6855
  "as \<ge> length aprog"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6856
  and abc_exec: 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6857
  -- {* Supposing after @{text "stp"} step of execution, Abacus program @{text "aprog"}
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6858
  reaches such a halt state: *}
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6859
  "abc_steps_l (0, lm) aprog stp = (as, am)"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6860
  and rs_locate: 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6861
   -- {* @{text "n"} is a memory address in the range of Abacus memory @{text "am"}: *}
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6862
  "n < length am"  
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6863
  and mopup_start: 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6864
   -- {* The startling label for mopup mahines, according to the layout and Abacus program 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6865
   should be @{text "mop_ss"}: *}
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6866
  "mop_ss = start_of ly (length aprog)"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6867
  shows 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6868
  -- {* 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6869
  After @{text "stp"} steps of execution of the TM composed of @{text "tprog"} and the mopup 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6870
  TM @{text "(tMp n (mop_ss - 1))"} will halt and gives rise to a configuration which 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6871
  only hold the content of memory cell @{text "n"}:
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6872
  *}
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6873
  "\<exists> stp m l. steps (Suc 0, Bk # Bk # ires, <lm> @ Bk\<^bsup>rn\<^esup>) (tprog @ (tMp n (mop_ss - 1))) stp
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6874
                      = (0, Bk\<^bsup>m\<^esup> @ Bk # Bk # ires, Oc\<^bsup>Suc (abc_lm_v am n)\<^esup> @ Bk\<^bsup>l\<^esup>)"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6875
  using layout compiled halt_state abc_exec rs_locate mopup_start
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6876
  by(rule_tac abacus_turing_eq_halt_pre, auto)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6877
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6878
lemma abacus_turing_eq_uhalt': 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6879
 "\<lbrakk>ly = layout_of aprog; 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6880
   tprog = tm_of aprog; 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6881
   \<forall> stp. ((\<lambda> (as, am). as < length aprog) 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6882
                   (abc_steps_l (0, lm) aprog stp));
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6883
   mop_ss = start_of ly (length aprog)\<rbrakk>
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6884
  \<Longrightarrow> (\<not> (\<exists> stp. isS0 (steps (Suc 0, [Bk, Bk], <lm>) 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6885
                      (tprog @ (tMp n (mop_ss - 1))) stp)))"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6886
apply(drule_tac tc = "(Suc 0, [Bk, Bk], <lm>)" and n = n and ires = "[]" in 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6887
         abacus_turing_eq_unhalt_case, auto intro: crsp_l_start)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6888
apply(simp add: crsp_l.simps start_of.simps)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6889
apply(erule_tac x = stp in allE, erule_tac x = stp in allE)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6890
apply(subgoal_tac 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6891
   "length (tm_of aprog @ tMp n 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6892
         (start_of ly (length aprog) - Suc 0)) mod 2 = 0")
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6893
apply(simp add: steps_eq, auto simp: isS0_def)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6894
done
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6895
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6896
text {*
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6897
  Main theorem for the case when the original Abacus program does not halt.
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6898
  *}
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6899
lemma abacus_turing_eq_uhalt:
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6900
  assumes layout: 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6901
  -- {* There is an Abacus program @{text "aprog"} with layout @{text "ly"}: *}
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6902
  "ly = layout_of aprog"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6903
  and compiled:
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6904
   -- {* The TM compiled from @{text "aprog"} is @{text "tprog"}: *}
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6905
  "tprog = tm_of aprog"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6906
  and abc_unhalt:
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6907
  -- {*
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6908
  If, no matter how many steps the Abacus program @{text "aprog"} executes, it
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6909
  may never reach a halt state. 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6910
  *}
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6911
  "\<forall> stp. ((\<lambda> (as, am). as < length aprog) 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6912
                      (abc_steps_l (0, lm) aprog stp))"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6913
  and mop_start: "mop_ss = start_of ly (length aprog)"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6914
  shows 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6915
   -- {*
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6916
  The the TM composed of TM @{text "tprog"} and the moupup TM may never reach a halt state as well.
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6917
  *}
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6918
  "\<not> (\<exists> stp. isS0 (steps (Suc 0, [Bk, Bk], <lm>) 
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6919
                    (tprog @ (tMp n (mop_ss - 1))) stp))"
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6920
  using abacus_turing_eq_uhalt'
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6921
        layout compiled abc_unhalt mop_start
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6922
  by(auto)
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6923
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6924
end
aa8656a8dbef initial setup
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  6925