thys/abacus.thy
author Christian Urban <christian dot urban at kcl dot ac dot uk>
Sun, 20 Jan 2013 16:01:16 +0000
changeset 60 c8ff97d9f8da
parent 48 559e5c6e5113
child 61 7edbd5657702
permissions -rw-r--r--
new version of abacus
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
47
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
     1
header {* 
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
     2
 {\em abacus} a kind of register machine
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
     3
*}
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
     4
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
     5
theory abacus
60
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
     6
imports Main turing_hoare
47
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
     7
begin
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
     8
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
     9
text {*
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    10
  {\em Abacus} instructions:
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    11
*}
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    12
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    13
datatype abc_inst =
251e192339b7 added abacus
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.
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    15
     *}
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    16
     Inc nat
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    17
  -- {*
251e192339b7 added abacus
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. 
251e192339b7 added abacus
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
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    20
      the instruction labeled by @{text "label"}.
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    21
     *}
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    22
   | Dec nat nat
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    23
  -- {*
251e192339b7 added abacus
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"}.
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    25
  *}
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    26
   | Goto nat
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    27
  
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    28
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    29
text {*
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    30
  Abacus programs are defined as lists of Abacus instructions.
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    31
*}
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    32
type_synonym abc_prog = "abc_inst list"
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    33
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    34
section {*
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    35
  Sample Abacus programs
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    36
  *}
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    37
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    38
text {*
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    39
  Abacus for addition and clearance.
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    40
*}
251e192339b7 added abacus
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"  
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    42
  where
251e192339b7 added abacus
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]"
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    44
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    45
text {*
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    46
  Abacus for clearing memory untis.
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    47
*}
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    48
fun clear :: "nat \<Rightarrow> nat \<Rightarrow> abc_prog"
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    49
  where
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    50
  "clear n e = [Dec n e, Goto 0]"
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    51
251e192339b7 added abacus
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"
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    53
  where
251e192339b7 added abacus
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,
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    55
                   Goto 0, Dec p e, Inc m, Goto 4]"
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    56
251e192339b7 added abacus
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"
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    58
  where
251e192339b7 added abacus
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"
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    60
251e192339b7 added abacus
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"
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    62
  where
251e192339b7 added abacus
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"
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    64
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    65
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    66
text {*
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    67
  The state of Abacus machine.
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    68
  *}
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    69
type_synonym abc_state = nat
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    70
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    71
(* text {*
251e192339b7 added abacus
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.
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    73
*}
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    74
type_synonym abc_mem = "nat \<Rightarrow> nat" *)
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    75
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    76
text {*
251e192339b7 added abacus
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 
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    78
  every units addressed by index into the list.
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    79
  *}
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    80
type_synonym abc_lm = "nat list"
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    81
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    82
text {*
251e192339b7 added abacus
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
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    84
  as having content @{text "0"}.
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    85
*}
251e192339b7 added abacus
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"
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    87
  where 
251e192339b7 added abacus
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)"         
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    89
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    90
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    91
text {*
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    92
  Set the content of memory unit @{text "n"} to value @{text "v"}.
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    93
  @{text "am"} is the Abacus memory before setting.
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    94
  If address @{text "n"} is outside to scope of @{text "am"}, @{text "am"} 
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    95
  is extended so that @{text "n"} becomes in scope.
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    96
*}
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    97
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    98
fun abc_lm_s :: "abc_lm \<Rightarrow> nat \<Rightarrow> nat \<Rightarrow> abc_lm"
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    99
  where
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   100
    "abc_lm_s am n v = (if (n < length am) then (am[n:=v]) else 
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   101
                           am@ (replicate (n - length am) 0) @ [v])"
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   102
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   103
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   104
text {*
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   105
  The configuration of Abaucs machines consists of its current state and its
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   106
  current memory:
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   107
*}
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   108
type_synonym abc_conf = "abc_state \<times> abc_lm"
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   109
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   110
text {*
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   111
  Fetch instruction out of Abacus program:
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   112
*}
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   113
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   114
fun abc_fetch :: "nat \<Rightarrow> abc_prog \<Rightarrow> abc_inst option" 
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   115
  where
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   116
  "abc_fetch s p = (if (s < length p) then Some (p ! s)
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   117
                    else None)"
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   118
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   119
text {*
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   120
  Single step execution of Abacus machine. If no instruction is feteched, 
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   121
  configuration does not change.
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   122
*}
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   123
fun abc_step_l :: "abc_conf \<Rightarrow> abc_inst option \<Rightarrow> abc_conf"
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   124
  where
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   125
  "abc_step_l (s, lm) a = (case a of 
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   126
               None \<Rightarrow> (s, lm) |
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   127
               Some (Inc n)  \<Rightarrow> (let nv = abc_lm_v lm n in
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   128
                       (s + 1, abc_lm_s lm n (nv + 1))) |
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   129
               Some (Dec n e) \<Rightarrow> (let nv = abc_lm_v lm n in
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   130
                       if (nv = 0) then (e, abc_lm_s lm n 0) 
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   131
                       else (s + 1,  abc_lm_s lm n (nv - 1))) |
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   132
               Some (Goto n) \<Rightarrow> (n, lm) 
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   133
               )"
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   134
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   135
text {*
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   136
  Multi-step execution of Abacus machine.
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   137
*}
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   138
fun abc_steps_l :: "abc_conf \<Rightarrow> abc_prog \<Rightarrow> nat \<Rightarrow> abc_conf"
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   139
  where
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   140
  "abc_steps_l (s, lm) p 0 = (s, lm)" |
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   141
  "abc_steps_l (s, lm) p (Suc n) = 
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   142
      abc_steps_l (abc_step_l (s, lm) (abc_fetch s p)) p n"
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   143
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   144
section {*
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   145
  Compiling Abacus machines into Truing machines
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   146
*}
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   147
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   148
subsection {*
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   149
  Compiling functions
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   150
*}
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   151
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   152
text {*
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   153
  @{text "findnth n"} returns the TM which locates the represention of
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   154
  memory cell @{text "n"} on the tape and changes representation of zero
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   155
  on the way.
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   156
*}
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   157
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   158
fun findnth :: "nat \<Rightarrow> instr list"
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   159
  where
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   160
  "findnth 0 = []" |
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   161
  "findnth (Suc n) = (findnth n @ [(W1, 2 * n + 1), 
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   162
           (R, 2 * n + 2), (R, 2 * n + 3), (R, 2 * n + 2)])"
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   163
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   164
text {*
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   165
  @{text "tinc_b"} returns the TM which increments the representation 
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   166
  of the memory cell under rw-head by one and move the representation 
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   167
  of cells afterwards to the right accordingly.
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   168
  *}
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   169
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   170
definition tinc_b :: "instr list"
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   171
  where
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   172
  "tinc_b \<equiv> [(W1, 1), (R, 2), (W1, 3), (R, 2), (W1, 3), (R, 4), 
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   173
             (L, 7), (W0, 5), (R, 6), (W0, 5), (W1, 3), (R, 6),
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   174
             (L, 8), (L, 7), (R, 9), (L, 7), (R, 10), (W0, 9)]" 
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   175
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   176
text {*
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   177
  @{text "tinc ss n"} returns the TM which simulates the execution of 
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   178
  Abacus instruction @{text "Inc n"}, assuming that TM is located at
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   179
  location @{text "ss"} in the final TM complied from the whole
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   180
  Abacus program.
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   181
*}
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   182
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   183
fun tinc :: "nat \<Rightarrow> nat \<Rightarrow> instr list"
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   184
  where
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   185
  "tinc ss n = shift (findnth n @ shift tinc_b (2 * n)) (ss - 1)"
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   186
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   187
text {*
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   188
  @{text "tinc_b"} returns the TM which decrements the representation 
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   189
  of the memory cell under rw-head by one and move the representation 
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   190
  of cells afterwards to the left accordingly.
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   191
  *}
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   192
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   193
definition tdec_b :: "instr list"
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   194
  where
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   195
  "tdec_b \<equiv>  [(W1, 1), (R, 2), (L, 14), (R, 3), (L, 4), (R, 3),
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   196
              (R, 5), (W0, 4), (R, 6), (W0, 5), (L, 7), (L, 8),
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   197
              (L, 11), (W0, 7), (W1, 8), (R, 9), (L, 10), (R, 9),
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   198
              (R, 5), (W0, 10), (L, 12), (L, 11), (R, 13), (L, 11),
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   199
              (R, 17), (W0, 13), (L, 15), (L, 14), (R, 16), (L, 14),
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   200
              (R, 0), (W0, 16)]"
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   201
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   202
text {*
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   203
  @{text "sete tp e"} attaches the termination edges (edges leading to state @{text "0"}) 
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   204
  of TM @{text "tp"} to the intruction labelled by @{text "e"}.
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   205
  *}
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   206
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   207
fun sete :: "instr list \<Rightarrow> nat \<Rightarrow> instr list"
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   208
  where
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   209
  "sete tp e = map (\<lambda> (action, state). (action, if state = 0 then e else state)) tp"
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   210
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   211
text {*
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   212
  @{text "tdec ss n label"} returns the TM which simulates the execution of 
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   213
  Abacus instruction @{text "Dec n label"}, assuming that TM is located at
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   214
  location @{text "ss"} in the final TM complied from the whole
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   215
  Abacus program.
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   216
*}
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   217
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   218
fun tdec :: "nat \<Rightarrow> nat \<Rightarrow> nat \<Rightarrow> instr list"
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   219
  where
60
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   220
  "tdec ss n e = shift (findnth n) (ss - 1) @ sete (shift (shift tdec_b (2 * n)) (ss - 1)) e"
47
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   221
 
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   222
text {*
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   223
  @{text "tgoto f(label)"} returns the TM simulating the execution of Abacus instruction
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   224
  @{text "Goto label"}, where @{text "f(label)"} is the corresponding location of
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   225
  @{text "label"} in the final TM compiled from the overall Abacus program.
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   226
*}
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   227
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   228
fun tgoto :: "nat \<Rightarrow> instr list"
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   229
  where
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   230
  "tgoto n = [(Nop, n), (Nop, n)]"
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   231
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   232
text {*
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   233
  The layout of the final TM compiled from an Abacus program is represented
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   234
  as a list of natural numbers, where the list element at index @{text "n"} represents the 
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   235
  starting state of the TM simulating the execution of @{text "n"}-th instruction
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   236
  in the Abacus program.
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   237
*}
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   238
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   239
type_synonym layout = "nat list"
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   240
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   241
text {*
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   242
  @{text "length_of i"} is the length of the 
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   243
  TM simulating the Abacus instruction @{text "i"}.
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   244
*}
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   245
fun length_of :: "abc_inst \<Rightarrow> nat"
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   246
  where
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   247
  "length_of i = (case i of 
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   248
                    Inc n   \<Rightarrow> 2 * n + 9 |
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   249
                    Dec n e \<Rightarrow> 2 * n + 16 |
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   250
                    Goto n  \<Rightarrow> 1)"
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   251
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   252
text {*
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   253
  @{text "layout_of ap"} returns the layout of Abacus program @{text "ap"}.
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   254
*}
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   255
fun layout_of :: "abc_prog \<Rightarrow> layout"
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   256
  where "layout_of ap = map length_of ap"
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   257
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   258
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   259
text {*
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   260
  @{text "start_of layout n"} looks out the starting state of @{text "n"}-th
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   261
  TM in the finall TM.
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   262
*}
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   263
thm listsum_def
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   264
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   265
fun start_of :: "nat list \<Rightarrow> nat \<Rightarrow> nat"
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   266
  where
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   267
  "start_of ly x = (Suc (listsum (take x ly))) "
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   268
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   269
text {*
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   270
  @{text "ci lo ss i"} complies Abacus instruction @{text "i"}
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   271
  assuming the TM of @{text "i"} starts from state @{text "ss"} 
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   272
  within the overal layout @{text "lo"}.
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   273
*}
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   274
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   275
fun ci :: "layout \<Rightarrow> nat \<Rightarrow> abc_inst \<Rightarrow> instr list"
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   276
  where
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   277
  "ci ly ss (Inc n) = tinc ss n"
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   278
| "ci ly ss (Dec n e) = tdec ss n (start_of ly e)"
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   279
| "ci ly ss (Goto n) = tgoto (start_of ly n)"
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   280
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   281
text {*
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   282
  @{text "tpairs_of ap"} transfroms Abacus program @{text "ap"} pairing
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   283
  every instruction with its starting state.
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   284
*}
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   285
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   286
fun tpairs_of :: "abc_prog \<Rightarrow> (nat \<times> abc_inst) list"
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   287
  where "tpairs_of ap = (zip (map (start_of (layout_of ap)) 
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   288
                         [0..<(length ap)]) ap)"
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   289
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   290
text {*
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   291
  @{text "tms_of ap"} returns the list of TMs, where every one of them simulates
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   292
  the corresponding Abacus intruction in @{text "ap"}.
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   293
*}
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   294
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   295
fun tms_of :: "abc_prog \<Rightarrow> (instr list) list"
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   296
  where "tms_of ap = map (\<lambda> (n, tm). ci (layout_of ap) n tm) 
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   297
                         (tpairs_of ap)"
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   298
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   299
text {*
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   300
  @{text "tm_of ap"} returns the final TM machine compiled from Abacus program @{text "ap"}.
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   301
*}
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   302
fun tm_of :: "abc_prog \<Rightarrow> instr list"
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   303
  where "tm_of ap = concat (tms_of ap)"
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   304
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   305
text {*
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   306
  The following two functions specify the well-formedness of complied TM.
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   307
*}
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   308
(*
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   309
fun t_ncorrect :: "tprog \<Rightarrow> bool"
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   310
  where
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   311
  "t_ncorrect tp = (length tp mod 2 = 0)"
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   312
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   313
fun abc2t_correct :: "abc_prog \<Rightarrow> bool"
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   314
  where 
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   315
  "abc2t_correct ap = list_all (\<lambda> (n, tm). 
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   316
             t_ncorrect (ci (layout_of ap) n tm)) (tpairs_of ap)"
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   317
*)
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   318
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   319
lemma length_findnth: 
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   320
  "length (findnth n) = 4 * n"
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   321
apply(induct n, auto)
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   322
done
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   323
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   324
lemma ci_length : "length (ci ns n ai) div 2 = length_of ai"
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   325
apply(auto simp: ci.simps tinc_b_def tdec_b_def length_findnth
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   326
                 split: abc_inst.splits)
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   327
done
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   328
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   329
subsection {*
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   330
  Representation of Abacus memory by TM tape
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   331
*}
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   332
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   333
text {*
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   334
  @{text "crsp acf tcf"} meams the abacus configuration @{text "acf"}
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   335
  is corretly represented by the TM configuration @{text "tcf"}.
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   336
*}
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   337
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   338
fun crsp :: "layout \<Rightarrow> abc_conf \<Rightarrow> config \<Rightarrow> cell list \<Rightarrow> bool"
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   339
  where 
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   340
  "crsp ly (as, lm) (s, l, r) inres = 
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   341
           (s = start_of ly as \<and> (\<exists> x. r = <lm> @ Bk\<up>x) \<and> 
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   342
            l = Bk # Bk # inres)"
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   343
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   344
declare crsp.simps[simp del]
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   345
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   346
subsection {*
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   347
  A more general definition of TM execution. 
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   348
*}
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   349
60
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   350
(*
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   351
fun nnth_of :: "(taction \<times> nat) list \<Rightarrow> nat \<Rightarrow> nat \<Rightarrow> (taction \<times> nat)"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   352
  where
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   353
  "nnth_of p s b = (if 2*s < length p 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   354
                    then (p ! (2*s + b)) else (Nop, 0))"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   355
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   356
thm nth_of.simps
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   357
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   358
fun nfetch :: "tprog \<Rightarrow> nat \<Rightarrow> block \<Rightarrow> taction \<times> nat"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   359
  where
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   360
  "nfetch p 0 b = (Nop, 0)" |
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   361
  "nfetch p (Suc s) b = 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   362
             (case b of 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   363
                Bk \<Rightarrow> nnth_of p s 0 |
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   364
                Oc \<Rightarrow> nnth_of p s 1)"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   365
*)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   366
47
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   367
                    
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   368
text {*
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   369
  The type of invarints expressing correspondence between 
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   370
  Abacus configuration and TM configuration.
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   371
*}
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   372
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   373
type_synonym inc_inv_t = "abc_conf \<Rightarrow> config \<Rightarrow> cell list \<Rightarrow> bool"
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   374
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   375
declare tms_of.simps[simp del] tm_of.simps[simp del]
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   376
        layout_of.simps[simp del] abc_fetch.simps [simp del]  
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   377
        tpairs_of.simps[simp del] start_of.simps[simp del]
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   378
        ci.simps [simp del] length_of.simps[simp del] 
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   379
        layout_of.simps[simp del]
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   380
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   381
(*
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   382
subsection {* The compilation of @{text "Inc n"} *}
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   383
*)
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   384
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   385
text {*
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   386
  The lemmas in this section lead to the correctness of 
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   387
  the compilation of @{text "Inc n"} instruction.
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   388
*}
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   389
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   390
declare abc_step_l.simps[simp del] abc_steps_l.simps[simp del]
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   391
lemma [simp]: "start_of ly as > 0"
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   392
apply(simp add: start_of.simps)
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   393
done
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   394
60
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   395
lemma abc_steps_l_0: "abc_steps_l ac ap 0 = ac"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   396
by(case_tac ac, simp add: abc_steps_l.simps)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   397
47
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   398
lemma abc_step_red: 
60
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   399
 "abc_steps_l (as, am) ap stp = (bs, bm) \<Longrightarrow> 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   400
  abc_steps_l (as, am) ap (Suc stp) = abc_step_l (bs, bm) (abc_fetch bs ap) "
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   401
proof(induct stp arbitrary: as am bs bm)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   402
  case 0
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   403
  thus "?case"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   404
    by(simp add: abc_steps_l.simps abc_steps_l_0)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   405
next
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   406
  case (Suc stp as am bs bm)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   407
  have ind: "\<And>as am bs bm. abc_steps_l (as, am) ap stp = (bs, bm) \<Longrightarrow> 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   408
    abc_steps_l (as, am) ap (Suc stp) = abc_step_l (bs, bm) (abc_fetch bs ap)"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   409
    by fact
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   410
  have h:" abc_steps_l (as, am) ap (Suc stp) = (bs, bm)" by fact
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   411
  obtain as' am' where g: "abc_step_l (as, am) (abc_fetch as ap) = (as', am')"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   412
    by(case_tac "abc_step_l (as, am) (abc_fetch as ap)", auto)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   413
  then have "abc_steps_l (as', am') ap (Suc stp) = abc_step_l (bs, bm) (abc_fetch bs ap)"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   414
    using h
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   415
    by(rule_tac ind, simp add: abc_steps_l.simps)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   416
  thus "?case"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   417
    using g
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   418
    by(simp add: abc_steps_l.simps)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   419
qed
47
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   420
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   421
lemma tm_shift_fetch: 
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   422
  "\<lbrakk>fetch A s b = (ac, ns); ns \<noteq> 0 \<rbrakk>
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   423
  \<Longrightarrow> fetch (shift A off) s b = (ac, ns + off)"
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   424
apply(case_tac b)
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   425
apply(case_tac [!] s, auto simp: fetch.simps shift.simps)
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   426
done
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   427
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   428
lemma tm_shift_eq_step:
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   429
  assumes exec: "step (s, l, r) (A, 0) = (s', l', r')"
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   430
  and notfinal: "s' \<noteq> 0"
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   431
  shows "step (s + off, l, r) (shift A off, off) = (s' + off, l', r')"
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   432
using assms
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   433
apply(simp add: step.simps)
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   434
apply(case_tac "fetch A s (read r)", auto)
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   435
apply(drule_tac [!] off = off in tm_shift_fetch, simp_all)
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   436
done
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   437
60
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   438
declare step.simps[simp del] steps.simps[simp del] shift.simps[simp del]
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   439
47
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   440
lemma tm_shift_eq_steps: 
60
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   441
  assumes exec: "steps (s, l, r) (A, 0) stp = (s', l', r')"
47
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   442
  and notfinal: "s' \<noteq> 0"
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   443
  shows "steps (s + off, l, r) (shift A off, off) stp = (s' + off, l', r')"
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   444
  using exec notfinal
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   445
proof(induct stp arbitrary: s' l' r', simp add: steps.simps)
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   446
  fix stp s' l' r'
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   447
  assume ind: "\<And>s' l' r'. \<lbrakk>steps (s, l, r) (A, 0) stp = (s', l', r'); s' \<noteq> 0\<rbrakk> 
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   448
     \<Longrightarrow> steps (s + off, l, r) (shift A off, off) stp = (s' + off, l', r')"
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   449
  and h: " steps (s, l, r) (A, 0) (Suc stp) = (s', l', r')" "s' \<noteq> 0"
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   450
  obtain s1 l1 r1 where g: "steps (s, l, r) (A, 0) stp = (s1, l1, r1)" 
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   451
    apply(case_tac "steps (s, l, r) (A, 0) stp") by blast
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   452
  moreover then have "s1 \<noteq> 0"
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   453
    using h
60
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   454
    apply(simp add: step_red)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   455
    apply(case_tac "0 < s1", auto)
47
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   456
    done
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   457
  ultimately have "steps (s + off, l, r) (shift A off, off) stp =
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   458
                   (s1 + off, l1, r1)"
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   459
    apply(rule_tac ind, simp_all)
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   460
    done
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   461
  thus "steps (s + off, l, r) (shift A off, off) (Suc stp) = (s' + off, l', r')"
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   462
    using h g assms
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   463
    apply(simp add: step_red)
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   464
    apply(rule_tac tm_shift_eq_step, auto)
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   465
    done
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   466
qed
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   467
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   468
lemma startof_not0[simp]: "0 < start_of ly as"
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   469
apply(simp add: start_of.simps)
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   470
done
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   471
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   472
lemma startof_ge1[simp]: "Suc 0 \<le> start_of ly as"
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   473
apply(simp add: start_of.simps)
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   474
done
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   475
60
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   476
lemma start_of_Suc1: "\<lbrakk>ly = layout_of ap; 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   477
       abc_fetch as ap = Some (Inc n)\<rbrakk>
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   478
       \<Longrightarrow> start_of ly (Suc as) = start_of ly as + 2 * n + 9"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   479
apply(auto simp: start_of.simps layout_of.simps  
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   480
                 length_of.simps abc_fetch.simps 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   481
                 take_Suc_conv_app_nth split: if_splits)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   482
done
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   483
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   484
lemma start_of_Suc2:
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   485
  "\<lbrakk>ly = layout_of ap;
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   486
  abc_fetch as ap = Some (Dec n e)\<rbrakk> \<Longrightarrow> 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   487
        start_of ly (Suc as) = 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   488
            start_of ly as + 2 * n + 16"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   489
apply(auto simp: start_of.simps layout_of.simps  
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   490
                 length_of.simps abc_fetch.simps 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   491
                 take_Suc_conv_app_nth split: if_splits)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   492
done
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   493
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   494
lemma start_of_Suc3:
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   495
  "\<lbrakk>ly = layout_of ap;
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   496
  abc_fetch as ap = Some (Goto n)\<rbrakk> \<Longrightarrow> 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   497
  start_of ly (Suc as) = start_of ly as + 1"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   498
apply(auto simp: start_of.simps layout_of.simps  
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   499
                 length_of.simps abc_fetch.simps 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   500
                 take_Suc_conv_app_nth split: if_splits)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   501
done
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   502
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   503
lemma length_ci_inc: 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   504
  "length (ci ly ss (Inc n)) = 4*n + 18"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   505
apply(auto simp: ci.simps length_findnth tinc_b_def)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   506
done
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   507
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   508
lemma length_ci_dec: 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   509
  "length (ci ly ss (Dec n e)) = 4*n + 32"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   510
apply(auto simp: ci.simps length_findnth tdec_b_def)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   511
done
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   512
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   513
lemma length_ci_goto: 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   514
  "length (ci ly ss (Goto n )) = 2"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   515
apply(auto simp: ci.simps length_findnth tdec_b_def)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   516
done
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   517
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   518
lemma take_Suc_last[elim]: "Suc as \<le> length xs \<Longrightarrow> 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   519
            take (Suc as) xs = take as xs @ [xs ! as]"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   520
apply(induct xs arbitrary: as, simp, simp)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   521
apply(case_tac as, simp, simp)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   522
done
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   523
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   524
lemma concat_suc: "Suc as \<le> length xs \<Longrightarrow> 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   525
       concat (take (Suc as) xs) = concat (take as xs) @ xs! as"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   526
apply(subgoal_tac "take (Suc as) xs = take as xs @ [xs ! as]", simp)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   527
by auto
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   528
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   529
lemma concat_take_suc_iff: "Suc n \<le> length tps \<Longrightarrow> 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   530
       concat (take n tps) @ (tps ! n) = concat (take (Suc n) tps)"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   531
apply(drule_tac concat_suc, simp)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   532
done
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   533
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   534
lemma concat_drop_suc_iff: 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   535
   "Suc n < length tps \<Longrightarrow> concat (drop (Suc n) tps) = 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   536
           tps ! Suc n @ concat (drop (Suc (Suc n)) tps)"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   537
apply(induct tps arbitrary: n, simp, simp)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   538
apply(case_tac tps, simp, simp)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   539
apply(case_tac n, simp, simp)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   540
done
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   541
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   542
declare append_assoc[simp del]
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   543
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   544
lemma  tm_append:
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   545
  "\<lbrakk>n < length tps; tp = tps ! n\<rbrakk> \<Longrightarrow> 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   546
  \<exists> tp1 tp2. concat tps = tp1 @ tp @ tp2 \<and> tp1 = 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   547
  concat (take n tps) \<and> tp2 = concat (drop (Suc n) tps)"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   548
apply(rule_tac x = "concat (take n tps)" in exI)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   549
apply(rule_tac x = "concat (drop (Suc n) tps)" in exI)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   550
apply(auto)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   551
apply(induct n, simp)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   552
apply(case_tac tps, simp, simp, simp)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   553
apply(subgoal_tac "concat (take n tps) @ (tps ! n) = 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   554
               concat (take (Suc n) tps)")
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   555
apply(simp only: append_assoc[THEN sym], simp only: append_assoc)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   556
apply(subgoal_tac " concat (drop (Suc n) tps) = tps ! Suc n @ 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   557
                  concat (drop (Suc (Suc n)) tps)", simp)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   558
apply(rule_tac concat_drop_suc_iff, simp)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   559
apply(rule_tac concat_take_suc_iff, simp)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   560
done
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   561
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   562
declare append_assoc[simp]
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   563
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   564
lemma map_of:  "n < length xs \<Longrightarrow> (map f xs) ! n = f (xs ! n)"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   565
by(auto)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   566
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   567
lemma [simp]: "length (tms_of aprog) = length aprog"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   568
apply(auto simp: tms_of.simps tpairs_of.simps)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   569
done
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   570
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   571
lemma ci_nth: 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   572
  "\<lbrakk>ly = layout_of aprog; 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   573
  abc_fetch as aprog = Some ins\<rbrakk>
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   574
  \<Longrightarrow> ci ly (start_of ly as) ins = tms_of aprog ! as"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   575
apply(simp add: tms_of.simps tpairs_of.simps 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   576
      abc_fetch.simps  map_of del: map_append split: if_splits)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   577
done
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   578
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   579
lemma t_split:"\<lbrakk>
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   580
        ly = layout_of aprog;
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   581
        abc_fetch as aprog = Some ins\<rbrakk>
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   582
      \<Longrightarrow> \<exists> tp1 tp2. concat (tms_of aprog) = 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   583
            tp1 @ (ci ly (start_of ly as) ins) @ tp2
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   584
            \<and> tp1 = concat (take as (tms_of aprog)) \<and> 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   585
              tp2 = concat (drop (Suc as) (tms_of aprog))"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   586
apply(insert tm_append[of "as" "tms_of aprog" 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   587
                             "ci ly (start_of ly as) ins"], simp)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   588
apply(subgoal_tac "ci ly (start_of ly as) ins = (tms_of aprog) ! as")
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   589
apply(subgoal_tac "length (tms_of aprog) = length aprog")
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   590
apply(simp add: abc_fetch.simps split: if_splits, simp)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   591
apply(rule_tac ci_nth, auto)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   592
done
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   593
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   594
lemma math_sub: "\<lbrakk>x >= Suc 0; x - 1 = z\<rbrakk> \<Longrightarrow> x + y - Suc 0 = z + y"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   595
by auto
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   596
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   597
lemma start_more_one: "as \<noteq> 0 \<Longrightarrow> start_of ly as >= Suc 0"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   598
apply(induct as, simp add: start_of.simps)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   599
apply(case_tac as, auto simp: start_of.simps)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   600
done
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   601
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   602
lemma div_apart: "\<lbrakk>x mod (2::nat) = 0; y mod 2 = 0\<rbrakk> 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   603
          \<Longrightarrow> (x + y) div 2 = x div 2 + y div 2"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   604
apply(drule mod_eqD)+
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   605
apply(auto)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   606
done
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   607
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   608
lemma div_apart_iff: "\<lbrakk>x mod (2::nat) = 0; y mod 2 = 0\<rbrakk> \<Longrightarrow> 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   609
           (x + y) mod 2 = 0"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   610
apply(auto)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   611
done
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   612
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   613
lemma [simp]: "length (layout_of aprog) = length aprog"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   614
apply(auto simp: layout_of.simps)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   615
done
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   616
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   617
lemma start_of_ind: "\<lbrakk>as < length aprog; ly = layout_of aprog\<rbrakk> \<Longrightarrow> 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   618
       start_of ly (Suc as) = start_of ly as + 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   619
                          length ((tms_of aprog) ! as) div 2"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   620
apply(simp only: start_of.simps, simp)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   621
apply(auto simp: start_of.simps tms_of.simps layout_of.simps 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   622
                 tpairs_of.simps)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   623
apply(simp add: ci_length take_Suc take_Suc_conv_app_nth)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   624
done
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   625
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   626
lemma concat_take_suc: "Suc n \<le> length xs \<Longrightarrow>
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   627
  concat (take (Suc n) xs) = concat (take n xs) @ (xs ! n)"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   628
apply(subgoal_tac "take (Suc n) xs =
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   629
                   take n xs @ [xs ! n]")
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   630
apply(auto)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   631
done
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   632
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   633
lemma [simp]: 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   634
  "\<lbrakk>as < length aprog; (abc_fetch as aprog) = Some ins\<rbrakk>
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   635
  \<Longrightarrow> ci (layout_of aprog) 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   636
  (start_of (layout_of aprog) as) (ins) \<in> set (tms_of aprog)"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   637
apply(insert ci_nth[of "layout_of aprog" aprog as], simp)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   638
done
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   639
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   640
lemma [simp]: "length (tms_of ap) = length ap"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   641
by(auto simp: tms_of.simps tpairs_of.simps)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   642
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   643
lemma [intro]:  "n < length ap \<Longrightarrow> length (tms_of ap ! n) mod 2 = 0"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   644
apply(auto simp: tms_of.simps tpairs_of.simps)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   645
apply(case_tac "ap ! n", auto simp: ci.simps length_findnth tinc_b_def tdec_b_def)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   646
apply arith
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   647
by arith
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   648
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   649
lemma compile_mod2: "length (concat (take n (tms_of ap))) mod 2 = 0"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   650
apply(induct n, auto)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   651
apply(case_tac "n < length (tms_of ap)", simp add: take_Suc_conv_app_nth, auto)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   652
apply(subgoal_tac "length (tms_of ap ! n) mod 2 = 0")
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   653
apply arith
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   654
by auto
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   655
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   656
lemma tpa_states:
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   657
  "\<lbrakk>tp = concat (take as (tms_of ap));
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   658
  as \<le> length ap\<rbrakk> \<Longrightarrow> 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   659
  start_of (layout_of ap) as = Suc (length tp div 2)"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   660
proof(induct as arbitrary: tp)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   661
  case 0
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   662
  thus "?case"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   663
    by(simp add: start_of.simps)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   664
next
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   665
  case (Suc as tp)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   666
  have ind: "\<And>tp. \<lbrakk>tp = concat (take as (tms_of ap)); as \<le> length ap\<rbrakk> \<Longrightarrow>
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   667
    start_of (layout_of ap) as = Suc (length tp div 2)" by fact
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   668
  have tp: "tp = concat (take (Suc as) (tms_of ap))" by fact
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   669
  have le: "Suc as \<le> length ap" by fact
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   670
  have a: "start_of (layout_of ap) as = Suc (length (concat (take as (tms_of ap))) div 2)"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   671
    using le
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   672
    by(rule_tac ind, simp_all)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   673
  from a tp le show "?case"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   674
    apply(simp add: start_of.simps take_Suc_conv_app_nth)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   675
    apply(subgoal_tac "length (concat (take as (tms_of ap))) mod 2= 0")
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   676
    apply(subgoal_tac " length (tms_of ap ! as) mod 2 = 0")
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   677
    apply(simp add: abacus.div_apart) 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   678
    apply(simp add: layout_of.simps ci_length  tms_of.simps tpairs_of.simps)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   679
    apply(auto  intro: compile_mod2)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   680
    done
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   681
qed
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   682
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   683
lemma append_append_fetch: 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   684
    "\<lbrakk>length tp1 mod 2 = 0; length tp mod 2 = 0;
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   685
      length tp1 div 2 < a \<and> a \<le> length tp1 div 2 + length tp div 2\<rbrakk>
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   686
    \<Longrightarrow>fetch (tp1 @ tp @ tp2) a b = fetch tp (a - length tp1 div 2) b "
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   687
apply(subgoal_tac "\<exists> x. a = length tp1 div 2 + x", erule exE, simp)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   688
apply(case_tac x, simp)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   689
apply(subgoal_tac "length tp1 div 2 + Suc nat = 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   690
             Suc (length tp1 div 2 + nat)")
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   691
apply(simp only: fetch.simps nth_of.simps, auto)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   692
apply(case_tac b, simp)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   693
apply(subgoal_tac "2 * (length tp1 div 2) = length tp1", simp)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   694
apply(subgoal_tac "2 * nat < length tp", simp add: nth_append, simp)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   695
apply(subgoal_tac "2 * (length tp1 div 2) = length tp1", simp)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   696
apply(subgoal_tac "2 * nat < length tp", simp add: nth_append, auto)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   697
apply(auto simp: nth_append)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   698
apply(rule_tac x = "a - length tp1 div 2" in exI, simp)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   699
done
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   700
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   701
lemma step_eq_fetch':
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   702
  assumes layout: "ly = layout_of ap"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   703
  and compile: "tp = tm_of ap"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   704
  and fetch: "abc_fetch as ap = Some ins"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   705
  and range1: "s \<ge> start_of ly as"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   706
  and range2: "s < start_of ly (Suc as)"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   707
  shows "fetch tp s b = fetch (ci ly (start_of ly as) ins)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   708
       (Suc s - start_of ly as) b "
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   709
proof -
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   710
  have "\<exists>tp1 tp2. concat (tms_of ap) = tp1 @ ci ly (start_of ly as) ins @ tp2 \<and>
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   711
    tp1 = concat (take as (tms_of ap)) \<and> tp2 = concat (drop (Suc as) (tms_of ap))"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   712
    using assms
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   713
    by(rule_tac t_split, simp_all)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   714
  then obtain tp1 tp2 where a: "concat (tms_of ap) = tp1 @ ci ly (start_of ly as) ins @ tp2 \<and>
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   715
    tp1 = concat (take as (tms_of ap)) \<and> tp2 = concat (drop (Suc as) (tms_of ap))" by blast
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   716
  then have b: "start_of (layout_of ap) as = Suc (length tp1 div 2)"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   717
    using fetch
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   718
    apply(rule_tac tpa_states, simp, simp add: abc_fetch.simps split: if_splits)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   719
    done
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   720
  have "fetch (tp1 @ (ci ly (start_of ly as) ins) @ tp2)  s b = 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   721
        fetch (ci ly (start_of ly as) ins) (s - length tp1 div 2) b"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   722
  proof(rule_tac append_append_fetch)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   723
    show "length tp1 mod 2 = 0"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   724
      using a
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   725
      by(auto, rule_tac compile_mod2)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   726
  next
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   727
    show "length (ci ly (start_of ly as) ins) mod 2 = 0"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   728
      apply(case_tac ins, auto simp: ci.simps length_findnth tinc_b_def tdec_b_def)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   729
      by(arith, arith)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   730
  next
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   731
    show "length tp1 div 2 < s \<and> s \<le> 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   732
      length tp1 div 2 + length (ci ly (start_of ly as) ins) div 2"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   733
    proof -
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   734
      have "length (ci ly (start_of ly as) ins) div 2 = length_of ins"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   735
        using ci_length by simp
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   736
      moreover have "start_of ly (Suc as) = start_of ly as + length_of ins"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   737
        using fetch layout
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   738
        apply(simp add: start_of.simps abc_fetch.simps List.take_Suc_conv_app_nth 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   739
          split: if_splits)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   740
        apply(simp add: layout_of.simps)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   741
        done
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   742
      ultimately show "?thesis"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   743
        using b layout range1 range2
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   744
        apply(simp)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   745
        done
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   746
    qed
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   747
  qed
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   748
  thus "?thesis"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   749
    using b layout a compile  
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   750
    apply(simp add: tm_of.simps)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   751
    done
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   752
qed
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   753
47
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   754
lemma step_eq_fetch: 
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   755
  assumes layout: "ly = layout_of ap"
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   756
  and compile: "tp = tm_of ap"
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   757
  and abc_fetch: "abc_fetch as ap = Some ins" 
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   758
  and fetch: "fetch (ci ly (start_of ly as) ins)
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   759
       (Suc s - start_of ly as) b = (ac, ns)"
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   760
  and notfinal: "ns \<noteq> 0"
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   761
  shows "fetch tp s b = (ac, ns)"
60
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   762
proof -
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   763
  have "s \<ge> start_of ly as"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   764
  proof(cases "s \<ge> start_of ly as")
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   765
    case True thus "?thesis" by simp
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   766
  next
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   767
    case False 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   768
    have "\<not> start_of ly as \<le> s" by fact
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   769
    then have "Suc s - start_of ly as = 0"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   770
      by arith
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   771
    then have "fetch (ci ly (start_of ly as) ins)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   772
       (Suc s - start_of ly as) b = (Nop, 0)"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   773
      by(simp add: fetch.simps)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   774
    with notfinal fetch show "?thesis"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   775
      by(simp)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   776
  qed
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   777
  moreover have "s < start_of ly (Suc as)"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   778
  proof(cases "s < start_of ly (Suc as)")
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   779
    case True thus "?thesis" by simp
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   780
  next
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   781
    case False
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   782
    have h: "\<not> s < start_of ly (Suc as)"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   783
      by fact
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   784
    then have "s > start_of ly as"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   785
      using abc_fetch layout
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   786
      apply(simp add: start_of.simps abc_fetch.simps split: if_splits)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   787
      apply(simp add: List.take_Suc_conv_app_nth, auto)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   788
      apply(subgoal_tac "layout_of ap ! as > 0") 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   789
      apply arith
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   790
      apply(simp add: layout_of.simps)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   791
      apply(case_tac "ap!as", auto simp: length_of.simps)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   792
      done
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   793
    from this and h have "fetch (ci ly (start_of ly as) ins) (Suc s - start_of ly as) b = (Nop, 0)"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   794
      using abc_fetch layout
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   795
      apply(case_tac b, simp_all add: Suc_diff_le)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   796
      apply(case_tac [!] ins, simp_all add: start_of_Suc2 start_of_Suc1 start_of_Suc3)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   797
      apply(simp_all only: length_ci_inc length_ci_dec length_ci_goto, auto)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   798
      using layout
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   799
      apply(subgoal_tac [!] "start_of ly (Suc as) = start_of ly as + 2*nat1 + 16", simp_all)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   800
      apply(rule_tac [!] start_of_Suc2, auto)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   801
      done
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   802
    from fetch and notfinal this show "?thesis"by simp
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   803
  qed
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   804
  ultimately show "?thesis"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   805
    using assms
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   806
    apply(drule_tac b= b and ins = ins in step_eq_fetch', auto)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   807
    done
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   808
qed
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   809
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   810
47
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   811
lemma step_eq_in:
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   812
  assumes layout: "ly = layout_of ap"
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   813
  and compile: "tp = tm_of ap"
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   814
  and fetch: "abc_fetch as ap = Some ins"    
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   815
  and exec: "step (s, l, r) (ci ly (start_of ly as) ins, start_of ly as - 1) 
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   816
  = (s', l', r')"
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   817
  and notfinal: "s' \<noteq> 0"
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   818
  shows "step (s, l, r) (tp, 0) = (s', l', r')"
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   819
  using assms
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   820
  apply(simp add: step.simps)
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   821
  apply(case_tac "fetch (ci (layout_of ap) (start_of (layout_of ap) as) ins)
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   822
    (Suc s - start_of (layout_of ap) as) (read r)", simp)
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   823
  using layout
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   824
  apply(drule_tac s = s and b = "read r" and ac = a in step_eq_fetch, auto)
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   825
  done
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   826
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   827
lemma steps_eq_in:
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   828
  assumes layout: "ly = layout_of ap"
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   829
  and compile: "tp = tm_of ap"
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   830
  and crsp: "crsp ly (as, lm) (s, l, r) ires"
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   831
  and fetch: "abc_fetch as ap = Some ins"    
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   832
  and exec: "steps (s, l, r) (ci ly (start_of ly as) ins, start_of ly as - 1) stp 
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   833
  = (s', l', r')"
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   834
  and notfinal: "s' \<noteq> 0"
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   835
  shows "steps (s, l, r) (tp, 0) stp = (s', l', r')"
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   836
  using exec notfinal
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   837
proof(induct stp arbitrary: s' l' r', simp add: steps.simps)
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   838
  fix stp s' l' r'
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   839
  assume ind: 
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   840
    "\<And>s' l' r'. \<lbrakk>steps (s, l, r) (ci ly (start_of ly as) ins, start_of ly as - 1) stp = (s', l', r'); s' \<noteq> 0\<rbrakk>
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   841
              \<Longrightarrow> steps (s, l, r) (tp, 0) stp = (s', l', r')"
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   842
  and h: "steps (s, l, r) (ci ly (start_of ly as) ins, start_of ly as - 1) (Suc stp) = (s', l', r')" "s' \<noteq> 0"
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   843
  obtain s1 l1 r1 where g: "steps (s, l, r) (ci ly (start_of ly as) ins, start_of ly as - 1) stp = 
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   844
                        (s1, l1, r1)"
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   845
    apply(case_tac "steps (s, l, r) (ci ly (start_of ly as) ins, start_of ly as - 1) stp") by blast
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   846
  moreover hence "s1 \<noteq> 0"
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   847
    using h
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   848
    apply(simp add: step_red)
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   849
    apply(case_tac "0 < s1", simp_all)
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   850
    done
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   851
  ultimately have "steps (s, l, r) (tp, 0) stp = (s1, l1, r1)"
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   852
    apply(rule_tac ind, auto)
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   853
    done
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   854
  thus "steps (s, l, r) (tp, 0) (Suc stp) = (s', l', r')"
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   855
    using h g assms
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   856
    apply(simp add: step_red)
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   857
    apply(rule_tac step_eq_in, auto)
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   858
    done
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   859
qed
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   860
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   861
lemma tm_append_fetch_first: 
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   862
  "\<lbrakk>fetch A s b = (ac, ns); ns \<noteq> 0\<rbrakk> \<Longrightarrow> 
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   863
    fetch (A @ B) s b = (ac, ns)"
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   864
apply(case_tac b)
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   865
apply(case_tac [!] s, auto simp: fetch.simps nth_append split: if_splits)
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   866
done
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   867
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   868
lemma tm_append_first_step_eq: 
60
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   869
  assumes "step (s, l, r) (A, off) = (s', l', r')"
47
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   870
  and "s' \<noteq> 0"
60
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   871
  shows "step (s, l, r) (A @ B, off) = (s', l', r')"
47
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   872
using assms
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   873
apply(simp add: step.simps)
60
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   874
apply(case_tac "fetch A (s - off) (read r)")
47
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   875
apply(frule_tac  B = B and b = "read r" in tm_append_fetch_first, auto)
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   876
done
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   877
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   878
lemma tm_append_first_steps_eq: 
60
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   879
  assumes "steps (s, l, r) (A, off) stp = (s', l', r')"
47
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   880
  and "s' \<noteq> 0"
60
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   881
  shows "steps (s, l, r) (A @ B, off) stp = (s', l', r')"
47
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   882
using assms
60
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   883
proof(induct stp arbitrary: s' l' r', simp add: steps.simps)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   884
  fix stp s' l' r'
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   885
  assume ind: "\<And>s' l' r'. \<lbrakk>steps (s, l, r) (A, off) stp = (s', l', r'); s' \<noteq> 0\<rbrakk>
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   886
    \<Longrightarrow> steps (s, l, r) (A @ B, off) stp = (s', l', r')"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   887
    and h: "steps (s, l, r) (A, off) (Suc stp) = (s', l', r')" "s' \<noteq> 0"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   888
  obtain sa la ra where a: "steps (s, l, r) (A, off) stp = (sa, la, ra)"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   889
    apply(case_tac "steps (s, l, r) (A, off) stp") by blast
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   890
  hence "steps (s, l, r) (A @ B, off) stp = (sa, la, ra) \<and> sa \<noteq> 0"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   891
    using h ind[of sa la ra]
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   892
    apply(case_tac sa, simp_all)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   893
    done
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   894
  thus "steps (s, l, r) (A @ B, off) (Suc stp) = (s', l', r')"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   895
    using h a
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   896
    apply(simp add: step_red)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   897
    apply(rule_tac tm_append_first_step_eq, simp_all)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   898
    done
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   899
qed
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   900
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   901
lemma tm_append_second_fetch_eq:
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   902
  assumes
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   903
  even: "length A mod 2 = 0"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   904
  and off: "off = length A div 2"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   905
  and fetch: "fetch B s b = (ac, ns)"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   906
  and notfinal: "ns \<noteq> 0"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   907
  shows "fetch (A @ shift B off) (s + off) b = (ac, ns + off)"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   908
using assms
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   909
apply(case_tac b)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   910
apply(case_tac [!] s, auto simp: fetch.simps nth_append shift.simps 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   911
  split: if_splits)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   912
done
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   913
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   914
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   915
lemma tm_append_second_step_eq: 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   916
  assumes 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   917
  exec: "step0 (s, l, r) B = (s', l', r')"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   918
  and notfinal: "s' \<noteq> 0"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   919
  and off: "off = length A div 2"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   920
  and even: "length A mod 2 = 0"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   921
  shows "step0 (s + off, l, r) (A @ shift B off) = (s' + off, l', r')"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   922
using assms
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   923
apply(simp add: step.simps)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   924
apply(case_tac "fetch B s (read r)")
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   925
apply(frule_tac tm_append_second_fetch_eq, simp_all, auto)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   926
done
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   927
47
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   928
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   929
lemma tm_append_second_steps_eq: 
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   930
  assumes 
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   931
  exec: "steps (s, l, r) (B, 0) stp = (s', l', r')"
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   932
  and notfinal: "s' \<noteq> 0"
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   933
  and off: "off = length A div 2"
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   934
  and even: "length A mod 2 = 0"
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   935
  shows "steps (s + off, l, r) (A @ shift B off, 0) stp = (s' + off, l', r')"
60
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   936
using exec notfinal
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   937
proof(induct stp arbitrary: s' l' r')
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   938
  case 0
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   939
  thus "steps0 (s + off, l, r) (A @ shift B off) 0 = (s' + off, l', r')"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   940
    by(simp add: steps.simps)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   941
next
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   942
  case (Suc stp s' l' r')
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   943
  have ind: "\<And>s' l' r'. \<lbrakk>steps0 (s, l, r) B stp = (s', l', r'); s' \<noteq> 0\<rbrakk> \<Longrightarrow> 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   944
    steps0 (s + off, l, r) (A @ shift B off) stp = (s' + off, l', r')"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   945
    by fact
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   946
  have h: "steps0 (s, l, r) B (Suc stp) = (s', l', r')" by fact
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   947
  have k: "s' \<noteq> 0" by fact
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   948
  obtain s'' l'' r'' where a: "steps0 (s, l, r) B stp = (s'', l'', r'')"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   949
    by (metis prod_cases3)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   950
  then have b: "s'' \<noteq> 0"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   951
    using h k
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   952
    by(rule_tac notI, auto simp: step_red)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   953
  from a b have c: "steps0 (s + off, l, r) (A @ shift B off) stp = (s'' + off, l'', r'')"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   954
    by(erule_tac ind, simp)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   955
  from c b h a k assms show "?case"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   956
    thm tm_append_second_step_eq
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   957
    apply(simp add: step_red) by(rule tm_append_second_step_eq, simp_all)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   958
qed
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   959
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   960
lemma tm_append_second_fetch0_eq:
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   961
  assumes
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   962
  even: "length A mod 2 = 0"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   963
  and off: "off = length A div 2"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   964
  and fetch: "fetch B s b = (ac, 0)"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   965
  and notfinal: "s \<noteq> 0"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   966
  shows "fetch (A @ shift B off) (s + off) b = (ac, 0)"
47
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   967
using assms
60
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   968
apply(case_tac b)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   969
apply(case_tac [!] s, auto simp: fetch.simps nth_append shift.simps 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   970
  split: if_splits)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   971
done
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   972
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   973
lemma tm_append_second_halt_eq:
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   974
  assumes 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   975
  exec: "steps (Suc 0, l, r) (B, 0) stp = (0, l', r')"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   976
  and wf_B: "tm_wf (B, 0)"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   977
  and off: "off = length A div 2"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   978
  and even: "length A mod 2 = 0"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   979
  shows "steps (Suc off, l, r) (A @ shift B off, 0) stp = (0, l', r')"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   980
proof -
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   981
  thm before_final
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   982
  have "\<exists>n. \<not> is_final (steps0 (1, l, r) B n) \<and> steps0 (1, l, r) B (Suc n) = (0, l', r')"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   983
    using exec by(rule_tac before_final, simp)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   984
 then obtain n where a: 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   985
   "\<not> is_final (steps0 (1, l, r) B n) \<and> steps0 (1, l, r) B (Suc n) = (0, l', r')" ..
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   986
 obtain s'' l'' r'' where b: "steps0 (1, l, r) B n = (s'', l'', r'') \<and> s'' >0"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   987
   using a
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   988
   by(case_tac "steps0 (1, l, r) B n", auto)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   989
 have c: "steps (Suc 0 + off, l, r) (A @ shift B off, 0) n = (s'' + off, l'', r'')"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   990
   using a b assms
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   991
   by(rule_tac tm_append_second_steps_eq, simp_all)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   992
 obtain ac where d: "fetch B s'' (read r'') = (ac, 0)"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   993
   using  b a
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   994
   by(case_tac "fetch B s'' (read r'')", auto simp: step_red step.simps)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   995
 then have "fetch (A @ shift B off) (s'' + off) (read r'') = (ac, 0)"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   996
   using assms b
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   997
   by(rule_tac tm_append_second_fetch0_eq, simp_all)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   998
 then have e: "steps (Suc 0 + off, l, r) (A @ shift B off, 0) (Suc n) = (0, l', r')"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   999
   using a b assms c d
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1000
   by(simp add: step_red step.simps)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1001
 from a have "n < stp"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1002
   using exec
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1003
 proof(cases "n < stp")
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1004
   case  True thus "?thesis" by simp
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1005
 next
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1006
   case False
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1007
   have "\<not> n < stp" by fact
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1008
   then obtain d where  "n = stp + d"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1009
     by (metis add.comm_neutral less_imp_add_positive nat_neq_iff)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1010
   thus "?thesis"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1011
     using a e exec
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1012
     by(simp add: steps_add)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1013
 qed
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1014
 then obtain d where "stp = Suc n + d"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1015
   by(metis add_Suc less_iff_Suc_add)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1016
 thus "?thesis"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1017
   using e
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1018
   by(simp only: steps_add, simp)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1019
qed
47
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1020
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1021
lemma tm_append_steps: 
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1022
  assumes 
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1023
  aexec: "steps (s, l, r) (A, 0) stpa = (Suc (length A div 2), la, ra)"
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1024
  and bexec: "steps (Suc 0, la, ra) (B, 0) stpb =  (sb, lb, rb)"
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1025
  and notfinal: "sb \<noteq> 0"
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1026
  and off: "off = length A div 2"
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1027
  and even: "length A mod 2 = 0"
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1028
  shows "steps (s, l, r) (A @ shift B off, 0) (stpa + stpb) = (sb + off, lb, rb)"
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1029
proof -
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1030
  have "steps (s, l, r) (A@shift B off, 0) stpa = (Suc (length A div 2), la, ra)"
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1031
    apply(rule_tac tm_append_first_steps_eq)
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1032
    apply(auto simp: assms)
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1033
    done
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1034
  moreover have "steps (1 + off, la, ra) (A @ shift B off, 0) stpb = (sb + off, lb, rb)"
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1035
    apply(rule_tac tm_append_second_steps_eq)
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1036
    apply(auto simp: assms bexec)
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1037
    done
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1038
  ultimately show "steps (s, l, r) (A @ shift B off, 0) (stpa + stpb) = (sb + off, lb, rb)"
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1039
    apply(simp add: steps_add off)
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1040
    done
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1041
qed
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1042
       
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1043
subsection {* Crsp of Inc*}
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1044
60
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1045
fun at_begin_fst_bwtn :: "inc_inv_t"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1046
  where
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1047
  "at_begin_fst_bwtn (as, lm) (s, l, r) ires = 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1048
      (\<exists> lm1 tn rn. lm1 = (lm @ 0\<up>tn) \<and> length lm1 = s \<and> 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1049
          (if lm1 = [] then l = Bk # Bk # ires
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1050
           else l = [Bk]@<rev lm1>@Bk#Bk#ires) \<and> r = Bk\<up>rn)" 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1051
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1052
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1053
fun at_begin_fst_awtn :: "inc_inv_t"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1054
  where
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1055
  "at_begin_fst_awtn (as, lm) (s, l, r) ires = 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1056
      (\<exists> lm1 tn rn. lm1 = (lm @ 0\<up>tn) \<and> length lm1 = s \<and>
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1057
         (if lm1 = []  then l = Bk # Bk # ires
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1058
          else l = [Bk]@<rev lm1>@Bk#Bk#ires) \<and> r = [Oc]@Bk\<up>rn)"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1059
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1060
fun at_begin_norm :: "inc_inv_t"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1061
  where
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1062
  "at_begin_norm (as, lm) (s, l, r) ires= 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1063
      (\<exists> lm1 lm2 rn. lm = lm1 @ lm2 \<and> length lm1 = s \<and> 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1064
        (if lm1 = [] then l = Bk # Bk # ires
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1065
         else l = Bk # <rev lm1> @ Bk # Bk # ires ) \<and> r = <lm2>@Bk\<up>rn)"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1066
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1067
fun in_middle :: "inc_inv_t"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1068
  where
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1069
  "in_middle (as, lm) (s, l, r) ires = 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1070
      (\<exists> lm1 lm2 tn m ml mr rn. lm @ 0\<up>tn = lm1 @ [m] @ lm2
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1071
       \<and> length lm1 = s \<and> m + 1 = ml + mr \<and>  
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1072
         ml \<noteq> 0 \<and> tn = s + 1 - length lm \<and> 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1073
       (if lm1 = [] then l = Oc\<up>ml @ Bk # Bk # ires 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1074
        else l = Oc\<up>ml@[Bk]@<rev lm1>@
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1075
                 Bk # Bk # ires) \<and> (r = Oc\<up>mr @ [Bk] @ <lm2>@ Bk\<up>rn \<or> 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1076
      (lm2 = [] \<and> r = Oc\<up>mr))
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1077
      )"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1078
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1079
fun inv_locate_a :: "inc_inv_t"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1080
  where "inv_locate_a (as, lm) (s, l, r) ires = 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1081
     (at_begin_norm (as, lm) (s, l, r) ires \<or>
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1082
      at_begin_fst_bwtn (as, lm) (s, l, r) ires \<or>
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1083
      at_begin_fst_awtn (as, lm) (s, l, r) ires
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1084
      )"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1085
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1086
fun inv_locate_b :: "inc_inv_t"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1087
  where "inv_locate_b (as, lm) (s, l, r) ires = 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1088
        (in_middle (as, lm) (s, l, r)) ires "
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1089
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1090
fun inv_after_write :: "inc_inv_t"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1091
  where "inv_after_write (as, lm) (s, l, r) ires = 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1092
           (\<exists> rn m lm1 lm2. lm = lm1 @ m # lm2 \<and>
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1093
             (if lm1 = [] then l = Oc\<up>m @ Bk # Bk # ires
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1094
              else Oc # l = Oc\<up>Suc m@ Bk # <rev lm1> @ 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1095
                      Bk # Bk # ires) \<and> r = [Oc] @ <lm2> @ Bk\<up>rn)"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1096
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1097
fun inv_after_move :: "inc_inv_t"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1098
  where "inv_after_move (as, lm) (s, l, r) ires = 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1099
      (\<exists> rn m lm1 lm2. lm = lm1 @ m # lm2 \<and>
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1100
        (if lm1 = [] then l = Oc\<up>Suc m @ Bk # Bk # ires
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1101
         else l = Oc\<up>Suc m@ Bk # <rev lm1> @ Bk # Bk # ires) \<and> 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1102
        r = <lm2> @ Bk\<up>rn)"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1103
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1104
fun inv_after_clear :: "inc_inv_t"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1105
  where "inv_after_clear (as, lm) (s, l, r) ires =
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1106
       (\<exists> rn m lm1 lm2 r'. lm = lm1 @ m # lm2 \<and> 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1107
        (if lm1 = [] then l = Oc\<up>Suc m @ Bk # Bk # ires
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1108
         else l = Oc\<up>Suc m @ Bk # <rev lm1> @ Bk # Bk # ires) \<and> 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1109
          r = Bk # r' \<and> Oc # r' = <lm2> @ Bk\<up>rn)"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1110
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1111
fun inv_on_right_moving :: "inc_inv_t"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1112
  where "inv_on_right_moving (as, lm) (s, l, r) ires = 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1113
       (\<exists> lm1 lm2 m ml mr rn. lm = lm1 @ [m] @ lm2 \<and> 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1114
            ml + mr = m \<and> 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1115
          (if lm1 = [] then l = Oc\<up>ml @ Bk # Bk # ires
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1116
          else l = Oc\<up>ml  @ [Bk] @ <rev lm1> @ Bk # Bk # ires) \<and> 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1117
         ((r = Oc\<up>mr @ [Bk] @ <lm2> @ Bk\<up>rn) \<or> 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1118
          (r = Oc\<up>mr \<and> lm2 = [])))"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1119
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1120
fun inv_on_left_moving_norm :: "inc_inv_t"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1121
  where "inv_on_left_moving_norm (as, lm) (s, l, r) ires =
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1122
      (\<exists> lm1 lm2 m ml mr rn. lm = lm1 @ [m] @ lm2 \<and>  
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1123
             ml + mr = Suc m \<and> mr > 0 \<and> (if lm1 = [] then l = Oc\<up>ml @ Bk # Bk # ires
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1124
                                         else l =  Oc\<up>ml @ Bk # <rev lm1> @ Bk # Bk # ires)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1125
        \<and> (r = Oc\<up>mr @ Bk # <lm2> @ Bk\<up>rn \<or> 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1126
           (lm2 = [] \<and> r = Oc\<up>mr)))"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1127
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1128
fun inv_on_left_moving_in_middle_B:: "inc_inv_t"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1129
  where "inv_on_left_moving_in_middle_B (as, lm) (s, l, r) ires =
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1130
                (\<exists> lm1 lm2 rn. lm = lm1 @ lm2 \<and>  
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1131
                     (if lm1 = [] then l = Bk # ires
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1132
                      else l = <rev lm1> @ Bk # Bk # ires) \<and> 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1133
                      r = Bk # <lm2> @ Bk\<up>rn)"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1134
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1135
fun inv_on_left_moving :: "inc_inv_t"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1136
  where "inv_on_left_moving (as, lm) (s, l, r) ires = 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1137
       (inv_on_left_moving_norm  (as, lm) (s, l, r) ires \<or>
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1138
        inv_on_left_moving_in_middle_B (as, lm) (s, l, r) ires)"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1139
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1140
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1141
fun inv_check_left_moving_on_leftmost :: "inc_inv_t"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1142
  where "inv_check_left_moving_on_leftmost (as, lm) (s, l, r) ires = 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1143
                (\<exists> rn. l = ires \<and> r = [Bk, Bk] @ <lm> @  Bk\<up>rn)"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1144
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1145
fun inv_check_left_moving_in_middle :: "inc_inv_t"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1146
  where "inv_check_left_moving_in_middle (as, lm) (s, l, r) ires = 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1147
              (\<exists> lm1 lm2 r' rn. lm = lm1 @ lm2 \<and>
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1148
                 (Oc # l = <rev lm1> @ Bk # Bk # ires) \<and> r = Oc # Bk # r' \<and> 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1149
                           r' = <lm2> @  Bk\<up>rn)"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1150
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1151
fun inv_check_left_moving :: "inc_inv_t"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1152
  where "inv_check_left_moving (as, lm) (s, l, r) ires = 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1153
             (inv_check_left_moving_on_leftmost (as, lm) (s, l, r) ires \<or>
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1154
             inv_check_left_moving_in_middle (as, lm) (s, l, r) ires)"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1155
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1156
fun inv_after_left_moving :: "inc_inv_t"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1157
  where "inv_after_left_moving (as, lm) (s, l, r) ires= 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1158
              (\<exists> rn. l = Bk # ires \<and> r = Bk # <lm> @  Bk\<up>rn)"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1159
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1160
fun inv_stop :: "inc_inv_t"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1161
  where "inv_stop (as, lm) (s, l, r) ires= 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1162
              (\<exists> rn. l = Bk # Bk # ires \<and> r = <lm> @  Bk\<up>rn)"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1163
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1164
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1165
lemma halt_lemma2': 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1166
  "\<lbrakk>wf LE;  \<forall> n. ((\<not> P (f n) \<and> Q (f n)) \<longrightarrow> 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1167
    (Q (f (Suc n)) \<and> (f (Suc n), (f n)) \<in> LE)); Q (f 0)\<rbrakk> 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1168
      \<Longrightarrow> \<exists> n. P (f n)"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1169
apply(intro exCI, simp)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1170
apply(subgoal_tac "\<forall> n. Q (f n)", simp)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1171
apply(drule_tac f = f in wf_inv_image)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1172
apply(simp add: inv_image_def)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1173
apply(erule wf_induct, simp)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1174
apply(erule_tac x = x in allE)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1175
apply(erule_tac x = n in allE, erule_tac x = n in allE)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1176
apply(erule_tac x = "Suc x" in allE, simp)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1177
apply(rule_tac allI)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1178
apply(induct_tac n, simp)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1179
apply(erule_tac x = na in allE, simp)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1180
done
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1181
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1182
lemma halt_lemma2'': 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1183
  "\<lbrakk>P (f n); \<not> P (f (0::nat))\<rbrakk> \<Longrightarrow> 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1184
         \<exists> n. (P (f n) \<and> (\<forall> i < n. \<not> P (f i)))"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1185
apply(induct n rule: nat_less_induct, auto)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1186
done
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1187
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1188
lemma halt_lemma2''':
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1189
 "\<lbrakk>\<forall>n. \<not> P (f n) \<and> Q (f n) \<longrightarrow> Q (f (Suc n)) \<and> (f (Suc n), f n) \<in> LE;
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1190
                 Q (f 0);  \<forall>i<na. \<not> P (f i)\<rbrakk> \<Longrightarrow> Q (f na)"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1191
apply(induct na, simp, simp)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1192
done
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1193
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1194
lemma halt_lemma2: 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1195
  "\<lbrakk>wf LE;  
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1196
    Q (f 0); \<not> P (f 0);
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1197
    \<forall> n. ((\<not> P (f n) \<and> Q (f n)) \<longrightarrow> (Q (f (Suc n)) \<and> (f (Suc n), (f n)) \<in> LE))\<rbrakk> 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1198
  \<Longrightarrow> \<exists> n. P (f n) \<and> Q (f n)"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1199
apply(insert halt_lemma2' [of LE P f Q], simp, erule_tac exE)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1200
apply(subgoal_tac "\<exists> n. (P (f n) \<and> (\<forall> i < n. \<not> P (f i)))")
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1201
apply(erule_tac exE)+
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1202
apply(rule_tac x = na in exI, auto)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1203
apply(rule halt_lemma2''', simp, simp, simp)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1204
apply(erule_tac halt_lemma2'', simp)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1205
done
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1206
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1207
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1208
fun findnth_inv :: "layout \<Rightarrow> nat \<Rightarrow> inc_inv_t"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1209
  where
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1210
  "findnth_inv ly n (as, lm) (s, l, r) ires =
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1211
              (if s = 0 then False
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1212
               else if s \<le> Suc (2*n) then 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1213
                  if s mod 2 = 1 then inv_locate_a (as, lm) ((s - 1) div 2, l, r) ires
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1214
                  else inv_locate_b (as, lm) ((s - 1) div 2, l, r) ires
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1215
               else False)"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1216
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1217
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1218
fun findnth_state :: "config \<Rightarrow> nat \<Rightarrow> nat"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1219
  where
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1220
  "findnth_state (s, l, r) n = (Suc (2*n) - s)"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1221
  
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1222
fun findnth_step :: "config \<Rightarrow> nat \<Rightarrow> nat"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1223
  where
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1224
  "findnth_step (s, l, r) n = 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1225
           (if s mod 2 = 1 then
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1226
                   (if (r \<noteq> [] \<and> hd r = Oc) then 0
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1227
                    else 1)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1228
            else length r)"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1229
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1230
fun findnth_measure :: "config \<times> nat \<Rightarrow> nat \<times> nat"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1231
  where
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1232
  "findnth_measure (c, n) = 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1233
     (findnth_state c n, findnth_step c n)"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1234
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1235
definition lex_pair :: "((nat \<times> nat) \<times> nat \<times> nat) set"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1236
  where
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1237
  "lex_pair \<equiv> less_than <*lex*> less_than"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1238
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1239
definition findnth_LE :: "((config \<times> nat) \<times> (config \<times> nat)) set"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1240
  where
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1241
   "findnth_LE \<equiv> (inv_image lex_pair findnth_measure)"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1242
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1243
lemma wf_findnth_LE: "wf findnth_LE"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1244
by(auto intro:wf_inv_image simp: findnth_LE_def lex_pair_def)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1245
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1246
declare findnth_inv.simps[simp del]
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1247
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1248
lemma [simp]: 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1249
  "\<lbrakk>x < Suc (Suc (2 * n)); Suc x mod 2 = Suc 0; \<not> x < 2 * n\<rbrakk>
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1250
 \<Longrightarrow> x = 2*n"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1251
by arith
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1252
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1253
lemma [simp]: 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1254
  "\<lbrakk>0 < a; a < Suc (2 * n); a mod 2 = Suc 0\<rbrakk> 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1255
      \<Longrightarrow> fetch (findnth n) a Bk = (W1, a)"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1256
apply(case_tac a, simp_all)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1257
apply(induct n, auto simp: findnth.simps length_findnth nth_append)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1258
apply arith
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1259
done
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1260
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1261
lemma [simp]: 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1262
  "\<lbrakk>0 < a; a < Suc (2 * n); a mod 2 = Suc 0\<rbrakk> 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1263
      \<Longrightarrow> fetch (findnth n) a Oc = (R, Suc a)"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1264
apply(case_tac a, simp_all)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1265
apply(induct n, auto simp: findnth.simps length_findnth nth_append)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1266
apply(subgoal_tac "nat = 2 * n", simp)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1267
by arith
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1268
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1269
lemma [simp]: 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1270
  "\<lbrakk>0 < a; a < Suc (2*n); a mod 2 \<noteq> Suc 0\<rbrakk>
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1271
     \<Longrightarrow> fetch (findnth n) a Oc = (R, a)"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1272
apply(case_tac a, simp_all)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1273
apply(induct n, auto simp: findnth.simps length_findnth nth_append)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1274
apply(subgoal_tac "nat = Suc (2 * n)", simp)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1275
apply arith
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1276
done
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1277
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1278
lemma [simp]: 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1279
  "\<lbrakk>0 < a; a < Suc (2*n); a mod 2 \<noteq> Suc 0\<rbrakk>
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1280
     \<Longrightarrow> fetch (findnth n) a Bk = (R, Suc a)"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1281
apply(case_tac a, simp_all)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1282
apply(induct n, auto simp: findnth.simps length_findnth nth_append)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1283
apply(subgoal_tac "nat = Suc (2 * n)", simp)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1284
by arith
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1285
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1286
declare at_begin_norm.simps[simp del] at_begin_fst_bwtn.simps[simp del] 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1287
   at_begin_fst_awtn.simps[simp del] in_middle.simps[simp del] 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1288
   abc_lm_s.simps[simp del] abc_lm_v.simps[simp del]  
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1289
   ci.simps[simp del] inv_after_move.simps[simp del] 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1290
   inv_on_left_moving_norm.simps[simp del] 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1291
   inv_on_left_moving_in_middle_B.simps[simp del]
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1292
   inv_after_clear.simps[simp del] 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1293
   inv_after_write.simps[simp del] inv_on_left_moving.simps[simp del]
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1294
   inv_on_right_moving.simps[simp del] 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1295
   inv_check_left_moving.simps[simp del] 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1296
   inv_check_left_moving_in_middle.simps[simp del]
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1297
   inv_check_left_moving_on_leftmost.simps[simp del] 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1298
   inv_after_left_moving.simps[simp del]
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1299
   inv_stop.simps[simp del] inv_locate_a.simps[simp del] 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1300
   inv_locate_b.simps[simp del]
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1301
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1302
lemma [intro]: "\<exists>rn. [Bk] = Bk \<up> rn"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1303
apply(rule_tac x = "Suc 0" in exI, simp)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1304
done
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1305
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1306
lemma [intro]:  "at_begin_norm (as, am) (q, aaa, []) ires
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1307
             \<Longrightarrow> at_begin_norm (as, am) (q, aaa, [Bk]) ires"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1308
apply(simp add: at_begin_norm.simps, erule_tac exE, erule_tac exE)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1309
apply(rule_tac x = lm1 in exI, simp, auto)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1310
done
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1311
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1312
lemma [intro]: "at_begin_fst_bwtn (as, am) (q, aaa, []) ires 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1313
            \<Longrightarrow> at_begin_fst_bwtn (as, am) (q, aaa, [Bk]) ires"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1314
apply(simp only: at_begin_fst_bwtn.simps, erule_tac exE, erule_tac exE, erule_tac exE)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1315
apply(rule_tac x = "am @ 0\<up>tn" in exI, auto)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1316
done
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1317
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1318
lemma [intro]: "at_begin_fst_awtn (as, am) (q, aaa, []) ires
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1319
           \<Longrightarrow> at_begin_fst_awtn (as, am) (q, aaa, [Bk]) ires"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1320
apply(auto simp: at_begin_fst_awtn.simps)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1321
done 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1322
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1323
lemma [intro]: "inv_locate_a (as, am) (q, aaa, []) ires
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1324
            \<Longrightarrow> inv_locate_a (as, am) (q, aaa, [Bk]) ires"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1325
apply(simp only: inv_locate_a.simps)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1326
apply(erule disj_forward)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1327
defer
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1328
apply(erule disj_forward, auto)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1329
done
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1330
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1331
lemma tape_of_nl_cons: "<m # lm> = (if lm = [] then Oc\<up>(Suc m)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1332
                    else Oc\<up>(Suc m) @ Bk # <lm>)"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1333
apply(case_tac lm, simp_all add: tape_of_nl_abv  split: if_splits)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1334
done
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1335
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1336
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1337
lemma locate_a_2_locate_a[simp]: "inv_locate_a (as, am) (q, aaa, Bk # xs) ires
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1338
       \<Longrightarrow> inv_locate_a (as, am) (q, aaa, Oc # xs) ires"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1339
apply(simp only: inv_locate_a.simps at_begin_norm.simps 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1340
                 at_begin_fst_bwtn.simps at_begin_fst_awtn.simps)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1341
apply(erule_tac disjE, erule exE, erule exE, erule exE, 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1342
      rule disjI2, rule disjI2)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1343
defer
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1344
apply(erule_tac disjE, erule exE, erule exE, 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1345
      erule exE, rule disjI2, rule disjI2)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1346
prefer 2
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1347
apply(simp)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1348
proof-
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1349
  fix lm1 tn rn
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1350
  assume k: "lm1 = am @ 0\<up>tn \<and> length lm1 = q \<and> (if lm1 = [] then aaa = Bk # Bk # 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1351
    ires else aaa = [Bk] @ <rev lm1> @ Bk # Bk # ires) \<and> Bk # xs = Bk\<up>rn"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1352
  thus "\<exists>lm1 tn rn. lm1 = am @ 0 \<up> tn \<and> length lm1 = q \<and> 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1353
    (if lm1 = [] then aaa = Bk # Bk # ires else aaa = [Bk] @ <rev lm1> @ Bk # Bk # ires) \<and> Oc # xs = [Oc] @ Bk \<up> rn"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1354
    (is "\<exists>lm1 tn rn. ?P lm1 tn rn")
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1355
  proof -
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1356
    from k have "?P lm1 tn (rn - 1)"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1357
      apply(auto simp: Oc_def)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1358
      by(case_tac [!] "rn::nat", auto)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1359
    thus ?thesis by blast
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1360
  qed
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1361
next
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1362
  fix lm1 lm2 rn
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1363
  assume h1: "am = lm1 @ lm2 \<and> length lm1 = q \<and> (if lm1 = [] 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1364
    then aaa = Bk # Bk # ires else aaa = Bk # <rev lm1> @ Bk # Bk # ires) \<and>
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1365
    Bk # xs = <lm2> @ Bk\<up>rn"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1366
  from h1 have h2: "lm2 = []"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1367
    apply(auto split: if_splits)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1368
    apply(case_tac [!] lm2, simp_all add: tape_of_nl_cons split: if_splits)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1369
    done
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1370
  from h1 and h2 show "\<exists>lm1 tn rn. lm1 = am @ 0\<up>tn \<and> length lm1 = q \<and> 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1371
    (if lm1 = [] then aaa = Bk # Bk # ires else aaa = [Bk] @ <rev lm1> @ Bk # Bk # ires) \<and>
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1372
    Oc # xs = [Oc] @ Bk\<up>rn" 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1373
    (is "\<exists>lm1 tn rn. ?P lm1 tn rn")
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1374
  proof -
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1375
    from h1 and h2  have "?P lm1 0 (rn - 1)"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1376
      apply(auto simp: Oc_def
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1377
                      tape_of_nl_abv tape_of_nat_list.simps)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1378
      by(case_tac "rn::nat", simp, simp)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1379
    thus ?thesis by blast
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1380
  qed
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1381
qed
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1382
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1383
lemma [simp]: "inv_locate_a (as, am) (q, aaa, []) ires \<Longrightarrow> 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1384
               inv_locate_a (as, am) (q, aaa, [Oc]) ires"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1385
apply(insert locate_a_2_locate_a [of as am q aaa "[]"])
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1386
apply(subgoal_tac "inv_locate_a (as, am) (q, aaa, [Bk]) ires", auto)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1387
done
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1388
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1389
(*inv: from locate_b to locate_b*)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1390
lemma [simp]: "inv_locate_b (as, am) (q, aaa, Oc # xs) ires
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1391
         \<Longrightarrow> inv_locate_b (as, am) (q, Oc # aaa, xs) ires"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1392
apply(simp only: inv_locate_b.simps in_middle.simps)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1393
apply(erule exE)+
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1394
apply(rule_tac x = lm1 in exI, rule_tac x = lm2 in exI, 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1395
      rule_tac x = tn in exI, rule_tac x = m in exI)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1396
apply(rule_tac x = "Suc ml" in exI, rule_tac x = "mr - 1" in exI,
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1397
      rule_tac x = rn in exI)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1398
apply(case_tac mr, simp_all, auto)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1399
done
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1400
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1401
(*
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1402
lemma zero_and_nil[intro]: "(Bk # Bk\<^bsup>n\<^esup> = Oc\<^bsup>mr\<^esup> @ Bk # <lm::nat list> @ 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1403
                             Bk\<^bsup>rn \<^esup>) \<or> (lm2 = [] \<and> Bk # Bk\<^bsup>n\<^esup> = Oc\<^bsup>mr\<^esup>)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1404
       \<Longrightarrow> mr = 0 \<and> lm = []"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1405
apply(rule context_conjI)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1406
apply(case_tac mr, auto simp:exponent_def)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1407
apply(insert BkCons_nil[of "replicate (n - 1) Bk" lm rn])
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1408
apply(case_tac n, auto simp: exponent_def Bk_def  tape_of_nl_nil_eq)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1409
done
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1410
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1411
lemma tape_of_nat_def: "<[m::nat]> =  Oc # Oc\<^bsup>m\<^esup>"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1412
apply(simp add: tape_of_nl_abv tape_of_nat_list.simps)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1413
done
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1414
*)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1415
lemma [simp]:  "<[x::nat]> = Oc\<up>(Suc x)"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1416
apply(simp add: tape_of_nat_abv tape_of_nl_abv)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1417
done
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1418
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1419
lemma [simp]: " <([]::nat list)> = []"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1420
apply(simp add: tape_of_nl_abv)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1421
done
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1422
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1423
lemma [simp]: "\<lbrakk>inv_locate_b (as, am) (q, aaa, Bk # xs) ires; \<exists>n. xs = Bk\<up>n\<rbrakk>
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1424
            \<Longrightarrow> inv_locate_a (as, am) (Suc q, Bk # aaa, xs) ires"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1425
apply(simp add: inv_locate_b.simps inv_locate_a.simps)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1426
apply(rule_tac disjI2, rule_tac disjI1)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1427
apply(simp only: in_middle.simps at_begin_fst_bwtn.simps)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1428
apply(erule_tac exE)+
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1429
apply(rule_tac x = "lm1 @ [m]" in exI, rule_tac x = tn in exI, simp split: if_splits)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1430
apply(case_tac mr, simp_all)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1431
apply(case_tac "length am", simp_all, case_tac tn, simp_all)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1432
apply(case_tac lm2, simp_all add: tape_of_nl_cons split: if_splits)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1433
apply(case_tac am, simp_all)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1434
apply(case_tac n, simp_all)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1435
apply(case_tac n, simp_all)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1436
apply(case_tac mr, simp_all)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1437
apply(case_tac lm2, simp_all add: tape_of_nl_cons split: if_splits, auto)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1438
apply(case_tac [!] n, simp_all)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1439
done
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1440
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1441
lemma [simp]: "(Oc # r = Bk \<up> rn) = False"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1442
apply(case_tac rn, simp_all)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1443
done
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1444
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1445
lemma [simp]: "(\<exists>rna. Bk \<up> rn = Bk # Bk \<up> rna) \<or> rn = 0"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1446
apply(case_tac rn, auto)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1447
done
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1448
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1449
lemma [simp]: "(\<forall> x. a \<noteq> x) = False"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1450
by auto
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1451
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1452
lemma exp_ind: "a\<up>(Suc x) = a\<up>x @ [a]"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1453
apply(induct x, auto)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1454
done
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1455
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1456
lemma [simp]: 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1457
      "inv_locate_a (as, lm) (q, l, Oc # r) ires
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1458
       \<Longrightarrow> inv_locate_b (as, lm) (q, Oc # l, r) ires"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1459
apply(simp only: inv_locate_a.simps inv_locate_b.simps in_middle.simps
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1460
          at_begin_norm.simps at_begin_fst_bwtn.simps
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1461
          at_begin_fst_awtn.simps)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1462
apply(erule disjE, erule exE, erule exE, erule exE)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1463
apply(rule_tac x = lm1 in exI, rule_tac x = "tl lm2" in exI, simp)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1464
apply(rule_tac x = 0 in exI, rule_tac x = "hd lm2" in exI)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1465
apply(case_tac lm2, auto simp: tape_of_nl_cons )
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1466
apply(rule_tac x = 1 in exI, rule_tac x = a in exI, auto)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1467
apply(case_tac list, simp_all)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1468
apply(case_tac rn, simp_all)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1469
apply(rule_tac x = "lm @ replicate tn 0" in exI, 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1470
      rule_tac x = "[]" in exI, 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1471
      rule_tac x = "Suc tn" in exI, 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1472
      rule_tac x = 0 in exI, auto)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1473
apply(simp only: replicate_Suc[THEN sym] exp_ind)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1474
apply(rule_tac x = "Suc 0" in exI, auto)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1475
done
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1476
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1477
lemma length_equal: "xs = ys \<Longrightarrow> length xs = length ys"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1478
by auto
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1479
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1480
lemma [simp]: "\<lbrakk>inv_locate_b (as, am) (q, aaa, Bk # xs) ires; 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1481
                \<not> (\<exists>n. xs = Bk\<up>n)\<rbrakk> 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1482
       \<Longrightarrow> inv_locate_a (as, am) (Suc q, Bk # aaa, xs) ires"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1483
apply(simp add: inv_locate_b.simps inv_locate_a.simps)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1484
apply(rule_tac disjI1)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1485
apply(simp only: in_middle.simps at_begin_norm.simps)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1486
apply(erule_tac exE)+
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1487
apply(rule_tac x = "lm1 @ [m]" in exI, rule_tac x = lm2 in exI, simp)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1488
apply(subgoal_tac "tn = 0", simp , auto split: if_splits)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1489
apply(case_tac [!] mr, simp_all, auto)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1490
apply(simp add: tape_of_nl_cons)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1491
apply(drule_tac length_equal, simp)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1492
apply(case_tac "length am", simp_all, erule_tac x = rn in allE, simp)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1493
apply(drule_tac length_equal, simp)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1494
apply(case_tac "(Suc (length lm1) - length am)", simp_all)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1495
apply(case_tac lm2, simp, simp)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1496
done
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1497
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1498
lemma locate_b_2_a[intro]: 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1499
       "inv_locate_b (as, am) (q, aaa, Bk # xs) ires
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1500
    \<Longrightarrow> inv_locate_a (as, am) (Suc q, Bk # aaa, xs) ires"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1501
apply(case_tac "\<exists> n. xs = Bk\<up>n", simp, simp)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1502
done
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1503
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1504
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1505
lemma [simp]:  "inv_locate_b (as, am) (q, l, []) ires 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1506
           \<Longrightarrow>  inv_locate_b (as, am) (q, l, [Bk]) ires"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1507
apply(simp only: inv_locate_b.simps in_middle.simps)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1508
apply(erule exE)+
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1509
apply(rule_tac x = lm1 in exI, rule_tac x = lm2 in exI, 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1510
      rule_tac x = tn in exI, rule_tac x = m in exI, 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1511
      rule_tac x = ml in exI, rule_tac x = mr in exI)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1512
apply(auto)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1513
done
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1514
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1515
(*inv: from locate_b to after_write*)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1516
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1517
lemma [simp]: "(a mod 2 \<noteq> Suc 0) = (a mod 2 = 0)  "
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1518
by arith
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1519
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1520
lemma [simp]: "(a mod 2 \<noteq> 0) = (a mod 2 = Suc 0)  "
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1521
by arith
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1522
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1523
lemma mod_ex1: "(a mod 2 = Suc 0) = (\<exists> q. a = Suc (2 * q))"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1524
by arith
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1525
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1526
lemma mod_ex2: "(a mod (2::nat) = 0) = (\<exists> q. a = 2 * q)"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1527
by arith
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1528
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1529
lemma [simp]: "(2*q - Suc 0) div 2 = (q - 1)"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1530
by arith
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1531
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1532
lemma [simp]: "(Suc (2*q)) div 2 = q"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1533
by arith
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1534
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1535
lemma mod_2: "x mod 2  = 0 \<or>  x mod 2 = Suc 0"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1536
by arith
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1537
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1538
lemma [simp]: "x mod 2 = 0 \<Longrightarrow> Suc x mod 2 = Suc 0"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1539
by arith
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1540
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1541
lemma [simp]: "x mod 2 = Suc 0 \<Longrightarrow> Suc x mod 2 = 0"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1542
by arith
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1543
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1544
lemma [simp]:  "inv_locate_b (as, am) (q, l, []) ires 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1545
           \<Longrightarrow>  inv_locate_b (as, am) (q, l, [Bk]) ires"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1546
apply(simp only: inv_locate_b.simps in_middle.simps)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1547
apply(erule exE)+
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1548
apply(rule_tac x = lm1 in exI, rule_tac x = lm2 in exI, 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1549
      rule_tac x = tn in exI, rule_tac x = m in exI, 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1550
      rule_tac x = ml in exI, rule_tac x = mr in exI)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1551
apply(auto)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1552
done
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1553
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1554
lemma locate_b_2_locate_a[simp]: 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1555
    "\<lbrakk>q > 0;  inv_locate_b (as, am) (q - Suc 0, aaa, Bk # xs) ires\<rbrakk>
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1556
   \<Longrightarrow>  inv_locate_a (as, am) (q, Bk # aaa, xs) ires"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1557
apply(insert locate_b_2_a [of as am "q - 1" aaa xs ires], simp)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1558
done
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1559
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1560
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1561
lemma [simp]:  "inv_locate_b (as, am) (q, l, []) ires 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1562
           \<Longrightarrow>  inv_locate_b (as, am) (q, l, [Bk]) ires"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1563
apply(simp only: inv_locate_b.simps in_middle.simps)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1564
apply(erule exE)+
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1565
apply(rule_tac x = lm1 in exI, rule_tac x = lm2 in exI, 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1566
      rule_tac x = tn in exI, rule_tac x = m in exI, 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1567
      rule_tac x = ml in exI, rule_tac x = mr in exI)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1568
apply(auto)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1569
done
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1570
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1571
(*inv: from locate_b to after_write*)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1572
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1573
lemma [simp]:
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1574
  "crsp (layout_of ap) (as, lm) (s, l, r) ires
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1575
  \<Longrightarrow> findnth_inv (layout_of ap) n (as, lm) (Suc 0, l, r) ires"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1576
apply(auto simp: crsp.simps findnth_inv.simps inv_locate_a.simps
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1577
               at_begin_norm.simps at_begin_fst_awtn.simps at_begin_fst_bwtn.simps)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1578
done
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1579
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1580
lemma findnth_correct_pre: 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1581
  assumes layout: "ly = layout_of ap"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1582
  and crsp: "crsp ly (as, lm) (s, l, r) ires"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1583
  and not0: "n > 0"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1584
  and f: "f = (\<lambda> stp. (steps (Suc 0, l, r) (findnth n, 0) stp, n))"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1585
  and P: "P = (\<lambda> ((s, l, r), n). s = Suc (2 * n))"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1586
  and Q: "Q = (\<lambda> ((s, l, r), n). findnth_inv ly n (as, lm) (s, l, r) ires)"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1587
  shows "\<exists> stp. P (f stp) \<and> Q (f stp)"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1588
thm halt_lemma2
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1589
proof(rule_tac LE = findnth_LE in halt_lemma2)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1590
  show "wf findnth_LE"  by(intro wf_findnth_LE)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1591
next
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1592
  show "Q (f 0)"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1593
    using crsp layout
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1594
    apply(simp add: f P Q steps.simps)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1595
    done
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1596
next
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1597
  show "\<not> P (f 0)"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1598
    using not0
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1599
    apply(simp add: f P steps.simps)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1600
    done
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1601
next
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1602
  show "\<forall>n. \<not> P (f n) \<and> Q (f n) \<longrightarrow> Q (f (Suc n)) \<and> (f (Suc n), f n) 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1603
        \<in> findnth_LE"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1604
  proof(rule_tac allI, rule_tac impI, simp add: f, 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1605
      case_tac "steps (Suc 0, l, r) (findnth n, 0) na", simp add: P)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1606
    fix na a b c
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1607
    assume "a \<noteq> Suc (2 * n) \<and> Q ((a, b, c), n)"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1608
    thus  "Q (step (a, b, c) (findnth n, 0), n) \<and> 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1609
        ((step (a, b, c) (findnth n, 0), n), (a, b, c), n) \<in> findnth_LE"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1610
      apply(case_tac c, case_tac [2] aa)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1611
      apply(simp_all add: step.simps findnth_LE_def Q findnth_inv.simps mod_2  lex_pair_def split: if_splits)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1612
      apply(auto simp: mod_ex1 mod_ex2)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1613
      done
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1614
  qed
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1615
qed
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1616
            
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1617
lemma [intro]: "inv_locate_a (as, lm) (0, Bk # Bk # ires, <lm> @ Bk \<up> x) ires"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1618
apply(auto simp: crsp.simps inv_locate_a.simps at_begin_norm.simps)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1619
done
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1620
lemma [simp]: "crsp ly (as, lm) (s, l, r) ires \<Longrightarrow> inv_locate_a (as, lm) (0, l, r) ires"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1621
apply(auto simp: crsp.simps inv_locate_a.simps at_begin_norm.simps)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1622
done
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1623
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1624
lemma findnth_correct: 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1625
  assumes layout: "ly = layout_of ap"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1626
  and crsp: "crsp ly (as, lm) (s, l, r) ires"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1627
  shows "\<exists> stp l' r'. steps (Suc 0, l, r) (findnth n, 0) stp = (Suc (2 * n), l', r')
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1628
              \<and> inv_locate_a (as, lm) (n, l', r') ires"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1629
  using crsp
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1630
  apply(case_tac "n = 0")
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1631
  apply(rule_tac x = 0 in exI, auto simp: steps.simps)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1632
  using assms
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1633
  apply(drule_tac findnth_correct_pre, auto)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1634
  apply(rule_tac x = stp in exI, simp add: findnth_inv.simps)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1635
  done
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1636
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1637
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1638
fun inc_inv :: "nat \<Rightarrow> inc_inv_t"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1639
  where
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1640
  "inc_inv n (as, lm) (s, l, r) ires =
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1641
              (let lm' = abc_lm_s lm n (Suc (abc_lm_v lm n)) in
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1642
                if s = 0 then False
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1643
                else if s = 1 then 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1644
                   inv_locate_a (as, lm) (n, l, r) ires
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1645
                else if s = 2 then 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1646
                   inv_locate_b (as, lm) (n, l, r) ires
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1647
                else if s = 3 then 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1648
                   inv_after_write (as, lm') (s, l, r) ires
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1649
                else if s = Suc 3 then 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1650
                   inv_after_move (as, lm') (s, l, r) ires
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1651
                else if s = Suc 4 then 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1652
                   inv_after_clear (as, lm') (s, l, r) ires
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1653
                else if s = Suc (Suc 4) then 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1654
                   inv_on_right_moving (as, lm') (s, l, r) ires
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1655
                else if s = Suc (Suc 5) then 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1656
                   inv_on_left_moving (as, lm') (s, l, r) ires
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1657
                else if s = Suc (Suc (Suc 5)) then 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1658
                   inv_check_left_moving (as, lm') (s, l, r) ires
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1659
                else if s = Suc (Suc (Suc (Suc 5))) then 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1660
                   inv_after_left_moving (as, lm') (s, l, r) ires
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1661
                else if s = Suc (Suc (Suc (Suc (Suc 5)))) then 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1662
                   inv_stop (as, lm') (s, l, r) ires
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1663
                else False)"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1664
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1665
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1666
fun abc_inc_stage1 :: "config \<Rightarrow> nat"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1667
  where
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1668
  "abc_inc_stage1 (s, l, r) = 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1669
            (if s = 0 then 0
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1670
             else if s \<le> 2 then 5
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1671
             else if s \<le> 6 then 4
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1672
             else if s \<le> 8 then 3
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1673
             else if s = 9 then 2
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1674
             else 1)"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1675
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1676
fun abc_inc_stage2 :: "config \<Rightarrow> nat"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1677
  where
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1678
  "abc_inc_stage2 (s, l, r) =
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1679
                (if s = 1 then 2
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1680
                 else if s = 2 then 1
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1681
                 else if s = 3 then length r
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1682
                 else if s = 4 then length r
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1683
                 else if s = 5 then length r
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1684
                 else if s = 6 then 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1685
                                  if r \<noteq> [] then length r
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1686
                                  else 1
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1687
                 else if s = 7 then length l
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1688
                 else if s = 8 then length l
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1689
                 else 0)"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1690
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1691
fun abc_inc_stage3 :: "config \<Rightarrow>  nat"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1692
  where
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1693
  "abc_inc_stage3 (s, l, r) = (
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1694
              if s = 4 then 4
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1695
              else if s = 5 then 3
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1696
              else if s = 6 then 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1697
                   if r \<noteq> [] \<and> hd r = Oc then 2
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1698
                   else 1
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1699
              else if s = 3 then 0
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1700
              else if s = 2 then length r
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1701
              else if s = 1 then 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1702
                      if (r \<noteq> [] \<and> hd r = Oc) then 0
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1703
                      else 1
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1704
              else 10 - s)"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1705
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1706
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1707
definition inc_measure :: "config \<Rightarrow> nat \<times> nat \<times> nat"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1708
  where
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1709
  "inc_measure c = 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1710
    (abc_inc_stage1 c, abc_inc_stage2 c, abc_inc_stage3 c)"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1711
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1712
definition lex_triple :: 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1713
   "((nat \<times> (nat \<times> nat)) \<times> (nat \<times> (nat \<times> nat))) set"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1714
  where "lex_triple \<equiv> less_than <*lex*> lex_pair"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1715
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1716
definition inc_LE :: "(config \<times> config) set"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1717
  where
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1718
  "inc_LE \<equiv> (inv_image lex_triple inc_measure)"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1719
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1720
declare inc_inv.simps[simp del]
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1721
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1722
lemma wf_inc_le[intro]: "wf inc_LE"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1723
by(auto intro:wf_inv_image simp: inc_LE_def lex_triple_def lex_pair_def)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1724
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1725
lemma numeral_5_eq_5: "5 = Suc (Suc (Suc (Suc (Suc 0))))"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1726
by arith
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1727
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1728
lemma numeral_6_eq_6: "6 = Suc (Suc (Suc (Suc (Suc 1))))"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1729
by arith
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1730
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1731
lemma numeral_7_eq_7: "7 = Suc (Suc (Suc (Suc (Suc 2))))"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1732
by arith
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1733
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1734
lemma numeral_8_eq_8: "8 = Suc (Suc (Suc (Suc (Suc 3))))"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1735
by arith
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1736
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1737
lemma numeral_9_eq_9: "9 = Suc (Suc (Suc (Suc (Suc (Suc 3)))))"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1738
by arith
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1739
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1740
lemma numeral_10_eq_10: "10 = Suc (Suc (Suc (Suc (Suc (Suc (Suc 3))))))"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1741
by arith
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1742
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1743
lemma inv_locate_b_2_after_write[simp]: 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1744
      "inv_locate_b (as, am) (n, aaa, Bk # xs) ires
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1745
      \<Longrightarrow> inv_after_write (as, abc_lm_s am n (Suc (abc_lm_v am n)))
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1746
          (s, aaa, Oc # xs) ires"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1747
apply(auto simp: in_middle.simps inv_after_write.simps 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1748
                 abc_lm_v.simps abc_lm_s.simps  inv_locate_b.simps)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1749
apply(case_tac [!] mr, auto split: if_splits)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1750
apply(rule_tac x = rn in exI, rule_tac x = "Suc m" in exI,
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1751
      rule_tac x = "lm1" in exI, simp)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1752
apply(rule_tac x = "lm2" in exI, simp)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1753
apply(simp only: Suc_diff_le exp_ind)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1754
apply(subgoal_tac "lm2 = []", simp)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1755
apply(drule_tac length_equal, simp)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1756
done
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1757
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1758
lemma [simp]: "inv_locate_b (as, am) (n, aaa, []) ires \<Longrightarrow> 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1759
     inv_after_write (as, abc_lm_s am n (Suc (abc_lm_v am n))) 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1760
                     (s, aaa, [Oc]) ires"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1761
apply(insert inv_locate_b_2_after_write [of as am n aaa "[]"])
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1762
by(simp)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1763
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1764
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1765
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1766
(*inv: from after_write to after_move*)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1767
lemma [simp]: "inv_after_write (as, lm) (x, l, Oc # r) ires
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1768
                \<Longrightarrow> inv_after_move (as, lm) (y, Oc # l, r) ires"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1769
apply(auto simp:inv_after_move.simps inv_after_write.simps split: if_splits)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1770
done
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1771
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1772
lemma [simp]: "inv_after_write (as, abc_lm_s am n (Suc (abc_lm_v am n)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1773
                )) (x, aaa, Bk # xs) ires = False"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1774
apply(simp add: inv_after_write.simps )
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1775
done
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1776
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1777
lemma [simp]: 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1778
 "inv_after_write (as, abc_lm_s am n (Suc (abc_lm_v am n))) 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1779
                        (x, aaa, []) ires = False"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1780
apply(simp add: inv_after_write.simps )
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1781
done
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1782
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1783
(*inv: from after_move to after_clear*)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1784
lemma [simp]: "inv_after_move (as, lm) (s, l, Oc # r) ires
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1785
                \<Longrightarrow> inv_after_clear (as, lm) (s', l, Bk # r) ires"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1786
apply(auto simp: inv_after_move.simps inv_after_clear.simps split: if_splits)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1787
done
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1788
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1789
(*inv: from after_move to on_leftmoving*)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1790
lemma [intro]: "Bk \<up> rn = Bk # Bk \<up> (rn - Suc 0) \<or> rn = 0"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1791
apply(case_tac rn, auto)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1792
done
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1793
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1794
lemma inv_after_move_2_inv_on_left_moving[simp]:  
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1795
   "inv_after_move (as, lm) (s, l, Bk # r) ires
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1796
   \<Longrightarrow> (l = [] \<longrightarrow> 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1797
         inv_on_left_moving (as, lm) (s', [], Bk # Bk # r) ires) \<and>
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1798
      (l \<noteq> [] \<longrightarrow> 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1799
         inv_on_left_moving (as, lm) (s', tl l, hd l # Bk # r) ires)"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1800
apply(simp only: inv_after_move.simps inv_on_left_moving.simps)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1801
apply(subgoal_tac "l \<noteq> []", rule conjI, simp, rule impI, 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1802
                rule disjI1, simp only: inv_on_left_moving_norm.simps)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1803
apply(erule exE)+
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1804
apply(subgoal_tac "lm2 = []")
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1805
apply(rule_tac x = lm1 in exI, rule_tac x = lm2 in exI,  
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1806
    rule_tac x = m in exI, rule_tac x = m in exI, 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1807
    rule_tac x = 1 in exI,  
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1808
    rule_tac x = "rn - 1" in exI, auto)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1809
apply(auto split: if_splits)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1810
apply(case_tac [1-2] rn, simp_all)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1811
apply(case_tac [!] lm2, simp_all add: tape_of_nl_cons split: if_splits)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1812
done
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1813
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1814
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1815
lemma inv_after_move_2_inv_on_left_moving_B[simp]: 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1816
    "inv_after_move (as, lm) (s, l, []) ires
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1817
      \<Longrightarrow> (l = [] \<longrightarrow> inv_on_left_moving (as, lm) (s', [], [Bk]) ires) \<and>
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1818
          (l \<noteq> [] \<longrightarrow> inv_on_left_moving (as, lm) (s', tl l, [hd l]) ires)"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1819
apply(simp only: inv_after_move.simps inv_on_left_moving.simps)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1820
apply(subgoal_tac "l \<noteq> []", rule conjI, simp, rule impI, rule disjI1,
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1821
        simp only: inv_on_left_moving_norm.simps)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1822
apply(erule exE)+
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1823
apply(subgoal_tac "lm2 = []")
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1824
apply(rule_tac x = lm1 in exI, rule_tac x = lm2 in exI,  
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1825
      rule_tac x = m in exI, rule_tac x = m in exI, 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1826
      rule_tac x = 1 in exI, rule_tac x = "rn - 1" in exI, simp, case_tac rn)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1827
apply(auto split: if_splits)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1828
apply(case_tac [!] lm2, auto simp: tape_of_nl_cons split: if_splits)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1829
done
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1830
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1831
(*inv: from after_clear to on_right_moving*)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1832
lemma [simp]: "Oc # r = replicate rn Bk = False"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1833
apply(case_tac rn, simp, simp)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1834
done
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1835
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1836
lemma inv_after_clear_2_inv_on_right_moving[simp]: 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1837
     "inv_after_clear (as, lm) (x, l, Bk # r) ires
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1838
      \<Longrightarrow> inv_on_right_moving (as, lm) (y, Bk # l, r) ires"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1839
apply(auto simp: inv_after_clear.simps inv_on_right_moving.simps )
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1840
apply(subgoal_tac "lm2 \<noteq> []")
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1841
apply(rule_tac x = "lm1 @ [m]" in exI, rule_tac x = "tl lm2" in exI, 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1842
      rule_tac x = "hd lm2" in exI, simp)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1843
apply(rule_tac x = 0 in exI, rule_tac x = "hd lm2" in exI)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1844
apply(simp, rule conjI)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1845
apply(case_tac [!] "lm2::nat list", auto)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1846
apply(case_tac rn, auto split: if_splits simp: tape_of_nl_cons)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1847
apply(case_tac [!] rn, simp_all)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1848
done
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1849
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1850
lemma [simp]: "inv_after_clear (as, lm) (x, l, []) ires\<Longrightarrow> 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1851
               inv_after_clear (as, lm) (y, l, [Bk]) ires" 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1852
by(auto simp: inv_after_clear.simps)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1853
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1854
lemma [simp]: "inv_after_clear (as, lm) (x, l, []) ires
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1855
             \<Longrightarrow> inv_on_right_moving (as, lm) (y, Bk # l, []) ires"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1856
by(insert 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1857
    inv_after_clear_2_inv_on_right_moving[of as lm n l "[]"], simp)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1858
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1859
(*inv: from on_right_moving to on_right_movign*)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1860
lemma [simp]: "inv_on_right_moving (as, lm) (x, l, Oc # r) ires
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1861
      \<Longrightarrow> inv_on_right_moving (as, lm) (y, Oc # l, r) ires"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1862
apply(auto simp: inv_on_right_moving.simps)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1863
apply(rule_tac x = lm1 in exI, rule_tac x = lm2 in exI, 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1864
           rule_tac x = "ml + mr" in exI, simp)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1865
apply(rule_tac x = "Suc ml" in exI, 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1866
           rule_tac x = "mr - 1" in exI, simp)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1867
apply(case_tac mr, auto)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1868
apply(rule_tac x = lm1 in exI, rule_tac x = "[]" in exI, 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1869
      rule_tac x = "ml + mr" in exI, simp)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1870
apply(rule_tac x = "Suc ml" in exI, 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1871
      rule_tac x = "mr - 1" in exI, simp)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1872
apply(case_tac mr, auto split: if_splits)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1873
done
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1874
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1875
lemma inv_on_right_moving_2_inv_on_right_moving[simp]: 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1876
     "inv_on_right_moving (as, lm) (x, l, Bk # r) ires
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1877
     \<Longrightarrow> inv_after_write (as, lm) (y, l, Oc # r) ires"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1878
apply(auto simp: inv_on_right_moving.simps inv_after_write.simps )
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1879
apply(case_tac mr, auto simp: split: if_splits)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1880
apply(case_tac [!] mr, simp_all)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1881
done
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1882
      
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1883
lemma [simp]: "inv_on_right_moving (as, lm) (x, l, []) ires\<Longrightarrow> 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1884
             inv_on_right_moving (as, lm) (y, l, [Bk]) ires"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1885
apply(auto simp: inv_on_right_moving.simps)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1886
apply(rule_tac x = lm1 in exI, rule_tac x = "[]" in exI, simp)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1887
done
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1888
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1889
(*inv: from on_right_moving to after_write*)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1890
lemma [simp]: "inv_on_right_moving (as, lm) (x, l, []) ires
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1891
       \<Longrightarrow> inv_after_write (as, lm) (y, l, [Oc]) ires"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1892
apply(rule_tac inv_on_right_moving_2_inv_on_right_moving, simp)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1893
done
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1894
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1895
(*inv: from on_left_moving to on_left_moving*)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1896
lemma [simp]: "inv_on_left_moving_in_middle_B (as, lm) 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1897
               (s, l, Oc # r) ires = False"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1898
apply(auto simp: inv_on_left_moving_in_middle_B.simps )
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1899
done
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1900
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1901
lemma [simp]: "inv_on_left_moving_norm (as, lm) (s, l, Bk # r) ires 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1902
             = False"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1903
apply(auto simp: inv_on_left_moving_norm.simps)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1904
apply(case_tac [!] mr, auto simp: )
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1905
done
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1906
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1907
lemma [simp]: 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1908
  "\<lbrakk>inv_on_left_moving_norm (as, lm) (s, l, Oc # r) ires;
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1909
    hd l = Bk; l \<noteq> []\<rbrakk> \<Longrightarrow> 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1910
     inv_on_left_moving_in_middle_B (as, lm) (s, tl l, Bk # Oc # r) ires"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1911
apply(case_tac l, simp, simp)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1912
apply(simp only: inv_on_left_moving_norm.simps 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1913
                 inv_on_left_moving_in_middle_B.simps)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1914
apply(erule_tac exE)+
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1915
apply(rule_tac x = lm1 in exI, rule_tac x = "m # lm2" in exI, auto)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1916
apply(case_tac [!] ml, auto)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1917
apply(auto simp: tape_of_nl_cons split: if_splits)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1918
apply(rule_tac [!] x = "Suc rn" in exI, simp_all)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1919
done
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1920
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1921
lemma [simp]: "\<lbrakk>inv_on_left_moving_norm (as, lm) (s, l, Oc # r) ires; 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1922
                hd l = Oc; l \<noteq> []\<rbrakk>
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1923
            \<Longrightarrow> inv_on_left_moving_norm (as, lm) 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1924
                                        (s, tl l, Oc # Oc # r) ires"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1925
apply(simp only: inv_on_left_moving_norm.simps)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1926
apply(erule exE)+
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1927
apply(rule_tac x = lm1 in exI, rule_tac x = lm2 in exI, 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1928
      rule_tac x = m in exI, rule_tac x = "ml - 1" in exI,
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1929
      rule_tac x = "Suc mr" in exI, rule_tac x = rn in exI, simp)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1930
apply(case_tac ml, auto simp: split: if_splits)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1931
done
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1932
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1933
lemma [simp]: "inv_on_left_moving_norm (as, lm) (s, [], Oc # r) ires
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1934
     \<Longrightarrow> inv_on_left_moving_in_middle_B (as, lm) (s, [], Bk # Oc # r) ires"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1935
apply(auto simp: inv_on_left_moving_norm.simps 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1936
                 inv_on_left_moving_in_middle_B.simps split: if_splits)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1937
done
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1938
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1939
lemma [simp]:"inv_on_left_moving (as, lm) (s, l, Oc # r) ires
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1940
    \<Longrightarrow> (l = [] \<longrightarrow> inv_on_left_moving (as, lm) (s, [], Bk # Oc # r) ires)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1941
 \<and>  (l \<noteq> [] \<longrightarrow> inv_on_left_moving (as, lm) (s, tl l, hd l # Oc # r) ires)"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1942
apply(simp add: inv_on_left_moving.simps)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1943
apply(case_tac "l \<noteq> []", rule conjI, simp, simp)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1944
apply(case_tac "hd l", simp, simp, simp)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1945
done
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1946
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1947
(*inv: from on_left_moving to check_left_moving*)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1948
lemma [simp]: "inv_on_left_moving_in_middle_B (as, lm) 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1949
                                      (s, Bk # list, Bk # r) ires
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1950
          \<Longrightarrow> inv_check_left_moving_on_leftmost (as, lm) 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1951
                                      (s', list, Bk # Bk # r) ires"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1952
apply(auto simp: inv_on_left_moving_in_middle_B.simps 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1953
                 inv_check_left_moving_on_leftmost.simps split: if_splits)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1954
apply(case_tac [!] "rev lm1", simp_all)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1955
apply(case_tac [!] lista, simp_all add: tape_of_nl_abv tape_of_nat_list.simps)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1956
done
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1957
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1958
lemma [simp]:
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1959
    "inv_check_left_moving_in_middle (as, lm) (s, l, Bk # r) ires= False"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1960
by(auto simp: inv_check_left_moving_in_middle.simps )
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1961
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1962
lemma [simp]: 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1963
 "inv_on_left_moving_in_middle_B (as, lm) (s, [], Bk # r) ires\<Longrightarrow> 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1964
  inv_check_left_moving_on_leftmost (as, lm) (s', [], Bk # Bk # r) ires"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1965
apply(auto simp: inv_on_left_moving_in_middle_B.simps 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1966
                 inv_check_left_moving_on_leftmost.simps split: if_splits)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1967
done
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1968
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1969
lemma [simp]: "inv_check_left_moving_on_leftmost (as, lm) 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1970
                                       (s, list, Oc # r) ires= False"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1971
by(auto simp: inv_check_left_moving_on_leftmost.simps split: if_splits)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1972
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1973
lemma [simp]: "inv_on_left_moving_in_middle_B (as, lm) 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1974
                                         (s, Oc # list, Bk # r) ires
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1975
 \<Longrightarrow> inv_check_left_moving_in_middle (as, lm) (s', list, Oc # Bk # r) ires"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1976
apply(auto simp: inv_on_left_moving_in_middle_B.simps 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1977
                 inv_check_left_moving_in_middle.simps  split: if_splits)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1978
done
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1979
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1980
lemma inv_on_left_moving_2_check_left_moving[simp]:
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1981
 "inv_on_left_moving (as, lm) (s, l, Bk # r) ires
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1982
 \<Longrightarrow> (l = [] \<longrightarrow> inv_check_left_moving (as, lm) (s', [], Bk # Bk # r) ires)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1983
 \<and> (l \<noteq> [] \<longrightarrow> 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1984
      inv_check_left_moving (as, lm) (s', tl l, hd l # Bk # r) ires)"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1985
apply(simp add: inv_on_left_moving.simps inv_check_left_moving.simps)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1986
apply(case_tac l, simp, simp)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1987
apply(case_tac a, simp, simp)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1988
done
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1989
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1990
lemma [simp]: "inv_on_left_moving_norm (as, lm) (s, l, []) ires = False"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1991
apply(auto simp: inv_on_left_moving_norm.simps)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1992
done
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1993
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1994
lemma [simp]: "inv_on_left_moving (as, lm) (s, l, []) ires\<Longrightarrow> 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1995
     inv_on_left_moving (as, lm) (6 + 2 * n, l, [Bk]) ires"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1996
apply(simp add: inv_on_left_moving.simps)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1997
apply(auto simp: inv_on_left_moving_in_middle_B.simps)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1998
done
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  1999
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2000
lemma [simp]: "inv_on_left_moving (as, lm) (s, l, []) ires = False"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2001
apply(simp add: inv_on_left_moving.simps)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2002
apply(simp add: inv_on_left_moving_in_middle_B.simps)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2003
done
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2004
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2005
lemma [simp]: "inv_on_left_moving (as, lm) (s, l, []) ires
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2006
 \<Longrightarrow> (l = [] \<longrightarrow> inv_check_left_moving (as, lm) (s', [], [Bk]) ires) \<and>
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2007
    (l \<noteq> [] \<longrightarrow> inv_check_left_moving (as, lm) (s', tl l, [hd l]) ires)"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2008
by simp
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2009
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2010
lemma [intro]: "\<exists>rna. Bk # Bk \<up> rn = Bk \<up> rna"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2011
apply(rule_tac x = "Suc rn" in exI, simp)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2012
done
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2013
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2014
lemma 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2015
inv_check_left_moving_in_middle_2_on_left_moving_in_middle_B[simp]:
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2016
"inv_check_left_moving_in_middle (as, lm) (s, Bk # list, Oc # r) ires
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2017
  \<Longrightarrow> inv_on_left_moving_in_middle_B (as, lm) (s', list, Bk # Oc # r) ires"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2018
apply(simp only: inv_check_left_moving_in_middle.simps 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2019
                 inv_on_left_moving_in_middle_B.simps)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2020
apply(erule_tac exE)+
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2021
apply(rule_tac x = "rev (tl (rev lm1))" in exI, 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2022
      rule_tac x = "[hd (rev lm1)] @ lm2" in exI, auto)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2023
apply(case_tac [!] "rev lm1",simp_all add: tape_of_nl_abv tape_of_nat_list.simps)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2024
apply(case_tac [!] a, simp_all)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2025
apply(case_tac [1] lm2, simp_all add: tape_of_nat_list.simps, auto)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2026
apply(case_tac [3] lm2, simp_all add: tape_of_nat_list.simps, auto)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2027
apply(case_tac [!] lista, simp_all add: tape_of_nat_list.simps)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2028
done
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2029
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2030
lemma [simp]: 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2031
 "inv_check_left_moving_in_middle (as, lm) (s, [], Oc # r) ires\<Longrightarrow>
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2032
     inv_check_left_moving_in_middle (as, lm) (s', [Bk], Oc # r) ires"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2033
apply(auto simp: inv_check_left_moving_in_middle.simps )
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2034
done
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2035
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2036
lemma [simp]: 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2037
 "inv_check_left_moving_in_middle (as, lm) (s, [], Oc # r) ires
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2038
   \<Longrightarrow> inv_on_left_moving_in_middle_B (as, lm) (s', [], Bk # Oc # r) ires"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2039
apply(insert 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2040
inv_check_left_moving_in_middle_2_on_left_moving_in_middle_B[of 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2041
                  as lm n "[]" r], simp)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2042
done 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2043
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2044
lemma [simp]: "inv_check_left_moving_in_middle (as, lm) 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2045
                       (s, Oc # list, Oc # r) ires
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2046
   \<Longrightarrow> inv_on_left_moving_norm (as, lm) (s', list, Oc # Oc # r) ires"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2047
apply(auto simp: inv_check_left_moving_in_middle.simps 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2048
                 inv_on_left_moving_norm.simps)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2049
apply(rule_tac x = "rev (tl (rev lm1))" in exI, 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2050
      rule_tac x = lm2 in exI, rule_tac x = "hd (rev lm1)" in exI)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2051
apply(rule_tac conjI)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2052
apply(case_tac "rev lm1", simp, simp)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2053
apply(rule_tac x = "hd (rev lm1) - 1" in exI, auto)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2054
apply(rule_tac [!] x = "Suc (Suc 0)" in exI, simp)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2055
apply(case_tac [!] "rev lm1", simp_all)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2056
apply(case_tac [!] a, simp_all add: tape_of_nl_cons split: if_splits)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2057
done
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2058
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2059
lemma [simp]: "inv_check_left_moving (as, lm) (s, l, Oc # r) ires
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2060
\<Longrightarrow> (l = [] \<longrightarrow> inv_on_left_moving (as, lm) (s', [], Bk # Oc # r) ires) \<and>
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2061
   (l \<noteq> [] \<longrightarrow> inv_on_left_moving (as, lm) (s', tl l, hd l # Oc # r) ires)"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2062
apply(case_tac l, 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2063
      auto simp: inv_check_left_moving.simps inv_on_left_moving.simps)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2064
apply(case_tac a, simp, simp)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2065
done
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2066
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2067
(*inv: check_left_moving to after_left_moving*)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2068
lemma [simp]: "inv_check_left_moving (as, lm) (s, l, Bk # r) ires
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2069
                \<Longrightarrow> inv_after_left_moving (as, lm) (s', Bk # l, r) ires"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2070
apply(auto simp: inv_check_left_moving.simps 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2071
 inv_check_left_moving_on_leftmost.simps inv_after_left_moving.simps)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2072
done
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2073
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2074
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2075
lemma [simp]:"inv_check_left_moving (as, lm) (s, l, []) ires
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2076
      \<Longrightarrow> inv_after_left_moving (as, lm) (s', Bk # l, []) ires"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2077
by(simp add: inv_check_left_moving.simps  
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2078
inv_check_left_moving_in_middle.simps 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2079
inv_check_left_moving_on_leftmost.simps)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2080
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2081
(*inv: after_left_moving to inv_stop*)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2082
lemma [simp]: "inv_after_left_moving (as, lm) (s, l, Bk # r) ires
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2083
       \<Longrightarrow> inv_stop (as, lm) (s', Bk # l, r) ires"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2084
apply(auto simp: inv_after_left_moving.simps inv_stop.simps)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2085
done
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2086
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2087
lemma [simp]: "inv_after_left_moving (as, lm) (s, l, []) ires
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2088
             \<Longrightarrow> inv_stop (as, lm) (s', Bk # l, []) ires"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2089
by(auto simp: inv_after_left_moving.simps)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2090
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2091
(*inv: stop to stop*)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2092
lemma [simp]: "inv_stop (as, lm) (x, l, r) ires \<Longrightarrow> 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2093
               inv_stop (as, lm) (y, l, r) ires"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2094
apply(simp add: inv_stop.simps)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2095
done
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2096
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2097
lemma [simp]: "inv_after_clear (as, lm) (s, aaa, Oc # xs) ires= False"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2098
apply(auto simp: inv_after_clear.simps )
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2099
done
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2100
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2101
lemma [simp]: 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2102
  "inv_after_left_moving (as, lm) (s, aaa, Oc # xs) ires = False"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2103
by(auto simp: inv_after_left_moving.simps  )
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2104
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2105
lemma [simp]: "inv_after_clear (as, abc_lm_s lm n (Suc (abc_lm_v lm n))) (s, b, []) ires = False"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2106
apply(auto simp: inv_after_clear.simps)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2107
done
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2108
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2109
lemma [simp]: "inv_on_left_moving (as, abc_lm_s lm n (Suc (abc_lm_v lm n))) 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2110
           (s, b, Oc # list) ires \<Longrightarrow> b \<noteq> []"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2111
apply(auto simp: inv_on_left_moving.simps inv_on_left_moving_norm.simps split: if_splits)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2112
done
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2113
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2114
lemma [simp]: "inv_check_left_moving (as, abc_lm_s lm n (Suc (abc_lm_v lm n))) (s, b, Oc # list) ires \<Longrightarrow> b \<noteq> []"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2115
apply(auto simp: inv_check_left_moving.simps inv_check_left_moving_in_middle.simps split: if_splits)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2116
done
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2117
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2118
lemma tinc_correct_pre:
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2119
  assumes layout: "ly = layout_of ap"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2120
  and inv_start: "inv_locate_a (as, lm) (n, l, r) ires"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2121
  and lm': "lm' = abc_lm_s lm n (Suc (abc_lm_v lm n))"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2122
  and f: "f = steps (Suc 0, l, r) (tinc_b, 0)"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2123
  and P: "P = (\<lambda> (s, l, r). s = 10)"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2124
  and Q: "Q = (\<lambda> (s, l, r). inc_inv n (as, lm) (s, l, r) ires)" 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2125
  shows "\<exists> stp. P (f stp) \<and> Q (f stp)"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2126
proof(rule_tac LE = inc_LE in halt_lemma2)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2127
  show "wf inc_LE" by(auto)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2128
next
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2129
  show "Q (f 0)"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2130
    using inv_start
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2131
    apply(simp add: f P Q steps.simps inc_inv.simps)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2132
    done
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2133
next
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2134
  show "\<not> P (f 0)"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2135
    apply(simp add: f P steps.simps)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2136
    done
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2137
next
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2138
  show "\<forall>n. \<not> P (f n) \<and> Q (f n) \<longrightarrow> Q (f (Suc n)) \<and> (f (Suc n), f n) 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2139
        \<in> inc_LE"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2140
  proof(rule_tac allI, rule_tac impI, simp add: f, 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2141
      case_tac "steps (Suc 0, l, r) (tinc_b, 0) n", simp add: P)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2142
    fix n a b c
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2143
    assume "a \<noteq> 10 \<and> Q (a, b, c)"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2144
    thus  "Q (step (a, b, c) (tinc_b, 0)) \<and> (step (a, b, c) (tinc_b, 0), a, b, c) \<in> inc_LE"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2145
      apply(simp add:Q)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2146
      apply(simp add: inc_inv.simps)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2147
      apply(case_tac c, case_tac [2] aa)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2148
      apply(auto simp: Let_def step.simps tinc_b_def numeral_2_eq_2 numeral_3_eq_3  split: if_splits)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2149
      apply(simp_all add: inc_inv.simps inc_LE_def lex_triple_def lex_pair_def inc_measure_def numeral_5_eq_5
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2150
                          numeral_6_eq_6 numeral_7_eq_7 numeral_8_eq_8 numeral_9_eq_9)         
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2151
      done
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2152
  qed
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2153
qed
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2154
         
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2155
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2156
lemma tinc_correct: 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2157
  assumes layout: "ly = layout_of ap"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2158
  and inv_start: "inv_locate_a (as, lm) (n, l, r) ires"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2159
  and lm': "lm' = abc_lm_s lm n (Suc (abc_lm_v lm n))"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2160
  shows "\<exists> stp l' r'. steps (Suc 0, l, r) (tinc_b, 0) stp = (10, l', r')
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2161
              \<and> inv_stop (as, lm') (10, l', r') ires"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2162
  using assms
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2163
  apply(drule_tac tinc_correct_pre, auto)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2164
  apply(rule_tac x = stp in exI, simp)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2165
  apply(simp add: inc_inv.simps)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2166
  done
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2167
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2168
declare inv_locate_a.simps[simp del] abc_lm_s.simps[simp del]
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2169
        abc_lm_v.simps[simp del]
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2170
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2171
lemma [simp]: "(4::nat) * n mod 2 = 0"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2172
apply(arith)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2173
done
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2174
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2175
lemma crsp_step_inc_pre:
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2176
  assumes layout: "ly = layout_of ap"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2177
  and crsp: "crsp ly (as, lm) (s, l, r) ires"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2178
  and aexec: "abc_step_l (as, lm) (Some (Inc n)) = (asa, lma)"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2179
  shows "\<exists> stp k. steps (Suc 0, l, r) (findnth n @ shift tinc_b (2 * n), 0) stp 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2180
        = (2*n + 10, Bk # Bk # ires, <lma> @ Bk\<up>k) \<and> stp > 0"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2181
proof -
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2182
  thm tm_append_steps
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2183
  have "\<exists> stp l' r'. steps (Suc 0, l, r) (findnth n, 0) stp = (Suc (2 * n), l', r')
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2184
    \<and> inv_locate_a (as, lm) (n, l', r') ires"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2185
    using assms
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2186
    apply(rule_tac findnth_correct, simp_all add: crsp layout)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2187
    done
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2188
  from this obtain stp l' r' where a:
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2189
    "steps (Suc 0, l, r) (findnth n, 0) stp = (Suc (2 * n), l', r')
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2190
    \<and> inv_locate_a (as, lm) (n, l', r') ires" by blast
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2191
  moreover have
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2192
    "\<exists> stp la ra. steps (Suc 0, l', r') (tinc_b, 0) stp = (10, la, ra)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2193
                        \<and> inv_stop (as, lma) (10, la, ra) ires"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2194
    using assms a
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2195
  proof(rule_tac lm' = lma and n = n and lm = lm and ly = ly and ap = ap in tinc_correct,
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2196
      simp, simp)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2197
    show "lma = abc_lm_s lm n (Suc (abc_lm_v lm n))"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2198
      using aexec
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2199
      apply(simp add: abc_step_l.simps)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2200
      done
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2201
  qed
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2202
  from this obtain stpa la ra where b:
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2203
    "steps (Suc 0, l', r') (tinc_b, 0) stpa = (10, la, ra)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2204
    \<and> inv_stop (as, lma) (10, la, ra) ires" by blast
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2205
  from a b show "\<exists>stp k. steps (Suc 0, l, r) (findnth n @ shift tinc_b (2 * n), 0) stp
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2206
    = (2 * n + 10, Bk # Bk # ires, <lma> @ Bk \<up> k) \<and> stp > 0"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2207
    apply(rule_tac x = "stp + stpa" in exI)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2208
    using tm_append_steps[of "Suc 0" l r "findnth n" stp l' r' tinc_b stpa 10 la ra "length (findnth n) div 2"]
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2209
    apply(simp add: length_findnth inv_stop.simps)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2210
    apply(case_tac stpa, simp_all add: steps.simps)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2211
    done
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2212
qed 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2213
     
47
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2214
lemma crsp_step_inc:
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2215
  assumes layout: "ly = layout_of ap"
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2216
  and crsp: "crsp ly (as, lm) (s, l, r) ires"
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2217
  and fetch: "abc_fetch as ap = Some (Inc n)"
60
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2218
  shows "\<exists>stp > 0. crsp ly (abc_step_l (as, lm) (Some (Inc n)))
47
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2219
  (steps (s, l, r) (ci ly (start_of ly as) (Inc n), start_of ly as - Suc 0) stp) ires"
60
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2220
proof(case_tac "(abc_step_l (as, lm) (Some (Inc n)))")
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2221
  fix a b
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2222
  assume aexec: "abc_step_l (as, lm) (Some (Inc n)) = (a, b)"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2223
  then have "\<exists> stp k. steps (Suc 0, l, r) (findnth n @ shift tinc_b (2 * n), 0) stp 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2224
        = (2*n + 10, Bk # Bk # ires, <b> @ Bk\<up>k) \<and> stp > 0"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2225
    using assms
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2226
    apply(rule_tac crsp_step_inc_pre, simp_all)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2227
    done
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2228
  thus "?thesis"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2229
    using assms aexec
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2230
    apply(erule_tac exE)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2231
    apply(erule_tac exE)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2232
    apply(erule_tac conjE)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2233
    apply(rule_tac x = stp in exI, simp add: ci.simps tm_shift_eq_steps)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2234
    apply(drule_tac off = "(start_of (layout_of ap) as - Suc 0)" in tm_shift_eq_steps)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2235
    apply(auto simp: crsp.simps abc_step_l.simps fetch start_of_Suc1)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2236
    done
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2237
qed
47
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2238
    
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2239
subsection{* Crsp of Dec n e*}
60
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2240
declare sete.simps[simp del]
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2241
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2242
type_synonym dec_inv_t = "(nat * nat list) \<Rightarrow> config \<Rightarrow> cell list \<Rightarrow>  bool"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2243
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2244
fun dec_first_on_right_moving :: "nat \<Rightarrow> dec_inv_t"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2245
  where
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2246
  "dec_first_on_right_moving n (as, lm) (s, l, r) ires = 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2247
               (\<exists> lm1 lm2 m ml mr rn. lm = lm1 @ [m] @ lm2 \<and> 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2248
         ml + mr = Suc m \<and> length lm1 = n \<and> ml > 0 \<and> m > 0 \<and>
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2249
             (if lm1 = [] then l = Oc\<up>ml @ Bk # Bk # ires
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2250
                          else  l = Oc\<up>ml @ [Bk] @ <rev lm1> @ Bk # Bk # ires) \<and> 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2251
    ((r = Oc\<up>mr @ [Bk] @ <lm2> @ Bk\<up>rn) \<or> (r = Oc\<up>mr \<and> lm2 = [])))"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2252
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2253
fun dec_on_right_moving :: "dec_inv_t"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2254
  where
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2255
  "dec_on_right_moving (as, lm) (s, l, r) ires =  
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2256
   (\<exists> lm1 lm2 m ml mr rn. lm = lm1 @ [m] @ lm2 \<and> 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2257
                             ml + mr = Suc (Suc m) \<and>
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2258
   (if lm1 = [] then l = Oc\<up>ml@ Bk # Bk # ires
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2259
                else  l = Oc\<up>ml @ [Bk] @ <rev lm1> @ Bk # Bk # ires) \<and> 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2260
   ((r = Oc\<up>mr @ [Bk] @ <lm2> @ Bk\<up>rn) \<or> (r = Oc\<up>mr \<and> lm2 = [])))"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2261
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2262
fun dec_after_clear :: "dec_inv_t"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2263
  where
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2264
  "dec_after_clear (as, lm) (s, l, r) ires = 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2265
              (\<exists> lm1 lm2 m ml mr rn. lm = lm1 @ [m] @ lm2 \<and> 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2266
                ml + mr = Suc m \<and> ml = Suc m \<and> r \<noteq> [] \<and> r \<noteq> [] \<and>
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2267
               (if lm1 = [] then l = Oc\<up>ml@ Bk # Bk # ires
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2268
                            else l = Oc\<up>ml @ [Bk] @ <rev lm1> @ Bk # Bk # ires) \<and> 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2269
               (tl r = Bk # <lm2> @ Bk\<up>rn \<or> tl r = [] \<and> lm2 = []))"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2270
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2271
fun dec_after_write :: "dec_inv_t"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2272
  where
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2273
  "dec_after_write (as, lm) (s, l, r) ires = 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2274
         (\<exists> lm1 lm2 m ml mr rn. lm = lm1 @ [m] @ lm2 \<and> 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2275
       ml + mr = Suc m \<and> ml = Suc m \<and> lm2 \<noteq> [] \<and>
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2276
       (if lm1 = [] then l = Bk # Oc\<up>ml @ Bk # Bk # ires
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2277
                    else l = Bk # Oc\<up>ml @ [Bk] @ <rev lm1> @ Bk # Bk # ires) \<and> 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2278
       tl r = <lm2> @ Bk\<up>rn)"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2279
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2280
fun dec_right_move :: "dec_inv_t"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2281
  where
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2282
  "dec_right_move (as, lm) (s, l, r) ires = 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2283
        (\<exists> lm1 lm2 m ml mr rn. lm = lm1 @ [m] @ lm2 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2284
            \<and> ml = Suc m \<and> mr = (0::nat) \<and> 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2285
              (if lm1 = [] then l = Bk # Oc\<up>ml @ Bk # Bk # ires
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2286
                          else l = Bk # Oc\<up>ml @ [Bk] @ <rev lm1> @ Bk # Bk # ires) 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2287
           \<and> (r = Bk # <lm2> @ Bk\<up>rn \<or> r = [] \<and> lm2 = []))"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2288
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2289
fun dec_check_right_move :: "dec_inv_t"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2290
  where
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2291
  "dec_check_right_move (as, lm) (s, l, r) ires = 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2292
        (\<exists> lm1 lm2 m ml mr rn. lm = lm1 @ [m] @ lm2 \<and> 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2293
           ml = Suc m \<and> mr = (0::nat) \<and> 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2294
           (if lm1 = [] then l = Bk # Bk # Oc\<up>ml @ Bk # Bk # ires
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2295
                       else l = Bk # Bk # Oc\<up>ml @ [Bk] @ <rev lm1> @ Bk # Bk # ires) \<and> 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2296
           r = <lm2> @ Bk\<up>rn)"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2297
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2298
fun dec_left_move :: "dec_inv_t"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2299
  where
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2300
  "dec_left_move (as, lm) (s, l, r) ires = 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2301
    (\<exists> lm1 m rn. (lm::nat list) = lm1 @ [m::nat] \<and>   
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2302
    rn > 0 \<and> 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2303
   (if lm1 = [] then l = Bk # Oc\<up>Suc m @ Bk # Bk # ires
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2304
    else l = Bk # Oc\<up>Suc m @ Bk # <rev lm1> @ Bk # Bk # ires) \<and> r = Bk\<up>rn)"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2305
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2306
declare
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2307
  dec_on_right_moving.simps[simp del] dec_after_clear.simps[simp del] 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2308
  dec_after_write.simps[simp del] dec_left_move.simps[simp del] 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2309
  dec_check_right_move.simps[simp del] dec_right_move.simps[simp del] 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2310
  dec_first_on_right_moving.simps[simp del]
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2311
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2312
fun inv_locate_n_b :: "inc_inv_t"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2313
  where
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2314
  "inv_locate_n_b (as, lm) (s, l, r) ires= 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2315
    (\<exists> lm1 lm2 tn m ml mr rn. lm @ 0\<up>tn = lm1 @ [m] @ lm2 \<and> 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2316
     length lm1 = s \<and> m + 1 = ml + mr \<and> 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2317
     ml = 1 \<and> tn = s + 1 - length lm \<and>
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2318
     (if lm1 = [] then l = Oc\<up>ml @ Bk # Bk # ires
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2319
      else l = Oc\<up>ml @ Bk # <rev lm1> @ Bk # Bk # ires) \<and> 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2320
     (r = Oc\<up>mr @ [Bk] @ <lm2>@ Bk\<up>rn \<or> (lm2 = [] \<and> r = Oc\<up>mr))
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2321
  )"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2322
(*
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2323
fun dec_inv_1 :: "layout \<Rightarrow> nat \<Rightarrow> nat \<Rightarrow> dec_inv_t"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2324
  where
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2325
  "dec_inv_1 ly n e (as, am) (s, l, r) ires = 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2326
           (let ss = start_of ly as in
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2327
            let am' = abc_lm_s am n (abc_lm_v am n - Suc 0) in
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2328
            let am'' = abc_lm_s am n (abc_lm_v am n) in
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2329
              if s = start_of ly e then inv_stop (as, am'') (s, l, r) ires
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2330
              else if s = ss then False
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2331
              else if s = ss + 2 * n then 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2332
                  inv_locate_a (as, am) (n, l, r) ires
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2333
                \<or> inv_locate_a (as, am'') (n, l, r) ires
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2334
              else if s = ss + 2 * n + 1 then 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2335
                  inv_locate_b (as, am) (n, l, r) ires
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2336
              else if s = ss + 2 * n + 13 then 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2337
                  inv_on_left_moving (as, am'') (s, l, r) ires
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2338
              else if s = ss + 2 * n + 14 then 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2339
                  inv_check_left_moving (as, am'') (s, l, r) ires
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2340
              else if s = ss + 2 * n + 15 then 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2341
                  inv_after_left_moving (as, am'') (s, l, r) ires
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2342
              else False)"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2343
*)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2344
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2345
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2346
fun dec_inv_1 :: "layout \<Rightarrow> nat \<Rightarrow> nat \<Rightarrow> dec_inv_t"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2347
  where
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2348
  "dec_inv_1 ly n e (as, am) (s, l, r) ires = 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2349
           (let ss = start_of ly as in
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2350
            let am' = abc_lm_s am n (abc_lm_v am n - Suc 0) in
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2351
            let am'' = abc_lm_s am n (abc_lm_v am n) in
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2352
              if s = start_of ly e then inv_stop (as, am'') (s, l, r) ires
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2353
              else if s = ss then False
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2354
              else if s = ss + 2 * n + 1 then 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2355
                  inv_locate_b (as, am) (n, l, r) ires
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2356
              else if s = ss + 2 * n + 13 then 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2357
                  inv_on_left_moving (as, am'') (s, l, r) ires
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2358
              else if s = ss + 2 * n + 14 then 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2359
                  inv_check_left_moving (as, am'') (s, l, r) ires
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2360
              else if s = ss + 2 * n + 15 then 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2361
                  inv_after_left_moving (as, am'') (s, l, r) ires
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2362
              else False)"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2363
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2364
declare fetch.simps[simp del]
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2365
lemma [simp]:
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2366
  "fetch (ci ly (start_of ly as) (Dec n e)) (Suc (2 * n)) Bk = (W1,  start_of ly as + 2 *n)"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2367
apply(auto simp: fetch.simps length_ci_dec)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2368
apply(auto simp: ci.simps nth_append length_findnth sete.simps shift.simps tdec_b_def)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2369
using startof_not0[of ly as] by simp
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2370
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2371
lemma [simp]:
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2372
  "fetch (ci ly (start_of ly as) (Dec n e)) (Suc (2 * n)) Oc = (R,  Suc (start_of ly as) + 2 *n)"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2373
apply(auto simp: fetch.simps length_ci_dec)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2374
apply(auto simp: ci.simps nth_append length_findnth sete.simps shift.simps tdec_b_def)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2375
done
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2376
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2377
lemma [simp]: 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2378
  "\<lbrakk>r = [] \<or> hd r = Bk; inv_locate_a (as, lm) (n, l, r) ires\<rbrakk>
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2379
    \<Longrightarrow> \<exists>stp la ra.
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2380
  steps (start_of ly as + 2 * n, l, r) (ci ly (start_of ly as) (Dec n e), 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2381
  start_of ly as - Suc 0) stp = (Suc (start_of ly as + 2 * n), la, ra) \<and>
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2382
  inv_locate_b (as, lm) (n, la, ra) ires"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2383
apply(rule_tac x = "Suc (Suc 0)" in exI)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2384
apply(auto simp: steps.simps step.simps length_ci_dec)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2385
apply(case_tac r, simp_all)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2386
done
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2387
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2388
lemma [simp]: 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2389
  "\<lbrakk>inv_locate_a (as, lm) (n, l, r) ires; r \<noteq> [] \<and> hd r \<noteq> Bk\<rbrakk>
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2390
    \<Longrightarrow> \<exists>stp la ra.
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2391
  steps (start_of ly as + 2 * n, l, r) (ci ly (start_of ly as) (Dec n e), 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2392
  start_of ly as - Suc 0) stp = (Suc (start_of ly as + 2 * n), la, ra) \<and>
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2393
  inv_locate_b (as, lm) (n, la, ra) ires"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2394
apply(rule_tac x = "(Suc 0)" in exI, case_tac "hd r", simp_all)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2395
apply(auto simp: steps.simps step.simps length_ci_dec)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2396
apply(case_tac r, simp_all)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2397
done
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2398
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2399
fun abc_dec_1_stage1:: "config \<Rightarrow> nat \<Rightarrow> nat \<Rightarrow> nat"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2400
  where
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2401
  "abc_dec_1_stage1 (s, l, r) ss n = 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2402
       (if s > ss \<and> s \<le> ss + 2*n + 1 then 4
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2403
        else if s = ss + 2 * n + 13 \<or> s = ss + 2*n + 14 then 3
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2404
        else if s = ss + 2*n + 15 then 2
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2405
        else 0)"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2406
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2407
fun abc_dec_1_stage2:: "config \<Rightarrow> nat \<Rightarrow> nat \<Rightarrow> nat"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2408
  where
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2409
  "abc_dec_1_stage2 (s, l, r) ss n = 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2410
       (if s \<le> ss + 2 * n + 1 then (ss + 2 * n + 16 - s)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2411
        else if s = ss + 2*n + 13 then length l
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2412
        else if s = ss + 2*n + 14 then length l
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2413
        else 0)"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2414
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2415
fun abc_dec_1_stage3 :: "config \<Rightarrow> nat \<Rightarrow> nat \<Rightarrow> nat"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2416
  where
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2417
  "abc_dec_1_stage3 (s, l, r) ss n  = 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2418
        (if s \<le> ss + 2*n + 1 then 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2419
             if (s - ss) mod 2 = 0 then 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2420
                         if r \<noteq> [] \<and> hd r = Oc then 0 else 1  
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2421
                         else length r
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2422
         else if s = ss + 2 * n + 13 then 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2423
             if r \<noteq> [] \<and> hd r = Oc then 2 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2424
             else 1
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2425
         else if s = ss + 2 * n + 14 then 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2426
             if r \<noteq> [] \<and> hd r = Oc then 3 else 0 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2427
         else 0)"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2428
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2429
fun abc_dec_1_measure :: "(config \<times> nat \<times> nat) \<Rightarrow> (nat \<times> nat \<times> nat)"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2430
  where
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2431
  "abc_dec_1_measure (c, ss, n) = (abc_dec_1_stage1 c ss n, 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2432
                   abc_dec_1_stage2 c ss n, abc_dec_1_stage3 c ss n)"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2433
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2434
definition abc_dec_1_LE ::
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2435
  "((config \<times> nat \<times>
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2436
  nat) \<times> (config \<times> nat \<times> nat)) set"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2437
  where "abc_dec_1_LE \<equiv> (inv_image lex_triple abc_dec_1_measure)"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2438
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2439
lemma wf_dec_le: "wf abc_dec_1_LE"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2440
by(auto intro:wf_inv_image simp:abc_dec_1_LE_def lex_triple_def lex_pair_def)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2441
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2442
lemma startof_Suc2:
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2443
  "abc_fetch as ap = Some (Dec n e) \<Longrightarrow> 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2444
        start_of (layout_of ap) (Suc as) = 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2445
            start_of (layout_of ap) as + 2 * n + 16"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2446
apply(auto simp: start_of.simps layout_of.simps  
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2447
                 length_of.simps abc_fetch.simps 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2448
                 take_Suc_conv_app_nth split: if_splits)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2449
done
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2450
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2451
lemma start_of_less_2: 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2452
  "start_of ly e \<le> start_of ly (Suc e)"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2453
thm take_Suc
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2454
apply(case_tac "e < length ly")
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2455
apply(auto simp: start_of.simps take_Suc take_Suc_conv_app_nth)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2456
done
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2457
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2458
lemma start_of_less_1: "start_of ly e \<le> start_of ly (e + d)"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2459
proof(induct d)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2460
  case 0 thus "?case" by simp
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2461
next
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2462
  case (Suc d)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2463
  have "start_of ly e \<le> start_of ly (e + d)"  by fact
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2464
  moreover have "start_of ly (e + d) \<le> start_of ly (Suc (e + d))"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2465
    by(rule_tac start_of_less_2)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2466
  ultimately show"?case"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2467
    by(simp)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2468
qed
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2469
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2470
lemma start_of_less: 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2471
  assumes "e < as"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2472
  shows "start_of ly e \<le> start_of ly as"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2473
proof -
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2474
  obtain d where " as = e + d"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2475
    using assms by (metis less_imp_add_positive)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2476
  thus "?thesis"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2477
    by(simp add: start_of_less_1)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2478
qed
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2479
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2480
lemma start_of_ge: 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2481
  assumes fetch: "abc_fetch as ap = Some (Dec n e)"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2482
  and layout: "ly = layout_of ap"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2483
  and great: "e > as"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2484
  shows "start_of ly e \<ge> start_of ly as + 2*n + 16"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2485
proof(cases "e = Suc as")
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2486
  case True
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2487
  have "e = Suc as" by fact
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2488
  moreover hence "start_of ly (Suc as) = start_of ly as + 2*n + 16"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2489
    using layout fetch
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2490
    by(simp add: startof_Suc2)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2491
  ultimately show "?thesis" by (simp)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2492
next
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2493
  case False
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2494
  have "e \<noteq> Suc as" by fact
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2495
  then have "e > Suc as" using great by arith
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2496
  then have "start_of ly (Suc as) \<le> start_of ly e"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2497
    by(simp add: start_of_less)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2498
  moreover have "start_of ly (Suc as) = start_of ly as + 2*n + 16"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2499
    using layout fetch
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2500
    by(simp add: startof_Suc2)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2501
  ultimately show "?thesis"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2502
    by arith
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2503
qed
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2504
    
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2505
lemma [elim]: "\<lbrakk>abc_fetch as ap = Some (Dec n e); as < e; 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2506
  Suc (start_of (layout_of ap) as + 2 * n) = start_of (layout_of ap) e\<rbrakk> \<Longrightarrow> RR"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2507
apply(drule_tac start_of_ge, simp_all)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2508
apply(auto)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2509
done
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2510
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2511
lemma [elim]: "\<lbrakk>abc_fetch as ap = Some (Dec n e); as > e;
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2512
  Suc (start_of (layout_of ap) as + 2 * n) = start_of (layout_of ap) e\<rbrakk> \<Longrightarrow> RR"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2513
apply(drule_tac ly = "layout_of ap" in start_of_less[of])
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2514
apply(arith)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2515
done
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2516
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2517
lemma [elim]: "\<lbrakk>abc_fetch as ap = Some (Dec n e);
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2518
  Suc (start_of (layout_of ap) as + 2 * n) = start_of (layout_of ap) e\<rbrakk> \<Longrightarrow> RR"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2519
apply(subgoal_tac "as = e \<or> as < e \<or> as > e", auto)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2520
done
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2521
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2522
lemma [simp]:"fetch (ci (ly) (start_of ly as) (Dec n e)) (Suc (2 * n))  Oc
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2523
  = (R, start_of ly as + 2*n + 1)"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2524
apply(auto simp: ci.simps findnth.simps fetch.simps
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2525
                  nth_of.simps shift.simps nth_append tdec_b_def length_findnth sete.simps)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2526
done
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2527
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2528
lemma [simp]: "(start_of ly as = 0) = False"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2529
apply(simp add: start_of.simps)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2530
done
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2531
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2532
lemma [simp]: "fetch (ci (ly) 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2533
  (start_of ly as) (Dec n e)) (Suc (2 * n))  Bk
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2534
  = (W1, start_of ly as + 2*n)"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2535
apply(auto simp: ci.simps findnth.simps fetch.simps
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2536
                  nth_of.simps shift.simps nth_append tdec_b_def length_findnth sete.simps)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2537
done
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2538
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2539
lemma [simp]: 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2540
  "fetch (ci (ly) 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2541
                (start_of ly as) (Dec n e)) (Suc (Suc (2 * n)))  Oc
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2542
      = (R, start_of ly as + 2*n + 2)"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2543
apply(auto simp: ci.simps findnth.simps fetch.simps
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2544
                  nth_of.simps shift.simps nth_append tdec_b_def length_findnth sete.simps)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2545
done
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2546
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2547
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2548
lemma [simp]: "fetch (ci (ly) 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2549
                  (start_of ly as) (Dec n e)) (Suc (Suc (2 * n))) Bk
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2550
      = (L, start_of ly as + 2*n + 13)"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2551
apply(auto simp: ci.simps findnth.simps fetch.simps
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2552
                  nth_of.simps shift.simps nth_append tdec_b_def length_findnth sete.simps)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2553
done
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2554
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2555
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2556
lemma [simp]: "fetch (ci (ly) 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2557
             (start_of ly as) (Dec n e)) (Suc (Suc (Suc (2 * n))))  Oc
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2558
     = (R, start_of ly as + 2*n + 2)"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2559
apply(auto simp: ci.simps findnth.simps fetch.simps
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2560
                  nth_of.simps shift.simps nth_append tdec_b_def length_findnth sete.simps)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2561
done
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2562
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2563
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2564
lemma [simp]: "fetch (ci (ly) (start_of ly as) (Dec n e)) 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2565
                             (Suc (Suc (Suc (2 * n))))  Bk
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2566
     = (L, start_of ly as + 2*n + 3)"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2567
apply(auto simp: ci.simps findnth.simps fetch.simps
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2568
                  nth_of.simps shift.simps nth_append tdec_b_def length_findnth sete.simps)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2569
done
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2570
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2571
lemma [simp]:
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2572
     "fetch (ci (ly) 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2573
                      (start_of ly as) (Dec n e)) (2 * n + 4) Oc
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2574
    = (W0, start_of ly as + 2*n + 3)"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2575
apply(subgoal_tac "2*n + 4 = Suc (2*n + 3)", simp only: fetch.simps)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2576
apply(auto simp: ci.simps findnth.simps fetch.simps
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2577
                  nth_of.simps shift.simps nth_append tdec_b_def length_findnth sete.simps)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2578
done
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2579
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2580
lemma [simp]: "fetch (ci (ly) 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2581
                   (start_of ly as) (Dec n e)) (2 * n + 4) Bk
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2582
    = (R, start_of ly as + 2*n + 4)"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2583
apply(subgoal_tac "2*n + 4 = Suc (2*n + 3)", simp only: fetch.simps)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2584
apply(auto simp: ci.simps findnth.simps fetch.simps
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2585
                  nth_of.simps shift.simps nth_append tdec_b_def length_findnth sete.simps)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2586
done
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2587
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2588
lemma [simp]:"fetch (ci (ly) 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2589
                          (start_of ly as) (Dec n e)) (2 * n + 5) Bk
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2590
    = (R, start_of ly as + 2*n + 5)"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2591
apply(subgoal_tac "2*n + 5 = Suc (2*n + 4)", simp only: fetch.simps)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2592
apply(auto simp: ci.simps findnth.simps fetch.simps
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2593
                  nth_of.simps shift.simps nth_append tdec_b_def length_findnth sete.simps)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2594
done
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2595
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2596
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2597
lemma [simp]: 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2598
  "fetch (ci (ly)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2599
                (start_of ly as) (Dec n e)) (2 * n + 6) Bk
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2600
    = (L, start_of ly as + 2*n + 6)"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2601
apply(subgoal_tac "2*n + 6 = Suc (2*n + 5)", simp only: fetch.simps)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2602
apply(auto simp: ci.simps findnth.simps fetch.simps
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2603
                  nth_of.simps shift.simps nth_append tdec_b_def length_findnth sete.simps)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2604
done
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2605
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2606
lemma [simp]: 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2607
  "fetch (ci (ly) (start_of ly as) 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2608
                      (Dec n e)) (2 * n + 6) Oc
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2609
    = (L, start_of ly as + 2*n + 7)"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2610
apply(subgoal_tac "2*n + 6 = Suc (2*n + 5)", simp only: fetch.simps)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2611
apply(auto simp: ci.simps findnth.simps fetch.simps
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2612
                  nth_of.simps shift.simps nth_append tdec_b_def length_findnth sete.simps)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2613
done
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2614
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2615
lemma [simp]:"fetch (ci (ly) 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2616
             (start_of ly as) (Dec n e)) (2 * n + 7) Bk
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2617
    = (L, start_of ly as + 2*n + 10)"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2618
apply(subgoal_tac "2*n + 7 = Suc (2*n + 6)", simp only: fetch.simps)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2619
apply(auto simp: ci.simps findnth.simps fetch.simps
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2620
                  nth_of.simps shift.simps nth_append tdec_b_def length_findnth sete.simps)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2621
done
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2622
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2623
lemma [simp]:
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2624
  "fetch (ci (ly) 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2625
                   (start_of ly as) (Dec n e)) (2 * n + 8) Bk
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2626
    = (W1, start_of ly as + 2*n + 7)"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2627
apply(subgoal_tac "2*n + 8 = Suc (2*n + 7)", simp only: fetch.simps)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2628
apply(auto simp: ci.simps findnth.simps fetch.simps
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2629
                  nth_of.simps shift.simps nth_append tdec_b_def length_findnth sete.simps)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2630
done
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2631
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2632
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2633
lemma [simp]: 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2634
  "fetch (ci (ly) 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2635
                   (start_of ly as) (Dec n e)) (2 * n + 8) Oc
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2636
    = (R, start_of ly as + 2*n + 8)"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2637
apply(subgoal_tac "2*n + 8 = Suc (2*n + 7)", simp only: fetch.simps)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2638
apply(auto simp: ci.simps findnth.simps fetch.simps
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2639
                  nth_of.simps shift.simps nth_append tdec_b_def length_findnth sete.simps)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2640
done
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2641
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2642
lemma [simp]: 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2643
  "fetch (ci (ly) 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2644
  (start_of ly as) (Dec n e)) (2 * n + 9) Bk
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2645
  = (L, start_of ly as + 2*n + 9)"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2646
apply(subgoal_tac "2*n + 9 = Suc (2*n + 8)", simp only: fetch.simps)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2647
apply(auto simp: ci.simps findnth.simps fetch.simps
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2648
                  nth_of.simps shift.simps nth_append tdec_b_def length_findnth sete.simps)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2649
done
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2650
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2651
lemma [simp]: 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2652
  "fetch (ci (ly) 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2653
  (start_of ly as) (Dec n e)) (2 * n + 9) Oc
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2654
  = (R, start_of ly as + 2*n + 8)"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2655
apply(subgoal_tac "2*n + 9 = Suc (2*n + 8)", simp only: fetch.simps)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2656
apply(auto simp: ci.simps findnth.simps fetch.simps
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2657
                  nth_of.simps shift.simps nth_append tdec_b_def length_findnth sete.simps)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2658
done
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2659
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2660
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2661
lemma [simp]: 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2662
  "fetch (ci (ly) 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2663
  (start_of ly as) (Dec n e)) (2 * n + 10) Bk
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2664
  = (R, start_of ly as + 2*n + 4)" 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2665
apply(subgoal_tac "2*n + 10 = Suc (2*n + 9)", simp only: fetch.simps)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2666
apply(auto simp: ci.simps findnth.simps fetch.simps
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2667
                  nth_of.simps shift.simps nth_append tdec_b_def length_findnth sete.simps)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2668
done
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2669
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2670
lemma [simp]: "fetch (ci (ly) 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2671
             (start_of ly as) (Dec n e)) (2 * n + 10) Oc
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2672
    = (W0, start_of ly as + 2*n + 9)"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2673
apply(subgoal_tac "2*n + 10 = Suc (2*n + 9)", simp only: fetch.simps)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2674
apply(auto simp: ci.simps findnth.simps fetch.simps
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2675
                  nth_of.simps shift.simps nth_append tdec_b_def length_findnth sete.simps)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2676
done
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2677
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2678
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2679
lemma [simp]: 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2680
  "fetch (ci (ly) 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2681
  (start_of ly as) (Dec n e)) (2 * n + 11) Oc
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2682
  = (L, start_of ly as + 2*n + 10)"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2683
apply(subgoal_tac "2*n + 11 = Suc (2*n + 10)", simp only: fetch.simps)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2684
apply(auto simp: ci.simps findnth.simps fetch.simps
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2685
                  nth_of.simps shift.simps nth_append tdec_b_def length_findnth sete.simps)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2686
done
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2687
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2688
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2689
lemma [simp]: 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2690
  "fetch (ci (ly) 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2691
  (start_of ly as) (Dec n e)) (2 * n + 11) Bk
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2692
  = (L, start_of ly as + 2*n + 11)"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2693
apply(subgoal_tac "2*n + 11 = Suc (2*n + 10)", simp only: fetch.simps)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2694
apply(auto simp: ci.simps findnth.simps fetch.simps
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2695
                  nth_of.simps shift.simps nth_append tdec_b_def length_findnth sete.simps)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2696
done
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2697
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2698
lemma [simp]:
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2699
  "fetch (ci (ly) 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2700
  (start_of ly as) (Dec n e)) (2 * n + 12) Oc
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2701
  = (L, start_of ly as + 2*n + 10)"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2702
apply(subgoal_tac "2*n + 12 = Suc (2*n + 11)", simp only: fetch.simps)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2703
apply(auto simp: ci.simps findnth.simps fetch.simps
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2704
                  nth_of.simps shift.simps nth_append tdec_b_def length_findnth sete.simps)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2705
done
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2706
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2707
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2708
lemma [simp]: 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2709
  "fetch (ci (ly) 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2710
  (start_of ly as) (Dec n e)) (2 * n + 12) Bk
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2711
  = (R, start_of ly as + 2*n + 12)"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2712
apply(subgoal_tac "2*n + 12 = Suc (2*n + 11)", simp only: fetch.simps)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2713
apply(auto simp: ci.simps findnth.simps fetch.simps
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2714
                  nth_of.simps shift.simps nth_append tdec_b_def length_findnth sete.simps)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2715
done
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2716
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2717
lemma [simp]: 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2718
  "fetch (ci (ly) 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2719
  (start_of ly as) (Dec n e)) (2 * n + 13) Bk
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2720
  = (R, start_of ly as + 2*n + 16)"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2721
apply(subgoal_tac "2*n + 13 = Suc (2*n + 12)", simp only: fetch.simps)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2722
apply(auto simp: ci.simps findnth.simps fetch.simps
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2723
                  nth_of.simps shift.simps nth_append tdec_b_def length_findnth sete.simps)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2724
done
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2725
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2726
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2727
lemma [simp]: 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2728
  "fetch (ci (ly) 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2729
  (start_of ly as) (Dec n e)) (14 + 2 * n) Oc
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2730
  = (L, start_of ly as + 2*n + 13)"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2731
apply(subgoal_tac "14 + 2*n = Suc (2*n + 13)", simp only: fetch.simps)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2732
apply(auto simp: ci.simps findnth.simps fetch.simps
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2733
                  nth_of.simps shift.simps nth_append tdec_b_def length_findnth sete.simps)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2734
done
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2735
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2736
lemma [simp]: 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2737
  "fetch (ci (ly) 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2738
  (start_of ly as) (Dec n e)) (14 + 2 * n) Bk
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2739
  = (L, start_of ly as + 2*n + 14)"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2740
apply(subgoal_tac "14 + 2*n = Suc (2*n + 13)", simp only: fetch.simps)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2741
apply(auto simp: ci.simps findnth.simps fetch.simps
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2742
                  nth_of.simps shift.simps nth_append tdec_b_def length_findnth sete.simps)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2743
done
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2744
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2745
lemma [simp]: 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2746
  "fetch (ci (ly) 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2747
  (start_of ly as) (Dec n e)) (15 + 2 * n)  Oc
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2748
  = (L, start_of ly as + 2*n + 13)"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2749
apply(subgoal_tac "15 + 2*n = Suc (2*n + 14)", simp only: fetch.simps)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2750
apply(auto simp: ci.simps findnth.simps fetch.simps
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2751
                  nth_of.simps shift.simps nth_append tdec_b_def length_findnth sete.simps)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2752
done
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2753
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2754
lemma [simp]: 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2755
  "fetch (ci (ly) 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2756
  (start_of ly as) (Dec n e)) (15 + 2 * n)  Bk
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2757
 = (R, start_of ly as + 2*n + 15)"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2758
apply(subgoal_tac "15 + 2*n = Suc (2*n + 14)", simp only: fetch.simps)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2759
apply(auto simp: ci.simps findnth.simps fetch.simps
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2760
                  nth_of.simps shift.simps nth_append tdec_b_def length_findnth sete.simps)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2761
done
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2762
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2763
lemma [simp]: 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2764
  "abc_fetch as aprog = Some (Dec n e) \<Longrightarrow> 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2765
     fetch (ci (ly) (start_of (ly) as) 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2766
              (Dec n e)) (16 + 2 * n)  Bk
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2767
 = (R, start_of (ly) e)"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2768
apply(subgoal_tac "16 + 2*n = Suc (2*n + 15)", simp only: fetch.simps)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2769
apply(auto simp: ci.simps findnth.simps fetch.simps
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2770
                  nth_of.simps shift.simps nth_append tdec_b_def length_findnth sete.simps)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2771
done
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2772
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2773
declare dec_inv_1.simps[simp del]
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2774
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2775
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2776
lemma [simp]: 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2777
 "\<lbrakk>abc_fetch as aprog = Some (Dec n e); ly = layout_of aprog\<rbrakk>
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2778
   \<Longrightarrow> (start_of ly e \<noteq> Suc (start_of ly as + 2 * n) \<and>
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2779
        start_of ly e \<noteq> Suc (Suc (start_of ly as + 2 * n)) \<and>  
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2780
        start_of ly e \<noteq> start_of ly as + 2 * n + 3 \<and> 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2781
        start_of ly e \<noteq> start_of ly as + 2 * n + 4 \<and>
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2782
        start_of ly e \<noteq> start_of ly as + 2 * n + 5 \<and> 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2783
        start_of ly e \<noteq> start_of ly as + 2 * n + 6 \<and> 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2784
        start_of ly e \<noteq> start_of ly as + 2 * n + 7 \<and>
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2785
        start_of ly e \<noteq> start_of ly as + 2 * n + 8 \<and> 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2786
        start_of ly e \<noteq> start_of ly as + 2 * n + 9 \<and> 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2787
        start_of ly e \<noteq> start_of ly as + 2 * n + 10 \<and>
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2788
        start_of ly e \<noteq> start_of ly as + 2 * n + 11 \<and> 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2789
        start_of ly e \<noteq> start_of ly as + 2 * n + 12 \<and> 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2790
        start_of ly e \<noteq> start_of ly as + 2 * n + 13 \<and>
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2791
        start_of ly e \<noteq> start_of ly as + 2 * n + 14 \<and> 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2792
        start_of ly e \<noteq> start_of ly as + 2 * n + 15)"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2793
using start_of_ge[of as aprog n e ly] start_of_less[of e as ly]
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2794
apply(case_tac "e < as", simp)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2795
apply(case_tac "e = as", simp, simp)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2796
done
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2797
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2798
lemma [simp]: "\<lbrakk>abc_fetch as aprog = Some (Dec n e); ly = layout_of aprog\<rbrakk>
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2799
      \<Longrightarrow> (Suc (start_of ly as + 2 * n) \<noteq> start_of ly e \<and>
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2800
          Suc (Suc (start_of ly as + 2 * n)) \<noteq> start_of ly e \<and> 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2801
          start_of ly as + 2 * n + 3 \<noteq> start_of ly e \<and> 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2802
          start_of ly as + 2 * n + 4 \<noteq> start_of ly e \<and>
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2803
          start_of ly as + 2 * n + 5 \<noteq>start_of ly e \<and> 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2804
          start_of ly as + 2 * n + 6 \<noteq> start_of ly e \<and>
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2805
          start_of ly as + 2 * n + 7 \<noteq> start_of ly e \<and> 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2806
          start_of ly as + 2 * n + 8 \<noteq> start_of ly e \<and> 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2807
          start_of ly as + 2 * n + 9 \<noteq> start_of ly e \<and> 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2808
          start_of ly as + 2 * n + 10 \<noteq> start_of ly e \<and>
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2809
          start_of ly as + 2 * n + 11 \<noteq> start_of ly e \<and> 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2810
          start_of ly as + 2 * n + 12 \<noteq> start_of ly e \<and> 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2811
          start_of ly as + 2 * n + 13 \<noteq> start_of ly e \<and> 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2812
          start_of ly as + 2 * n + 14 \<noteq> start_of ly e \<and> 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2813
          start_of ly as + 2 * n + 15 \<noteq> start_of ly e)"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2814
using start_of_ge[of as aprog n e ly] start_of_less[of e as ly]
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2815
apply(case_tac "e < as", simp, simp)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2816
apply(case_tac "e = as", simp, simp)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2817
done
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2818
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2819
lemma [simp]: "inv_locate_b (as, lm) (n, [], []) ires = False"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2820
apply(auto simp: inv_locate_b.simps in_middle.simps split: if_splits)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2821
done
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2822
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2823
lemma [simp]: "inv_locate_b (as, lm) (n, [], Bk # list) ires = False"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2824
apply(auto simp: inv_locate_b.simps in_middle.simps split: if_splits)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2825
done
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2826
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2827
(*
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2828
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2829
lemma  inv_locate_b_2_on_left_moving_b[simp]: 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2830
   "inv_locate_b (as, am) (n, l, []) ires
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2831
     \<Longrightarrow> inv_on_left_moving (as, 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2832
                  abc_lm_s am n (abc_lm_v am n)) (s, [], [Bk]) ires"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2833
apply(auto simp: inv_locate_b.simps inv_on_left_moving.simps inv_on_left_moving_in_middle_B.simps
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2834
                 in_middle.simps split: if_splits)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2835
apply(drule_tac length_equal, simp)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2836
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2837
apply(insert inv_locate_b_2_on_left_moving[of as am n l "[]" ires s])
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2838
apply(simp only: inv_on_left_moving.simps, simp)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2839
apply(subgoal_tac "\<not> inv_on_left_moving_in_middle_B 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2840
         (as, abc_lm_s am n (abc_lm_v am n)) (s, tl l, [hd l]) ires", simp)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2841
*)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2842
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2843
(*
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2844
lemma [simp]:
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2845
  "inv_locate_b (as, am) (n, l, []) ires; l \<noteq> []\<rbrakk>
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2846
 \<Longrightarrow> inv_on_left_moving (as, abc_lm_s am n 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2847
                  (abc_lm_v am n)) (s, tl l, [hd l]) ires"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2848
apply(auto simp: inv_locate_b.simps inv_on_left_moving.simps inv_on_left_moving_in_middle_B.simps
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2849
                 in_middle.simps split: if_splits)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2850
apply(drule_tac length_equal, simp)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2851
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2852
apply(insert inv_locate_b_2_on_left_moving[of as am n l "[]" ires s])
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2853
apply(simp only: inv_on_left_moving.simps, simp)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2854
apply(subgoal_tac "\<not> inv_on_left_moving_in_middle_B 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2855
         (as, abc_lm_s am n (abc_lm_v am n)) (s, tl l, [hd l]) ires", simp)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2856
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2857
apply(insert inv_locate_b_2_on_left_moving[of as am n l "[]" ires s])
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2858
apply(simp only: inv_on_left_moving.simps, simp)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2859
apply(subgoal_tac "\<not> inv_on_left_moving_in_middle_B 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2860
         (as, abc_lm_s am n (abc_lm_v am n)) (s, tl l, [hd l]) ires", simp)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2861
apply(simp only: inv_on_left_moving_norm.simps)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2862
apply(erule_tac exE)+
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2863
apply(erule_tac conjE)+
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2864
apply(rule_tac x = lm1 in exI, rule_tac x = lm2 in exI, 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2865
      rule_tac x = m in exI, rule_tac x = ml in exI, 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2866
      rule_tac x = mr in exI, simp)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2867
apply(case_tac mr, simp, simp, case_tac nat, auto intro: nil_2_nil)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2868
done
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2869
*)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2870
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2871
lemma [simp]: 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2872
 "\<lbrakk>dec_first_on_right_moving n (as, am) (s, aaa, Oc # xs) ires\<rbrakk>
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2873
   \<Longrightarrow> dec_first_on_right_moving n (as, am) (s', Oc # aaa, xs) ires"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2874
apply(simp only: dec_first_on_right_moving.simps)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2875
apply(erule exE)+
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2876
apply(rule_tac x = lm1 in exI, rule_tac x = lm2 in exI, 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2877
      rule_tac x = m in exI, simp)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2878
apply(rule_tac x = "Suc ml" in exI, 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2879
      rule_tac x = "mr - 1" in exI, auto)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2880
apply(case_tac [!] mr, auto)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2881
done
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2882
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2883
lemma [simp]: 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2884
  "dec_first_on_right_moving n (as, am) (s, l, Bk # xs) ires \<Longrightarrow> l \<noteq> []"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2885
apply(auto simp: dec_first_on_right_moving.simps split: if_splits)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2886
done
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2887
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2888
lemma [elim]: 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2889
  "\<lbrakk>\<not> length lm1 < length am; 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2890
    am @ replicate (length lm1 - length am) 0 @ [0::nat] = 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2891
                                                lm1 @ m # lm2;
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2892
    0 < m\<rbrakk>
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2893
   \<Longrightarrow> RR"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2894
apply(subgoal_tac "lm2 = []", simp)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2895
apply(drule_tac length_equal, simp)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2896
done
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2897
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2898
lemma [simp]: 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2899
 "\<lbrakk>dec_first_on_right_moving n (as, 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2900
                   abc_lm_s am n (abc_lm_v am n)) (s, l, Bk # xs) ires\<rbrakk>
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2901
\<Longrightarrow> dec_after_clear (as, abc_lm_s am n 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2902
                 (abc_lm_v am n - Suc 0)) (s', tl l, hd l # Bk # xs) ires"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2903
apply(simp only: dec_first_on_right_moving.simps 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2904
                 dec_after_clear.simps abc_lm_s.simps abc_lm_v.simps)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2905
apply(erule_tac exE)+
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2906
apply(case_tac "n < length am")
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2907
apply(rule_tac x = lm1 in exI, rule_tac x = lm2 in exI, 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2908
      rule_tac x = "m - 1" in exI, auto simp: )
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2909
apply(case_tac [!] mr, auto)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2910
done
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2911
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2912
lemma [simp]: 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2913
 "\<lbrakk>dec_first_on_right_moving n (as, 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2914
                   abc_lm_s am n (abc_lm_v am n)) (s, l, []) ires\<rbrakk>
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2915
\<Longrightarrow> (l = [] \<longrightarrow> dec_after_clear (as, 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2916
             abc_lm_s am n (abc_lm_v am n - Suc 0)) (s', [], [Bk]) ires) \<and>
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2917
    (l \<noteq> [] \<longrightarrow> dec_after_clear (as, abc_lm_s am n 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2918
                      (abc_lm_v am n - Suc 0)) (s', tl l, [hd l]) ires)"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2919
apply(subgoal_tac "l \<noteq> []", 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2920
      simp only: dec_first_on_right_moving.simps 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2921
                 dec_after_clear.simps abc_lm_s.simps abc_lm_v.simps)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2922
apply(erule_tac exE)+
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2923
apply(case_tac "n < length am", simp)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2924
apply(rule_tac x = lm1 in exI, rule_tac x = "m - 1" in exI, auto)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2925
apply(case_tac [1-2] m, auto)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2926
apply(auto simp: dec_first_on_right_moving.simps split: if_splits)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2927
done
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2928
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2929
lemma [simp]: "\<lbrakk>dec_after_clear (as, am) (s, l, Oc # r) ires\<rbrakk>
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2930
                \<Longrightarrow> dec_after_clear (as, am) (s', l, Bk # r) ires"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2931
apply(auto simp: dec_after_clear.simps)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2932
done
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2933
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2934
lemma [simp]: "\<lbrakk>dec_after_clear (as, am) (s, l, Bk # r) ires\<rbrakk>
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2935
                \<Longrightarrow> dec_right_move (as, am) (s', Bk # l, r) ires"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2936
apply(auto simp: dec_after_clear.simps dec_right_move.simps split: if_splits)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2937
done
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2938
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2939
lemma [simp]: "\<lbrakk>dec_after_clear (as, am) (s, l, []) ires\<rbrakk>
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2940
             \<Longrightarrow> dec_right_move (as, am) (s', Bk # l, []) ires"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2941
apply(auto simp: dec_after_clear.simps dec_right_move.simps )
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2942
done
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2943
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2944
lemma [simp]: "\<lbrakk>dec_after_clear (as, am) (s, l, []) ires\<rbrakk>
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2945
             \<Longrightarrow> dec_right_move (as, am) (s', Bk # l, [Bk]) ires"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2946
apply(auto simp: dec_after_clear.simps dec_right_move.simps split: if_splits)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2947
done
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2948
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2949
lemma [simp]:"dec_right_move (as, am) (s, l, Oc # r) ires = False"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2950
apply(auto simp: dec_right_move.simps)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2951
done
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2952
              
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2953
lemma dec_right_move_2_check_right_move[simp]:
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2954
     "\<lbrakk>dec_right_move (as, am) (s, l, Bk # r) ires\<rbrakk>
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2955
      \<Longrightarrow> dec_check_right_move (as, am) (s', Bk # l, r) ires"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2956
apply(auto simp: dec_right_move.simps dec_check_right_move.simps split: if_splits)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2957
done
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2958
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2959
lemma [simp]: "(<lm::nat list> = []) = (lm = [])"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2960
apply(case_tac lm, simp_all add: tape_of_nl_cons)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2961
done
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2962
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2963
lemma [simp]: 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2964
 "dec_right_move (as, am) (s, l, []) ires= 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2965
  dec_right_move (as, am) (s, l, [Bk]) ires"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2966
apply(simp add: dec_right_move.simps)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2967
done
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2968
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2969
lemma [simp]: "\<lbrakk>dec_right_move (as, am) (s, l, []) ires\<rbrakk>
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2970
             \<Longrightarrow> dec_check_right_move (as, am) (s, Bk # l, []) ires"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2971
apply(insert dec_right_move_2_check_right_move[of as am s l "[]" s'], 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2972
      simp)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2973
done
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2974
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2975
lemma [simp]: "dec_check_right_move (as, am) (s, l, r) ires\<Longrightarrow> l \<noteq> []"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2976
apply(auto simp: dec_check_right_move.simps split: if_splits)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2977
done
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2978
 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2979
lemma [simp]: "\<lbrakk>dec_check_right_move (as, am) (s, l, Oc # r) ires\<rbrakk>
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2980
             \<Longrightarrow> dec_after_write (as, am) (s', tl l, hd l # Oc # r) ires"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2981
apply(auto simp: dec_check_right_move.simps dec_after_write.simps)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2982
apply(rule_tac x = lm1 in exI, rule_tac x = lm2 in exI, 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2983
      rule_tac x = m in exI, auto)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2984
done
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2985
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2986
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2987
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2988
lemma [simp]: "\<lbrakk>dec_check_right_move (as, am) (s, l, Bk # r) ires\<rbrakk>
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2989
                \<Longrightarrow> dec_left_move (as, am) (s', tl l, hd l # Bk # r) ires"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2990
apply(auto simp: dec_check_right_move.simps 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2991
                 dec_left_move.simps inv_after_move.simps)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2992
apply(rule_tac x = lm1 in exI, rule_tac x = m in exI, auto split: if_splits)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2993
apply(case_tac [!] lm2, simp_all add: tape_of_nl_cons split: if_splits)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2994
apply(rule_tac [!] x = "(Suc rn)" in exI, simp_all)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2995
done
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2996
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2997
lemma [simp]: "\<lbrakk>dec_check_right_move (as, am) (s, l, []) ires\<rbrakk>
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2998
             \<Longrightarrow> dec_left_move (as, am) (s', tl l, [hd l]) ires"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  2999
apply(auto simp: dec_check_right_move.simps 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3000
                 dec_left_move.simps inv_after_move.simps)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3001
apply(rule_tac x = lm1 in exI, rule_tac x = m in exI, auto)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3002
done
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3003
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3004
lemma [simp]: "dec_left_move (as, am) (s, aaa, Oc # xs) ires = False"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3005
apply(auto simp: dec_left_move.simps inv_after_move.simps)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3006
done
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3007
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3008
lemma [simp]: "dec_left_move (as, am) (s, l, r) ires
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3009
             \<Longrightarrow> l \<noteq> []"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3010
apply(auto simp: dec_left_move.simps split: if_splits)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3011
done
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3012
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3013
lemma [simp]: "inv_on_left_moving_in_middle_B (as, [m])
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3014
  (s', Oc # Oc\<up>m @ Bk # Bk # ires, Bk # Bk\<up>rn) ires"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3015
apply(simp add: inv_on_left_moving_in_middle_B.simps)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3016
apply(rule_tac x = "[m]" in exI, auto)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3017
done
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3018
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3019
lemma [simp]: "inv_on_left_moving_in_middle_B (as, [m])
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3020
  (s', Oc # Oc\<up>m @ Bk # Bk # ires, [Bk]) ires"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3021
apply(simp add: inv_on_left_moving_in_middle_B.simps)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3022
done
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3023
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3024
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3025
lemma [simp]: "lm1 \<noteq> [] \<Longrightarrow> 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3026
  inv_on_left_moving_in_middle_B (as, lm1 @ [m]) (s', 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3027
  Oc # Oc\<up>m @ Bk # <rev lm1> @ Bk # Bk # ires, Bk # Bk\<up>rn) ires"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3028
apply(simp only: inv_on_left_moving_in_middle_B.simps)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3029
apply(rule_tac x = "lm1 @ [m ]" in exI, rule_tac x = "[]" in exI, simp)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3030
apply(simp add: tape_of_nl_cons split: if_splits)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3031
done
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3032
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3033
lemma [simp]: "lm1 \<noteq> [] \<Longrightarrow> 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3034
  inv_on_left_moving_in_middle_B (as, lm1 @ [m]) (s', 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3035
  Oc # Oc\<up> m @ Bk # <rev lm1> @ Bk # Bk # ires, [Bk]) ires"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3036
apply(simp only: inv_on_left_moving_in_middle_B.simps)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3037
apply(rule_tac x = "lm1 @ [m ]" in exI, rule_tac x = "[]" in exI, simp)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3038
apply(simp add: tape_of_nl_cons split: if_splits)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3039
done
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3040
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3041
lemma [simp]: "dec_left_move (as, am) (s, l, Bk # r) ires
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3042
       \<Longrightarrow> inv_on_left_moving (as, am) (s', tl l, hd l # Bk # r) ires"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3043
apply(auto simp: dec_left_move.simps inv_on_left_moving.simps split: if_splits)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3044
done
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3045
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3046
(*
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3047
lemma [simp]: "inv_on_left_moving_in_middle_B (as, lm1 @ [m]) 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3048
                        (s', Oc # Oc\<^bsup>m\<^esup> @ Bk # <rev lm1> @ Bk\<^bsup>ln\<^esup>, [Bk])  ires"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3049
apply(auto simp: inv_on_left_moving_in_middle_B.simps)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3050
apply(rule_tac x = "lm1 @ [m]" in exI, rule_tac x = "[]" in exI, auto)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3051
done
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3052
*)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3053
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3054
lemma [simp]: "dec_left_move (as, am) (s, l, []) ires
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3055
             \<Longrightarrow> inv_on_left_moving (as, am) (s', tl l, [hd l]) ires"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3056
apply(auto simp: dec_left_move.simps inv_on_left_moving.simps split: if_splits)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3057
done
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3058
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3059
lemma [simp]: "dec_after_write (as, am) (s, l, Oc # r) ires
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3060
       \<Longrightarrow> dec_on_right_moving (as, am) (s', Oc # l, r) ires"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3061
apply(auto simp: dec_after_write.simps dec_on_right_moving.simps)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3062
apply(rule_tac x = "lm1 @ [m]" in exI, rule_tac x = "tl lm2" in exI, 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3063
      rule_tac x = "hd lm2" in exI, simp)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3064
apply(rule_tac x = "Suc 0" in exI,rule_tac x =  "Suc (hd lm2)" in exI)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3065
apply(case_tac lm2, auto split: if_splits simp: tape_of_nl_cons)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3066
done
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3067
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3068
lemma [simp]: "dec_after_write (as, am) (s, l, Bk # r) ires
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3069
       \<Longrightarrow> dec_after_write (as, am) (s', l, Oc # r) ires"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3070
apply(auto simp: dec_after_write.simps)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3071
done
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3072
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3073
lemma [simp]: "dec_after_write (as, am) (s, aaa, []) ires
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3074
             \<Longrightarrow> dec_after_write (as, am) (s', aaa, [Oc]) ires"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3075
apply(auto simp: dec_after_write.simps)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3076
done
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3077
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3078
lemma [simp]: "dec_on_right_moving (as, am) (s, l, Oc # r) ires
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3079
       \<Longrightarrow> dec_on_right_moving (as, am) (s', Oc # l, r) ires"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3080
apply(simp only: dec_on_right_moving.simps)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3081
apply(erule_tac exE)+
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3082
apply(erule conjE)+
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3083
apply(rule_tac x = lm1 in exI, rule_tac x = lm2 in exI,
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3084
      rule_tac x = "m" in exI, rule_tac x = "Suc ml" in exI, 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3085
      rule_tac x = "mr - 1" in exI, simp)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3086
apply(case_tac mr, auto)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3087
done
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3088
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3089
lemma [simp]: "dec_on_right_moving (as, am) (s, l, r) ires\<Longrightarrow>  l \<noteq> []"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3090
apply(auto simp: dec_on_right_moving.simps split: if_splits)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3091
done
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3092
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3093
lemma [simp]: "dec_on_right_moving (as, am) (s, l, Bk # r) ires
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3094
      \<Longrightarrow>  dec_after_clear (as, am) (s', tl l, hd l # Bk # r) ires"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3095
apply(auto simp: dec_on_right_moving.simps dec_after_clear.simps)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3096
apply(case_tac [!] mr, auto split: if_splits)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3097
done
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3098
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3099
lemma [simp]: "dec_on_right_moving (as, am) (s, l, []) ires
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3100
             \<Longrightarrow> dec_after_clear (as, am) (s', tl l, [hd l]) ires"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3101
apply(auto simp: dec_on_right_moving.simps dec_after_clear.simps)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3102
apply(simp_all split: if_splits)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3103
apply(rule_tac x = lm1 in exI, simp)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3104
done
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3105
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3106
lemma [simp]: 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3107
 "inv_stop (as, abc_lm_s am n (abc_lm_v am n)) (s, l, r) ires \<Longrightarrow> l \<noteq> []"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3108
apply(auto simp: inv_stop.simps)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3109
done
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3110
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3111
lemma dec_false_1[simp]:
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3112
 "\<lbrakk>abc_lm_v am n = 0; inv_locate_b (as, am) (n, aaa, Oc # xs) ires\<rbrakk>
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3113
  \<Longrightarrow> False"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3114
apply(auto simp: inv_locate_b.simps in_middle.simps)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3115
apply(case_tac "length lm1 \<ge> length am", auto)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3116
apply(subgoal_tac "lm2 = []", simp, subgoal_tac "m = 0", simp)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3117
apply(case_tac mr, auto simp: )
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3118
apply(subgoal_tac "Suc (length lm1) - length am = 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3119
                   Suc (length lm1 - length am)", 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3120
      simp add: exp_ind del: replicate.simps, simp)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3121
apply(drule_tac xs = "am @ replicate (Suc (length lm1) - length am) 0"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3122
                and ys = "lm1 @ m # lm2" in length_equal, simp)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3123
apply(case_tac mr, auto simp: abc_lm_v.simps)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3124
apply(case_tac "mr = 0", simp_all split: if_splits)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3125
apply(subgoal_tac "Suc (length lm1) - length am = 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3126
                       Suc (length lm1 - length am)", 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3127
      simp add: exp_ind del: replicate.simps, simp)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3128
done
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3129
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3130
lemma [simp]: 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3131
 "\<lbrakk>inv_locate_b (as, am) (n, aaa, Bk # xs) ires; 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3132
   abc_lm_v am n = 0\<rbrakk>
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3133
   \<Longrightarrow> inv_on_left_moving (as, abc_lm_s am n 0) 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3134
                         (s, tl aaa, hd aaa # Bk # xs) ires"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3135
apply(simp add: inv_on_left_moving.simps)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3136
apply(simp only: inv_locate_b.simps in_middle.simps) 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3137
apply(erule_tac exE)+
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3138
apply(simp add: inv_on_left_moving.simps)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3139
apply(subgoal_tac "\<not> inv_on_left_moving_in_middle_B 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3140
         (as, abc_lm_s am n 0) (s, tl aaa, hd aaa # Bk # xs) ires", simp)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3141
apply(simp only: inv_on_left_moving_norm.simps)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3142
apply(erule_tac conjE)+
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3143
apply(rule_tac x = lm1 in exI, rule_tac x = lm2 in exI, 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3144
      rule_tac x =  m in exI, rule_tac x = m in exI, 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3145
      rule_tac x = "Suc 0" in exI, simp add: abc_lm_s.simps)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3146
apply(case_tac mr, simp_all, auto simp: abc_lm_v.simps)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3147
apply(simp only: exp_ind[THEN sym] replicate_Suc Nat.Suc_diff_le)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3148
apply(auto simp: inv_on_left_moving_in_middle_B.simps split: if_splits)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3149
done
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3150
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3151
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3152
lemma [simp]:
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3153
 "\<lbrakk>abc_lm_v am n = 0; inv_locate_b (as, am) (n, aaa, []) ires\<rbrakk>
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3154
   \<Longrightarrow> inv_on_left_moving (as, abc_lm_s am n 0) (s, tl aaa, [hd aaa]) ires"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3155
apply(simp add: inv_on_left_moving.simps)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3156
apply(simp only: inv_locate_b.simps in_middle.simps) 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3157
apply(erule_tac exE)+
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3158
apply(simp add: inv_on_left_moving.simps)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3159
apply(subgoal_tac "\<not> inv_on_left_moving_in_middle_B 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3160
         (as, abc_lm_s am n 0) (s, tl aaa, [hd aaa]) ires", simp)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3161
apply(simp only: inv_on_left_moving_norm.simps)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3162
apply(erule_tac conjE)+
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3163
apply(rule_tac x = lm1 in exI, rule_tac x = lm2 in exI, 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3164
      rule_tac x =  m in exI, rule_tac x = m in exI, 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3165
      rule_tac x = "Suc 0" in exI, simp add: abc_lm_s.simps)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3166
apply(case_tac mr, simp_all, auto simp: abc_lm_v.simps)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3167
apply(simp_all only: exp_ind Nat.Suc_diff_le del: replicate_Suc, simp_all)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3168
apply(auto simp: inv_on_left_moving_in_middle_B.simps split: if_splits)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3169
apply(case_tac [!] m, simp_all)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3170
done
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3171
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3172
lemma [simp]: "\<lbrakk>am ! n = (0::nat); n < length am\<rbrakk> \<Longrightarrow> am[n := 0] = am"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3173
apply(simp add: list_update_same_conv)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3174
done
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3175
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3176
lemma  [intro]: "\<lbrakk>abc_lm_v (a # list) 0 = 0\<rbrakk> \<Longrightarrow> a = 0"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3177
apply(simp add: abc_lm_v.simps split: if_splits)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3178
done
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3179
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3180
lemma [simp]: 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3181
 "inv_stop (as, abc_lm_s am n 0) 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3182
          (start_of (layout_of aprog) e, aaa, Oc # xs) ires
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3183
  \<Longrightarrow> inv_locate_a (as, abc_lm_s am n 0) (0, aaa, Oc # xs) ires"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3184
apply(simp add: inv_locate_a.simps)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3185
apply(rule disjI1)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3186
apply(auto simp: inv_stop.simps at_begin_norm.simps)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3187
done
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3188
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3189
lemma [simp]: 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3190
 "\<lbrakk>inv_stop (as, abc_lm_s am n 0) 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3191
          (start_of (layout_of aprog) e, aaa, Oc # xs) ires\<rbrakk>
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3192
  \<Longrightarrow> inv_locate_b (as, am) (0, Oc # aaa, xs) ires \<or> 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3193
      inv_locate_b (as, abc_lm_s am n 0) (0, Oc # aaa, xs) ires"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3194
apply(simp)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3195
done
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3196
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3197
lemma dec_false2: 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3198
 "inv_stop (as, abc_lm_s am n 0) 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3199
  (start_of (layout_of aprog) e, aaa, Bk # xs) ires = False"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3200
apply(auto simp: inv_stop.simps abc_lm_s.simps)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3201
apply(case_tac [!] am, auto)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3202
apply(case_tac [!] n, auto simp: tape_of_nl_cons split: if_splits)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3203
done
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3204
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3205
lemma dec_false3:
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3206
   "inv_stop (as, abc_lm_s am n 0) 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3207
              (start_of (layout_of aprog) e, aaa, []) ires = False"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3208
apply(auto simp: inv_stop.simps abc_lm_s.simps)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3209
done
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3210
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3211
lemma [simp]:
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3212
  "fetch (ci (layout_of aprog) 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3213
       (start_of (layout_of aprog) as) (Dec n e)) 0 b = (Nop, 0)"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3214
by(simp add: fetch.simps)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3215
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3216
declare dec_inv_1.simps[simp del]
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3217
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3218
declare inv_locate_n_b.simps [simp del]
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3219
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3220
lemma [simp]:
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3221
  "\<lbrakk>0 < abc_lm_v am n; 0 < n; 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3222
    at_begin_fst_bwtn (as, am) (n, aaa, Oc # xs) ires\<rbrakk>
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3223
 \<Longrightarrow> inv_locate_n_b (as, am) (n, Oc # aaa, xs) ires"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3224
apply(simp add: at_begin_fst_bwtn.simps inv_locate_n_b.simps )
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3225
done
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3226
 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3227
lemma Suc_minus:"length am + tn = n
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3228
       \<Longrightarrow> Suc tn = Suc n - length am "
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3229
apply(arith)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3230
done
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3231
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3232
lemma [simp]: 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3233
 "\<lbrakk>0 < abc_lm_v am n; 0 < n; 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3234
   at_begin_fst_awtn (as, am) (n, aaa, Oc # xs) ires\<rbrakk>
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3235
 \<Longrightarrow> inv_locate_n_b (as, am) (n, Oc # aaa, xs) ires"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3236
apply(simp only: at_begin_fst_awtn.simps inv_locate_n_b.simps )
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3237
apply(erule exE)+
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3238
apply(erule conjE)+
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3239
apply(rule_tac x = lm1 in exI, rule_tac x = "[]" in exI, 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3240
      rule_tac x = "Suc tn" in exI, rule_tac x = 0 in exI)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3241
apply(simp add: exp_ind del: replicate.simps)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3242
apply(rule conjI)+
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3243
apply(auto)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3244
done
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3245
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3246
lemma [simp]:
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3247
 "\<lbrakk>inv_locate_n_b (as, am) (n, aaa, Oc # xs) ires\<rbrakk>
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3248
 \<Longrightarrow> dec_first_on_right_moving n (as, abc_lm_s am n (abc_lm_v am n))  
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3249
                                      (s, Oc # aaa, xs) ires"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3250
apply(auto simp: inv_locate_n_b.simps dec_first_on_right_moving.simps 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3251
                 abc_lm_s.simps abc_lm_v.simps)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3252
apply(rule_tac x = lm1 in exI, rule_tac x = lm2 in exI, 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3253
      rule_tac x = m in exI, simp)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3254
apply(rule_tac x = "Suc (Suc 0)" in exI, 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3255
      rule_tac x = "m - 1" in exI, simp)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3256
apply(case_tac m, auto)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3257
apply(rule_tac x = lm1 in exI, rule_tac x = lm2 in exI, 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3258
      rule_tac x = m in exI, 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3259
      simp add: Suc_diff_le exp_ind del: replicate.simps)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3260
apply(rule_tac x = "Suc (Suc 0)" in exI, 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3261
      rule_tac x = "m - 1" in exI, simp)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3262
apply(case_tac m, auto)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3263
apply(rule_tac x = lm1 in exI, rule_tac x = "[]" in exI, 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3264
      rule_tac x = m in exI, simp)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3265
apply(rule_tac x = "Suc (Suc 0)" in exI, 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3266
      rule_tac x = "m - 1" in exI, simp)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3267
apply(case_tac m, auto)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3268
apply(rule_tac x = lm1 in exI, rule_tac x = lm2 in exI, 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3269
      rule_tac x = m in exI, 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3270
      simp add: Suc_diff_le exp_ind del: replicate.simps, simp)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3271
done
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3272
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3273
lemma [simp]: "inv_on_left_moving (as, am) (s, [], r) ires 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3274
  = False"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3275
apply(simp add: inv_on_left_moving.simps inv_on_left_moving_norm.simps
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3276
                inv_on_left_moving_in_middle_B.simps)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3277
done
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3278
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3279
lemma [simp]: 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3280
  "inv_check_left_moving (as, abc_lm_s am n 0)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3281
  (start_of (layout_of aprog) as + 2 * n + 14, [], Oc # xs) ires
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3282
 = False"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3283
apply(simp add: inv_check_left_moving.simps inv_check_left_moving_in_middle.simps)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3284
done
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3285
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3286
lemma [simp]: "inv_check_left_moving (as, abc_lm_s lm n (abc_lm_v lm n)) (s, [], Oc # list) ires = False"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3287
apply(simp add: inv_check_left_moving.simps inv_check_left_moving_in_middle.simps)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3288
done
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3289
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3290
lemma [elim]: "\<lbrakk>abc_fetch as ap = Some (Dec n e);
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3291
                start_of (layout_of ap) as < start_of (layout_of ap) e; 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3292
                start_of (layout_of ap) e \<le> Suc (start_of (layout_of ap) as + 2 * n)\<rbrakk>
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3293
       \<Longrightarrow> RR"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3294
  using start_of_less[of e as "layout_of ap"] start_of_ge[of as ap n e "layout_of ap"]
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3295
apply(case_tac "as < e", simp)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3296
apply(case_tac "as = e", simp, simp)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3297
done
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3298
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3299
lemma crsp_step_dec_b_e_pre':
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3300
  assumes layout: "ly = layout_of ap"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3301
  and inv_start: "inv_locate_b (as, lm) (n, la, ra) ires"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3302
  and fetch: "abc_fetch as ap = Some (Dec n e)"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3303
  and dec_0: "abc_lm_v lm n = 0"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3304
  and f: "f = (\<lambda> stp. (steps (Suc (start_of ly as) + 2 * n, la, ra) (ci ly (start_of ly as) (Dec n e), 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3305
            start_of ly as - Suc 0) stp, start_of ly as, n))"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3306
  and P: "P = (\<lambda> ((s, l, r), ss, x). s = start_of ly e)"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3307
  and Q: "Q = (\<lambda> ((s, l, r), ss, x). dec_inv_1 ly x e (as, lm) (s, l, r) ires)"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3308
  shows "\<exists> stp. P (f stp) \<and> Q (f stp)"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3309
proof(rule_tac LE = abc_dec_1_LE in halt_lemma2)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3310
  show "wf abc_dec_1_LE" by(intro wf_dec_le)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3311
next
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3312
  show "Q (f 0)"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3313
    using layout fetch
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3314
    apply(simp add: f steps.simps Q dec_inv_1.simps)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3315
    apply(subgoal_tac "e > as \<or> e = as \<or> e < as")
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3316
    apply(auto simp: Let_def start_of_ge start_of_less inv_start)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3317
    done
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3318
next
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3319
  show "\<not> P (f 0)"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3320
    using layout fetch
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3321
    apply(simp add: f steps.simps P)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3322
    done
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3323
next
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3324
  show "\<forall>n. \<not> P (f n) \<and> Q (f n) \<longrightarrow> Q (f (Suc n)) \<and> (f (Suc n), f n) \<in> abc_dec_1_LE"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3325
    using fetch
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3326
  proof(rule_tac allI, rule_tac impI)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3327
    fix na
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3328
    assume "\<not> P (f na) \<and> Q (f na)"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3329
    thus "Q (f (Suc na)) \<and> (f (Suc na), f na) \<in> abc_dec_1_LE"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3330
      apply(simp add: f)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3331
      apply(case_tac "steps (Suc (start_of ly as + 2 * n), la, ra)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3332
        (ci ly (start_of ly as) (Dec n e), start_of ly as - Suc 0) na", simp)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3333
    proof -
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3334
      fix a b c 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3335
      assume "\<not> P ((a, b, c), start_of ly as, n) \<and> Q ((a, b, c), start_of ly as, n)"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3336
      thus "Q (step (a, b, c) (ci ly (start_of ly as) (Dec n e), start_of ly as - Suc 0), start_of ly as, n) \<and>
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3337
               ((step (a, b, c) (ci ly (start_of ly as) (Dec n e), start_of ly as - Suc 0), start_of ly as, n), 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3338
                   (a, b, c), start_of ly as, n) \<in> abc_dec_1_LE"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3339
        apply(simp add: Q)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3340
        apply(case_tac c, case_tac [2] aa)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3341
        apply(simp_all add: dec_inv_1.simps Let_def split: if_splits)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3342
        using fetch layout dec_0
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3343
        apply(auto simp: step.simps P dec_inv_1.simps Let_def abc_dec_1_LE_def lex_triple_def lex_pair_def)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3344
        using dec_0
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3345
        apply(drule_tac dec_false_1, simp_all)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3346
        done
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3347
    qed
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3348
  qed
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3349
qed
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3350
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3351
lemma crsp_step_dec_b_e_pre:
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3352
  assumes "ly = layout_of ap"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3353
  and inv_start: "inv_locate_b (as, lm) (n, la, ra) ires"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3354
  and dec_0: "abc_lm_v lm n  = 0"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3355
  and fetch: "abc_fetch as ap = Some (Dec n e)"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3356
  shows "\<exists>stp lb rb.
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3357
       steps (Suc (start_of ly as) + 2 * n, la, ra) (ci ly (start_of ly as) (Dec n e), 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3358
       start_of ly as - Suc 0) stp = (start_of ly e, lb, rb) \<and>
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3359
       dec_inv_1 ly n e (as, lm) (start_of ly e, lb, rb) ires"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3360
  using assms
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3361
  apply(drule_tac crsp_step_dec_b_e_pre', auto)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3362
  apply(rule_tac x = stp in exI, simp)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3363
  done
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3364
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3365
lemma [simp]:
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3366
  "\<lbrakk>abc_lm_v lm n = 0;
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3367
  inv_stop (as, abc_lm_s lm n (abc_lm_v lm n)) (start_of ly e, lb, rb) ires\<rbrakk>
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3368
  \<Longrightarrow> crsp ly (abc_step_l (as, lm) (Some (Dec n e))) (start_of ly e, lb, rb) ires"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3369
apply(auto simp: crsp.simps abc_step_l.simps inv_stop.simps)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3370
done
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3371
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3372
lemma crsp_step_dec_b_e:
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3373
  assumes layout: "ly = layout_of ap"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3374
  and inv_start: "inv_locate_a (as, lm) (n, l, r) ires"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3375
  and dec_0: "abc_lm_v lm n = 0"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3376
  and fetch: "abc_fetch as ap = Some (Dec n e)"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3377
  shows "\<exists>stp > 0. crsp ly (abc_step_l (as, lm) (Some (Dec n e)))
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3378
  (steps (start_of ly as + 2 * n, l, r) (ci ly (start_of ly as) (Dec n e), start_of ly as - Suc 0) stp) ires"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3379
proof -
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3380
  let ?P = "ci ly (start_of ly as) (Dec n e)"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3381
  let ?off = "start_of ly as - Suc 0"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3382
  have "\<exists> stp la ra. steps (start_of ly as + 2 * n, l, r) (?P, ?off) stp = (Suc (start_of ly as) + 2*n, la, ra)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3383
             \<and>  inv_locate_b (as, lm) (n, la, ra) ires"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3384
    using inv_start
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3385
    apply(case_tac "r = [] \<or> hd r = Bk", simp_all)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3386
    done
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3387
  from this obtain stpa la ra where a:
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3388
    "steps (start_of ly as + 2 * n, l, r) (?P, ?off) stpa = (Suc (start_of ly as) + 2*n, la, ra)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3389
             \<and>  inv_locate_b (as, lm) (n, la, ra) ires" by blast
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3390
  term dec_inv_1
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3391
  have "\<exists> stp lb rb. steps (Suc (start_of ly as) + 2 * n, la, ra) (?P, ?off) stp = (start_of ly e, lb, rb)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3392
             \<and>  dec_inv_1 ly n e (as, lm) (start_of ly e, lb, rb) ires"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3393
    using assms a
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3394
    apply(rule_tac crsp_step_dec_b_e_pre, auto)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3395
    done
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3396
  from this obtain stpb lb rb where b:
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3397
    "steps (Suc (start_of ly as) + 2 * n, la, ra) (?P, ?off) stpb = (start_of ly e, lb, rb)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3398
             \<and>  dec_inv_1 ly n e (as, lm) (start_of ly e, lb, rb) ires"  by blast
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3399
  from a b show "\<exists>stp > 0. crsp ly (abc_step_l (as, lm) (Some (Dec n e))) 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3400
    (steps (start_of ly as + 2 * n, l, r) (?P, ?off) stp) ires"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3401
    apply(rule_tac x = "stpa + stpb" in exI)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3402
    apply(simp add: steps_add)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3403
    using dec_0
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3404
    apply(simp add: dec_inv_1.simps)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3405
    apply(case_tac stpa, simp_all add: steps.simps)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3406
    done
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3407
qed    
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3408
  
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3409
fun dec_inv_2 :: "layout \<Rightarrow> nat \<Rightarrow> nat \<Rightarrow> dec_inv_t"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3410
  where
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3411
  "dec_inv_2 ly n e (as, am) (s, l, r) ires =
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3412
           (let ss = start_of ly as in
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3413
            let am' = abc_lm_s am n (abc_lm_v am n - Suc 0) in
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3414
            let am'' = abc_lm_s am n (abc_lm_v am n) in
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3415
              if s = 0 then False
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3416
              else if s = ss + 2 * n then 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3417
                      inv_locate_a (as, am) (n, l, r) ires
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3418
              else if s = ss + 2 * n + 1 then 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3419
                      inv_locate_n_b (as, am) (n, l, r) ires
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3420
              else if s = ss + 2 * n + 2 then 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3421
                      dec_first_on_right_moving n (as, am'') (s, l, r) ires
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3422
              else if s = ss + 2 * n + 3 then 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3423
                      dec_after_clear (as, am') (s, l, r) ires
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3424
              else if s = ss + 2 * n + 4 then 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3425
                      dec_right_move (as, am') (s, l, r) ires
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3426
              else if s = ss + 2 * n + 5 then 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3427
                      dec_check_right_move (as, am') (s, l, r) ires
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3428
              else if s = ss + 2 * n + 6 then 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3429
                      dec_left_move (as, am') (s, l, r) ires
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3430
              else if s = ss + 2 * n + 7 then 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3431
                      dec_after_write (as, am') (s, l, r) ires
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3432
              else if s = ss + 2 * n + 8 then 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3433
                      dec_on_right_moving (as, am') (s, l, r) ires
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3434
              else if s = ss + 2 * n + 9 then 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3435
                      dec_after_clear (as, am') (s, l, r) ires
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3436
              else if s = ss + 2 * n + 10 then 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3437
                      inv_on_left_moving (as, am') (s, l, r) ires
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3438
              else if s = ss + 2 * n + 11 then 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3439
                      inv_check_left_moving (as, am') (s, l, r) ires
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3440
              else if s = ss + 2 * n + 12 then 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3441
                      inv_after_left_moving (as, am') (s, l, r) ires
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3442
              else if s = ss + 2 * n + 16 then 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3443
                      inv_stop (as, am') (s, l, r) ires
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3444
              else False)"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3445
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3446
declare dec_inv_2.simps[simp del]
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3447
fun abc_dec_2_stage1 :: "config \<Rightarrow> nat \<Rightarrow> nat \<Rightarrow> nat"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3448
  where
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3449
  "abc_dec_2_stage1 (s, l, r) ss n = 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3450
              (if s \<le> ss + 2*n + 1 then 7
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3451
               else if s = ss + 2*n + 2 then 6 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3452
               else if s = ss + 2*n + 3 then 5
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3453
               else if s \<ge> ss + 2*n + 4 \<and> s \<le> ss + 2*n + 9 then 4
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3454
               else if s = ss + 2*n + 6 then 3
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3455
               else if s = ss + 2*n + 10 \<or> s = ss + 2*n + 11 then 2
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3456
               else if s = ss + 2*n + 12 then 1
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3457
               else 0)"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3458
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3459
fun abc_dec_2_stage2 :: "config \<Rightarrow> nat \<Rightarrow> nat \<Rightarrow> nat"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3460
  where
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3461
  "abc_dec_2_stage2 (s, l, r) ss n = 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3462
       (if s \<le> ss + 2 * n + 1 then (ss + 2 * n + 16 - s)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3463
        else if s = ss + 2*n + 10 then length l
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3464
        else if s = ss + 2*n + 11 then length l
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3465
        else if s = ss + 2*n + 4 then length r - 1
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3466
        else if s = ss + 2*n + 5 then length r 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3467
        else if s = ss + 2*n + 7 then length r - 1
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3468
        else if s = ss + 2*n + 8 then  
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3469
              length r + length (takeWhile (\<lambda> a. a = Oc) l) - 1
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3470
        else if s = ss + 2*n + 9 then 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3471
              length r + length (takeWhile (\<lambda> a. a = Oc) l) - 1
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3472
        else 0)"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3473
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3474
fun abc_dec_2_stage3 :: "config \<Rightarrow> nat \<Rightarrow> nat \<Rightarrow> nat"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3475
  where
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3476
  "abc_dec_2_stage3 (s, l, r) ss n  =
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3477
        (if s \<le> ss + 2*n + 1 then 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3478
            if (s - ss) mod 2 = 0 then if r \<noteq> [] \<and> 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3479
                                          hd r = Oc then 0 else 1  
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3480
            else length r
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3481
         else if s = ss + 2 * n + 10 then 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3482
             if  r \<noteq> [] \<and> hd r = Oc then 2
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3483
             else 1
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3484
         else if s = ss + 2 * n + 11 then 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3485
             if r \<noteq> [] \<and> hd r = Oc then 3 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3486
             else 0 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3487
         else (ss + 2 * n + 16 - s))"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3488
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3489
fun abc_dec_2_stage4 :: "config \<Rightarrow> nat \<Rightarrow> nat \<Rightarrow> nat"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3490
  where
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3491
  "abc_dec_2_stage4 (s, l, r) ss n = 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3492
          (if s = ss + 2*n + 2 then length r
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3493
           else if s = ss + 2*n + 8 then length r
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3494
           else if s = ss + 2*n + 3 then 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3495
               if r \<noteq> [] \<and> hd r = Oc then 1
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3496
               else 0
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3497
           else if s = ss + 2*n + 7 then 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3498
               if r \<noteq> [] \<and> hd r = Oc then 0 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3499
               else 1
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3500
           else if s = ss + 2*n + 9 then 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3501
               if r \<noteq> [] \<and> hd r = Oc then 1
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3502
               else 0 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3503
           else 0)"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3504
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3505
fun abc_dec_2_measure :: "(config \<times> nat \<times> nat) \<Rightarrow> (nat \<times> nat \<times> nat \<times> nat)"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3506
  where
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3507
  "abc_dec_2_measure (c, ss, n) = 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3508
  (abc_dec_2_stage1 c ss n, 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3509
  abc_dec_2_stage2 c ss n, abc_dec_2_stage3 c ss n,  abc_dec_2_stage4 c ss n)"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3510
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3511
definition lex_square:: 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3512
   "((nat \<times> nat \<times> nat \<times> nat) \<times> (nat \<times> nat \<times> nat \<times> nat)) set"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3513
  where "lex_square \<equiv> less_than <*lex*> lex_triple"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3514
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3515
definition abc_dec_2_LE ::
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3516
  "((config \<times> nat \<times>
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3517
  nat) \<times> (config \<times> nat \<times> nat)) set"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3518
  where "abc_dec_2_LE \<equiv> (inv_image lex_square abc_dec_2_measure)"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3519
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3520
lemma wf_dec2_le: "wf abc_dec_2_LE"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3521
by(auto intro:wf_inv_image simp:abc_dec_2_LE_def lex_square_def lex_triple_def lex_pair_def)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3522
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3523
lemma fix_add: "fetch ap ((x::nat) + 2*n) b = fetch ap (2*n + x) b"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3524
by (metis Suc_1 mult_2 nat_add_commute)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3525
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3526
lemma [elim]: 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3527
 "\<lbrakk>0 < abc_lm_v am n; inv_locate_n_b (as, am) (n, aaa, Bk # xs) ires\<rbrakk> 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3528
 \<Longrightarrow> RR"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3529
apply(auto simp: inv_locate_n_b.simps abc_lm_v.simps split: if_splits)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3530
apply(case_tac [!] m, auto)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3531
done
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3532
 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3533
lemma [elim]:
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3534
 "\<lbrakk>0 < abc_lm_v am n; inv_locate_n_b (as, am) 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3535
                                (n, aaa, []) ires\<rbrakk> \<Longrightarrow> RR"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3536
apply(auto simp: inv_locate_n_b.simps abc_lm_v.simps split: if_splits)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3537
done
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3538
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3539
lemma [simp]: "dec_after_write (as, am) (s, aa, r) ires
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3540
           \<Longrightarrow> takeWhile (\<lambda>a. a = Oc) aa = []"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3541
apply(simp only : dec_after_write.simps)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3542
apply(erule exE)+
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3543
apply(erule_tac conjE)+
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3544
apply(case_tac aa, simp)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3545
apply(case_tac a, simp only: takeWhile.simps , simp_all split: if_splits)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3546
done
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3547
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3548
lemma [simp]: 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3549
     "\<lbrakk>dec_on_right_moving (as, lm) (s, aa, []) ires; 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3550
       length (takeWhile (\<lambda>a. a = Oc) (tl aa)) 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3551
           \<noteq> length (takeWhile (\<lambda>a. a = Oc) aa) - Suc 0\<rbrakk>
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3552
    \<Longrightarrow> length (takeWhile (\<lambda>a. a = Oc) (tl aa)) < 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3553
                       length (takeWhile (\<lambda>a. a = Oc) aa) - Suc 0"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3554
apply(simp only: dec_on_right_moving.simps)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3555
apply(erule_tac exE)+
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3556
apply(erule_tac conjE)+
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3557
apply(case_tac mr, auto split: if_splits)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3558
done
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3559
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3560
lemma [simp]: 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3561
  "dec_after_clear (as, abc_lm_s am n (abc_lm_v am n - Suc 0)) 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3562
             (start_of (layout_of aprog) as + 2 * n + 9, aa, Bk # xs) ires
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3563
 \<Longrightarrow> length xs - Suc 0 < length xs + 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3564
                             length (takeWhile (\<lambda>a. a = Oc) aa)"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3565
apply(simp only: dec_after_clear.simps)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3566
apply(erule_tac exE)+
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3567
apply(erule conjE)+
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3568
apply(simp split: if_splits )
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3569
done
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3570
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3571
lemma [simp]: 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3572
 "\<lbrakk>dec_after_clear (as, abc_lm_s am n (abc_lm_v am n - Suc 0))
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3573
       (start_of (layout_of aprog) as + 2 * n + 9, aa, []) ires\<rbrakk>
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3574
    \<Longrightarrow> Suc 0 < length (takeWhile (\<lambda>a. a = Oc) aa)"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3575
apply(simp add: dec_after_clear.simps split: if_splits)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3576
done
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3577
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3578
lemma [elim]: 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3579
  "inv_check_left_moving (as, lm)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3580
  (s, [], Oc # xs) ires
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3581
 \<Longrightarrow> RR"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3582
apply(simp add: inv_check_left_moving.simps inv_check_left_moving_in_middle.simps)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3583
done
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3584
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3585
lemma [simp]:
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3586
"\<lbrakk>0 < abc_lm_v am n; 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3587
  at_begin_norm (as, am) (n, aaa, Oc # xs) ires\<rbrakk>
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3588
  \<Longrightarrow> inv_locate_n_b (as, am) (n, Oc # aaa, xs) ires"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3589
apply(simp only: at_begin_norm.simps inv_locate_n_b.simps)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3590
apply(erule_tac exE)+
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3591
apply(rule_tac x = lm1 in exI, simp)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3592
apply(case_tac "length lm2", simp)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3593
apply(case_tac "lm2", simp, simp)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3594
apply(case_tac "lm2", auto simp: tape_of_nl_cons split: if_splits)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3595
done
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3596
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3597
lemma [simp]: 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3598
 "\<lbrakk>0 < abc_lm_v am n; 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3599
   at_begin_fst_awtn (as, am) (n, aaa, Oc # xs) ires\<rbrakk>
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3600
 \<Longrightarrow> inv_locate_n_b (as, am) (n, Oc # aaa, xs) ires"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3601
apply(simp only: at_begin_fst_awtn.simps inv_locate_n_b.simps )
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3602
apply(erule exE)+
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3603
apply(erule conjE)+
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3604
apply(rule_tac x = lm1 in exI, rule_tac x = "[]" in exI, 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3605
      rule_tac x = "Suc tn" in exI, rule_tac x = 0 in exI)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3606
apply(simp add: exp_ind del: replicate.simps)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3607
apply(rule conjI)+
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3608
apply(auto)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3609
done
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3610
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3611
lemma [simp]: 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3612
 "\<lbrakk>0 < abc_lm_v am n; inv_locate_a (as, am) (n, aaa, Oc # xs) ires\<rbrakk>
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3613
 \<Longrightarrow> inv_locate_n_b (as, am) (n, Oc#aaa, xs) ires"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3614
apply(auto simp: inv_locate_a.simps at_begin_fst_bwtn.simps)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3615
done
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3616
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3617
lemma [simp]: 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3618
 "\<lbrakk>dec_on_right_moving (as, am) (s, aa, Bk # xs) ires; 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3619
   Suc (length (takeWhile (\<lambda>a. a = Oc) (tl aa)))
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3620
   \<noteq> length (takeWhile (\<lambda>a. a = Oc) aa)\<rbrakk>
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3621
  \<Longrightarrow> Suc (length (takeWhile (\<lambda>a. a = Oc) (tl aa))) 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3622
    < length (takeWhile (\<lambda>a. a = Oc) aa)"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3623
apply(simp only: dec_on_right_moving.simps)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3624
apply(erule exE)+
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3625
apply(erule conjE)+
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3626
apply(case_tac ml, auto split: if_splits )
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3627
done
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3628
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3629
lemma crsp_step_dec_b_suc_pre:
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3630
  assumes layout: "ly = layout_of ap"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3631
  and crsp: "crsp ly (as, lm) (s, l, r) ires"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3632
  and inv_start: "inv_locate_a (as, lm) (n, la, ra) ires"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3633
  and fetch: "abc_fetch as ap = Some (Dec n e)"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3634
  and dec_suc: "0 < abc_lm_v lm n"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3635
  and f: "f = (\<lambda> stp. (steps (start_of ly as + 2 * n, la, ra) (ci ly (start_of ly as) (Dec n e), 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3636
            start_of ly as - Suc 0) stp, start_of ly as, n))"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3637
  and P: "P = (\<lambda> ((s, l, r), ss, x). s = start_of ly as + 2*n + 16)"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3638
  and Q: "Q = (\<lambda> ((s, l, r), ss, x). dec_inv_2 ly x e (as, lm) (s, l, r) ires)"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3639
  shows "\<exists> stp. P (f stp) \<and> Q(f stp)"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3640
  proof(rule_tac LE = abc_dec_2_LE in halt_lemma2)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3641
  show "wf abc_dec_2_LE" by(intro wf_dec2_le)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3642
next
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3643
  show "Q (f 0)"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3644
    using layout fetch inv_start
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3645
    apply(simp add: f steps.simps Q)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3646
    apply(simp only: dec_inv_2.simps)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3647
    apply(auto simp: Let_def start_of_ge start_of_less inv_start dec_inv_2.simps)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3648
    done
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3649
next
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3650
  show "\<not> P (f 0)"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3651
    using layout fetch
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3652
    apply(simp add: f steps.simps P)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3653
    done
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3654
next
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3655
  show "\<forall>n. \<not> P (f n) \<and> Q (f n) \<longrightarrow> Q (f (Suc n)) \<and> (f (Suc n), f n) \<in> abc_dec_2_LE"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3656
    using fetch
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3657
  proof(rule_tac allI, rule_tac impI)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3658
    fix na
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3659
    assume "\<not> P (f na) \<and> Q (f na)"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3660
    thus "Q (f (Suc na)) \<and> (f (Suc na), f na) \<in> abc_dec_2_LE"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3661
      apply(simp add: f)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3662
      apply(case_tac "steps ((start_of ly as + 2 * n), la, ra)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3663
        (ci ly (start_of ly as) (Dec n e), start_of ly as - Suc 0) na", simp)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3664
    proof -
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3665
      fix a b c 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3666
      assume "\<not> P ((a, b, c), start_of ly as, n) \<and> Q ((a, b, c), start_of ly as, n)"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3667
      thus "Q (step (a, b, c) (ci ly (start_of ly as) (Dec n e), start_of ly as - Suc 0), start_of ly as, n) \<and>
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3668
               ((step (a, b, c) (ci ly (start_of ly as) (Dec n e), start_of ly as - Suc 0), start_of ly as, n), 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3669
                   (a, b, c), start_of ly as, n) \<in> abc_dec_2_LE"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3670
        apply(simp add: Q)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3671
        apply(erule_tac conjE)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3672
        apply(case_tac c, case_tac [2] aa)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3673
        apply(simp_all add: dec_inv_2.simps Let_def)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3674
        apply(simp_all split: if_splits)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3675
        using fetch layout dec_suc
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3676
        apply(auto simp: step.simps P dec_inv_2.simps Let_def abc_dec_2_LE_def lex_triple_def lex_pair_def lex_square_def
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3677
                         fix_add numeral_3_eq_3) 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3678
        done
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3679
    qed
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3680
  qed
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3681
qed
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3682
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3683
lemma [simp]: 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3684
  "\<lbrakk>inv_stop (as, abc_lm_s lm n (abc_lm_v lm n - Suc 0)) 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3685
  (start_of (layout_of ap) as + 2 * n + 16, a, b) ires;
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3686
   abc_lm_v lm n > 0;
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3687
   abc_fetch as ap = Some (Dec n e)\<rbrakk>
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3688
  \<Longrightarrow> crsp (layout_of ap) (abc_step_l (as, lm) (Some (Dec n e))) 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3689
  (start_of (layout_of ap) as + 2 * n + 16, a, b) ires"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3690
apply(auto simp: inv_stop.simps crsp.simps  abc_step_l.simps startof_Suc2)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3691
apply(drule_tac startof_Suc2, simp)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3692
done
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3693
  
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3694
lemma crsp_step_dec_b_suc:
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3695
  assumes layout: "ly = layout_of ap"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3696
  and crsp: "crsp ly (as, lm) (s, l, r) ires"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3697
  and inv_start: "inv_locate_a (as, lm) (n, la, ra) ires"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3698
  and fetch: "abc_fetch as ap = Some (Dec n e)"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3699
  and dec_suc: "0 < abc_lm_v lm n"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3700
  shows "\<exists>stp > 0. crsp ly (abc_step_l (as, lm) (Some (Dec n e)))
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3701
              (steps (start_of ly as + 2 * n, la, ra) (ci (layout_of ap) 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3702
                  (start_of ly as) (Dec n e), start_of ly as - Suc 0) stp) ires"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3703
  using assms
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3704
  apply(drule_tac crsp_step_dec_b_suc_pre, auto)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3705
  apply(rule_tac x = stp in exI, simp)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3706
  apply(simp add: dec_inv_2.simps)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3707
  apply(case_tac stp, simp_all add: steps.simps)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3708
  done
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3709
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3710
lemma crsp_step_dec_b:
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3711
  assumes layout: "ly = layout_of ap"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3712
  and crsp: "crsp ly (as, lm) (s, l, r) ires"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3713
  and inv_start: "inv_locate_a (as, lm) (n, la, ra) ires"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3714
  and fetch: "abc_fetch as ap = Some (Dec n e)"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3715
  shows "\<exists>stp > 0. crsp ly (abc_step_l (as, lm) (Some (Dec n e)))
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3716
  (steps (start_of ly as + 2 * n, la, ra) (ci ly (start_of ly as) (Dec n e), start_of ly as - Suc 0) stp) ires"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3717
using assms
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3718
apply(case_tac "abc_lm_v lm n = 0")
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3719
apply(rule_tac crsp_step_dec_b_e, simp_all)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3720
apply(rule_tac crsp_step_dec_b_suc, simp_all)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3721
done
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3722
47
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3723
lemma crsp_step_dec: 
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3724
  assumes layout: "ly = layout_of ap"
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3725
  and crsp: "crsp ly (as, lm) (s, l, r) ires"
60
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3726
  and fetch: "abc_fetch as ap = Some (Dec n e)"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3727
  shows "\<exists>stp > 0. crsp ly (abc_step_l (as, lm) (Some (Dec n e)))
47
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3728
  (steps (s, l, r) (ci ly (start_of ly as) (Dec n e), start_of ly as - Suc 0) stp) ires"
60
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3729
proof(simp add: ci.simps)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3730
  let ?off = "start_of ly as - Suc 0"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3731
  let ?A = "findnth n"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3732
  let ?B = "sete (shift (shift tdec_b (2 * n)) ?off) (start_of ly e)"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3733
  have "\<exists> stp la ra. steps (s, l, r) (shift ?A ?off @ ?B, ?off) stp = (start_of ly as + 2*n, la, ra)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3734
                    \<and> inv_locate_a (as, lm) (n, la, ra) ires"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3735
  proof -
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3736
    have "\<exists>stp l' r'. steps (Suc 0, l, r) (?A, 0) stp = (Suc (2 * n), l', r') \<and> 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3737
                     inv_locate_a (as, lm) (n, l', r') ires"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3738
      using assms
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3739
      apply(rule_tac findnth_correct, simp_all)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3740
      done
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3741
    then obtain stp l' r' where a: 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3742
      "steps (Suc 0, l, r) (?A, 0) stp = (Suc (2 * n), l', r') \<and> 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3743
      inv_locate_a (as, lm) (n, l', r') ires" by blast
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3744
    then have "steps (Suc 0 + ?off, l, r) (shift ?A ?off, ?off) stp = (Suc (2 * n) + ?off, l', r')"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3745
      apply(rule_tac tm_shift_eq_steps, simp_all)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3746
      done
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3747
    moreover have "s = start_of ly as"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3748
      using crsp
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3749
      apply(auto simp: crsp.simps)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3750
      done
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3751
    ultimately show "\<exists> stp la ra. steps (s, l, r) (shift ?A ?off @ ?B, ?off) stp = (start_of ly as + 2*n, la, ra)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3752
                    \<and> inv_locate_a (as, lm) (n, la, ra) ires"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3753
      using a
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3754
      apply(drule_tac B = ?B in tm_append_first_steps_eq, auto)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3755
      apply(rule_tac x = stp in exI, simp)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3756
      done
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3757
  qed
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3758
  from this obtain stpa la ra where a: 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3759
    "steps (s, l, r) (shift ?A ?off @ ?B, ?off) stpa = (start_of ly as + 2*n, la, ra)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3760
                    \<and> inv_locate_a (as, lm) (n, la, ra) ires" by blast
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3761
  have "\<exists>stp. crsp ly (abc_step_l (as, lm) (Some (Dec n e)))
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3762
           (steps (start_of ly as + 2*n, la, ra) (shift ?A ?off @ ?B, ?off) stp) ires \<and> stp > 0"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3763
    using assms a
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3764
    apply(drule_tac crsp_step_dec_b, auto)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3765
    apply(rule_tac x = stp in exI, simp add: ci.simps)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3766
    done
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3767
  then obtain stpb where b: 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3768
    "crsp ly (abc_step_l (as, lm) (Some (Dec n e)))
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3769
    (steps (start_of ly as + 2*n, la, ra) (shift ?A ?off @ ?B, ?off) stpb) ires \<and> stpb > 0" ..
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3770
  from a b show "\<exists> stp>0. crsp ly (abc_step_l (as, lm) (Some (Dec n e)))
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3771
    (steps (s, l, r) (shift ?A ?off @ ?B, ?off) stp) ires"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3772
    apply(rule_tac x = "stpa + stpb" in exI)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3773
    apply(simp add: steps_add)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3774
    done
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3775
qed    
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3776
  
47
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3777
subsection{*Crsp of Goto*}
60
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3778
47
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3779
lemma crsp_step_goto:
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3780
  assumes layout: "ly = layout_of ap"
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3781
  and crsp: "crsp ly (as, lm) (s, l, r) ires"
60
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3782
  shows "\<exists>stp>0. crsp ly (abc_step_l (as, lm) (Some (Goto n)))
47
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3783
  (steps (s, l, r) (ci ly (start_of ly as) (Goto n), 
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3784
            start_of ly as - Suc 0) stp) ires"
60
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3785
using crsp
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3786
apply(rule_tac x = "Suc 0" in exI)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3787
apply(case_tac r, case_tac [2] a)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3788
apply(simp_all add: ci.simps steps.simps step.simps crsp.simps fetch.simps
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3789
  crsp.simps abc_step_l.simps)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3790
done
47
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3791
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3792
lemma crsp_step_in:
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3793
  assumes layout: "ly = layout_of ap"
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3794
  and compile: "tp = tm_of ap"
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3795
  and crsp: "crsp ly (as, lm) (s, l, r) ires"
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3796
  and fetch: "abc_fetch as ap = Some ins"
60
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3797
  shows "\<exists> stp>0. crsp ly (abc_step_l (as, lm) (Some ins))
47
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3798
                      (steps (s, l, r) (ci ly (start_of ly as) ins, start_of ly as - 1) stp) ires"
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3799
  using assms
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3800
  apply(case_tac ins, simp_all)
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3801
  apply(rule crsp_step_inc, simp_all)
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3802
  apply(rule crsp_step_dec, simp_all)
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3803
  apply(rule_tac crsp_step_goto, simp_all)
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3804
  done
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3805
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3806
lemma crsp_step:
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3807
  assumes layout: "ly = layout_of ap"
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3808
  and compile: "tp = tm_of ap"
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3809
  and crsp: "crsp ly (as, lm) (s, l, r) ires"
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3810
  and fetch: "abc_fetch as ap = Some ins"
60
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3811
  shows "\<exists> stp>0. crsp ly (abc_step_l (as, lm) (Some ins))
47
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3812
                      (steps (s, l, r) (tp, 0) stp) ires"
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3813
proof -
60
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3814
  have "\<exists> stp>0. crsp ly (abc_step_l (as, lm) (Some ins))
47
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3815
                      (steps (s, l, r) (ci ly (start_of ly as) ins, start_of ly as - 1) stp) ires"
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3816
    using assms
60
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3817
    apply(rule_tac crsp_step_in, simp_all)
47
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3818
    done
60
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3819
  from this obtain stp where d: "stp > 0 \<and> crsp ly (abc_step_l (as, lm) (Some ins))
47
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3820
                      (steps (s, l, r) (ci ly (start_of ly as) ins, start_of ly as - 1) stp) ires" ..
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3821
  obtain s' l' r' where e:
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3822
    "(steps (s, l, r) (ci ly (start_of ly as) ins, start_of ly as - 1) stp) = (s', l', r')"
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3823
    apply(case_tac "(steps (s, l, r) (ci ly (start_of ly as) ins, start_of ly as - 1) stp)")
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3824
    by blast
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3825
  then have "steps (s, l, r) (tp, 0) stp = (s', l', r')"
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3826
    using assms d
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3827
    apply(rule_tac steps_eq_in)
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3828
    apply(simp_all)
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3829
    apply(case_tac "(abc_step_l (as, lm) (Some ins))", simp add: crsp.simps)
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3830
    done    
60
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3831
  thus " \<exists>stp>0. crsp ly (abc_step_l (as, lm) (Some ins)) (steps (s, l, r) (tp, 0) stp) ires"
47
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3832
    using d e
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3833
    apply(rule_tac x = stp in exI, simp)
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3834
    done
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3835
qed
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3836
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3837
lemma crsp_steps:
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3838
  assumes layout: "ly = layout_of ap"
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3839
  and compile: "tp = tm_of ap"
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3840
  and crsp: "crsp ly (as, lm) (s, l, r) ires"
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3841
  shows "\<exists> stp. crsp ly (abc_steps_l (as, lm) ap n)
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3842
                      (steps (s, l, r) (tp, 0) stp) ires"
60
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3843
(*
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3844
proof(induct n)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3845
  case 0
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3846
  have "crsp ly (abc_steps_l (as, lm) ap 0) (steps (s, l, r) (tp, 0) 0) ires"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3847
    using crsp by(simp add: steps.simps abc_steps_l.simps)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3848
  thus "?case"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3849
    by(rule_tac x = 0 in exI, simp)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3850
next
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3851
  case (Suc n)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3852
  obtain as' lm' where a: "abc_steps_l (as, lm) ap n = (as', lm')"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3853
    by(case_tac "abc_steps_l (as, lm) ap n", auto) 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3854
  have "\<exists>stp\<ge>n. crsp ly (abc_steps_l (as, lm) ap n) (steps (s, l, r) (tp, 0) stp) ires"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3855
    by fact
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3856
  from this a obtain stpa where b:
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3857
    "stpa\<ge>n \<and> crsp ly (as', lm') (steps (s, l, r) (tp, 0) stpa) ires" by auto
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3858
  obtain s' l' r' where "steps (s, l, r) (tp, 0) stpa = (s', l', r')"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3859
    by(case_tac "steps (s, l, r) (tp, 0) stpa")
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3860
  then have "stpa\<ge>n \<and> crsp ly (as', lm') (s', l', r') ires" using b by simp
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3861
  from a and this show "?case"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3862
  proof(cases "abc_fetch as' ap")
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3863
    case None
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3864
    
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3865
  
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3866
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3867
    have "crsp ly (abc_steps_l (as, lm) ap 0) (steps (s, l, r) (tp, 0) stp) ires"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3868
    apply(simp add: steps.simps abc_steps_l.simps)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3869
*)
47
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3870
  using crsp
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3871
  apply(induct n)
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3872
  apply(rule_tac x = 0 in exI) 
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3873
  apply(simp add: steps.simps abc_steps_l.simps, simp)
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3874
  apply(case_tac "(abc_steps_l (as, lm) ap n)", auto)
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3875
  apply(frule_tac abc_step_red, simp)
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3876
  apply(case_tac "abc_fetch a ap", simp add: abc_step_l.simps, auto)
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3877
  apply(case_tac "steps (s, l, r) (tp, 0) stp", simp)
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3878
  using assms
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3879
  apply(drule_tac s = ab and l = ba and r = c in crsp_step, auto)
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3880
  apply(rule_tac x = "stp + stpa" in exI, simp add: steps_add)
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3881
  done
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3882
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3883
lemma tp_correct': 
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3884
  assumes layout: "ly = layout_of ap"
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3885
  and compile: "tp = tm_of ap"
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3886
  and crsp: "crsp ly (0, lm) (Suc 0, l, r) ires"
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3887
  and abc_halt: "abc_steps_l (0, lm) ap stp = (length ap, am)"
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3888
  shows "\<exists> stp k. steps (Suc 0, l, r) (tp, 0) stp = (start_of ly (length ap), Bk # Bk # ires, <am> @ Bk\<up>k)"
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3889
  using assms
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3890
  apply(drule_tac n = stp in crsp_steps, auto)
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3891
  apply(rule_tac x = stpa in exI)
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3892
  apply(case_tac "steps (Suc 0, l, r) (tm_of ap, 0) stpa", simp add: crsp.simps)
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3893
  done
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3894
60
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3895
text{*The tp @ [(Nop, 0), (Nop, 0)] is nomoral turing machines, so we can use Hoare_plus when composing with Mop machine*}
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3896
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3897
thm layout_of.simps
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3898
lemma layout_id_cons: "layout_of (ap @ [p]) = layout_of ap @ [length_of p]"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3899
apply(simp add: layout_of.simps)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3900
done
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3901
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3902
lemma [simp]: "length (layout_of xs) = length xs"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3903
by(simp add: layout_of.simps)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3904
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3905
thm tms_of.simps
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3906
term ci
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3907
thm tms_of.simps
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3908
thm tpairs_of.simps
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3909
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3910
lemma [simp]:  
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3911
  "map (start_of (layout_of xs @ [length_of x])) [0..<length xs] =  (map (start_of (layout_of xs)) [0..<length xs])"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3912
apply(auto)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3913
apply(simp add: layout_of.simps start_of.simps)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3914
done
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3915
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3916
lemma tpairs_id_cons: 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3917
  "tpairs_of (xs @ [x]) = tpairs_of xs @ [(start_of (layout_of (xs @ [x])) (length xs), x)]"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3918
apply(auto simp: tpairs_of.simps layout_id_cons )
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3919
done
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3920
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3921
lemma map_length_ci:
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3922
  "(map (length \<circ> (\<lambda>(xa, y). ci (layout_of xs @ [length_of x]) xa y)) (tpairs_of xs)) = 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3923
  (map (length \<circ> (\<lambda>(x, y). ci (layout_of xs) x y)) (tpairs_of xs)) "
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3924
apply(auto)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3925
apply(case_tac b, auto simp: ci.simps sete.simps)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3926
done
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3927
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3928
lemma length_tp'[simp]: 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3929
  "\<lbrakk>ly = layout_of ap; tp = tm_of ap\<rbrakk> \<Longrightarrow>
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3930
       length tp = 2 * listsum (take (length ap) (layout_of ap))"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3931
proof(induct ap arbitrary: ly tp rule: rev_induct)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3932
  case Nil
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3933
  thus "?case"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3934
    by(simp add: tms_of.simps tm_of.simps tpairs_of.simps)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3935
next
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3936
  fix x xs ly tp
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3937
  assume ind: "\<And>ly tp. \<lbrakk>ly = layout_of xs; tp = tm_of xs\<rbrakk> \<Longrightarrow> 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3938
    length tp = 2 * listsum (take (length xs) (layout_of xs))"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3939
  and layout: "ly = layout_of (xs @ [x])"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3940
  and tp: "tp = tm_of (xs @ [x])"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3941
  obtain ly' where a: "ly' = layout_of xs"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3942
    by metis
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3943
  obtain tp' where b: "tp' = tm_of xs"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3944
    by metis
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3945
  have c: "length tp' = 2 * listsum (take (length xs) (layout_of xs))"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3946
    using a b
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3947
    by(erule_tac ind, simp)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3948
  thus "length tp = 2 * 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3949
    listsum (take (length (xs @ [x])) (layout_of (xs @ [x])))"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3950
    using tp b
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3951
    apply(auto simp: layout_id_cons tm_of.simps tms_of.simps length_concat tpairs_id_cons map_length_ci)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3952
    apply(case_tac x)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3953
    apply(auto simp: ci.simps tinc_b_def tdec_b_def length_findnth sete.simps length_of.simps
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3954
                 split: abc_inst.splits)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3955
    done
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3956
qed
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3957
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3958
lemma [simp]: 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3959
  "\<lbrakk>ly = layout_of ap; tp = tm_of ap\<rbrakk> \<Longrightarrow>
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3960
        fetch (tp @ [(Nop, 0), (Nop, 0)]) (start_of ly (length ap)) b = 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3961
       (Nop, 0)"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3962
apply(case_tac b)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3963
apply(simp_all add: start_of.simps fetch.simps nth_append)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3964
done
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3965
(*
47
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3966
lemma tp_correct: 
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3967
  assumes layout: "ly = layout_of ap"
60
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3968
  and compile: "tp = tm_of ap"
47
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3969
  and crsp: "crsp ly (0, lm) (Suc 0, l, r) ires"
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  3970
  and abc_halt: "abc_steps_l (0, lm) ap stp = (length ap, am)"
60
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3971
  shows "\<exists> stp k. steps (Suc 0, l, r) (tp @ [(Nop, 0), (Nop, 0)], 0) stp = (0, Bk # Bk # ires, <am> @ Bk\<up>k)"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3972
  using assms
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3973
proof -
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3974
  have "\<exists> stp k. steps (Suc 0, l, r) (tp @ [(Nop, 0), (Nop, 0)], 0) stp =
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3975
    (start_of ly (length ap), Bk # Bk # ires, <am> @ Bk\<up>k)"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3976
  proof -
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3977
    have "\<exists> stp k. steps (Suc 0, l, r) (tp, 0) stp =
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3978
    (start_of ly (length ap), Bk # Bk # ires, <am> @ Bk\<up>k)"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3979
      using assms
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3980
      apply(rule_tac tp_correct', simp_all)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3981
      done
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3982
    from this obtain stp k where "steps (Suc 0, l, r) (tp, 0) stp =
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3983
    (start_of ly (length ap), Bk # Bk # ires, <am> @ Bk\<up>k)" by blast
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3984
    thus "?thesis"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3985
      apply(rule_tac x = stp in exI, rule_tac x = k in exI)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3986
      apply(drule_tac tm_append_first_steps_eq, simp_all)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3987
      done
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3988
  qed
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3989
  from this obtain stp k where 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3990
    "steps (Suc 0, l, r) (tp @ [(Nop, 0), (Nop, 0)], 0) stp =
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3991
    (start_of ly (length ap), Bk # Bk # ires, <am> @ Bk\<up>k)"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3992
    by blast
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3993
  thus "\<exists>stp k. steps (Suc 0, l, r) (tp @ [(Nop, 0), (Nop, 0)], 0) stp 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3994
    = (0, Bk # Bk # ires, <am> @ Bk \<up> k)"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3995
    using assms
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3996
    apply(rule_tac x = "stp + Suc 0" in exI)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3997
    apply(simp add: steps_add)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3998
    apply(auto simp: step.simps)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  3999
    done
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4000
qed
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4001
 *)   
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4002
(********for mopup***********)
47
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4003
fun mopup_a :: "nat \<Rightarrow> instr list"
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4004
  where
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4005
  "mopup_a 0 = []" |
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4006
  "mopup_a (Suc n) = mopup_a n @ 
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4007
       [(R, 2*n + 3), (W0, 2*n + 2), (R, 2*n + 1), (W1, 2*n + 2)]"
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4008
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4009
definition mopup_b :: "instr list"
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4010
  where
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4011
  "mopup_b \<equiv> [(R, 2), (R, 1), (L, 5), (W0, 3), (R, 4), (W0, 3),
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4012
            (R, 2), (W0, 3), (L, 5), (L, 6), (R, 0), (L, 6)]"
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4013
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4014
fun mopup :: "nat \<Rightarrow> instr list"
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4015
  where 
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4016
  "mopup n = mopup_a n @ shift mopup_b (2*n)"
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4017
(****)
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4018
60
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4019
type_synonym mopup_type = "config \<Rightarrow> nat list \<Rightarrow> nat \<Rightarrow> cell list \<Rightarrow> bool"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4020
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4021
fun mopup_stop :: "mopup_type"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4022
  where
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4023
  "mopup_stop (s, l, r) lm n ires= 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4024
        (\<exists> ln rn. l = Bk\<up>ln @ Bk # Bk # ires \<and> r = <abc_lm_v lm n> @ Bk\<up>rn)"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4025
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4026
fun mopup_bef_erase_a :: "mopup_type"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4027
  where
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4028
  "mopup_bef_erase_a (s, l, r) lm n ires= 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4029
         (\<exists> ln m rn. l = Bk\<up>ln @ Bk # Bk # ires \<and> 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4030
                  r = Oc\<up>m@ Bk # <(drop ((s + 1) div 2) lm)> @ Bk\<up>rn)"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4031
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4032
fun mopup_bef_erase_b :: "mopup_type"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4033
  where
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4034
  "mopup_bef_erase_b (s, l, r) lm n ires = 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4035
      (\<exists> ln m rn. l = Bk\<up>ln @ Bk # Bk # ires \<and> r = Bk # Oc\<up>m @ Bk # 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4036
                                      <(drop (s div 2) lm)> @ Bk\<up>rn)"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4037
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4038
fun mopup_jump_over1 :: "mopup_type"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4039
  where
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4040
  "mopup_jump_over1 (s, l, r) lm n ires = 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4041
      (\<exists> ln m1 m2 rn. m1 + m2 = Suc (abc_lm_v lm n) \<and> 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4042
        l = Oc\<up>m1 @ Bk\<up>ln @ Bk # Bk # ires \<and> 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4043
     (r = Oc\<up>m2 @ Bk # <(drop (Suc n) lm)> @ Bk\<up>rn \<or> 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4044
     (r = Oc\<up>m2 \<and> (drop (Suc n) lm) = [])))"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4045
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4046
fun mopup_aft_erase_a :: "mopup_type"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4047
  where
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4048
  "mopup_aft_erase_a (s, l, r) lm n ires = 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4049
      (\<exists> lnl lnr rn (ml::nat list) m. 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4050
          m = Suc (abc_lm_v lm n) \<and> l = Bk\<up>lnr @ Oc\<up>m @ Bk\<up>lnl @ Bk # Bk # ires \<and> 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4051
                                   (r = <ml> @ Bk\<up>rn))"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4052
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4053
fun mopup_aft_erase_b :: "mopup_type"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4054
  where
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4055
  "mopup_aft_erase_b (s, l, r) lm n ires= 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4056
   (\<exists> lnl lnr rn (ml::nat list) m. 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4057
      m = Suc (abc_lm_v lm n) \<and> 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4058
      l = Bk\<up>lnr @ Oc\<up>m @ Bk\<up>lnl @ Bk # Bk # ires \<and> 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4059
     (r = Bk # <ml> @ Bk\<up>rn \<or>
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4060
      r = Bk # Bk # <ml> @ Bk\<up>rn))"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4061
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4062
fun mopup_aft_erase_c :: "mopup_type"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4063
  where
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4064
  "mopup_aft_erase_c (s, l, r) lm n ires = 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4065
 (\<exists> lnl lnr rn (ml::nat list) m. 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4066
     m = Suc (abc_lm_v lm n) \<and> 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4067
     l = Bk\<up>lnr @ Oc\<up>m @ Bk\<up>lnl @ Bk # Bk # ires \<and> 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4068
    (r = <ml> @ Bk\<up>rn \<or> r = Bk # <ml> @ Bk\<up>rn))"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4069
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4070
fun mopup_left_moving :: "mopup_type"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4071
  where
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4072
  "mopup_left_moving (s, l, r) lm n ires = 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4073
  (\<exists> lnl lnr rn m.
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4074
     m = Suc (abc_lm_v lm n) \<and> 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4075
   ((l = Bk\<up>lnr @ Oc\<up>m @ Bk\<up>lnl @ Bk # Bk # ires \<and> r = Bk\<up>rn) \<or>
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4076
    (l = Oc\<up>(m - 1) @ Bk\<up>lnl @ Bk # Bk # ires \<and> r = Oc # Bk\<up>rn)))"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4077
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4078
fun mopup_jump_over2 :: "mopup_type"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4079
  where
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4080
  "mopup_jump_over2 (s, l, r) lm n ires = 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4081
     (\<exists> ln rn m1 m2.
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4082
          m1 + m2 = Suc (abc_lm_v lm n) 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4083
        \<and> r \<noteq> [] 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4084
        \<and> (hd r = Oc \<longrightarrow> (l = Oc\<up>m1 @ Bk\<up>ln @ Bk # Bk # ires \<and> r = Oc\<up>m2 @ Bk\<up>rn)) 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4085
        \<and> (hd r = Bk \<longrightarrow> (l = Bk\<up>ln @ Bk # ires \<and> r = Bk # Oc\<up>(m1+m2)@ Bk\<up>rn)))"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4086
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4087
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4088
fun mopup_inv :: "mopup_type"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4089
  where
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4090
  "mopup_inv (s, l, r) lm n ires = 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4091
      (if s = 0 then mopup_stop (s, l, r) lm n ires
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4092
       else if s \<le> 2*n then
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4093
               if s mod 2 = 1 then mopup_bef_erase_a (s, l, r) lm n ires
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4094
                   else mopup_bef_erase_b (s, l, r) lm n ires
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4095
            else if s = 2*n + 1 then 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4096
                mopup_jump_over1 (s, l, r) lm n ires
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4097
            else if s = 2*n + 2 then mopup_aft_erase_a (s, l, r) lm n ires
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4098
            else if s = 2*n + 3 then mopup_aft_erase_b (s, l, r) lm n ires
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4099
            else if s = 2*n + 4 then mopup_aft_erase_c (s, l, r) lm n ires
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4100
            else if s = 2*n + 5 then mopup_left_moving (s, l, r) lm n ires
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4101
            else if s = 2*n + 6 then mopup_jump_over2 (s, l, r) lm n ires
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4102
            else False)"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4103
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4104
lemma mopup_fetch_0[simp]: 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4105
     "(fetch (mopup_a n @ shift mopup_b (2 * n)) 0 b) = (Nop, 0)"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4106
by(simp add: fetch.simps)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4107
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4108
lemma mop_bef_length[simp]: "length (mopup_a n) = 4 * n"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4109
apply(induct n, simp_all add: mopup_a.simps)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4110
done
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4111
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4112
lemma mopup_a_nth: 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4113
  "\<lbrakk>q < n; x < 4\<rbrakk> \<Longrightarrow> mopup_a n ! (4 * q + x) = 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4114
                             mopup_a (Suc q) ! ((4 * q) + x)"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4115
apply(induct n, simp)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4116
apply(case_tac "q < n", simp add: mopup_a.simps, auto)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4117
apply(simp add: nth_append)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4118
apply(subgoal_tac "q = n", simp)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4119
apply(arith)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4120
done
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4121
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4122
lemma fetch_bef_erase_a_o[simp]: 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4123
 "\<lbrakk>0 < s; s \<le> 2 * n; s mod 2 = Suc 0\<rbrakk>
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4124
  \<Longrightarrow> (fetch (mopup_a n @ shift mopup_b (2 * n)) s Oc) = (W0, s + 1)"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4125
apply(subgoal_tac "\<exists> q. s = 2*q + 1", auto)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4126
apply(subgoal_tac "length (mopup_a n) = 4*n")
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4127
apply(auto simp: fetch.simps nth_of.simps nth_append)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4128
apply(subgoal_tac "mopup_a n ! (4 * q + 1) = 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4129
                      mopup_a (Suc q) ! ((4 * q) + 1)", 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4130
      simp add: mopup_a.simps nth_append)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4131
apply(rule mopup_a_nth, auto)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4132
apply arith
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4133
done
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4134
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4135
lemma fetch_bef_erase_a_b[simp]:
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4136
  "\<lbrakk>0 < s; s \<le> 2 * n; s mod 2 = Suc 0\<rbrakk>
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4137
   \<Longrightarrow>  (fetch (mopup_a n @ shift mopup_b (2 * n)) s Bk) = (R, s + 2)"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4138
apply(subgoal_tac "\<exists> q. s = 2*q + 1", auto)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4139
apply(subgoal_tac "length (mopup_a n) = 4*n")
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4140
apply(auto simp: fetch.simps nth_of.simps nth_append)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4141
apply(subgoal_tac "mopup_a n ! (4 * q + 0) = 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4142
                       mopup_a (Suc q) ! ((4 * q + 0))", 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4143
      simp add: mopup_a.simps nth_append)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4144
apply(rule mopup_a_nth, auto)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4145
apply arith
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4146
done
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4147
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4148
lemma fetch_bef_erase_b_b: 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4149
  "\<lbrakk>n < length lm; 0 < s; s \<le> 2 * n; s mod 2 = 0\<rbrakk> \<Longrightarrow> 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4150
     (fetch (mopup_a n @ shift mopup_b (2 * n)) s Bk) = (R, s - 1)"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4151
apply(subgoal_tac "\<exists> q. s = 2 * q", auto)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4152
apply(case_tac qa, simp, simp)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4153
apply(auto simp: fetch.simps nth_of.simps nth_append)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4154
apply(subgoal_tac "mopup_a n ! (4 * nat + 2) = 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4155
                     mopup_a (Suc nat) ! ((4 * nat) + 2)", 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4156
      simp add: mopup_a.simps nth_append)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4157
apply(rule mopup_a_nth, auto)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4158
done
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4159
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4160
lemma fetch_jump_over1_o: 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4161
 "fetch (mopup_a n @ shift mopup_b (2 * n)) (Suc (2 * n)) Oc
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4162
  = (R, Suc (2 * n))"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4163
apply(subgoal_tac "length (mopup_a n) = 4 * n")
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4164
apply(auto simp: fetch.simps nth_of.simps mopup_b_def nth_append 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4165
                 shift.simps)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4166
done
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4167
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4168
lemma fetch_jump_over1_b: 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4169
 "fetch (mopup_a n @ shift mopup_b (2 * n)) (Suc (2 * n)) Bk 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4170
 = (R, Suc (Suc (2 * n)))"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4171
apply(subgoal_tac "length (mopup_a n) = 4 * n")
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4172
apply(auto simp: fetch.simps nth_of.simps mopup_b_def 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4173
                 nth_append shift.simps)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4174
done
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4175
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4176
lemma fetch_aft_erase_a_o: 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4177
 "fetch (mopup_a n @ shift mopup_b (2 * n)) (Suc (Suc (2 * n))) Oc 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4178
 = (W0, Suc (2 * n + 2))"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4179
apply(subgoal_tac "length (mopup_a n) = 4 * n")
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4180
apply(auto simp: fetch.simps nth_of.simps mopup_b_def 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4181
                 nth_append shift.simps)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4182
done
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4183
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4184
lemma fetch_aft_erase_a_b: 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4185
 "fetch (mopup_a n @ shift mopup_b (2 * n)) (Suc (Suc (2 * n))) Bk
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4186
  = (L, Suc (2 * n + 4))"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4187
apply(subgoal_tac "length (mopup_a n) = 4 * n")
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4188
apply(auto simp: fetch.simps nth_of.simps mopup_b_def 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4189
                 nth_append shift.simps)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4190
done
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4191
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4192
lemma fetch_aft_erase_b_b: 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4193
 "fetch (mopup_a n @ shift mopup_b (2 * n)) (2*n + 3) Bk
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4194
  = (R, Suc (2 * n + 3))"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4195
apply(subgoal_tac "length (mopup_a n) = 4 * n")
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4196
apply(subgoal_tac "2*n + 3 = Suc (2*n + 2)", simp only: fetch.simps)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4197
apply(auto simp: nth_of.simps mopup_b_def nth_append shift.simps)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4198
done
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4199
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4200
lemma fetch_aft_erase_c_o: 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4201
 "fetch (mopup_a n @ shift mopup_b (2 * n)) (2 * n + 4) Oc 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4202
 = (W0, Suc (2 * n + 2))"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4203
apply(subgoal_tac "length (mopup_a n) = 4 * n")
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4204
apply(subgoal_tac "2*n + 4 = Suc (2*n + 3)", simp only: fetch.simps)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4205
apply(auto simp: nth_of.simps mopup_b_def nth_append shift.simps)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4206
done
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4207
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4208
lemma fetch_aft_erase_c_b: 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4209
 "fetch (mopup_a n @ shift mopup_b (2 * n)) (2 * n + 4) Bk 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4210
 = (R, Suc (2 * n + 1))"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4211
apply(subgoal_tac "length (mopup_a n) = 4 * n")
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4212
apply(subgoal_tac "2*n + 4 = Suc (2*n + 3)", simp only: fetch.simps)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4213
apply(auto simp: nth_of.simps mopup_b_def nth_append shift.simps)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4214
done
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4215
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4216
lemma fetch_left_moving_o: 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4217
 "(fetch (mopup_a n @ shift mopup_b (2 * n)) (2 * n + 5) Oc) 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4218
 = (L, 2*n + 6)"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4219
apply(subgoal_tac "length (mopup_a n) = 4 * n")
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4220
apply(subgoal_tac "2*n + 5 = Suc (2*n + 4)", simp only: fetch.simps)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4221
apply(auto simp: nth_of.simps mopup_b_def nth_append shift.simps)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4222
done
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4223
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4224
lemma fetch_left_moving_b: 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4225
 "(fetch (mopup_a n @ shift mopup_b (2 * n)) (2 * n + 5) Bk)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4226
  = (L, 2*n + 5)"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4227
apply(subgoal_tac "length (mopup_a n) = 4 * n")
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4228
apply(subgoal_tac "2*n + 5 = Suc (2*n + 4)", simp only: fetch.simps)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4229
apply(auto simp: nth_of.simps mopup_b_def nth_append shift.simps)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4230
done
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4231
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4232
lemma fetch_jump_over2_b:
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4233
  "(fetch (mopup_a n @ shift mopup_b (2 * n)) (2 * n + 6) Bk) 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4234
 = (R, 0)"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4235
apply(subgoal_tac "length (mopup_a n) = 4 * n")
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4236
apply(subgoal_tac "2*n + 6 = Suc (2*n + 5)", simp only: fetch.simps)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4237
apply(auto simp: nth_of.simps mopup_b_def nth_append shift.simps)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4238
done
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4239
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4240
lemma fetch_jump_over2_o: 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4241
"(fetch (mopup_a n @ shift mopup_b (2 * n)) (2 * n + 6) Oc) 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4242
 = (L, 2*n + 6)"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4243
apply(subgoal_tac "length (mopup_a n) = 4 * n")
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4244
apply(subgoal_tac "2*n + 6 = Suc (2*n + 5)", simp only: fetch.simps)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4245
apply(auto simp: nth_of.simps mopup_b_def nth_append shift.simps)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4246
done
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4247
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4248
lemmas mopupfetchs = 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4249
fetch_bef_erase_a_o fetch_bef_erase_a_b fetch_bef_erase_b_b 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4250
fetch_jump_over1_o fetch_jump_over1_b fetch_aft_erase_a_o 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4251
fetch_aft_erase_a_b fetch_aft_erase_b_b fetch_aft_erase_c_o 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4252
fetch_aft_erase_c_b fetch_left_moving_o fetch_left_moving_b 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4253
fetch_jump_over2_b fetch_jump_over2_o
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4254
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4255
declare 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4256
  mopup_jump_over2.simps[simp del] mopup_left_moving.simps[simp del]
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4257
  mopup_aft_erase_c.simps[simp del] mopup_aft_erase_b.simps[simp del] 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4258
  mopup_aft_erase_a.simps[simp del] mopup_jump_over1.simps[simp del]
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4259
  mopup_bef_erase_a.simps[simp del] mopup_bef_erase_b.simps[simp del]
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4260
  mopup_stop.simps[simp del]
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4261
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4262
lemma [simp]: 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4263
  "\<lbrakk>mopup_bef_erase_a (s, l, Oc # xs) lm n ires\<rbrakk> \<Longrightarrow> 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4264
  mopup_bef_erase_b (Suc s, l, Bk # xs) lm n ires"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4265
apply(auto simp: mopup_bef_erase_a.simps mopup_bef_erase_b.simps )
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4266
apply(rule_tac x = "m - 1" in exI, rule_tac x = rn in exI)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4267
apply(case_tac m, simp, simp)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4268
done
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4269
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4270
lemma mopup_false1:
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4271
  "\<lbrakk>0 < s; s \<le> 2 * n; s mod 2 = Suc 0;  \<not> Suc s \<le> 2 * n\<rbrakk> 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4272
  \<Longrightarrow> RR"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4273
apply(arith)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4274
done
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4275
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4276
lemma [simp]: 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4277
 "\<lbrakk>n < length lm; 0 < s; s \<le> 2 * n; s mod 2 = Suc 0; 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4278
   mopup_bef_erase_a (s, l, Oc # xs) lm n ires; r = Oc # xs\<rbrakk>
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4279
 \<Longrightarrow> (Suc s \<le> 2 * n \<longrightarrow> mopup_bef_erase_b (Suc s, l, Bk # xs) lm n ires)  \<and>
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4280
     (\<not> Suc s \<le> 2 * n \<longrightarrow> mopup_jump_over1 (Suc s, l, Bk # xs) lm n ires) "
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4281
apply(auto elim: mopup_false1)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4282
done
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4283
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4284
lemma drop_tape_of_cons: 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4285
  "\<lbrakk>Suc q < length lm; x = lm ! q\<rbrakk> \<Longrightarrow> <drop q lm> = Oc # Oc \<up> x @ Bk # <drop (Suc q) lm>"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4286
by (metis Suc_lessD append_Cons list.simps(2) nth_drop' replicate_Suc tape_of_nl_cons)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4287
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4288
lemma erase2jumpover1:
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4289
  "\<lbrakk>q < length list; 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4290
             \<forall>rn. <drop q list> \<noteq> Oc # Oc \<up> abc_lm_v (a # list) (Suc q) @ Bk # <drop (Suc q) list> @ Bk \<up> rn\<rbrakk>
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4291
       \<Longrightarrow> <drop q list> = Oc # Oc \<up> abc_lm_v (a # list) (Suc q)"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4292
apply(erule_tac x = 0 in allE, simp)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4293
apply(case_tac "Suc q < length list")
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4294
apply(erule_tac notE)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4295
apply(rule_tac drop_tape_of_cons, simp_all add: abc_lm_v.simps)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4296
apply(subgoal_tac "length list = Suc q", auto)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4297
apply(subgoal_tac "drop q list = [list ! q]")
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4298
apply(simp add: tape_of_nl_abv)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4299
by (metis append_Nil2 append_eq_conv_conj lessI nth_drop')
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4300
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4301
lemma erase2jumpover2:
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4302
  "\<lbrakk>q < length list; \<forall>rn. <drop q list> @ Bk # Bk \<up> n \<noteq>
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4303
  Oc # Oc \<up> abc_lm_v (a # list) (Suc q) @ Bk # <drop (Suc q) list> @ Bk \<up> rn\<rbrakk>
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4304
  \<Longrightarrow> RR"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4305
apply(case_tac "Suc q < length list")
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4306
apply(erule_tac x = "Suc n" in allE, simp)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4307
apply(erule_tac notE)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4308
apply(rule_tac drop_tape_of_cons, simp_all add: abc_lm_v.simps)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4309
apply(subgoal_tac "length list = Suc q", auto)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4310
apply(erule_tac x = "n" in allE, simp)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4311
by (metis append_Nil2 append_eq_conv_conj lessI nth_drop'
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4312
  replicate_Suc tape_of_nat_list.simps(2) tape_of_nl_abv) 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4313
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4314
lemma mopup_bef_erase_a_2_jump_over[simp]: 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4315
 "\<lbrakk>n < length lm; 0 < s; s mod 2 = Suc 0;  s \<le> 2 * n;
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4316
   mopup_bef_erase_a (s, l, Bk # xs) lm n ires; \<not> (Suc (Suc s) \<le> 2 * n)\<rbrakk> 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4317
\<Longrightarrow> mopup_jump_over1 (s', Bk # l, xs) lm n ires"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4318
apply(auto simp: mopup_bef_erase_a.simps mopup_jump_over1.simps)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4319
apply(case_tac m, auto simp: mod_ex1)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4320
apply(subgoal_tac "n = Suc q", auto)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4321
apply(rule_tac x = "Suc ln" in exI, rule_tac x = 0 in exI, auto)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4322
apply(case_tac [!] lm, simp_all)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4323
apply(case_tac [!] rn, auto elim: erase2jumpover1 erase2jumpover2)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4324
apply(erule_tac x = 0 in allE, simp)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4325
apply(rule_tac classical, simp)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4326
apply(erule_tac notE)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4327
apply(rule_tac drop_tape_of_cons, simp_all add: abc_lm_v.simps)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4328
done
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4329
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4330
lemma Suc_Suc_div:  "\<lbrakk>0 < s; s mod 2 = Suc 0; Suc (Suc s) \<le> 2 * n\<rbrakk>
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4331
           \<Longrightarrow> (Suc (Suc (s div 2))) \<le> n"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4332
apply(arith)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4333
done
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4334
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4335
lemma mopup_bef_erase_a_2_a[simp]: 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4336
 "\<lbrakk>n < length lm; 0 < s; s mod 2 = Suc 0; 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4337
   mopup_bef_erase_a (s, l, Bk # xs) lm n ires; 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4338
   Suc (Suc s) \<le> 2 * n\<rbrakk> \<Longrightarrow> 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4339
   mopup_bef_erase_a (Suc (Suc s), Bk # l, xs) lm n ires"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4340
apply(auto simp: mopup_bef_erase_a.simps)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4341
apply(subgoal_tac "drop (Suc (Suc (s div 2))) lm \<noteq> []")
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4342
apply(case_tac m, simp_all)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4343
apply(rule_tac x = "Suc (abc_lm_v lm (Suc (s div 2)))" in exI, 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4344
      rule_tac x = rn in exI, auto simp: mod_ex1)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4345
apply(rule_tac drop_tape_of_cons)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4346
apply arith
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4347
apply(simp add: abc_lm_v.simps)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4348
done
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4349
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4350
lemma mopup_false2: 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4351
 "\<lbrakk>0 < s; s \<le> 2 * n; 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4352
   s mod 2 = Suc 0; Suc s \<noteq> 2 * n;
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4353
   \<not> Suc (Suc s) \<le> 2 * n\<rbrakk> \<Longrightarrow> RR"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4354
apply(arith)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4355
done
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4356
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4357
lemma [simp]: "mopup_bef_erase_a (s, l, []) lm n ires \<Longrightarrow> 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4358
                        mopup_bef_erase_a (s, l, [Bk]) lm n ires"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4359
apply(auto simp: mopup_bef_erase_a.simps)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4360
done
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4361
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4362
lemma [simp]:
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4363
   "\<lbrakk>n < length lm; 0 < s; s \<le> 2 * n; s mod 2 = Suc 0; \<not> Suc (Suc s) \<le> 2 *n;
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4364
     mopup_bef_erase_a (s, l, []) lm n ires\<rbrakk>
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4365
    \<Longrightarrow>  mopup_jump_over1 (s', Bk # l, []) lm n ires"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4366
by auto
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4367
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4368
lemma "mopup_bef_erase_b (s, l, Oc # xs) lm n ires \<Longrightarrow> l \<noteq> []"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4369
apply(auto simp: mopup_bef_erase_b.simps)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4370
done
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4371
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4372
lemma [simp]: "mopup_bef_erase_b (s, l, Oc # xs) lm n ires = False"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4373
apply(auto simp: mopup_bef_erase_b.simps )
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4374
done
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4375
 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4376
lemma [simp]: "\<lbrakk>0 < s; s \<le> 2 *n; s mod 2 \<noteq> Suc 0\<rbrakk> \<Longrightarrow> 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4377
                                      (s - Suc 0) mod 2 = Suc 0"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4378
apply(arith)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4379
done
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4380
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4381
lemma [simp]: "\<lbrakk>0 < s; s \<le> 2 *n; s mod 2 \<noteq> Suc 0\<rbrakk> \<Longrightarrow>
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4382
                                       s - Suc 0 \<le> 2 * n"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4383
apply(simp)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4384
done
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4385
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4386
lemma [simp]: "\<lbrakk>0 < s; s \<le> 2 *n; s mod 2 \<noteq> Suc 0\<rbrakk> \<Longrightarrow> \<not> s \<le> Suc 0"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4387
apply(arith)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4388
done
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4389
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4390
lemma [simp]: "\<lbrakk>n < length lm; 0 < s; s \<le> 2 * n; 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4391
               s mod 2 \<noteq> Suc 0; 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4392
               mopup_bef_erase_b (s, l, Bk # xs) lm n ires; r = Bk # xs\<rbrakk> 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4393
           \<Longrightarrow> mopup_bef_erase_a (s - Suc 0, Bk # l, xs) lm n ires"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4394
apply(auto simp: mopup_bef_erase_b.simps mopup_bef_erase_a.simps)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4395
done
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4396
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4397
lemma [simp]: "\<lbrakk>mopup_bef_erase_b (s, l, []) lm n ires\<rbrakk> \<Longrightarrow> 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4398
                   mopup_bef_erase_a (s - Suc 0, Bk # l, []) lm n ires"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4399
apply(auto simp: mopup_bef_erase_b.simps mopup_bef_erase_a.simps)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4400
done
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4401
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4402
lemma [simp]: 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4403
   "\<lbrakk>n < length lm;
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4404
    mopup_jump_over1 (Suc (2 * n), l, Oc # xs) lm n ires;
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4405
    r = Oc # xs\<rbrakk>
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4406
  \<Longrightarrow> mopup_jump_over1 (Suc (2 * n), Oc # l, xs) lm n ires"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4407
apply(auto simp: mopup_jump_over1.simps)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4408
apply(rule_tac x = ln in exI, rule_tac x = "Suc m1" in exI,
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4409
       rule_tac x = "m2 - 1" in exI, simp)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4410
apply(case_tac "m2", simp, simp)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4411
apply(rule_tac x = ln in exI, rule_tac x = "Suc m1" in exI, 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4412
      rule_tac x = "m2 - 1" in exI)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4413
apply(case_tac m2, simp, simp)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4414
done
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4415
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4416
lemma mopup_jump_over1_2_aft_erase_a[simp]:  
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4417
 "\<lbrakk>n < length lm; mopup_jump_over1 (Suc (2 * n), l, Bk # xs) lm n ires\<rbrakk>
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4418
  \<Longrightarrow> mopup_aft_erase_a (Suc (Suc (2 * n)), Bk # l, xs) lm n ires"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4419
apply(simp only: mopup_jump_over1.simps mopup_aft_erase_a.simps)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4420
apply(erule_tac exE)+
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4421
apply(rule_tac x = ln in exI, rule_tac x = "Suc 0" in exI)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4422
apply(case_tac m2, simp)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4423
apply(rule_tac x = rn in exI, rule_tac x = "drop (Suc n) lm" in exI, 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4424
      simp)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4425
apply(simp)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4426
done
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4427
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4428
lemma [simp]: 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4429
 "\<lbrakk>n < length lm; mopup_jump_over1 (Suc (2 * n), l, []) lm n ires\<rbrakk> \<Longrightarrow> 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4430
    mopup_aft_erase_a (Suc (Suc (2 * n)), Bk # l, []) lm n ires"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4431
apply(rule mopup_jump_over1_2_aft_erase_a, simp)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4432
apply(auto simp: mopup_jump_over1.simps)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4433
apply(rule_tac x = ln in exI, rule_tac x = "Suc (abc_lm_v lm n)" in exI, 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4434
      rule_tac x = 0 in exI, simp add: )
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4435
done
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4436
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4437
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4438
lemma [simp]: 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4439
 "\<lbrakk>n < length lm; 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4440
   mopup_aft_erase_a (Suc (Suc (2 * n)), l, Oc # xs) lm n ires\<rbrakk> 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4441
 \<Longrightarrow> mopup_aft_erase_b (Suc (Suc (Suc (2 * n))), l, Bk # xs) lm n ires"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4442
apply(auto simp: mopup_aft_erase_a.simps mopup_aft_erase_b.simps )
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4443
apply(case_tac ml)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4444
apply(simp_all add: tape_of_nl_cons split: if_splits)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4445
apply(case_tac a, simp_all)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4446
apply(rule_tac x = rn in exI, rule_tac x = "[]" in exI, simp)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4447
apply(rule_tac x = rn in exI, rule_tac x = "[nat]" in exI, simp)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4448
apply(case_tac a, simp_all)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4449
apply(rule_tac x = rn in exI, rule_tac x = "list" in exI, simp)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4450
apply(rule_tac x = rn in exI)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4451
apply(rule_tac x = "nat # list" in exI, simp add: tape_of_nl_cons)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4452
done
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4453
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4454
lemma [simp]:
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4455
  "mopup_aft_erase_a (Suc (Suc (2 * n)), l, Bk # xs) lm n ires \<Longrightarrow> l \<noteq> []"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4456
apply(auto simp: mopup_aft_erase_a.simps)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4457
done
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4458
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4459
lemma [simp]:
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4460
  "\<lbrakk>n < length lm;
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4461
    mopup_aft_erase_a (Suc (Suc (2 * n)), l, Bk # xs) lm n ires\<rbrakk>
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4462
  \<Longrightarrow> mopup_left_moving (5 + 2 * n, tl l, hd l # Bk # xs) lm n ires"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4463
apply(simp only: mopup_aft_erase_a.simps mopup_left_moving.simps)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4464
apply(erule exE)+
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4465
apply(case_tac lnr, simp)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4466
apply(case_tac ml, simp, simp add: tape_of_nl_cons split: if_splits)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4467
apply(auto)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4468
apply(case_tac ml, simp_all add: tape_of_nl_cons split: if_splits)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4469
apply(rule_tac x = "Suc rn" in exI, simp)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4470
done
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4471
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4472
lemma [simp]:
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4473
  "mopup_aft_erase_a (Suc (Suc (2 * n)), l, []) lm n ires \<Longrightarrow> l \<noteq> []"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4474
apply(simp only: mopup_aft_erase_a.simps)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4475
apply(erule exE)+
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4476
apply(auto)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4477
done
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4478
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4479
lemma [simp]:
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4480
  "\<lbrakk>n < length lm; mopup_aft_erase_a (Suc (Suc (2 * n)), l, []) lm n ires\<rbrakk>
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4481
  \<Longrightarrow> mopup_left_moving (5 + 2 * n, tl l, [hd l]) lm n ires"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4482
apply(simp only: mopup_aft_erase_a.simps mopup_left_moving.simps)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4483
apply(erule exE)+
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4484
apply(subgoal_tac "ml = [] \<and> rn = 0", erule conjE, erule conjE, simp)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4485
apply(case_tac lnr, simp)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4486
apply(rule_tac x = lnl in exI, simp)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4487
apply(rule_tac x = 1 in exI, simp)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4488
apply(case_tac ml, simp, simp)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4489
done
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4490
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4491
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4492
lemma [simp]: "mopup_aft_erase_b (2 * n + 3, l, Oc # xs) lm n ires = False"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4493
apply(auto simp: mopup_aft_erase_b.simps )
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4494
done
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4495
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4496
lemma tape_of_ex1[intro]: 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4497
  "\<exists>rna ml. Oc \<up> a @ Bk \<up> rn = <ml::nat list> @ Bk \<up> rna \<or> Oc \<up> a @ Bk \<up> rn = Bk # <ml> @ Bk \<up> rna"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4498
apply(case_tac a, simp_all)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4499
apply(rule_tac x = rn in exI, rule_tac x = "[]" in exI, simp)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4500
apply(rule_tac x = rn in exI, rule_tac x = "[nat]" in exI, simp)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4501
done
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4502
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4503
lemma [intro]: "\<exists>rna ml. Oc \<up> a @ Bk # <list::nat list> @ Bk \<up> rn = 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4504
  <ml> @ Bk \<up> rna \<or> Oc \<up> a @ Bk # <list> @ Bk \<up> rn = Bk # <ml::nat list> @ Bk \<up> rna"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4505
apply(case_tac "list = []", simp add: replicate_Suc[THEN sym] del: replicate_Suc)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4506
apply(rule_tac rn = "Suc rn" in tape_of_ex1)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4507
apply(case_tac a, simp)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4508
apply(rule_tac x = rn in exI, rule_tac x = list in exI, simp)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4509
apply(rule_tac x = rn in exI, rule_tac x = "nat # list" in exI)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4510
apply(simp add: tape_of_nl_cons)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4511
done
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4512
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4513
lemma [simp]: 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4514
 "\<lbrakk>n < length lm; 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4515
   mopup_aft_erase_c (2 * n + 4, l, Oc # xs) lm n ires\<rbrakk>
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4516
  \<Longrightarrow> mopup_aft_erase_b (Suc (Suc (Suc (2 * n))), l, Bk # xs) lm n ires"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4517
apply(auto simp: mopup_aft_erase_c.simps mopup_aft_erase_b.simps )
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4518
apply(case_tac ml, simp_all add: tape_of_nl_cons split: if_splits, auto)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4519
done
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4520
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4521
lemma mopup_aft_erase_c_aft_erase_a[simp]: 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4522
 "\<lbrakk>n < length lm; mopup_aft_erase_c (2 * n + 4, l, Bk # xs) lm n ires\<rbrakk> 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4523
 \<Longrightarrow> mopup_aft_erase_a (Suc (Suc (2 * n)), Bk # l, xs) lm n ires"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4524
apply(simp only: mopup_aft_erase_c.simps mopup_aft_erase_a.simps )
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4525
apply(erule_tac exE)+
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4526
apply(erule conjE, erule conjE, erule disjE)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4527
apply(subgoal_tac "ml = []", simp, case_tac rn, 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4528
      simp, simp, rule conjI)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4529
apply(rule_tac x = lnl in exI, rule_tac x = "Suc lnr" in exI, simp)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4530
apply(rule_tac x = nat in exI, rule_tac x = "[]" in exI, simp)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4531
apply(case_tac ml, simp, simp add: tape_of_nl_cons split: if_splits)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4532
apply(rule_tac x = lnl in exI, rule_tac x = "Suc lnr" in exI, simp)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4533
apply(rule_tac x = rn in exI, rule_tac x = "ml" in exI, simp)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4534
done
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4535
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4536
lemma [simp]: 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4537
 "\<lbrakk>n < length lm; mopup_aft_erase_c (2 * n + 4, l, []) lm n ires\<rbrakk> 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4538
 \<Longrightarrow> mopup_aft_erase_a (Suc (Suc (2 * n)), Bk # l, []) lm n ires"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4539
apply(rule mopup_aft_erase_c_aft_erase_a, simp)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4540
apply(simp only: mopup_aft_erase_c.simps)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4541
apply(erule exE)+
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4542
apply(rule_tac x = lnl in exI, rule_tac x = lnr in exI, simp add: )
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4543
apply(rule_tac x = 0 in exI, rule_tac x = "[]" in exI, simp)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4544
done
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4545
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4546
lemma mopup_aft_erase_b_2_aft_erase_c[simp]:
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4547
  "\<lbrakk>n < length lm; mopup_aft_erase_b (2 * n + 3, l, Bk # xs) lm n ires\<rbrakk>  
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4548
 \<Longrightarrow> mopup_aft_erase_c (4 + 2 * n, Bk # l, xs) lm n ires"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4549
apply(auto simp: mopup_aft_erase_b.simps mopup_aft_erase_c.simps)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4550
apply(rule_tac x = "lnl" in exI, rule_tac x = "Suc lnr" in exI, simp)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4551
apply(rule_tac x = "lnl" in exI, rule_tac x = "Suc lnr" in exI, simp)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4552
done
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4553
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4554
lemma [simp]: 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4555
 "\<lbrakk>n < length lm; mopup_aft_erase_b (2 * n + 3, l, []) lm n ires\<rbrakk> 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4556
 \<Longrightarrow> mopup_aft_erase_c (4 + 2 * n, Bk # l, []) lm n ires"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4557
apply(rule_tac mopup_aft_erase_b_2_aft_erase_c, simp)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4558
apply(simp add: mopup_aft_erase_b.simps)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4559
done
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4560
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4561
lemma [simp]: 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4562
    "mopup_left_moving (2 * n + 5, l, Oc # xs) lm n ires \<Longrightarrow> l \<noteq> []"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4563
apply(auto simp: mopup_left_moving.simps)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4564
done
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4565
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4566
lemma [simp]:  
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4567
 "\<lbrakk>n < length lm; mopup_left_moving (2 * n + 5, l, Oc # xs) lm n ires\<rbrakk>
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4568
  \<Longrightarrow> mopup_jump_over2 (2 * n + 6, tl l, hd l # Oc # xs) lm n ires"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4569
apply(simp only: mopup_left_moving.simps mopup_jump_over2.simps)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4570
apply(erule_tac exE)+
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4571
apply(erule conjE, erule disjE, erule conjE)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4572
apply(case_tac rn, simp, simp add: )
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4573
apply(case_tac "hd l", simp add:  )
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4574
apply(case_tac "abc_lm_v lm n", simp)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4575
apply(rule_tac x = "lnl" in exI, rule_tac x = rn in exI, 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4576
      rule_tac x = "Suc 0" in exI, rule_tac x = 0 in exI)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4577
apply(case_tac lnl, simp, simp, simp add: exp_ind[THEN sym], simp)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4578
apply(case_tac "abc_lm_v lm n", simp)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4579
apply(case_tac lnl, simp, simp)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4580
apply(rule_tac x = lnl in exI, rule_tac x = rn in exI)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4581
apply(rule_tac x = nat in exI, rule_tac x = "Suc (Suc 0)" in exI, simp)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4582
done
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4583
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4584
lemma [simp]: "mopup_left_moving (2 * n + 5, l, xs) lm n ires \<Longrightarrow> l \<noteq> []"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4585
apply(auto simp: mopup_left_moving.simps)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4586
done
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4587
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4588
lemma [simp]:
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4589
  "\<lbrakk>n < length lm; mopup_left_moving (2 * n + 5, l, Bk # xs) lm n ires\<rbrakk> 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4590
 \<Longrightarrow> mopup_left_moving (2 * n + 5, tl l, hd l # Bk # xs) lm n ires"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4591
apply(simp only: mopup_left_moving.simps)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4592
apply(erule exE)+
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4593
apply(case_tac lnr, simp)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4594
apply(rule_tac x = lnl in exI, rule_tac x = nat in exI, simp)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4595
apply(rule_tac x = "Suc rn" in exI, simp)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4596
done
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4597
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4598
lemma [simp]: 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4599
"\<lbrakk>n < length lm; mopup_left_moving (2 * n + 5, l, []) lm n ires\<rbrakk>
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4600
    \<Longrightarrow> mopup_left_moving (2 * n + 5, tl l, [hd l]) lm n ires"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4601
apply(simp only: mopup_left_moving.simps)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4602
apply(erule exE)+
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4603
apply(case_tac lnr, auto)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4604
done
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4605
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4606
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4607
lemma [simp]: 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4608
 "mopup_jump_over2 (2 * n + 6, l, Oc # xs) lm n ires \<Longrightarrow> l \<noteq> []"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4609
apply(auto simp: mopup_jump_over2.simps )
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4610
done
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4611
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4612
lemma [simp]: 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4613
"\<lbrakk>n < length lm; mopup_jump_over2 (2 * n + 6, l, Oc # xs) lm n ires\<rbrakk>
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4614
 \<Longrightarrow>  mopup_jump_over2 (2 * n + 6, tl l, hd l # Oc # xs) lm n ires"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4615
apply(simp only: mopup_jump_over2.simps)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4616
apply(erule_tac exE)+
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4617
apply(simp add:  , erule conjE, erule_tac conjE)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4618
apply(case_tac m1, simp)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4619
apply(rule_tac x = ln in exI, rule_tac x = rn in exI, 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4620
      rule_tac x = 0 in exI, simp)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4621
apply(case_tac ln, simp, simp, simp only: exp_ind[THEN sym], simp)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4622
apply(rule_tac x = ln in exI, rule_tac x = rn in exI, 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4623
      rule_tac x = nat in exI, rule_tac x = "Suc m2" in exI, simp)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4624
done
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4625
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4626
lemma [simp]: 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4627
 "\<lbrakk>n < length lm; mopup_jump_over2 (2 * n + 6, l, Bk # xs) lm n ires\<rbrakk> 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4628
  \<Longrightarrow> mopup_stop (0, Bk # l, xs) lm n ires"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4629
apply(auto simp: mopup_jump_over2.simps mopup_stop.simps)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4630
apply(simp_all add: tape_of_nat_abv exp_ind[THEN sym])
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4631
done
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4632
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4633
lemma [simp]: "mopup_jump_over2 (2 * n + 6, l, []) lm n ires = False"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4634
apply(simp only: mopup_jump_over2.simps, simp)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4635
done
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4636
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4637
lemma mopup_inv_step:
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4638
  "\<lbrakk>n < length lm; mopup_inv (s, l, r) lm n ires\<rbrakk>
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4639
  \<Longrightarrow> mopup_inv (step (s, l, r) (mopup_a n @ shift mopup_b (2 * n), 0)) lm n ires"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4640
apply(case_tac r, case_tac [2] a)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4641
apply(auto split:if_splits simp add:step.simps)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4642
apply(simp_all add: mopupfetchs)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4643
done
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4644
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4645
declare mopup_inv.simps[simp del]
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4646
lemma mopup_inv_steps: 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4647
"\<lbrakk>n < length lm; mopup_inv (s, l, r) lm n ires\<rbrakk> \<Longrightarrow> 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4648
     mopup_inv (steps (s, l, r) (mopup_a n @ shift mopup_b (2 * n), 0)  stp) lm n ires"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4649
apply(induct_tac stp, simp add: steps.simps)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4650
apply(simp add: step_red)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4651
apply(case_tac "steps (s, l, r) 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4652
                (mopup_a n @ shift mopup_b (2 * n), 0) na", simp)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4653
apply(rule_tac mopup_inv_step, simp, simp)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4654
done
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4655
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4656
fun abc_mopup_stage1 :: "config \<Rightarrow> nat \<Rightarrow> nat"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4657
  where
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4658
  "abc_mopup_stage1 (s, l, r) n = 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4659
           (if s > 0 \<and> s \<le> 2*n then 6
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4660
            else if s = 2*n + 1 then 4
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4661
            else if s \<ge> 2*n + 2 \<and> s \<le> 2*n + 4 then 3
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4662
            else if s = 2*n + 5 then 2
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4663
            else if s = 2*n + 6 then 1
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4664
            else 0)"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4665
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4666
fun abc_mopup_stage2 :: "config \<Rightarrow> nat \<Rightarrow> nat"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4667
  where
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4668
  "abc_mopup_stage2 (s, l, r) n = 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4669
           (if s > 0 \<and> s \<le> 2*n then length r
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4670
            else if s = 2*n + 1 then length r
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4671
            else if s = 2*n + 5 then length l
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4672
            else if s = 2*n + 6 then length l
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4673
            else if s \<ge> 2*n + 2 \<and> s \<le> 2*n + 4 then length r
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4674
            else 0)"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4675
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4676
fun abc_mopup_stage3 :: "config \<Rightarrow> nat \<Rightarrow> nat"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4677
  where
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4678
  "abc_mopup_stage3 (s, l, r) n = 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4679
          (if s > 0 \<and> s \<le> 2*n then 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4680
              if hd r = Bk then 0
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4681
              else 1
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4682
           else if s = 2*n + 2 then 1 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4683
           else if s = 2*n + 3 then 0
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4684
           else if s = 2*n + 4 then 2
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4685
           else 0)"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4686
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4687
fun abc_mopup_measure :: "(config \<times> nat) \<Rightarrow> (nat \<times> nat \<times> nat)"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4688
  where
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4689
  "abc_mopup_measure (c, n) = 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4690
    (abc_mopup_stage1 c n, abc_mopup_stage2 c n, 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4691
                                       abc_mopup_stage3 c n)"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4692
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4693
definition abc_mopup_LE ::
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4694
   "(((nat \<times> cell list \<times> cell list) \<times> nat) \<times> 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4695
    ((nat \<times> cell list \<times> cell list) \<times> nat)) set"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4696
  where
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4697
  "abc_mopup_LE \<equiv> (inv_image lex_triple abc_mopup_measure)"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4698
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4699
lemma wf_abc_mopup_le[intro]: "wf abc_mopup_LE"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4700
by(auto intro:wf_inv_image simp:abc_mopup_LE_def lex_triple_def lex_pair_def)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4701
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4702
lemma [simp]: "mopup_bef_erase_a (a, aa, []) lm n ires = False"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4703
apply(auto simp: mopup_bef_erase_a.simps)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4704
done
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4705
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4706
lemma [simp]: "mopup_bef_erase_b (a, aa, []) lm n ires = False"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4707
apply(auto simp: mopup_bef_erase_b.simps) 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4708
done
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4709
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4710
lemma [simp]: "mopup_aft_erase_b (2 * n + 3, aa, []) lm n ires = False"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4711
apply(auto simp: mopup_aft_erase_b.simps)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4712
done
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4713
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4714
declare mopup_inv.simps[simp del]
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4715
term mopup_inv
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4716
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4717
lemma [simp]: 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4718
  "\<lbrakk>0 < q; q \<le> n\<rbrakk> \<Longrightarrow> 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4719
     (fetch (mopup_a n @ shift mopup_b (2 * n)) (2*q) Bk) = (R, 2*q - 1)"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4720
apply(case_tac q, simp, simp)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4721
apply(auto simp: fetch.simps nth_of.simps nth_append)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4722
apply(subgoal_tac "mopup_a n ! (4 * nat + 2) = 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4723
                     mopup_a (Suc nat) ! ((4 * nat) + 2)", 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4724
      simp add: mopup_a.simps nth_append)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4725
apply(rule mopup_a_nth, auto)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4726
done
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4727
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4728
lemma mopup_halt:
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4729
  assumes 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4730
  less: "n < length lm"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4731
  and inv: "mopup_inv (Suc 0, l, r) lm n ires"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4732
  and f: "f = (\<lambda> stp. (steps (Suc 0, l, r) (mopup_a n @ shift mopup_b (2 * n), 0) stp, n))"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4733
  and P: "P = (\<lambda> (c, n). is_final c)"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4734
  shows "\<exists> stp. P (f stp)"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4735
proof(rule_tac LE = abc_mopup_LE in halt_lemma)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4736
  show "wf abc_mopup_LE" by(auto)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4737
next
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4738
  show "\<forall>n. \<not> P (f n) \<longrightarrow> (f (Suc n), f n) \<in> abc_mopup_LE"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4739
  proof(rule_tac allI, rule_tac impI)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4740
    fix na
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4741
    assume h: "\<not> P (f na)"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4742
    show "(f (Suc na), f na) \<in> abc_mopup_LE"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4743
    proof(simp add: f)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4744
      obtain a b c where g:"steps (Suc 0, l, r) (mopup_a n @ shift mopup_b (2 * n), 0) na = (a, b, c)"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4745
        apply(case_tac "steps (Suc 0, l, r) (mopup_a n @ shift mopup_b (2 * n), 0) na", auto)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4746
        done
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4747
      then have "mopup_inv (a, b, c) lm n ires"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4748
        thm mopup_inv_steps
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4749
        using inv less mopup_inv_steps[of n lm "Suc 0" l r ires na]
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4750
        apply(simp)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4751
        done
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4752
      moreover have "a > 0"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4753
        using h g
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4754
        apply(simp add: f P)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4755
        done
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4756
      ultimately have "((step (a, b, c) (mopup_a n @ shift mopup_b (2 * n), 0), n), (a, b, c), n) \<in> abc_mopup_LE"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4757
        apply(case_tac c, case_tac [2] aa)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4758
        apply(auto split:if_splits simp add:step.simps mopup_inv.simps)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4759
        apply(simp_all add: mopupfetchs abc_mopup_LE_def lex_triple_def lex_pair_def )
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4760
        done
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4761
      thus "((step (steps (Suc 0, l, r) (mopup_a n @ shift mopup_b (2 * n), 0) na) 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4762
        (mopup_a n @ shift mopup_b (2 * n), 0), n),
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4763
        steps (Suc 0, l, r) (mopup_a n @ shift mopup_b (2 * n), 0) na, n)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4764
        \<in> abc_mopup_LE"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4765
        using g by simp
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4766
    qed
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4767
  qed
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4768
qed     
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4769
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4770
lemma mopup_inv_start: 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4771
  "n < length am \<Longrightarrow> mopup_inv (Suc 0, Bk # Bk # ires, <am> @ Bk \<up> k) am n ires"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4772
apply(auto simp: mopup_inv.simps mopup_bef_erase_a.simps mopup_jump_over1.simps)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4773
apply(case_tac [!] am, auto split: if_splits simp: tape_of_nl_cons)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4774
apply(rule_tac x = "Suc a" in exI, rule_tac x = k in exI, simp)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4775
apply(case_tac [!] n, simp_all add: abc_lm_v.simps)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4776
apply(case_tac k, simp, simp_all)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4777
done
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4778
      
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4779
lemma mopup_correct:
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4780
  assumes less: "n < length (am::nat list)"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4781
  and rs: "abc_lm_v am n = rs"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4782
  shows "\<exists> stp i j. (steps (Suc 0, Bk # Bk # ires, <am> @ Bk \<up> k) (mopup_a n @ shift mopup_b (2 * n), 0) stp)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4783
    = (0, Bk\<up>i @ Bk # Bk # ires, Oc # Oc\<up> rs @ Bk\<up>j)"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4784
using less
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4785
proof -
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4786
  have a: "mopup_inv (Suc 0, Bk # Bk # ires, <am> @ Bk \<up> k) am n ires"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4787
    using less
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4788
    apply(simp add: mopup_inv_start)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4789
    done    
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4790
  then have "\<exists> stp. is_final (steps (Suc 0, Bk # Bk # ires, <am> @ Bk \<up> k) (mopup_a n @ shift mopup_b (2 * n), 0) stp)"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4791
    using less mopup_halt[of n am  "Bk # Bk # ires" "<am> @ Bk \<up> k" ires
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4792
      "(\<lambda>stp. (steps (Suc 0, Bk # Bk # ires, <am> @ Bk \<up> k) (mopup_a n @ shift mopup_b (2 * n), 0) stp, n))"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4793
      "(\<lambda>(c, n). is_final c)"]
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4794
    apply(simp)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4795
    done
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4796
  from this obtain stp where b:
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4797
    "is_final (steps (Suc 0, Bk # Bk # ires, <am> @ Bk \<up> k) (mopup_a n @ shift mopup_b (2 * n), 0) stp)" ..
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4798
  from a b have
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4799
    "mopup_inv (steps (Suc 0, Bk # Bk # ires, <am> @ Bk \<up> k) (mopup_a n @ shift mopup_b (2 * n), 0) stp)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4800
    am n ires"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4801
    apply(rule_tac mopup_inv_steps, simp_all add: less)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4802
    done    
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4803
  from b and this show "?thesis"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4804
    apply(rule_tac x = stp in exI, simp)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4805
    apply(case_tac "steps (Suc 0, Bk # Bk # ires, <am> @ Bk \<up> k) 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4806
      (mopup_a n @ shift mopup_b (2 * n), 0) stp")
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4807
    apply(simp add: mopup_inv.simps mopup_stop.simps rs)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4808
    using rs
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4809
    apply(simp add: tape_of_nat_abv)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4810
    done
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4811
qed
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4812
47
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4813
(*we can use Hoare_plus here*)
60
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4814
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4815
lemma wf_mopup[intro]: "tm_wf (mopup n, 0)"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4816
apply(induct n, simp add: mopup.simps shift.simps mopup_b_def tm_wf.simps)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4817
apply(auto simp: mopup.simps shift.simps mopup_b_def tm_wf.simps)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4818
done
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4819
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4820
lemma length_tp:
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4821
  "\<lbrakk>ly = layout_of ap; tp = tm_of ap\<rbrakk> \<Longrightarrow> 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4822
  start_of ly (length ap) = Suc (length tp div 2)"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4823
apply(frule_tac length_tp', simp_all)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4824
apply(simp add: start_of.simps)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4825
done
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4826
47
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4827
lemma compile_correct_halt: 
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4828
  assumes layout: "ly = layout_of ap"
60
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4829
  and compile: "tp = tm_of ap"
47
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4830
  and crsp: "crsp ly (0, lm) (Suc 0, l, r) ires"
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4831
  and abc_halt: "abc_steps_l (0, lm) ap stp = (length ap, am)"
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4832
  and rs_loc: "n < length am"
60
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4833
  and rs: "abc_lm_v am n = rs"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4834
  and off: "off = length tp div 2"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4835
  shows "\<exists> stp i j. steps (Suc 0, l, r) (tp @ shift (mopup n) off, 0) stp = (0, Bk\<up>i @ Bk # Bk # ires, Oc\<up>Suc rs @ Bk\<up>j)"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4836
proof -
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4837
  have "\<exists> stp k. steps (Suc 0, l, r) (tp, 0) stp = (Suc off, Bk # Bk # ires, <am> @ Bk\<up>k)"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4838
    using assms tp_correct'[of ly ap tp lm l r ires stp am]
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4839
    by(simp add: length_tp)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4840
  then obtain stp k where "steps (Suc 0, l, r) (tp, 0) stp = (Suc off, Bk # Bk # ires, <am> @ Bk\<up>k)"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4841
    by blast
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4842
  then have a: "steps (Suc 0, l, r) (tp@shift (mopup n) off , 0) stp = (Suc off, Bk # Bk # ires, <am> @ Bk\<up>k)"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4843
    using assms
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4844
    by(auto intro: tm_append_first_steps_eq)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4845
  have "\<exists> stp i j. (steps (Suc 0, Bk # Bk # ires, <am> @ Bk \<up> k) (mopup_a n @ shift mopup_b (2 * n), 0) stp)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4846
    = (0, Bk\<up>i @ Bk # Bk # ires, Oc # Oc\<up> rs @ Bk\<up>j)"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4847
    using assms
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4848
    by(auto intro: mopup_correct)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4849
  then obtain stpb i j where 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4850
    "steps (Suc 0, Bk # Bk # ires, <am> @ Bk \<up> k) (mopup_a n @ shift mopup_b (2 * n), 0) stpb
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4851
    = (0, Bk\<up>i @ Bk # Bk # ires, Oc # Oc\<up> rs @ Bk\<up>j)" by blast
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4852
  then have b: "steps (Suc 0 + off, Bk # Bk # ires, <am> @ Bk \<up> k) (tp @ shift (mopup n) off, 0) stpb
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4853
    = (0, Bk\<up>i @ Bk # Bk # ires, Oc # Oc\<up> rs @ Bk\<up>j)"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4854
    using assms wf_mopup
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4855
   thm tm_append_second_halt_eq
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4856
    apply(drule_tac tm_append_second_halt_eq, auto)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4857
    done
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4858
  from a b show "?thesis"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4859
    by(rule_tac x = "stp + stpb" in exI, simp add: steps_add)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4860
qed
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4861
 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4862
declare mopup.simps[simp del]
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4863
lemma abc_step_red2:
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4864
  "abc_steps_l (s, lm) p (Suc n) = (let (as', am') = abc_steps_l (s, lm) p n in
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4865
                                    abc_step_l (as', am') (abc_fetch as' p))"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4866
apply(case_tac "abc_steps_l (s, lm) p n", simp)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4867
apply(drule_tac abc_step_red, simp)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4868
done
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4869
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4870
lemma crsp_steps2:
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4871
  assumes 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4872
  layout: "ly = layout_of ap"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4873
  and compile: "tp = tm_of ap"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4874
  and crsp: "crsp ly (0, lm) (Suc 0, l, r) ires"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4875
  and nothalt: "as < length ap"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4876
  and aexec: "abc_steps_l (0, lm) ap stp = (as, am)"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4877
  shows "\<exists>stpa\<ge>stp. crsp ly (as, am) (steps (Suc 0, l, r) (tp, 0) stpa) ires"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4878
using nothalt aexec
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4879
proof(induct stp arbitrary: as am)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4880
  case 0
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4881
  thus "?case"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4882
    using crsp
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4883
    by(rule_tac x = 0 in exI, auto simp: abc_steps_l.simps steps.simps crsp)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4884
next
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4885
  case (Suc stp as am)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4886
  have ind: 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4887
    "\<And> as am.  \<lbrakk>as < length ap; abc_steps_l (0, lm) ap stp = (as, am)\<rbrakk> 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4888
    \<Longrightarrow> \<exists>stpa\<ge>stp. crsp ly (as, am) (steps (Suc 0, l, r) (tp, 0) stpa) ires" by fact
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4889
  have a: "as < length ap" by fact
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4890
  have b: "abc_steps_l (0, lm) ap (Suc stp) = (as, am)" by fact
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4891
  obtain as' am' where c: "abc_steps_l (0, lm) ap stp = (as', am')" 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4892
    by(case_tac "abc_steps_l (0, lm) ap stp", auto)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4893
  then have d: "as' < length ap"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4894
    using a b
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4895
    by(simp add: abc_step_red2, case_tac "as' < length ap", simp,
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4896
      simp add: abc_fetch.simps abc_steps_l.simps abc_step_l.simps)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4897
  have "\<exists>stpa\<ge>stp. crsp ly (as', am') (steps (Suc 0, l, r) (tp, 0) stpa) ires"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4898
    using d c ind by simp
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4899
  from this obtain stpa where e: 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4900
    "stpa \<ge> stp \<and>  crsp ly (as', am') (steps (Suc 0, l, r) (tp, 0) stpa) ires"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4901
    by blast
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4902
  obtain s' l' r' where f: "steps (Suc 0, l, r) (tp, 0) stpa = (s', l', r')"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4903
    by(case_tac "steps (Suc 0, l, r) (tp, 0) stpa", auto)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4904
  obtain ins where g: "abc_fetch as' ap = Some ins" using d 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4905
    by(case_tac "abc_fetch as' ap",auto simp: abc_fetch.simps)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4906
  then have "\<exists>stp> (0::nat). crsp ly (abc_step_l (as', am') (Some ins)) 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4907
    (steps (s', l', r') (tp, 0) stp) ires "
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4908
    using layout compile e f 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4909
    by(rule_tac crsp_step, simp_all)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4910
  then obtain stpb where "stpb > 0 \<and> crsp ly (abc_step_l (as', am') (Some ins)) 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4911
    (steps (s', l', r') (tp, 0) stpb) ires" ..
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4912
  from this show "?case" using b e g f c
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4913
    by(rule_tac x = "stpa + stpb" in exI, simp add: steps_add abc_step_red2)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4914
qed
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4915
    
47
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4916
lemma compile_correct_unhalt: 
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4917
  assumes layout: "ly = layout_of ap"
60
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4918
  and compile: "tp = tm_of ap"
47
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4919
  and crsp: "crsp ly (0, lm) (Suc 0, l, r) ires"
60
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4920
  and off: "off = length tp div 2"
47
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4921
  and abc_unhalt: "\<forall> stp. (\<lambda> (as, am). as < length ap) (abc_steps_l (0, lm) ap stp)"
60
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4922
  shows "\<forall> stp.\<not> is_final (steps (Suc 0, l, r) (tp @ shift (mopup n) off, 0) stp)"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4923
using assms
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4924
proof(rule_tac allI, rule_tac notI)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4925
  fix stp
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4926
  assume h: "is_final (steps (Suc 0, l, r) (tp @ shift (mopup n) off, 0) stp)"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4927
  obtain as am where a: "abc_steps_l (0, lm) ap stp = (as, am)"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4928
    by(case_tac "abc_steps_l (0, lm) ap stp", auto)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4929
  then have b: "as < length ap"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4930
    using abc_unhalt
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4931
    by(erule_tac x = stp in allE, simp)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4932
  have "\<exists> stpa\<ge>stp. crsp ly (as, am) (steps (Suc 0, l, r) (tp, 0) stpa) ires "
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4933
    using assms b a
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4934
    apply(rule_tac crsp_steps2, simp_all)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4935
    done
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4936
  then obtain stpa where
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4937
    "stpa\<ge>stp \<and> crsp ly (as, am) (steps (Suc 0, l, r) (tp, 0) stpa) ires" ..
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4938
  then obtain s' l' r' where b: "(steps (Suc 0, l, r) (tp, 0) stpa) = (s', l', r') \<and> 
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4939
       stpa\<ge>stp \<and> crsp ly (as, am) (s', l', r') ires"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4940
    by(case_tac "steps (Suc 0, l, r) (tp, 0) stpa", auto)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4941
  hence c:
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4942
    "(steps (Suc 0, l, r) (tp @ shift (mopup n) off, 0) stpa) = (s', l', r')"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4943
    by(rule_tac tm_append_first_steps_eq, simp_all add: crsp.simps)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4944
  from b have d: "s' > 0 \<and> stpa \<ge> stp"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4945
    by(simp add: crsp.simps)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4946
  then obtain diff where e: "stpa = stp + diff"   by (metis le_iff_add)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4947
  obtain s'' l'' r'' where f:
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4948
    "steps (Suc 0, l, r) (tp @ shift (mopup n) off, 0) stp = (s'', l'', r'') \<and> is_final (s'', l'', r'')"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4949
    using h
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4950
    by(case_tac "steps (Suc 0, l, r) (tp @ shift (mopup n) off, 0) stp", auto)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4951
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4952
  then have "is_final (steps (s'', l'', r'') (tp @ shift (mopup n) off, 0) diff)"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4953
    by(auto intro: is_final_steps)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4954
  then have "is_final (steps (Suc 0, l, r) (tp @ shift (mopup n) off, 0) stpa)"
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4955
    using e
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4956
    by(simp add: steps_add f)
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4957
  from this and c d show "False" by simp
c8ff97d9f8da new version of abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
  4958
qed
47
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4959
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4960
end
251e192339b7 added abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  4961