thys/Recursive.thy
author Christian Urban <christian dot urban at kcl dot ac dot uk>
Mon, 22 Apr 2013 08:26:16 +0100
changeset 237 06a6db387cd2
parent 230 49dcc0b9b0b3
child 240 696081f445c2
permissions -rw-r--r--
updated and small modification
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
163
67063c5365e1 changed theory names to uppercase
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 131
diff changeset
     1
theory Recursive
229
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
     2
imports Abacus Rec_Def Abacus_Hoare
70
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
     3
begin
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
     4
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
     5
fun addition :: "nat \<Rightarrow> nat \<Rightarrow> nat \<Rightarrow> abc_prog"
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
     6
  where
166
99a180fd4194 removed some dead code
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 163
diff changeset
     7
  "addition m n p = [Dec m 4, Inc n, Inc p, Goto 0, Dec p 7, Inc m, Goto 4]"
70
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
     8
237
06a6db387cd2 updated and small modification
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 230
diff changeset
     9
(* moves register m to register n *)
70
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    10
fun mv_box :: "nat \<Rightarrow> nat \<Rightarrow> abc_prog"
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    11
  where
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    12
  "mv_box m n = [Dec m 3, Inc n, Goto 0]"
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    13
166
99a180fd4194 removed some dead code
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 163
diff changeset
    14
text {* The compilation of @{text "z"}-operator. *}
70
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    15
definition rec_ci_z :: "abc_inst list"
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    16
  where
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    17
  "rec_ci_z \<equiv> [Goto 1]"
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    18
166
99a180fd4194 removed some dead code
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 163
diff changeset
    19
text {* The compilation of @{text "s"}-operator. *}
70
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    20
definition rec_ci_s :: "abc_inst list"
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    21
  where
237
06a6db387cd2 updated and small modification
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 230
diff changeset
    22
  "rec_ci_s \<equiv> addition 0 1 2 [+] [Inc 1]"
70
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    23
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    24
166
99a180fd4194 removed some dead code
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 163
diff changeset
    25
text {* The compilation of @{text "id i j"}-operator *}
70
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    26
fun rec_ci_id :: "nat \<Rightarrow> nat \<Rightarrow> abc_inst list"
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    27
  where
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    28
  "rec_ci_id i j = addition j i (i + 1)"
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    29
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    30
fun mv_boxes :: "nat \<Rightarrow> nat \<Rightarrow> nat \<Rightarrow> abc_inst list"
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    31
  where
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    32
  "mv_boxes ab bb 0 = []" |
166
99a180fd4194 removed some dead code
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 163
diff changeset
    33
  "mv_boxes ab bb (Suc n) = mv_boxes ab bb n [+] mv_box (ab + n) (bb + n)"
70
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    34
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    35
fun empty_boxes :: "nat \<Rightarrow> abc_inst list"
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    36
  where
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    37
  "empty_boxes 0 = []" |
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    38
  "empty_boxes (Suc n) = empty_boxes n [+] [Dec n 2, Goto 0]"
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    39
237
06a6db387cd2 updated and small modification
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 230
diff changeset
    40
fun cn_merge_gs :: "(abc_inst list \<times> nat \<times> nat) list \<Rightarrow> nat \<Rightarrow> abc_inst list"
70
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    41
  where
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    42
  "cn_merge_gs [] p = []" |
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    43
  "cn_merge_gs (g # gs) p = 
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    44
      (let (gprog, gpara, gn) = g in 
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    45
         gprog [+] mv_box gpara p [+] cn_merge_gs gs (Suc p))"
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    46
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    47
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    48
text {*
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    49
  The compiler of recursive functions, where @{text "rec_ci recf"} return 
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    50
  @{text "(ap, arity, fp)"}, where @{text "ap"} is the Abacus program, @{text "arity"} is the 
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    51
  arity of the recursive function @{text "recf"}, 
166
99a180fd4194 removed some dead code
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 163
diff changeset
    52
  @{text "fp"} is the amount of memory which is going to be
70
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    53
  used by @{text "ap"} for its execution. 
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    54
*}
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    55
203
514809bb7ce4 simplified slightly rec_compilation function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 190
diff changeset
    56
fun rec_ci :: "recf \<Rightarrow> abc_inst list \<times> nat \<times> nat"
70
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    57
  where
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    58
  "rec_ci z = (rec_ci_z, 1, 2)" |
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    59
  "rec_ci s = (rec_ci_s, 1, 3)" |
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    60
  "rec_ci (id m n) = (rec_ci_id m n, m, m + 2)" |
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    61
  "rec_ci (Cn n f gs) = 
203
514809bb7ce4 simplified slightly rec_compilation function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 190
diff changeset
    62
      (let cied_gs = map (\<lambda> g. rec_ci g) gs in
514809bb7ce4 simplified slightly rec_compilation function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 190
diff changeset
    63
       let (fprog, fpara, fn) = rec_ci f in 
514809bb7ce4 simplified slightly rec_compilation function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 190
diff changeset
    64
       let pstr = Max (set (Suc n # fn # (map (\<lambda> (aprog, p, n). n) cied_gs))) in
70
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    65
       let qstr = pstr + Suc (length gs) in 
203
514809bb7ce4 simplified slightly rec_compilation function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 190
diff changeset
    66
       (cn_merge_gs cied_gs pstr [+] mv_boxes 0 qstr n [+] 
70
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    67
          mv_boxes pstr 0 (length gs) [+] fprog [+] 
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    68
            mv_box fpara pstr [+] empty_boxes (length gs) [+] 
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    69
             mv_box pstr n [+] mv_boxes qstr 0 n, n,  qstr + n))" |
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    70
  "rec_ci (Pr n f g) = 
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    71
         (let (fprog, fpara, fn) = rec_ci f in 
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    72
          let (gprog, gpara, gn) = rec_ci g in 
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    73
          let p = Max (set ([n + 3, fn, gn])) in 
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    74
          let e = length gprog + 7 in 
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    75
           (mv_box n p [+] fprog [+] mv_box n (Suc n) [+] 
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    76
               (([Dec p e] [+] gprog [+] 
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    77
                 [Inc n, Dec (Suc n) 3, Goto 1]) @
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    78
                     [Dec (Suc (Suc n)) 0, Inc (Suc n), Goto (length gprog + 4)]),
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    79
             Suc n, p + 1))" |
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    80
  "rec_ci (Mn n f) =
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    81
         (let (fprog, fpara, fn) = rec_ci f in 
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    82
          let len = length (fprog) in 
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    83
            (fprog @ [Dec (Suc n) (len + 5), Dec (Suc n) (len + 3),
166
99a180fd4194 removed some dead code
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 163
diff changeset
    84
             Goto (len + 1), Inc n, Goto 0], n, max (Suc n) fn))"
70
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    85
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    86
declare rec_ci.simps [simp del] rec_ci_s_def[simp del] 
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    87
        rec_ci_z_def[simp del] rec_ci_id.simps[simp del]
229
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
    88
        mv_boxes.simps[simp del] 
70
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    89
        mv_box.simps[simp del] addition.simps[simp del]
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    90
  
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    91
declare abc_steps_l.simps[simp del] abc_fetch.simps[simp del] 
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    92
        abc_step_l.simps[simp del] 
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    93
237
06a6db387cd2 updated and small modification
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 230
diff changeset
    94
fun addition_inv :: "nat \<times> nat list \<Rightarrow> nat \<Rightarrow> nat \<Rightarrow> nat \<Rightarrow> nat list \<Rightarrow> bool"
70
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    95
  where
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    96
  "addition_inv (as, lm') m n p lm = 
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    97
        (let sn = lm ! n in
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    98
         let sm = lm ! m in
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    99
         lm ! p = 0 \<and>
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   100
             (if as = 0 then \<exists> x. x \<le> lm ! m \<and> lm' = lm[m := x,
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   101
                                    n := (sn + sm - x), p := (sm - x)]
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   102
             else if as = 1 then \<exists> x. x < lm ! m \<and> lm' = lm[m := x,
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   103
                            n := (sn + sm - x - 1), p := (sm - x - 1)]
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   104
             else if as = 2 then \<exists> x. x < lm ! m \<and> lm' = lm[m := x, 
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   105
                               n := (sn + sm - x), p := (sm - x - 1)]
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   106
             else if as = 3 then \<exists> x. x < lm ! m \<and> lm' = lm[m := x,
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   107
                                   n := (sn + sm - x), p := (sm - x)]
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   108
             else if as = 4 then \<exists> x. x \<le> lm ! m \<and> lm' = lm[m := x,
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   109
                                       n := (sn + sm), p := (sm - x)] 
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   110
             else if as = 5 then \<exists> x. x < lm ! m \<and> lm' = lm[m := x, 
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   111
                                  n := (sn + sm), p := (sm - x - 1)] 
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   112
             else if as = 6 then \<exists> x. x < lm ! m \<and> lm' =
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   113
                     lm[m := Suc x, n := (sn + sm), p := (sm - x - 1)]
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   114
             else if as = 7 then lm' = lm[m := sm, n := (sn + sm)]
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   115
             else False))"
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   116
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   117
fun addition_stage1 :: "nat \<times> nat list \<Rightarrow> nat \<Rightarrow> nat \<Rightarrow> nat"
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   118
  where
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   119
  "addition_stage1 (as, lm) m p = 
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   120
          (if as = 0 \<or> as = 1 \<or> as = 2 \<or> as = 3 then 2 
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   121
           else if as = 4 \<or> as = 5 \<or> as = 6 then 1
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   122
           else 0)"
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   123
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   124
fun addition_stage2 :: "nat \<times> nat list \<Rightarrow> nat \<Rightarrow>  nat \<Rightarrow> nat"
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   125
  where
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   126
  "addition_stage2 (as, lm) m p = 
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   127
              (if 0 \<le> as \<and> as \<le> 3 then lm ! m
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   128
               else if 4 \<le> as \<and> as \<le> 6 then lm ! p
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   129
               else 0)"
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   130
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   131
fun addition_stage3 :: "nat \<times> nat list \<Rightarrow> nat \<Rightarrow> nat \<Rightarrow> nat"
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   132
  where
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   133
  "addition_stage3 (as, lm) m p = 
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   134
             (if as = 1 then 4  
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   135
              else if as = 2 then 3 
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   136
              else if as = 3 then 2
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   137
              else if as = 0 then 1 
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   138
              else if as = 5 then 2
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   139
              else if as = 6 then 1 
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   140
              else if as = 4 then 0 
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   141
              else 0)"
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   142
237
06a6db387cd2 updated and small modification
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 230
diff changeset
   143
fun addition_measure :: "((nat \<times> nat list) \<times> nat \<times> nat) \<Rightarrow> (nat \<times> nat \<times> nat)"
70
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   144
  where
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   145
  "addition_measure ((as, lm), m, p) =
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   146
     (addition_stage1 (as, lm) m p, 
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   147
      addition_stage2 (as, lm) m p,
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   148
      addition_stage3 (as, lm) m p)"
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   149
237
06a6db387cd2 updated and small modification
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 230
diff changeset
   150
definition addition_LE :: "(((nat \<times> nat list) \<times> nat \<times> nat) \<times> ((nat \<times> nat list) \<times> nat \<times> nat)) set"
70
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   151
  where "addition_LE \<equiv> (inv_image lex_triple addition_measure)"
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   152
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   153
lemma [simp]: "wf addition_LE"
237
06a6db387cd2 updated and small modification
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 230
diff changeset
   154
by(auto simp: wf_inv_image addition_LE_def lex_triple_def lex_pair_def)
70
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   155
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   156
declare addition_inv.simps[simp del]
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   157
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   158
lemma addition_inv_init: 
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   159
  "\<lbrakk>m \<noteq> n; max m n < p; length lm > p; lm ! p = 0\<rbrakk> \<Longrightarrow>
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   160
                                   addition_inv (0, lm) m n p lm"
229
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   161
apply(simp add: addition_inv.simps Let_def)
70
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   162
apply(rule_tac x = "lm ! m" in exI, simp)
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   163
done
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   164
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   165
lemma [simp]: "abc_fetch 0 (addition m n p) = Some (Dec m 4)"
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   166
by(simp add: abc_fetch.simps addition.simps)
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   167
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   168
lemma [simp]: "abc_fetch (Suc 0) (addition m n p) = Some (Inc n)"
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   169
by(simp add: abc_fetch.simps addition.simps)
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   170
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   171
lemma [simp]: "abc_fetch 2 (addition m n p) = Some (Inc p)"
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   172
by(simp add: abc_fetch.simps addition.simps)
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   173
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   174
lemma [simp]: "abc_fetch 3 (addition m n p) = Some (Goto 0)"
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   175
by(simp add: abc_fetch.simps addition.simps)
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   176
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   177
lemma [simp]: "abc_fetch 4 (addition m n p) = Some (Dec p 7)"
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   178
by(simp add: abc_fetch.simps addition.simps)
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   179
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   180
lemma [simp]: "abc_fetch 5 (addition m n p) = Some (Inc m)"
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   181
by(simp add: abc_fetch.simps addition.simps)
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   182
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   183
lemma [simp]: "abc_fetch 6 (addition m n p) = Some (Goto 4)"
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   184
by(simp add: abc_fetch.simps addition.simps)
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   185
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   186
lemma [simp]:
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   187
  "\<lbrakk>m \<noteq> n; p < length lm; lm ! p = 0; m < p; n < p; x \<le> lm ! m; 0 < x\<rbrakk>
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   188
 \<Longrightarrow> \<exists>xa<lm ! m. lm[m := x, n := lm ! n + lm ! m - x, 
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   189
                    p := lm ! m - x, m := x - Suc 0] =
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   190
                 lm[m := xa, n := lm ! n + lm ! m - Suc xa,
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   191
                    p := lm ! m - Suc xa]"
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   192
apply(case_tac x, simp, simp)
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   193
apply(rule_tac x = nat in exI, simp add: list_update_swap 
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   194
                                         list_update_overwrite)
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   195
done
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   196
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   197
lemma [simp]:
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   198
  "\<lbrakk>m \<noteq> n; p < length lm; lm ! p = 0; m < p; n < p; x < lm ! m\<rbrakk>
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   199
   \<Longrightarrow> \<exists>xa<lm ! m. lm[m := x, n := lm ! n + lm ! m - Suc x,
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   200
                      p := lm ! m - Suc x, n := lm ! n + lm ! m - x]
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   201
                 = lm[m := xa, n := lm ! n + lm ! m - xa, 
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   202
                      p := lm ! m - Suc xa]"
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   203
apply(rule_tac x = x in exI, 
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   204
      simp add: list_update_swap list_update_overwrite)
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   205
done
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   206
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   207
lemma [simp]: 
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   208
  "\<lbrakk>m \<noteq> n; p < length lm; lm ! p = 0; m < p; n < p; x < lm ! m\<rbrakk>
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   209
   \<Longrightarrow> \<exists>xa<lm ! m. lm[m := x, n := lm ! n + lm ! m - x, 
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   210
                          p := lm ! m - Suc x, p := lm ! m - x]
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   211
                 = lm[m := xa, n := lm ! n + lm ! m - xa, 
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   212
                          p := lm ! m - xa]"
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   213
apply(rule_tac x = x in exI, simp add: list_update_overwrite)
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   214
done
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   215
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   216
lemma [simp]: 
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   217
  "\<lbrakk>m \<noteq> n; p < length lm; lm ! p = (0::nat); m < p; n < p; x < lm ! m\<rbrakk>
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   218
  \<Longrightarrow> \<exists>xa\<le>lm ! m. lm[m := x, n := lm ! n + lm ! m - x,
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   219
                                   p := lm ! m - x] = 
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   220
                  lm[m := xa, n := lm ! n + lm ! m - xa, 
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   221
                                   p := lm ! m - xa]"
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   222
apply(rule_tac x = x in exI, simp)
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   223
done
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   224
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   225
lemma [simp]: 
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   226
  "\<lbrakk>m \<noteq> n; p < length lm; lm ! p = 0; m < p; n < p;
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   227
    x \<le> lm ! m; lm ! m \<noteq> x\<rbrakk>
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   228
  \<Longrightarrow> \<exists>xa<lm ! m. lm[m := x, n := lm ! n + lm ! m, 
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   229
                       p := lm ! m - x, p := lm ! m - Suc x] 
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   230
               = lm[m := xa, n := lm ! n + lm ! m, 
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   231
                       p := lm ! m - Suc xa]"
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   232
apply(rule_tac x = x in exI, simp add: list_update_overwrite)
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   233
done
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   234
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   235
lemma [simp]:
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   236
  "\<lbrakk>m \<noteq> n; p < length lm; lm ! p = 0; m < p; n < p; x < lm ! m\<rbrakk>
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   237
  \<Longrightarrow> \<exists>xa<lm ! m. lm[m := x, n := lm ! n + lm ! m,
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   238
                             p := lm ! m - Suc x, m := Suc x]
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   239
                = lm[m := Suc xa, n := lm ! n + lm ! m, 
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   240
                             p := lm ! m - Suc xa]"
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   241
apply(rule_tac x = x in exI, 
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   242
     simp add: list_update_swap list_update_overwrite)
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   243
done
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   244
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   245
lemma [simp]: 
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   246
  "\<lbrakk>m \<noteq> n; p < length lm; lm ! p = 0; m < p; n < p; x < lm ! m\<rbrakk>
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   247
  \<Longrightarrow> \<exists>xa\<le>lm ! m. lm[m := Suc x, n := lm ! n + lm ! m, 
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   248
                             p := lm ! m - Suc x] 
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   249
               = lm[m := xa, n := lm ! n + lm ! m, p := lm ! m - xa]"
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   250
apply(rule_tac x = "Suc x" in exI, simp)
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   251
done
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   252
229
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   253
lemma abc_steps_zero: "abc_steps_l asm ap 0 = asm"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   254
apply(case_tac asm, simp add: abc_steps_l.simps)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   255
done
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   256
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   257
declare Let_def[simp]
70
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   258
lemma addition_halt_lemma: 
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   259
  "\<lbrakk>m \<noteq> n; max m n < p; length lm > p; lm ! p = 0\<rbrakk> \<Longrightarrow>
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   260
  \<forall>na. \<not> (\<lambda>(as, lm') (m, p). as = 7) 
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   261
        (abc_steps_l (0, lm) (addition m n p) na) (m, p) \<and> 
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   262
  addition_inv (abc_steps_l (0, lm) (addition m n p) na) m n p lm 
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   263
\<longrightarrow> addition_inv (abc_steps_l (0, lm) (addition m n p) 
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   264
                                 (Suc na)) m n p lm 
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   265
  \<and> ((abc_steps_l (0, lm) (addition m n p) (Suc na), m, p), 
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   266
     abc_steps_l (0, lm) (addition m n p) na, m, p) \<in> addition_LE"
229
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   267
apply(rule allI, rule impI, simp add: abc_step_red2)
70
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   268
apply(case_tac "(abc_steps_l (0, lm) (addition m n p) na)", simp)
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   269
apply(auto split:if_splits simp add: addition_inv.simps
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   270
                                 abc_steps_zero)
229
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   271
apply(simp_all add: addition.simps abc_steps_l.simps)
70
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   272
apply(auto simp add: addition_LE_def lex_triple_def lex_pair_def 
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   273
                     abc_step_l.simps addition_inv.simps 
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   274
                     abc_lm_v.simps abc_lm_s.simps nth_append
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   275
                split: if_splits)
229
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   276
apply(rule_tac [!] x = x in exI, simp_all add: list_update_overwrite Suc_diff_Suc)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   277
by (metis list_update_overwrite list_update_swap nat_neq_iff)
70
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   278
229
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   279
lemma  addition_correct': 
70
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   280
  "\<lbrakk>m \<noteq> n; max m n < p; length lm > p; lm ! p = 0\<rbrakk> \<Longrightarrow> 
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   281
  \<exists> stp. (\<lambda> (as, lm'). as = 7 \<and> addition_inv (as, lm') m n p lm) 
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   282
                        (abc_steps_l (0, lm) (addition m n p) stp)"
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   283
apply(insert halt_lemma2[of addition_LE
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   284
  "\<lambda> ((as, lm'), m, p). addition_inv (as, lm') m n p lm"
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   285
  "\<lambda> stp. (abc_steps_l (0, lm) (addition m n p) stp, m, p)"
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   286
  "\<lambda> ((as, lm'), m, p). as = 7"], 
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   287
  simp add: abc_steps_zero addition_inv_init)
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   288
apply(drule_tac addition_halt_lemma, simp, simp, simp,
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   289
      simp, erule_tac exE)
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   290
apply(rule_tac x = na in exI, 
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   291
      case_tac "(abc_steps_l (0, lm) (addition m n p) na)", auto)
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   292
done
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   293
229
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   294
lemma length_addition[simp]: "length (addition a b c) = 7"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   295
by(auto simp: addition.simps)
70
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   296
229
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   297
lemma addition_correct:
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   298
  "\<lbrakk>m \<noteq> n; max m n < p; length lm > p; lm ! p = 0\<rbrakk>
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   299
   \<Longrightarrow> {\<lambda> a. a = lm} (addition m n p) {\<lambda> nl. addition_inv (7, nl) m n p lm}"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   300
using assms
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   301
proof(rule_tac abc_Hoare_haltI, simp)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   302
  fix lma
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   303
  assume "m \<noteq> n" "m < p \<and> n < p" "p < length lm" "lm ! p = 0"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   304
  then have "\<exists> stp. (\<lambda> (as, lm'). as = 7 \<and> addition_inv (as, lm') m n p lm) 
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   305
                        (abc_steps_l (0, lm) (addition m n p) stp)"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   306
    by(rule_tac addition_correct', auto simp: addition_inv.simps)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   307
  thus "\<exists>na. abc_final (abc_steps_l (0, lm) (addition m n p) na) (addition m n p) \<and>
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   308
                  (\<lambda>nl. addition_inv (7, nl) m n p lm) abc_holds_for abc_steps_l (0, lm) (addition m n p) na"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   309
    apply(erule_tac exE)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   310
    apply(rule_tac x = stp in exI)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   311
    apply(auto)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   312
    done
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   313
qed
70
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   314
229
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   315
lemma compile_s_correct':
237
06a6db387cd2 updated and small modification
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 230
diff changeset
   316
  "{\<lambda>nl. nl = n # 0 \<up> 2 @ anything} 
06a6db387cd2 updated and small modification
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 230
diff changeset
   317
   addition 0 (Suc 0) 2 [+] [Inc (Suc 0)] 
06a6db387cd2 updated and small modification
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 230
diff changeset
   318
   {\<lambda>nl. nl = n # Suc n # 0 # anything}"
229
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   319
proof(rule_tac abc_Hoare_plus_halt)
237
06a6db387cd2 updated and small modification
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 230
diff changeset
   320
  show "{\<lambda>nl. nl = n # 0 \<up> 2 @ anything} 
06a6db387cd2 updated and small modification
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 230
diff changeset
   321
        addition 0 (Suc 0) 2 
06a6db387cd2 updated and small modification
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 230
diff changeset
   322
        {\<lambda>nl. addition_inv (7, nl) 0 (Suc 0) 2 (n # 0 \<up> 2 @ anything)}"
229
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   323
    by(rule_tac addition_correct, auto simp: numeral_2_eq_2)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   324
next
237
06a6db387cd2 updated and small modification
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 230
diff changeset
   325
  show "{\<lambda>nl. addition_inv (7, nl) 0 (Suc 0) 2 (n # 0 \<up> 2 @ anything)} 
06a6db387cd2 updated and small modification
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 230
diff changeset
   326
        [Inc (Suc 0)] 
06a6db387cd2 updated and small modification
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 230
diff changeset
   327
        {\<lambda>nl. nl = n # Suc n # 0 # anything}"
229
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   328
    by(rule_tac abc_Hoare_haltI, rule_tac x = 1 in exI, auto simp: addition_inv.simps 
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   329
      abc_steps_l.simps abc_step_l.simps abc_fetch.simps numeral_2_eq_2 abc_lm_s.simps abc_lm_v.simps)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   330
qed
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   331
  
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   332
declare rec_exec.simps[simp del]
70
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   333
229
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   334
lemma abc_comp_commute: "(A [+] B) [+] C = A [+] (B [+] C)"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   335
apply(auto simp: abc_comp.simps abc_shift.simps)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   336
apply(case_tac x, auto)
70
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   337
done
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   338
229
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   339
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   340
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   341
lemma compile_z_correct: 
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   342
  "\<lbrakk>rec_ci z = (ap, arity, fp); rec_exec z [n] = r\<rbrakk> \<Longrightarrow> 
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   343
  {\<lambda>nl. nl = n # 0 \<up> (fp - arity) @ anything} ap {\<lambda>nl. nl = n # r # 0 \<up> (fp - Suc arity) @ anything}"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   344
apply(rule_tac abc_Hoare_haltI)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   345
apply(rule_tac x = 1 in exI)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   346
apply(auto simp: abc_steps_l.simps rec_ci.simps rec_ci_z_def 
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   347
                 numeral_2_eq_2 abc_fetch.simps abc_step_l.simps rec_exec.simps)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   348
done
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   349
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   350
lemma compile_s_correct: 
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   351
  "\<lbrakk>rec_ci s = (ap, arity, fp); rec_exec s [n] = r\<rbrakk> \<Longrightarrow> 
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   352
  {\<lambda>nl. nl = n # 0 \<up> (fp - arity) @ anything} ap {\<lambda>nl. nl = n # r # 0 \<up> (fp - Suc arity) @ anything}"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   353
apply(auto simp: rec_ci.simps rec_ci_s_def compile_s_correct' rec_exec.simps)
70
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   354
done
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   355
229
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   356
lemma compile_id_correct':
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   357
  assumes "n < length args" 
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   358
  shows "{\<lambda>nl. nl = args @ 0 \<up> 2 @ anything} addition n (length args) (Suc (length args))
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   359
  {\<lambda>nl. nl = args @ rec_exec (recf.id (length args) n) args # 0 # anything}"
70
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   360
proof -
229
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   361
  have "{\<lambda>nl. nl = args @ 0 \<up> 2 @ anything} addition n (length args) (Suc (length args))
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   362
  {\<lambda>nl. addition_inv (7, nl) n (length args) (Suc (length args)) (args @ 0 \<up> 2 @ anything)}"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   363
    using assms
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   364
    by(rule_tac addition_correct, auto simp: numeral_2_eq_2 nth_append)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   365
  thus "?thesis"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   366
    using assms
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   367
    by(simp add: addition_inv.simps rec_exec.simps 
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   368
      nth_append numeral_2_eq_2 list_update_append)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   369
qed
70
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   370
229
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   371
lemma compile_id_correct: 
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   372
  "\<lbrakk>n < m; length xs = m; rec_ci (recf.id m n) = (ap, arity, fp); rec_exec (recf.id m n) xs = r\<rbrakk>
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   373
       \<Longrightarrow> {\<lambda>nl. nl = xs @ 0 \<up> (fp - arity) @ anything} ap {\<lambda>nl. nl = xs @ r # 0 \<up> (fp - Suc arity) @ anything}"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   374
apply(auto simp: rec_ci.simps rec_ci_id.simps compile_id_correct')
70
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   375
done
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   376
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   377
lemma cn_merge_gs_tl_app: 
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   378
  "cn_merge_gs (gs @ [g]) pstr = 
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   379
        cn_merge_gs gs pstr [+] cn_merge_gs [g] (pstr + length gs)"
229
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   380
apply(induct gs arbitrary: pstr, simp add: cn_merge_gs.simps, auto)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   381
apply(simp add: abc_comp_commute)
70
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   382
done
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   383
229
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   384
lemma footprint_ge: 
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   385
  "rec_ci a = (p, arity, fp) \<Longrightarrow> arity < fp"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   386
apply(induct a)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   387
apply(auto simp: rec_ci.simps)
70
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   388
apply(case_tac "rec_ci a", simp)
229
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   389
apply(case_tac "rec_ci a1", case_tac "rec_ci a2", auto)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   390
apply(case_tac "rec_ci a", auto)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   391
done
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   392
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   393
lemma param_pattern: 
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   394
  "\<lbrakk>terminate f xs; rec_ci f = (p, arity, fp)\<rbrakk> \<Longrightarrow> length xs = arity"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   395
apply(induct arbitrary: p arity fp rule: terminate.induct)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   396
apply(auto simp: rec_ci.simps)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   397
apply(case_tac "rec_ci f", simp)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   398
apply(case_tac "rec_ci f", case_tac "rec_ci g", simp)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   399
apply(case_tac "rec_ci f", case_tac "rec_ci gs", simp)
70
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   400
done
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   401
229
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   402
lemma replicate_merge_anywhere: 
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   403
  "x\<up>a @ x\<up>b @ ys = x\<up>(a+b) @ ys"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   404
by(simp add:replicate_add)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   405
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   406
fun mv_box_inv :: "nat \<times> nat list \<Rightarrow> nat \<Rightarrow> nat \<Rightarrow> nat list \<Rightarrow> bool"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   407
  where
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   408
  "mv_box_inv (as, lm) m n initlm = 
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   409
         (let plus = initlm ! m + initlm ! n in
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   410
           length initlm > max m n \<and> m \<noteq> n \<and> 
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   411
              (if as = 0 then \<exists> k l. lm = initlm[m := k, n := l] \<and> 
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   412
                    k + l = plus \<and> k \<le> initlm ! m 
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   413
              else if as = 1 then \<exists> k l. lm = initlm[m := k, n := l]
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   414
                             \<and> k + l + 1 = plus \<and> k < initlm ! m 
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   415
              else if as = 2 then \<exists> k l. lm = initlm[m := k, n := l] 
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   416
                              \<and> k + l = plus \<and> k \<le> initlm ! m
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   417
              else if as = 3 then lm = initlm[m := 0, n := plus]
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   418
              else False))"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   419
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   420
fun mv_box_stage1 :: "nat \<times> nat list \<Rightarrow> nat \<Rightarrow> nat"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   421
  where
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   422
  "mv_box_stage1 (as, lm) m  = 
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   423
            (if as = 3 then 0 
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   424
             else 1)"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   425
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   426
fun mv_box_stage2 :: "nat \<times> nat list \<Rightarrow> nat \<Rightarrow> nat"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   427
  where
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   428
  "mv_box_stage2 (as, lm) m = (lm ! m)"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   429
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   430
fun mv_box_stage3 :: "nat \<times> nat list \<Rightarrow> nat \<Rightarrow> nat"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   431
  where
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   432
  "mv_box_stage3 (as, lm) m = (if as = 1 then 3 
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   433
                                else if as = 2 then 2
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   434
                                else if as = 0 then 1 
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   435
                                else 0)"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   436
 
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   437
fun mv_box_measure :: "((nat \<times> nat list) \<times> nat) \<Rightarrow> (nat \<times> nat \<times> nat)"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   438
  where
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   439
  "mv_box_measure ((as, lm), m) = 
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   440
     (mv_box_stage1 (as, lm) m, mv_box_stage2 (as, lm) m,
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   441
      mv_box_stage3 (as, lm) m)"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   442
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   443
definition lex_pair :: "((nat \<times> nat) \<times> nat \<times> nat) set"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   444
  where
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   445
  "lex_pair = less_than <*lex*> less_than"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   446
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   447
definition lex_triple :: 
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   448
 "((nat \<times> (nat \<times> nat)) \<times> (nat \<times> (nat \<times> nat))) set"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   449
  where
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   450
  "lex_triple \<equiv> less_than <*lex*> lex_pair"
70
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   451
229
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   452
definition mv_box_LE :: 
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   453
 "(((nat \<times> nat list) \<times> nat) \<times> ((nat \<times> nat list) \<times> nat)) set"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   454
  where 
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   455
  "mv_box_LE \<equiv> (inv_image lex_triple mv_box_measure)"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   456
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   457
lemma wf_lex_triple: "wf lex_triple"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   458
  by (auto intro:wf_lex_prod simp:lex_triple_def lex_pair_def)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   459
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   460
lemma wf_mv_box_le[intro]: "wf mv_box_LE"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   461
by(auto intro:wf_inv_image wf_lex_triple simp: mv_box_LE_def)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   462
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   463
declare mv_box_inv.simps[simp del]
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   464
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   465
lemma mv_box_inv_init:  
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   466
"\<lbrakk>m < length initlm; n < length initlm; m \<noteq> n\<rbrakk> \<Longrightarrow> 
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   467
  mv_box_inv (0, initlm) m n initlm"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   468
apply(simp add: abc_steps_l.simps mv_box_inv.simps)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   469
apply(rule_tac x = "initlm ! m" in exI, 
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   470
      rule_tac x = "initlm ! n" in exI, simp)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   471
done
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   472
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   473
lemma [simp]: "abc_fetch 0 (mv_box m n) = Some (Dec m 3)"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   474
apply(simp add: mv_box.simps abc_fetch.simps)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   475
done
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   476
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   477
lemma [simp]: "abc_fetch (Suc 0) (mv_box m n) =
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   478
               Some (Inc n)"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   479
apply(simp add: mv_box.simps abc_fetch.simps)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   480
done
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   481
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   482
lemma [simp]: "abc_fetch 2 (mv_box m n) = Some (Goto 0)"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   483
apply(simp add: mv_box.simps abc_fetch.simps)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   484
done
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   485
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   486
lemma [simp]: "abc_fetch 3 (mv_box m n) = None"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   487
apply(simp add: mv_box.simps abc_fetch.simps)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   488
done
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   489
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   490
lemma replicate_Suc_iff_anywhere: "x # x\<up>b @ ys = x\<up>(Suc b) @ ys"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   491
by simp
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   492
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   493
lemma [simp]: 
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   494
  "\<lbrakk>m \<noteq> n; m < length initlm; n < length initlm;
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   495
    k + l = initlm ! m + initlm ! n; k \<le> initlm ! m; 0 < k\<rbrakk>
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   496
 \<Longrightarrow> \<exists>ka la. initlm[m := k, n := l, m := k - Suc 0] = 
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   497
     initlm[m := ka, n := la] \<and>
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   498
     Suc (ka + la) = initlm ! m + initlm ! n \<and> 
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   499
     ka < initlm ! m"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   500
apply(rule_tac x = "k - Suc 0" in exI, rule_tac x = l in exI, 
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   501
      simp, auto)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   502
apply(subgoal_tac 
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   503
      "initlm[m := k, n := l, m := k - Suc 0] = 
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   504
       initlm[n := l, m := k, m := k - Suc 0]")
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   505
apply(simp add: list_update_overwrite )
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   506
apply(simp add: list_update_swap)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   507
apply(simp add: list_update_swap)
70
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   508
done
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   509
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   510
lemma [simp]:
229
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   511
  "\<lbrakk>m \<noteq> n; m < length initlm; n < length initlm; 
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   512
    Suc (k + l) = initlm ! m + initlm ! n;
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   513
    k < initlm ! m\<rbrakk>
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   514
    \<Longrightarrow> \<exists>ka la. initlm[m := k, n := l, n := Suc l] = 
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   515
                initlm[m := ka, n := la] \<and> 
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   516
                ka + la = initlm ! m + initlm ! n \<and> 
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   517
                ka \<le> initlm ! m"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   518
apply(rule_tac x = k in exI, rule_tac x = "Suc l" in exI, auto)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   519
done
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   520
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   521
lemma [simp]: 
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   522
  "\<lbrakk>length initlm > max m n; m \<noteq> n\<rbrakk> \<Longrightarrow> 
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   523
   \<forall>na. \<not> (\<lambda>(as, lm) m. as = 3) 
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   524
    (abc_steps_l (0, initlm) (mv_box m n) na) m \<and> 
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   525
  mv_box_inv (abc_steps_l (0, initlm) 
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   526
           (mv_box m n) na) m n initlm \<longrightarrow>
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   527
  mv_box_inv (abc_steps_l (0, initlm) 
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   528
           (mv_box m n) (Suc na)) m n initlm \<and>
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   529
  ((abc_steps_l (0, initlm) (mv_box m n) (Suc na), m),
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   530
   abc_steps_l (0, initlm) (mv_box m n) na, m) \<in> mv_box_LE"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   531
apply(rule allI, rule impI, simp add: abc_step_red2)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   532
apply(case_tac "(abc_steps_l (0, initlm) (mv_box m n) na)",
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   533
      simp)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   534
apply(auto split:if_splits simp add:abc_steps_l.simps mv_box_inv.simps)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   535
apply(auto simp add: mv_box_LE_def lex_triple_def lex_pair_def 
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   536
                     abc_step_l.simps abc_steps_l.simps
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   537
                     mv_box_inv.simps abc_lm_v.simps abc_lm_s.simps
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   538
                split: if_splits )
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   539
apply(rule_tac x = k in exI, rule_tac x = "Suc l" in exI, simp)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   540
done
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   541
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   542
lemma mv_box_inv_halt: 
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   543
  "\<lbrakk>length initlm > max m n; m \<noteq> n\<rbrakk> \<Longrightarrow> 
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   544
  \<exists> stp. (\<lambda> (as, lm). as = 3 \<and> 
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   545
  mv_box_inv (as, lm) m n initlm) 
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   546
             (abc_steps_l (0::nat, initlm) (mv_box m n) stp)"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   547
apply(insert halt_lemma2[of mv_box_LE
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   548
    "\<lambda> ((as, lm), m). mv_box_inv (as, lm) m n initlm"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   549
    "\<lambda> stp. (abc_steps_l (0, initlm) (mv_box m n) stp, m)"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   550
    "\<lambda> ((as, lm), m). as = (3::nat)"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   551
    ])
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   552
apply(insert wf_mv_box_le)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   553
apply(simp add: mv_box_inv_init abc_steps_zero)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   554
apply(erule_tac exE)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   555
apply(rule_tac x = na in exI)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   556
apply(case_tac "(abc_steps_l (0, initlm) (mv_box m n) na)",
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   557
      simp, auto)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   558
done
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   559
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   560
lemma mv_box_halt_cond:
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   561
  "\<lbrakk>m \<noteq> n; mv_box_inv (a, b) m n lm; a = 3\<rbrakk> \<Longrightarrow> 
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   562
  b = lm[n := lm ! m + lm ! n, m := 0]"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   563
apply(simp add: mv_box_inv.simps, auto)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   564
apply(simp add: list_update_swap)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   565
done
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   566
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   567
lemma mv_box_correct':
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   568
  "\<lbrakk>length lm > max m n; m \<noteq> n\<rbrakk> \<Longrightarrow> 
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   569
  \<exists> stp. abc_steps_l (0::nat, lm) (mv_box m n) stp
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   570
  = (3, (lm[n := (lm ! m + lm ! n)])[m := 0::nat])"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   571
apply(drule mv_box_inv_halt, simp, erule_tac exE)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   572
apply(rule_tac x = stp in exI)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   573
apply(case_tac "abc_steps_l (0, lm) (mv_box m n) stp",
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   574
      simp)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   575
apply(erule_tac mv_box_halt_cond, auto)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   576
done
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   577
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   578
lemma length_mvbox[simp]: "length (mv_box m n) = 3"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   579
by(simp add: mv_box.simps)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   580
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   581
lemma mv_box_correct: 
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   582
  "\<lbrakk>length lm > max m n; m\<noteq>n\<rbrakk> 
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   583
  \<Longrightarrow> {\<lambda> nl. nl = lm} mv_box m n {\<lambda> nl. nl = lm[n := (lm ! m + lm ! n), m:=0]}"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   584
apply(drule_tac mv_box_correct', simp)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   585
apply(auto simp: abc_Hoare_halt_def)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   586
apply(rule_tac x = stp in exI, simp)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   587
done
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   588
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   589
declare list_update.simps(2)[simp del]
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   590
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   591
lemma [simp]:
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   592
  "\<lbrakk>length xs < gf; gf \<le> ft; n < length gs\<rbrakk>
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   593
  \<Longrightarrow> (rec_exec (gs ! n) xs # 0 \<up> (ft - Suc (length xs)) @ map (\<lambda>i. rec_exec i xs) (take n gs) @ 0 \<up> (length gs - n) @ 0 # 0 \<up> length xs @ anything)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   594
  [ft + n - length xs := rec_exec (gs ! n) xs, 0 := 0] =
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   595
  0 \<up> (ft - length xs) @ map (\<lambda>i. rec_exec i xs) (take n gs) @ rec_exec (gs ! n) xs # 0 \<up> (length gs - Suc n) @ 0 # 0 \<up> length xs @ anything"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   596
using list_update_append[of "rec_exec (gs ! n) xs # 0 \<up> (ft - Suc (length xs)) @ map (\<lambda>i. rec_exec i xs) (take n gs)"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   597
                             "0 \<up> (length gs - n) @ 0 # 0 \<up> length xs @ anything" "ft + n - length xs" "rec_exec (gs ! n) xs"]
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   598
apply(auto)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   599
apply(case_tac "length gs - n", simp, simp add: list_update.simps replicate_Suc_iff_anywhere Suc_diff_Suc del: replicate_Suc)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   600
apply(simp add: list_update.simps)
70
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   601
done
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   602
229
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   603
lemma compile_cn_gs_correct':
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   604
  assumes
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   605
  g_cond: "\<forall>g\<in>set (take n gs). terminate g xs \<and>
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   606
  (\<forall>x xa xb. rec_ci g = (x, xa, xb) \<longrightarrow> (\<forall>xc. {\<lambda>nl. nl = xs @ 0 \<up> (xb - xa) @ xc} x {\<lambda>nl. nl = xs @ rec_exec g xs # 0 \<up> (xb - Suc xa) @ xc}))"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   607
  and ft: "ft = max (Suc (length xs)) (Max (insert ffp ((\<lambda>(aprog, p, n). n) ` rec_ci ` set gs)))"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   608
  shows 
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   609
  "{\<lambda>nl. nl = xs @ 0 # 0 \<up> (ft + length gs) @ anything}
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   610
    cn_merge_gs (map rec_ci (take n gs)) ft
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   611
  {\<lambda>nl. nl = xs @ 0 \<up> (ft - length xs) @
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   612
                    map (\<lambda>i. rec_exec i xs) (take n gs) @ 0\<up>(length gs - n) @ 0 \<up> Suc (length xs) @ anything}"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   613
  using g_cond
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   614
proof(induct n)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   615
  case 0
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   616
  have "ft > length xs"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   617
    using ft
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   618
    by simp
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   619
  thus "?case"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   620
    apply(rule_tac abc_Hoare_haltI)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   621
    apply(rule_tac x = 0 in exI, simp add: abc_steps_l.simps replicate_add[THEN sym] 
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   622
      replicate_Suc[THEN sym] del: replicate_Suc)
70
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   623
    done
229
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   624
next
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   625
  case (Suc n)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   626
  have ind': "\<forall>g\<in>set (take n gs).
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   627
     terminate g xs \<and> (\<forall>x xa xb. rec_ci g = (x, xa, xb) \<longrightarrow> 
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   628
    (\<forall>xc. {\<lambda>nl. nl = xs @ 0 \<up> (xb - xa) @ xc} x {\<lambda>nl. nl = xs @ rec_exec g xs # 0 \<up> (xb - Suc xa) @ xc})) \<Longrightarrow>
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   629
    {\<lambda>nl. nl = xs @ 0 # 0 \<up> (ft + length gs) @ anything} cn_merge_gs (map rec_ci (take n gs)) ft 
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   630
    {\<lambda>nl. nl = xs @ 0 \<up> (ft - length xs) @ map (\<lambda>i. rec_exec i xs) (take n gs) @ 0 \<up> (length gs - n) @ 0 \<up> Suc (length xs) @ anything}"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   631
    by fact
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   632
  have g_newcond: "\<forall>g\<in>set (take (Suc n) gs).
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   633
     terminate g xs \<and> (\<forall>x xa xb. rec_ci g = (x, xa, xb) \<longrightarrow> (\<forall>xc. {\<lambda>nl. nl = xs @ 0 \<up> (xb - xa) @ xc} x {\<lambda>nl. nl = xs @ rec_exec g xs # 0 \<up> (xb - Suc xa) @ xc}))"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   634
    by fact
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   635
  from g_newcond have ind:
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   636
    "{\<lambda>nl. nl = xs @ 0 # 0 \<up> (ft + length gs) @ anything} cn_merge_gs (map rec_ci (take n gs)) ft 
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   637
    {\<lambda>nl. nl = xs @ 0 \<up> (ft - length xs) @ map (\<lambda>i. rec_exec i xs) (take n gs) @ 0 \<up> (length gs - n) @ 0 \<up> Suc (length xs) @ anything}"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   638
    apply(rule_tac ind', rule_tac ballI, erule_tac x = g in ballE, simp_all add: take_Suc)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   639
    by(case_tac "n < length gs", simp add:take_Suc_conv_app_nth, simp)    
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   640
  show "?case"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   641
  proof(cases "n < length gs")
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   642
    case True
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   643
    have h: "n < length gs" by fact
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   644
    thus "?thesis"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   645
    proof(simp add: take_Suc_conv_app_nth cn_merge_gs_tl_app)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   646
      obtain gp ga gf where a: "rec_ci (gs!n) = (gp, ga, gf)"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   647
        by (metis prod_cases3)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   648
      moreover have "min (length gs) n = n"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   649
        using h by simp
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   650
      moreover have 
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   651
        "{\<lambda>nl. nl = xs @ 0 # 0 \<up> (ft + length gs) @ anything}
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   652
        cn_merge_gs (map rec_ci (take n gs)) ft [+] (gp [+] mv_box ga (ft + n))
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   653
        {\<lambda>nl. nl = xs @ 0 \<up> (ft - length xs) @ map (\<lambda>i. rec_exec i xs) (take n gs) @ 
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   654
        rec_exec (gs ! n) xs # 0 \<up> (length gs - Suc n) @ 0 # 0 \<up> length xs @ anything}"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   655
      proof(rule_tac abc_Hoare_plus_halt)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   656
        show "{\<lambda>nl. nl = xs @ 0 # 0 \<up> (ft + length gs) @ anything} cn_merge_gs (map rec_ci (take n gs)) ft
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   657
          {\<lambda>nl. nl = xs @ 0 \<up> (ft - length xs) @ map (\<lambda>i. rec_exec i xs) (take n gs) @ 0 \<up> (length gs - n) @ 0 \<up> Suc (length xs) @ anything}"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   658
          using ind by simp
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   659
      next
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   660
        have x: "gs!n \<in> set (take (Suc n) gs)"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   661
          using h
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   662
          by(simp add: take_Suc_conv_app_nth)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   663
        have b: "terminate (gs!n) xs"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   664
          using a g_newcond h x
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   665
          by(erule_tac x = "gs!n" in ballE, simp_all)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   666
        hence c: "length xs = ga"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   667
          using a param_pattern by metis  
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   668
        have d: "gf > ga" using footprint_ge a by simp
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   669
        have e: "ft \<ge> gf" using ft a h
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   670
          by(simp,  rule_tac min_max.le_supI2, rule_tac Max_ge, simp, 
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   671
            rule_tac insertI2,  
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   672
            rule_tac f = "(\<lambda>(aprog, p, n). n)" and x = "rec_ci (gs!n)" in image_eqI, simp, 
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   673
            rule_tac x = "gs!n" in image_eqI, simp, simp)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   674
        show "{\<lambda>nl. nl = xs @ 0 \<up> (ft - length xs) @ 
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   675
          map (\<lambda>i. rec_exec i xs) (take n gs) @ 0 \<up> (length gs - n) @ 0 \<up> Suc (length xs) @ anything} gp [+] mv_box ga (ft + n)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   676
          {\<lambda>nl. nl = xs @ 0 \<up> (ft - length xs) @ map (\<lambda>i. rec_exec i xs) 
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   677
          (take n gs) @ rec_exec (gs ! n) xs # 0 \<up> (length gs - Suc n) @ 0 # 0 \<up> length xs @ anything}"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   678
        proof(rule_tac abc_Hoare_plus_halt)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   679
          show "{\<lambda>nl. nl = xs @ 0 \<up> (ft - length xs) @ map (\<lambda>i. rec_exec i xs) (take n gs) @ 0 \<up> (length gs - n) @ 0 \<up> Suc (length xs) @ anything} gp 
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   680
                {\<lambda>nl. nl = xs @ (rec_exec (gs!n) xs) # 0 \<up> (ft - Suc (length xs)) @ map (\<lambda>i. rec_exec i xs) 
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   681
                              (take n gs) @  0 \<up> (length gs - n) @ 0 # 0 \<up> length xs @ anything}"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   682
          proof -
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   683
            have 
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   684
              "({\<lambda>nl. nl = xs @ 0 \<up> (gf - ga) @ 0\<up>(ft - gf)@map (\<lambda>i. rec_exec i xs) (take n gs) @ 0 \<up> (length gs - n) @ 0 \<up> Suc (length xs) @ anything} 
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   685
            gp {\<lambda>nl. nl = xs @ (rec_exec (gs!n) xs) # 0 \<up> (gf - Suc ga) @ 
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   686
              0\<up>(ft - gf)@map (\<lambda>i. rec_exec i xs) (take n gs) @ 0 \<up> (length gs - n) @ 0 \<up> Suc (length xs) @ anything})"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   687
              using a g_newcond h x
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   688
              apply(erule_tac x = "gs!n" in ballE)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   689
              apply(simp, simp)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   690
              done            
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   691
            thus "?thesis"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   692
              using a b c d e
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   693
              by(simp add: replicate_merge_anywhere)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   694
          qed
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   695
        next
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   696
          show 
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   697
            "{\<lambda>nl. nl = xs @ rec_exec (gs ! n) xs #
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   698
            0 \<up> (ft - Suc (length xs)) @ map (\<lambda>i. rec_exec i xs) (take n gs) @ 0 \<up> (length gs - n) @ 0 # 0 \<up> length xs @ anything}
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   699
            mv_box ga (ft + n)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   700
            {\<lambda>nl. nl = xs @ 0 \<up> (ft - length xs) @ map (\<lambda>i. rec_exec i xs) (take n gs) @
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   701
            rec_exec (gs ! n) xs # 0 \<up> (length gs - Suc n) @ 0 # 0 \<up> length xs @ anything}"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   702
          proof -
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   703
            have "{\<lambda>nl. nl = xs @ rec_exec (gs ! n) xs # 0 \<up> (ft - Suc (length xs)) @
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   704
              map (\<lambda>i. rec_exec i xs) (take n gs) @ 0 \<up> (length gs - n) @ 0 # 0 \<up> length xs @ anything}
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   705
              mv_box ga (ft + n) {\<lambda>nl. nl = (xs @ rec_exec (gs ! n) xs # 0 \<up> (ft - Suc (length xs)) @
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   706
              map (\<lambda>i. rec_exec i xs) (take n gs) @ 0 \<up> (length gs - n) @ 0 # 0 \<up> length xs @ anything)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   707
              [ft + n := (xs @ rec_exec (gs ! n) xs # 0 \<up> (ft - Suc (length xs)) @ map (\<lambda>i. rec_exec i xs) (take n gs) @ 
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   708
              0 \<up> (length gs - n) @ 0 # 0 \<up> length xs @ anything) ! ga +
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   709
              (xs @ rec_exec (gs ! n) xs # 0 \<up> (ft - Suc (length xs)) @ 
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   710
              map (\<lambda>i. rec_exec i xs) (take n gs) @ 0 \<up> (length gs - n) @ 0 # 0 \<up> length xs @ anything) !
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   711
                      (ft + n),  ga := 0]}"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   712
              using a c d e h
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   713
              apply(rule_tac mv_box_correct)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   714
              apply(simp, arith, arith)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   715
              done
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   716
            moreover have "(xs @ rec_exec (gs ! n) xs # 0 \<up> (ft - Suc (length xs)) @
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   717
              map (\<lambda>i. rec_exec i xs) (take n gs) @ 0 \<up> (length gs - n) @ 0 # 0 \<up> length xs @ anything)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   718
              [ft + n := (xs @ rec_exec (gs ! n) xs # 0 \<up> (ft - Suc (length xs)) @ map (\<lambda>i. rec_exec i xs) (take n gs) @ 
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   719
              0 \<up> (length gs - n) @ 0 # 0 \<up> length xs @ anything) ! ga +
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   720
              (xs @ rec_exec (gs ! n) xs # 0 \<up> (ft - Suc (length xs)) @ 
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   721
              map (\<lambda>i. rec_exec i xs) (take n gs) @ 0 \<up> (length gs - n) @ 0 # 0 \<up> length xs @ anything) !
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   722
                      (ft + n),  ga := 0]= 
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   723
              xs @ 0 \<up> (ft - length xs) @ map (\<lambda>i. rec_exec i xs) (take n gs) @ rec_exec (gs ! n) xs # 0 \<up> (length gs - Suc n) @ 0 # 0 \<up> length xs @ anything"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   724
              using a c d e h
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   725
              by(simp add: list_update_append nth_append length_replicate split: if_splits del: list_update.simps(2), auto)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   726
            ultimately show "?thesis"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   727
              by(simp)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   728
          qed
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   729
        qed  
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   730
      qed
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   731
      ultimately show 
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   732
        "{\<lambda>nl. nl = xs @ 0 # 0 \<up> (ft + length gs) @ anything}
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   733
        cn_merge_gs (map rec_ci (take n gs)) ft [+] (case rec_ci (gs ! n) of (gprog, gpara, gn) \<Rightarrow>
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   734
        gprog [+] mv_box gpara (ft + min (length gs) n))
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   735
        {\<lambda>nl. nl = xs @ 0 \<up> (ft - length xs) @ map (\<lambda>i. rec_exec i xs) (take n gs) @ rec_exec (gs ! n) xs # 0 \<up> (length gs - Suc n) @ 0 # 0 \<up> length xs @ anything}"
70
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   736
        by simp
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   737
    qed
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   738
  next
229
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   739
    case False
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   740
    have h: "\<not> n < length gs" by fact
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   741
    hence ind': 
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   742
      "{\<lambda>nl. nl = xs @ 0 # 0 \<up> (ft + length gs) @ anything} cn_merge_gs (map rec_ci gs) ft
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   743
        {\<lambda>nl. nl = xs @ 0 \<up> (ft - length xs) @ map (\<lambda>i. rec_exec i xs) gs @ 0 \<up> Suc (length xs) @ anything}"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   744
      using ind
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   745
      by simp
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   746
    thus "?thesis"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   747
      using h
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   748
      by(simp)
70
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   749
  qed
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   750
qed
229
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   751
    
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   752
lemma compile_cn_gs_correct:
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   753
  assumes
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   754
  g_cond: "\<forall>g\<in>set gs. terminate g xs \<and>
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   755
  (\<forall>x xa xb. rec_ci g = (x, xa, xb) \<longrightarrow> (\<forall>xc. {\<lambda>nl. nl = xs @ 0 \<up> (xb - xa) @ xc} x {\<lambda>nl. nl = xs @ rec_exec g xs # 0 \<up> (xb - Suc xa) @ xc}))"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   756
  and ft: "ft = max (Suc (length xs)) (Max (insert ffp ((\<lambda>(aprog, p, n). n) ` rec_ci ` set gs)))"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   757
  shows 
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   758
  "{\<lambda>nl. nl = xs @ 0 # 0 \<up> (ft + length gs) @ anything}
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   759
    cn_merge_gs (map rec_ci gs) ft
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   760
  {\<lambda>nl. nl = xs @ 0 \<up> (ft - length xs) @
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   761
                    map (\<lambda>i. rec_exec i xs) gs @ 0 \<up> Suc (length xs) @ anything}"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   762
using assms
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   763
using compile_cn_gs_correct'[of "length gs" gs xs ft ffp anything ]
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   764
apply(auto)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   765
done
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   766
  
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   767
lemma length_mvboxes[simp]: "length (mv_boxes aa ba n) = 3*n"
70
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   768
by(induct n, auto simp: mv_boxes.simps)
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   769
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   770
lemma exp_suc: "a\<up>Suc b = a\<up>b @ [a]"
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   771
by(simp add: exp_ind del: replicate.simps)
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   772
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   773
lemma [simp]: 
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   774
  "\<lbrakk>Suc n \<le> ba - aa;  length lm2 = Suc n;
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   775
    length lm3 = ba - Suc (aa + n)\<rbrakk>
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   776
  \<Longrightarrow> (last lm2 # lm3 @ butlast lm2 @ 0 # lm4) ! (ba - aa) = (0::nat)"
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   777
proof -
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   778
  assume h: "Suc n \<le> ba - aa"
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   779
  and g: "length lm2 = Suc n" "length lm3 = ba - Suc (aa + n)"
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   780
  from h and g have k: "ba - aa = Suc (length lm3 + n)"
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   781
    by arith
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   782
  from  k show 
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   783
    "(last lm2 # lm3 @ butlast lm2 @ 0 # lm4) ! (ba - aa) = 0"
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   784
    apply(simp, insert g)
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   785
    apply(simp add: nth_append)
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   786
    done
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   787
qed
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   788
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   789
lemma [simp]: "length lm1 = aa \<Longrightarrow>
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   790
      (lm1 @ 0\<up>n @ last lm2 # lm3 @ butlast lm2 @ 0 # lm4) ! (aa + n) = last lm2"
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   791
apply(simp add: nth_append)
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   792
done
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   793
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   794
lemma [simp]: "\<lbrakk>Suc n \<le> ba - aa; aa < ba\<rbrakk> \<Longrightarrow> 
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   795
                    (ba < Suc (aa + (ba - Suc (aa + n) + n))) = False"
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   796
apply arith
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   797
done
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   798
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   799
lemma [simp]: "\<lbrakk>Suc n \<le> ba - aa; aa < ba; length lm1 = aa; 
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   800
       length lm2 = Suc n; length lm3 = ba - Suc (aa + n)\<rbrakk>
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   801
     \<Longrightarrow> (lm1 @ 0\<up>n @ last lm2 # lm3 @ butlast lm2 @ 0 # lm4) ! (ba + n) = 0"
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   802
using nth_append[of "lm1 @ (0\<Colon>'a)\<up>n @ last lm2 # lm3 @ butlast lm2" 
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   803
                     "(0\<Colon>'a) # lm4" "ba + n"]
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   804
apply(simp)
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   805
done
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   806
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   807
lemma [simp]: 
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   808
 "\<lbrakk>Suc n \<le> ba - aa; aa < ba; length lm1 = aa; length lm2 = Suc n;
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   809
                 length lm3 = ba - Suc (aa + n)\<rbrakk>
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   810
  \<Longrightarrow> (lm1 @ 0\<up>n @ last lm2 # lm3 @ butlast lm2 @ (0::nat) # lm4)
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   811
  [ba + n := last lm2, aa + n := 0] = 
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   812
  lm1 @ 0 # 0\<up>n @ lm3 @ lm2 @ lm4"
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   813
using list_update_append[of "lm1 @ 0\<up>n @ last lm2 # lm3 @ butlast lm2" "0 # lm4" 
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   814
                            "ba + n" "last lm2"]
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   815
apply(simp)
229
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   816
apply(simp add: list_update_append list_update.simps replicate_Suc_iff_anywhere exp_suc
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   817
  del: replicate_Suc)
70
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   818
apply(case_tac lm2, simp, simp)
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   819
done
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   820
229
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   821
lemma [simp]:
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   822
  "\<lbrakk>Suc (length lm1 + n) \<le> ba; length lm2 = Suc n; length lm3 = ba - Suc (length lm1 + n); 
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   823
  \<not> ba - Suc (length lm1) < ba - Suc (length lm1 + n); \<not> ba + n - length lm1 < n\<rbrakk>
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   824
    \<Longrightarrow> (0::nat) \<up> n @ (last lm2 # lm3 @ butlast lm2 @ 0 # lm4)[ba - length lm1 := last lm2, 0 := 0] =
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   825
  0 # 0 \<up> n @ lm3 @ lm2 @ lm4"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   826
apply(subgoal_tac "ba - length lm1 = Suc n + length lm3", simp add: list_update.simps list_update_append)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   827
apply(simp add: replicate_Suc_iff_anywhere exp_suc del: replicate_Suc)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   828
apply(case_tac lm2, simp, simp)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   829
apply(auto)
70
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   830
done
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   831
229
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   832
lemma mv_boxes_correct: 
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   833
  "\<lbrakk>aa + n \<le> ba; ba > aa; length lm1 = aa; length lm2 = n; length lm3 = ba - aa - n\<rbrakk>
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   834
 \<Longrightarrow> {\<lambda> nl. nl = lm1 @ lm2 @ lm3 @ 0\<up>n @ lm4} (mv_boxes aa ba n) 
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   835
     {\<lambda> nl. nl = lm1 @ 0\<up>n @ lm3 @ lm2 @ lm4}"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   836
proof(induct n arbitrary: lm2 lm3 lm4)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   837
  case 0
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   838
  thus "?case"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   839
    by(simp add: mv_boxes.simps abc_Hoare_halt_def, rule_tac  x = 0 in exI, simp add: abc_steps_l.simps)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   840
next
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   841
  case (Suc n)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   842
  have ind: 
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   843
    "\<And>lm2 lm3 lm4.
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   844
    \<lbrakk>aa + n \<le> ba; aa < ba; length lm1 = aa; length lm2 = n; length lm3 = ba - aa - n\<rbrakk>
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   845
    \<Longrightarrow> {\<lambda>nl. nl = lm1 @ lm2 @ lm3 @ 0 \<up> n @ lm4} mv_boxes aa ba n {\<lambda>nl. nl = lm1 @ 0 \<up> n @ lm3 @ lm2 @ lm4}"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   846
    by fact
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   847
  have h1: "aa + Suc n \<le> ba"  by fact
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   848
  have h2: "aa < ba" by fact
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   849
  have h3: "length lm1 = aa" by fact
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   850
  have h4: "length lm2 = Suc n" by fact 
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   851
  have h5: "length lm3 = ba - aa - Suc n" by fact
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   852
  have "{\<lambda>nl. nl = lm1 @ lm2 @ lm3 @ 0 \<up> Suc n @ lm4} mv_boxes aa ba n [+] mv_box (aa + n) (ba + n)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   853
    {\<lambda>nl. nl = lm1 @ 0 \<up> Suc n @ lm3 @ lm2 @ lm4}"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   854
  proof(rule_tac abc_Hoare_plus_halt)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   855
    have "{\<lambda>nl. nl = lm1 @ butlast lm2 @ (last lm2 # lm3) @ 0 \<up> n @ (0 # lm4)} mv_boxes aa ba n
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   856
          {\<lambda> nl. nl = lm1 @ 0\<up>n @ (last lm2 # lm3) @ butlast lm2 @ (0 # lm4)}"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   857
      using h1 h2 h3 h4 h5
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   858
      by(rule_tac ind, simp_all)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   859
    moreover have " lm1 @ butlast lm2 @ (last lm2 # lm3) @ 0 \<up> n @ (0 # lm4)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   860
                  = lm1 @ lm2 @ lm3 @ 0 \<up> Suc n @ lm4"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   861
      using h4
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   862
      by(simp add: replicate_Suc[THEN sym] exp_suc del: replicate_Suc, 
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   863
            case_tac lm2, simp_all)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   864
    ultimately show "{\<lambda>nl. nl = lm1 @ lm2 @ lm3 @ 0 \<up> Suc n @ lm4} mv_boxes aa ba n
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   865
          {\<lambda> nl. nl = lm1 @ 0\<up>n @ last lm2 # lm3 @ butlast lm2 @ 0 # lm4}"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   866
      by (metis append_Cons)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   867
  next
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   868
    let ?lm = "lm1 @ 0 \<up> n @ last lm2 # lm3 @ butlast lm2 @ 0 # lm4"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   869
    have "{\<lambda>nl. nl = ?lm} mv_box (aa + n) (ba + n)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   870
          {\<lambda> nl. nl = ?lm[(ba + n) := ?lm!(aa+n) + ?lm!(ba+n), (aa+n):=0]}"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   871
      using h1 h2 h3 h4  h5
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   872
      by(rule_tac mv_box_correct, simp_all)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   873
    moreover have "?lm[(ba + n) := ?lm!(aa+n) + ?lm!(ba+n), (aa+n):=0]
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   874
                 =  lm1 @ 0 \<up> Suc n @ lm3 @ lm2 @ lm4"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   875
      using h1 h2 h3 h4 h5
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   876
      by(auto simp: nth_append list_update_append split: if_splits)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   877
    ultimately show "{\<lambda>nl. nl = lm1 @ 0 \<up> n @ last lm2 # lm3 @ butlast lm2 @ 0 # lm4} mv_box (aa + n) (ba + n)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   878
          {\<lambda>nl. nl = lm1 @ 0 \<up> Suc n @ lm3 @ lm2 @ lm4}"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   879
     by simp
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   880
 qed
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   881
 thus "?case"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   882
   by(simp add: mv_boxes.simps)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   883
qed
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   884
    
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   885
lemma [simp]:
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   886
  "\<lbrakk>Suc n \<le> aa - length lm1; length lm1 < aa; 
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   887
  length lm2 = aa - Suc (length lm1 + n); 
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   888
  length lm3 = Suc n; 
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   889
  \<not> aa - Suc (length lm1) < aa - Suc (length lm1 + n);
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   890
  \<not> aa + n - length lm1 < n\<rbrakk>
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   891
  \<Longrightarrow> butlast lm3 @ ((0::nat) # lm2 @ 0 \<up> n @ last lm3 # lm4)[0 := last lm3, aa - length lm1 := 0] = lm3 @ lm2 @ 0 # 0 \<up> n @ lm4"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   892
  apply(subgoal_tac "aa - length lm1 = length lm2 + Suc n")
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   893
  apply(simp add: list_update.simps list_update_append)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   894
  apply(simp add: replicate_Suc[THEN sym] exp_suc del: replicate_Suc)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   895
  apply(case_tac lm3, simp, simp)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   896
  apply(auto)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   897
  done
70
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   898
229
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   899
lemma mv_boxes_correct2:
70
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   900
  "\<lbrakk>n \<le> aa - ba; 
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   901
    ba < aa; 
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   902
    length (lm1::nat list) = ba;
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   903
    length (lm2::nat list) = aa - ba - n; 
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   904
    length (lm3::nat list) = n\<rbrakk>
229
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   905
  \<Longrightarrow>{\<lambda> nl. nl = lm1 @ 0\<up>n @ lm2 @ lm3 @ lm4}
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   906
                (mv_boxes aa ba n) 
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   907
     {\<lambda> nl. nl = lm1 @ lm3 @ lm2 @ 0\<up>n @ lm4}"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   908
proof(induct n arbitrary: lm2 lm3 lm4)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   909
  case 0
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   910
  thus "?case"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   911
    by(simp add: mv_boxes.simps abc_Hoare_halt_def, rule_tac  x = 0 in exI, simp add: abc_steps_l.simps)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   912
next
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   913
  case (Suc n)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   914
  have ind:
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   915
    "\<And>lm2 lm3 lm4.
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   916
    \<lbrakk>n \<le> aa - ba; ba < aa; length lm1 = ba; length lm2 = aa - ba - n; length lm3 = n\<rbrakk>
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   917
    \<Longrightarrow> {\<lambda>nl. nl = lm1 @ 0 \<up> n @ lm2 @ lm3 @ lm4} mv_boxes aa ba n {\<lambda>nl. nl = lm1 @ lm3 @ lm2 @ 0 \<up> n @ lm4}"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   918
    by fact
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   919
  have h1: "Suc n \<le> aa - ba" by fact
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   920
  have h2: "ba < aa" by fact
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   921
  have h3: "length lm1 = ba" by fact 
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   922
  have h4: "length lm2 = aa - ba - Suc n" by fact
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   923
  have h5: "length lm3 = Suc n" by fact
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   924
  have "{\<lambda>nl. nl = lm1 @ 0 \<up> Suc n @ lm2 @ lm3 @ lm4}  mv_boxes aa ba n [+] mv_box (aa + n) (ba + n) 
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   925
    {\<lambda>nl. nl = lm1 @ lm3 @ lm2 @ 0 \<up> Suc n @ lm4}"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   926
  proof(rule_tac abc_Hoare_plus_halt)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   927
    have "{\<lambda> nl. nl = lm1 @ 0 \<up> n @ (0 # lm2) @ (butlast lm3) @ (last lm3 # lm4)} mv_boxes aa ba n
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   928
           {\<lambda> nl. nl = lm1 @ butlast lm3 @ (0 # lm2) @ 0\<up>n @ (last lm3 # lm4)}"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   929
      using h1 h2 h3 h4 h5
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   930
      by(rule_tac ind, simp_all)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   931
    moreover have "lm1 @ 0 \<up> n @ (0 # lm2) @ (butlast lm3) @ (last lm3 # lm4) 
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   932
                   = lm1 @ 0 \<up> Suc n @ lm2 @ lm3 @ lm4"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   933
      using h5
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   934
     by(simp add: replicate_Suc_iff_anywhere exp_suc 
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   935
        del: replicate_Suc, case_tac lm3, simp_all)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   936
   ultimately show "{\<lambda>nl. nl = lm1 @ 0 \<up> Suc n @ lm2 @ lm3 @ lm4} mv_boxes aa ba n
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   937
     {\<lambda> nl. nl = lm1 @ butlast lm3 @ (0 # lm2) @ 0\<up>n @ (last lm3 # lm4)}"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   938
     by metis
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   939
 next
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   940
   thm mv_box_correct
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   941
   let ?lm = "lm1 @ butlast lm3 @ (0 # lm2) @ 0 \<up> n @ last lm3 # lm4"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   942
   have "{\<lambda>nl. nl = ?lm} mv_box (aa + n) (ba + n)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   943
         {\<lambda>nl. nl = ?lm[ba+n := ?lm!(aa+n)+?lm!(ba+n), (aa+n):=0]}"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   944
     using h1 h2 h3 h4 h5
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   945
     by(rule_tac mv_box_correct, simp_all)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   946
   moreover have "?lm[ba+n := ?lm!(aa+n)+?lm!(ba+n), (aa+n):=0]
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   947
               = lm1 @ lm3 @ lm2 @ 0 \<up> Suc n @ lm4"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   948
     using h1 h2 h3 h4 h5
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   949
     by(auto simp: nth_append list_update_append split: if_splits)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   950
   ultimately show "{\<lambda>nl. nl = lm1 @ butlast lm3 @ (0 # lm2) @ 0 \<up> n @ last lm3 # lm4} mv_box (aa + n) (ba + n)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   951
     {\<lambda>nl. nl = lm1 @ lm3 @ lm2 @ 0 \<up> Suc n @ lm4}"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   952
     by simp
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   953
 qed
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   954
 thus "?case"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   955
   by(simp add: mv_boxes.simps)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   956
qed    
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   957
     
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   958
lemma save_paras: 
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   959
  "{\<lambda>nl. nl = xs @ 0 \<up> (max (Suc (length xs)) (Max (insert ffp ((\<lambda>(aprog, p, n). n) ` rec_ci ` set gs))) - length xs) @
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   960
  map (\<lambda>i. rec_exec i xs) gs @ 0 \<up> Suc (length xs) @ anything}
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   961
  mv_boxes 0 (Suc (max (Suc (length xs)) (Max (insert ffp ((\<lambda>(aprog, p, n). n) ` rec_ci ` set gs))) + length gs)) (length xs)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   962
  {\<lambda>nl. nl = 0 \<up> max (Suc (length xs)) (Max (insert ffp ((\<lambda>(aprog, p, n). n) ` rec_ci ` set gs))) @ map (\<lambda>i. rec_exec i xs) gs @ 0 # xs @ anything}"
70
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   963
proof -
229
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   964
  let ?ft = "max (Suc (length xs)) (Max (insert ffp ((\<lambda>(aprog, p, n). n) ` rec_ci ` set gs)))"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   965
  have "{\<lambda>nl. nl = [] @ xs @ (0\<up>(?ft - length xs) @  map (\<lambda>i. rec_exec i xs) gs @ [0]) @ 
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   966
          0 \<up> (length xs) @ anything} mv_boxes 0 (Suc ?ft + length gs) (length xs) 
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   967
        {\<lambda>nl. nl = [] @ 0 \<up> (length xs) @ (0\<up>(?ft - length xs) @  map (\<lambda>i. rec_exec i xs) gs @ [0]) @ xs @ anything}"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   968
    by(rule_tac mv_boxes_correct, auto)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   969
  thus "?thesis"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   970
    by(simp add: replicate_merge_anywhere)
70
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   971
qed
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   972
229
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   973
lemma [intro]: 
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   974
  "length gs \<le> ffp \<Longrightarrow> length gs \<le> max (Suc (length xs)) (Max (insert ffp ((\<lambda>(aprog, p, n). n) ` rec_ci ` set gs)))"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   975
 apply(rule_tac min_max.le_supI2)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   976
 apply(simp add: Max_ge_iff)
70
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   977
done
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   978
229
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   979
lemma restore_new_paras:
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   980
  "ffp \<ge> length gs 
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   981
 \<Longrightarrow> {\<lambda>nl. nl = 0 \<up> max (Suc (length xs)) (Max (insert ffp ((\<lambda>(aprog, p, n). n) ` rec_ci ` set gs))) @ map (\<lambda>i. rec_exec i xs) gs @ 0 # xs @ anything}
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   982
    mv_boxes (max (Suc (length xs)) (Max (insert ffp ((\<lambda>(aprog, p, n). n) ` rec_ci ` set gs)))) 0 (length gs)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   983
  {\<lambda>nl. nl = map (\<lambda>i. rec_exec i xs) gs @ 0 \<up> max (Suc (length xs)) (Max (insert ffp ((\<lambda>(aprog, p, n). n) ` rec_ci ` set gs))) @ 0 # xs @ anything}"
70
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   984
proof -
229
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   985
  let ?ft = "max (Suc (length xs)) (Max (insert ffp ((\<lambda>(aprog, p, n). n) ` rec_ci ` set gs)))"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   986
  assume j: "ffp \<ge> length gs"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   987
  hence "{\<lambda> nl. nl = [] @ 0\<up>length gs @ 0\<up>(?ft - length gs) @  map (\<lambda>i. rec_exec i xs) gs @ ((0 # xs) @ anything)}
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   988
       mv_boxes ?ft 0 (length gs)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   989
        {\<lambda> nl. nl = [] @ map (\<lambda>i. rec_exec i xs) gs @ 0\<up>(?ft - length gs) @ 0\<up>length gs @ ((0 # xs) @ anything)}"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   990
    by(rule_tac mv_boxes_correct2, auto)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   991
  moreover have "?ft \<ge> length gs"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   992
    using j
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   993
    by(auto)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   994
  ultimately show "?thesis"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   995
    using j
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   996
    by(simp add: replicate_merge_anywhere le_add_diff_inverse)
70
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   997
qed
229
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   998
   
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
   999
lemma [intro]: "ffp \<le> max (Suc (length xs)) (Max (insert ffp ((\<lambda>(aprog, p, n). n) ` rec_ci ` set gs)))"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1000
apply(rule_tac min_max.le_supI2)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1001
apply(rule_tac Max_ge, auto)
70
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1002
done
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1003
229
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1004
declare max_less_iff_conj[simp del]
70
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1005
229
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1006
lemma save_rs:
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1007
  "\<lbrakk>far = length gs;
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1008
  ffp \<le> max (Suc (length xs)) (Max (insert ffp ((\<lambda>(aprog, p, n). n) ` rec_ci ` set gs)));
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1009
  far < ffp\<rbrakk>
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1010
\<Longrightarrow>  {\<lambda>nl. nl = map (\<lambda>i. rec_exec i xs) gs @
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1011
  rec_exec (Cn (length xs) f gs) xs # 0 \<up> max (Suc (length xs))
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1012
  (Max (insert ffp ((\<lambda>(aprog, p, n). n) ` rec_ci ` set gs))) @ xs @ anything}
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1013
    mv_box far (max (Suc (length xs)) (Max (insert ffp ((\<lambda>(aprog, p, n). n) ` rec_ci ` set gs))))
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1014
    {\<lambda>nl. nl = map (\<lambda>i. rec_exec i xs) gs @
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1015
               0 \<up> (max (Suc (length xs)) (Max (insert ffp ((\<lambda>(aprog, p, n). n) ` rec_ci ` set gs))) - length gs) @
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1016
               rec_exec (Cn (length xs) f gs) xs # 0 \<up> length gs @ xs @ anything}"
70
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1017
proof -
229
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1018
  let ?ft = "max (Suc (length xs)) (Max (insert ffp ((\<lambda>(aprog, p, n). n) ` rec_ci ` set gs)))"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1019
  thm mv_box_correct
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1020
  let ?lm= " map (\<lambda>i. rec_exec i xs) gs @ rec_exec (Cn (length xs) f gs) xs # 0 \<up> ?ft @ xs @ anything"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1021
  assume h: "far = length gs" "ffp \<le> ?ft" "far < ffp"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1022
  hence "{\<lambda> nl. nl = ?lm} mv_box far ?ft {\<lambda> nl. nl = ?lm[?ft := ?lm!far + ?lm!?ft, far := 0]}"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1023
    apply(rule_tac mv_box_correct)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1024
    by(case_tac "rec_ci a", auto)  
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1025
  moreover have "?lm[?ft := ?lm!far + ?lm!?ft, far := 0]
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1026
    = map (\<lambda>i. rec_exec i xs) gs @
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1027
    0 \<up> (?ft - length gs) @
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1028
    rec_exec (Cn (length xs) f gs) xs # 0 \<up> length gs @ xs @ anything"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1029
    using h
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1030
    apply(simp add: nth_append)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1031
    using list_update_length[of "map (\<lambda>i. rec_exec i xs) gs @ rec_exec (Cn (length xs) f gs) xs #
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1032
       0 \<up> (?ft - Suc (length gs))" 0 "0 \<up> length gs @ xs @ anything" "rec_exec (Cn (length xs) f gs) xs"]
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1033
    apply(simp add: replicate_merge_anywhere replicate_Suc_iff_anywhere del: replicate_Suc)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1034
    by(simp add: list_update_append list_update.simps replicate_Suc_iff_anywhere del: replicate_Suc)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1035
  ultimately show "?thesis"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1036
    by(simp)
70
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1037
qed
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1038
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1039
lemma [simp]: "length (empty_boxes n) = 2*n"
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1040
apply(induct n, simp, simp)
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1041
done
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1042
229
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1043
lemma empty_one_box_correct:
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1044
  "{\<lambda>nl. nl = 0 \<up> n @ x # lm} [Dec n 2, Goto 0] {\<lambda>nl. nl = 0 # 0 \<up> n @ lm}"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1045
proof(induct x)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1046
  case 0
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1047
  thus "?case"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1048
    by(simp add: abc_Hoare_halt_def, 
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1049
          rule_tac x = 1 in exI, simp add: abc_steps_l.simps 
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1050
          abc_step_l.simps abc_fetch.simps abc_lm_v.simps nth_append abc_lm_s.simps
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1051
          replicate_Suc[THEN sym] exp_suc del: replicate_Suc)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1052
next
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1053
  case (Suc x)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1054
  have "{\<lambda>nl. nl = 0 \<up> n @ x # lm} [Dec n 2, Goto 0] {\<lambda>nl. nl = 0 # 0 \<up> n @ lm}"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1055
    by fact
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1056
  then obtain stp where "abc_steps_l (0, 0 \<up> n @ x # lm) [Dec n 2, Goto 0] stp
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1057
                      = (Suc (Suc 0), 0 # 0 \<up> n @ lm)"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1058
    apply(auto simp: abc_Hoare_halt_def)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1059
    by(case_tac "abc_steps_l (0, 0 \<up> n @ x # lm) [Dec n 2, Goto 0] na", simp)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1060
  moreover have "abc_steps_l (0, 0\<up>n @ Suc x # lm) [Dec n 2, Goto 0] (Suc (Suc 0)) 
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1061
        = (0,  0 \<up> n @ x # lm)"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1062
    by(auto simp: abc_steps_l.simps abc_step_l.simps abc_fetch.simps abc_lm_v.simps
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1063
      nth_append abc_lm_s.simps list_update.simps list_update_append)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1064
  ultimately have "abc_steps_l (0, 0\<up>n @ Suc x # lm) [Dec n 2, Goto 0] (Suc (Suc 0) + stp) 
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1065
                = (Suc (Suc 0), 0 # 0\<up>n @ lm)"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1066
    by(simp only: abc_steps_add)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1067
  thus "?case"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1068
    apply(simp add: abc_Hoare_halt_def)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1069
    apply(rule_tac x = "Suc (Suc stp)" in exI, simp)
70
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1070
    done
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1071
qed
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1072
229
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1073
lemma empty_boxes_correct: 
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1074
  "length lm \<ge> n \<Longrightarrow>
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1075
  {\<lambda> nl. nl = lm} empty_boxes n {\<lambda> nl. nl = 0\<up>n @ drop n lm}"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1076
proof(induct n)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1077
  case 0
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1078
  thus "?case"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1079
    by(simp add: empty_boxes.simps abc_Hoare_halt_def, 
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1080
          rule_tac x = 0 in exI, simp add: abc_steps_l.simps)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1081
next
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1082
  case (Suc n)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1083
  have ind: "n \<le> length lm \<Longrightarrow> {\<lambda>nl. nl = lm} empty_boxes n {\<lambda>nl. nl = 0 \<up> n @ drop n lm}" by fact
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1084
  have h: "Suc n \<le> length lm" by fact
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1085
  have "{\<lambda>nl. nl = lm} empty_boxes n [+] [Dec n 2, Goto 0] {\<lambda>nl. nl = 0 # 0 \<up> n @ drop (Suc n) lm}"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1086
  proof(rule_tac abc_Hoare_plus_halt)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1087
    show "{\<lambda>nl. nl = lm} empty_boxes n {\<lambda>nl. nl = 0 \<up> n @ drop n lm}"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1088
      using h
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1089
      by(rule_tac ind, simp)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1090
  next
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1091
    show "{\<lambda>nl. nl = 0 \<up> n @ drop n lm} [Dec n 2, Goto 0] {\<lambda>nl. nl = 0 # 0 \<up> n @ drop (Suc n) lm}"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1092
      using empty_one_box_correct[of n "lm ! n" "drop (Suc n) lm"]
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1093
      using h
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1094
      by(simp add: nth_drop')
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1095
  qed
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1096
  thus "?case"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1097
    by(simp add: empty_boxes.simps)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1098
qed
70
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1099
229
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1100
lemma [simp]: "length gs \<le> ffp \<Longrightarrow>
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1101
    length gs + (max (Suc (length xs)) (Max (insert ffp ((\<lambda>(aprog, p, n). n) ` rec_ci ` set gs))) - length gs) =
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1102
    max (Suc (length xs)) (Max (insert ffp ((\<lambda>(aprog, p, n). n) ` rec_ci ` set gs)))"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1103
apply(rule_tac le_add_diff_inverse)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1104
apply(rule_tac min_max.le_supI2)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1105
apply(simp add: Max_ge_iff)
70
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1106
done
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1107
229
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1108
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1109
lemma clean_paras: 
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1110
  "ffp \<ge> length gs \<Longrightarrow>
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1111
  {\<lambda>nl. nl = map (\<lambda>i. rec_exec i xs) gs @
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1112
  0 \<up> (max (Suc (length xs)) (Max (insert ffp ((\<lambda>(aprog, p, n). n) ` rec_ci ` set gs))) - length gs) @
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1113
  rec_exec (Cn (length xs) f gs) xs # 0 \<up> length gs @ xs @ anything}
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1114
  empty_boxes (length gs)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1115
  {\<lambda>nl. nl = 0 \<up> max (Suc (length xs)) (Max (insert ffp ((\<lambda>(aprog, p, n). n) ` rec_ci ` set gs))) @ 
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1116
  rec_exec (Cn (length xs) f gs) xs # 0 \<up> length gs @ xs @ anything}"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1117
proof-
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1118
  let ?ft = "max (Suc (length xs)) (Max (insert ffp ((\<lambda>(aprog, p, n). n) ` rec_ci ` set gs)))"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1119
  assume h: "length gs \<le> ffp"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1120
  let ?lm = "map (\<lambda>i. rec_exec i xs) gs @ 0 \<up> (?ft - length gs) @
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1121
    rec_exec (Cn (length xs) f gs) xs # 0 \<up> length gs @ xs @ anything"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1122
  have "{\<lambda> nl. nl = ?lm} empty_boxes (length gs) {\<lambda> nl. nl = 0\<up>length gs @ drop (length gs) ?lm}"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1123
    by(rule_tac empty_boxes_correct, simp)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1124
  moreover have "0\<up>length gs @ drop (length gs) ?lm 
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1125
           =  0 \<up> ?ft @  rec_exec (Cn (length xs) f gs) xs # 0 \<up> length gs @ xs @ anything"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1126
    using h
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1127
    by(simp add: replicate_merge_anywhere)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1128
  ultimately show "?thesis"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1129
    by metis
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1130
qed
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1131
 
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1132
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1133
lemma restore_rs:
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1134
  "{\<lambda>nl. nl = 0 \<up> max (Suc (length xs)) (Max (insert ffp ((\<lambda>(aprog, p, n). n) ` rec_ci ` set gs))) @ 
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1135
  rec_exec (Cn (length xs) f gs) xs # 0 \<up> length gs @ xs @ anything}
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1136
  mv_box (max (Suc (length xs)) (Max (insert ffp ((\<lambda>(aprog, p, n). n) ` rec_ci ` set gs)))) (length xs)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1137
  {\<lambda>nl. nl = 0 \<up> length xs @
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1138
  rec_exec (Cn (length xs) f gs) xs #
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1139
  0 \<up> (max (Suc (length xs)) (Max (insert ffp ((\<lambda>(aprog, p, n). n) ` rec_ci ` set gs))) - (length xs)) @
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1140
  0 \<up> length gs @ xs @ anything}"
70
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1141
proof -
229
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1142
  let ?ft = "max (Suc (length xs)) (Max (insert ffp ((\<lambda>(aprog, p, n). n) ` rec_ci ` set gs)))"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1143
  let ?lm = "0\<up>(length xs) @  0\<up>(?ft - (length xs)) @ rec_exec (Cn (length xs) f gs) xs # 0 \<up> length gs @ xs @ anything"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1144
  thm mv_box_correct
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1145
  have "{\<lambda> nl. nl = ?lm} mv_box ?ft (length xs) {\<lambda> nl. nl = ?lm[length xs := ?lm!?ft + ?lm!(length xs), ?ft := 0]}"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1146
    by(rule_tac mv_box_correct, simp, simp)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1147
  moreover have "?lm[length xs := ?lm!?ft + ?lm!(length xs), ?ft := 0]
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1148
               =  0 \<up> length xs @ rec_exec (Cn (length xs) f gs) xs # 0 \<up> (?ft - (length xs)) @ 0 \<up> length gs @ xs @ anything"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1149
    apply(auto simp: list_update_append nth_append)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1150
    apply(case_tac ?ft, simp_all add: Suc_diff_le list_update.simps)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1151
    apply(simp add: exp_suc replicate_Suc[THEN sym] del: replicate_Suc)
70
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1152
    done
229
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1153
  ultimately show "?thesis"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1154
    by(simp add: replicate_merge_anywhere)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1155
qed
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1156
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1157
lemma restore_orgin_paras:
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1158
  "{\<lambda>nl. nl = 0 \<up> length xs @
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1159
  rec_exec (Cn (length xs) f gs) xs #
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1160
  0 \<up> (max (Suc (length xs)) (Max (insert ffp ((\<lambda>(aprog, p, n). n) ` rec_ci ` set gs))) - length xs) @ 0 \<up> length gs @ xs @ anything}
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1161
  mv_boxes (Suc (max (Suc (length xs)) (Max (insert ffp ((\<lambda>(aprog, p, n). n) ` rec_ci ` set gs))) + length gs)) 0 (length xs)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1162
  {\<lambda>nl. nl = xs @ rec_exec (Cn (length xs) f gs) xs # 0 \<up> 
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1163
  (max (Suc (length xs)) (Max (insert ffp ((\<lambda>(aprog, p, n). n) ` rec_ci ` set gs))) + length gs) @ anything}"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1164
proof -
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1165
  let ?ft = "max (Suc (length xs)) (Max (insert ffp ((\<lambda>(aprog, p, n). n) ` rec_ci ` set gs)))"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1166
  thm mv_boxes_correct2
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1167
  have "{\<lambda> nl. nl = [] @ 0\<up>(length xs) @ (rec_exec (Cn (length xs) f gs) xs # 0 \<up> (?ft - length xs) @ 0 \<up> length gs) @ xs @ anything}
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1168
        mv_boxes (Suc ?ft + length gs) 0 (length xs)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1169
        {\<lambda> nl. nl = [] @ xs @ (rec_exec (Cn (length xs) f gs) xs # 0 \<up> (?ft - length xs) @ 0 \<up> length gs) @ 0\<up>length xs @ anything}"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1170
    by(rule_tac mv_boxes_correct2, auto)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1171
  thus "?thesis"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1172
    by(simp add: replicate_merge_anywhere)
70
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1173
qed
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1174
229
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1175
lemma compile_cn_correct':
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1176
  assumes f_ind: 
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1177
  "\<And> anything r. rec_exec f (map (\<lambda>g. rec_exec g xs) gs) = rec_exec (Cn (length xs) f gs) xs \<Longrightarrow>
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1178
  {\<lambda>nl. nl = map (\<lambda>g. rec_exec g xs) gs @ 0 \<up> (ffp - far) @ anything} fap
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1179
                {\<lambda>nl. nl = map (\<lambda>g. rec_exec g xs) gs @ rec_exec (Cn (length xs) f gs) xs # 0 \<up> (ffp - Suc far) @ anything}"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1180
  and compile: "rec_ci f = (fap, far, ffp)"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1181
  and term_f: "terminate f (map (\<lambda>g. rec_exec g xs) gs)"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1182
  and g_cond: "\<forall>g\<in>set gs. terminate g xs \<and>
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1183
  (\<forall>x xa xb. rec_ci g = (x, xa, xb) \<longrightarrow> 
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1184
  (\<forall>xc. {\<lambda>nl. nl = xs @ 0 \<up> (xb - xa) @ xc} x {\<lambda>nl. nl = xs @ rec_exec g xs # 0 \<up> (xb - Suc xa) @ xc}))"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1185
  shows 
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1186
  "{\<lambda>nl. nl = xs @ 0 # 0 \<up> (max (Suc (length xs)) (Max (insert ffp ((\<lambda>(aprog, p, n). n) ` rec_ci ` set gs))) + length gs) @ anything}
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1187
  cn_merge_gs (map rec_ci gs) (max (Suc (length xs)) (Max (insert ffp ((\<lambda>(aprog, p, n). n) ` rec_ci ` set gs)))) [+]
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1188
  (mv_boxes 0 (Suc (max (Suc (length xs)) (Max (insert ffp ((\<lambda>(aprog, p, n). n) ` rec_ci ` set gs))) + length gs)) (length xs) [+]
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1189
  (mv_boxes (max (Suc (length xs)) (Max (insert ffp ((\<lambda>(aprog, p, n). n) ` rec_ci ` set gs)))) 0 (length gs) [+]
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1190
  (fap [+] (mv_box far (max (Suc (length xs)) (Max (insert ffp ((\<lambda>(aprog, p, n). n) ` rec_ci ` set gs)))) [+]
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1191
  (empty_boxes (length gs) [+]
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1192
  (mv_box (max (Suc (length xs)) (Max (insert ffp ((\<lambda>(aprog, p, n). n) ` rec_ci ` set gs)))) (length xs) [+]
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1193
  mv_boxes (Suc (max (Suc (length xs)) (Max (insert ffp ((\<lambda>(aprog, p, n). n) ` rec_ci ` set gs))) + length gs)) 0 (length xs)))))))
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1194
  {\<lambda>nl. nl = xs @ rec_exec (Cn (length xs) f gs) xs # 
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1195
0 \<up> (max (Suc (length xs)) (Max (insert ffp ((\<lambda>(aprog, p, n). n) ` rec_ci ` set gs))) + length gs) @ anything}"
70
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1196
proof -
229
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1197
  let ?ft = "max (Suc (length xs)) (Max (insert ffp ((\<lambda>(aprog, p, n). n) ` rec_ci ` set gs)))"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1198
  let ?A = "cn_merge_gs (map rec_ci gs) ?ft"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1199
  let ?B = "mv_boxes 0 (Suc (?ft+length gs)) (length xs)"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1200
  let ?C = "mv_boxes ?ft 0 (length gs)"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1201
  let ?D = fap
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1202
  let ?E = "mv_box far ?ft"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1203
  let ?F = "empty_boxes (length gs)"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1204
  let ?G = "mv_box ?ft (length xs)"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1205
  let ?H = "mv_boxes (Suc (?ft + length gs)) 0 (length xs)"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1206
  let ?P1 = "\<lambda>nl. nl = xs @ 0 # 0 \<up> (?ft + length gs) @ anything"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1207
  let ?S = "\<lambda>nl. nl = xs @ rec_exec (Cn (length xs) f gs) xs # 0 \<up> (?ft + length gs) @ anything"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1208
  let ?Q1 = "\<lambda> nl. nl = xs @ 0\<up>(?ft - length xs) @ map (\<lambda> i. rec_exec i xs) gs @ 0\<up>(Suc (length xs)) @ anything"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1209
  show "{?P1} (?A [+] (?B [+] (?C [+] (?D [+] (?E [+] (?F [+] (?G [+] ?H))))))) {?S}"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1210
  proof(rule_tac abc_Hoare_plus_halt)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1211
    show "{?P1} ?A {?Q1}"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1212
      using g_cond
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1213
      by(rule_tac compile_cn_gs_correct, auto)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1214
  next
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1215
    let ?Q2 = "\<lambda>nl. nl = 0 \<up> ?ft @
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1216
                    map (\<lambda>i. rec_exec i xs) gs @ 0 # xs @ anything"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1217
    show "{?Q1} (?B [+] (?C [+] (?D [+] (?E [+] (?F [+] (?G [+] ?H)))))) {?S}"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1218
    proof(rule_tac abc_Hoare_plus_halt)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1219
      show "{?Q1} ?B {?Q2}"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1220
        by(rule_tac save_paras)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1221
    next
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1222
      let ?Q3 = "\<lambda> nl. nl = map (\<lambda>i. rec_exec i xs) gs @ 0\<up>?ft @ 0 # xs @ anything" 
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1223
      show "{?Q2} (?C [+] (?D [+] (?E [+] (?F [+] (?G [+] ?H))))) {?S}"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1224
      proof(rule_tac abc_Hoare_plus_halt)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1225
        have "ffp \<ge> length gs"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1226
          using compile term_f
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1227
          apply(subgoal_tac "length gs = far")
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1228
          apply(drule_tac footprint_ge, simp)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1229
          by(drule_tac param_pattern, auto)          
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1230
        thus "{?Q2} ?C {?Q3}"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1231
          by(erule_tac restore_new_paras)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1232
      next
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1233
        let ?Q4 = "\<lambda> nl. nl = map (\<lambda>i. rec_exec i xs) gs @ rec_exec (Cn (length xs) f gs) xs # 0\<up>?ft @ xs @ anything"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1234
        have a: "far = length gs"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1235
          using compile term_f
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1236
          by(drule_tac param_pattern, auto)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1237
        have b:"?ft \<ge> ffp"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1238
          by auto
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1239
        have c: "ffp > far"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1240
          using compile
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1241
          by(erule_tac footprint_ge)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1242
        show "{?Q3} (?D [+] (?E [+] (?F [+] (?G [+] ?H)))) {?S}"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1243
        proof(rule_tac abc_Hoare_plus_halt)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1244
          have "{\<lambda>nl. nl = map (\<lambda>g. rec_exec g xs) gs @ 0 \<up> (ffp - far) @ 0\<up>(?ft - ffp + far) @ 0 # xs @ anything} fap
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1245
            {\<lambda>nl. nl = map (\<lambda>g. rec_exec g xs) gs @ rec_exec (Cn (length xs) f gs) xs # 
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1246
            0 \<up> (ffp - Suc far) @ 0\<up>(?ft - ffp + far) @ 0 # xs @ anything}"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1247
            by(rule_tac f_ind, simp add: rec_exec.simps)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1248
          thus "{?Q3} fap {?Q4}"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1249
            using a b c
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1250
            by(simp add: replicate_merge_anywhere,
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1251
               case_tac "?ft", simp_all add: exp_suc del: replicate_Suc)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1252
        next
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1253
          let ?Q5 = "\<lambda>nl. nl = map (\<lambda>i. rec_exec i xs) gs @
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1254
               0\<up>(?ft - length gs) @ rec_exec (Cn (length xs) f gs) xs # 0\<up>(length gs)@ xs @ anything"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1255
          show "{?Q4} (?E [+] (?F [+] (?G [+] ?H))) {?S}"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1256
          proof(rule_tac abc_Hoare_plus_halt)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1257
            from a b c show "{?Q4} ?E {?Q5}"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1258
              by(erule_tac save_rs, simp_all)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1259
          next
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1260
            let ?Q6 = "\<lambda>nl. nl = 0\<up>?ft @ rec_exec (Cn (length xs) f gs) xs # 0\<up>(length gs)@ xs @ anything"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1261
            show "{?Q5} (?F [+] (?G [+] ?H)) {?S}"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1262
            proof(rule_tac abc_Hoare_plus_halt)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1263
              have "length gs \<le> ffp" using a b c
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1264
                by simp
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1265
              thus "{?Q5} ?F {?Q6}"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1266
                by(erule_tac clean_paras)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1267
            next
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1268
              let ?Q7 = "\<lambda>nl. nl = 0\<up>length xs @ rec_exec (Cn (length xs) f gs) xs # 0\<up>(?ft - (length xs)) @ 0\<up>(length gs)@ xs @ anything"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1269
              show "{?Q6} (?G [+] ?H) {?S}"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1270
              proof(rule_tac abc_Hoare_plus_halt)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1271
                show "{?Q6} ?G {?Q7}"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1272
                  by(rule_tac restore_rs)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1273
              next
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1274
                show "{?Q7} ?H {?S}"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1275
                  by(rule_tac restore_orgin_paras)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1276
              qed
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1277
            qed
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1278
          qed
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1279
        qed        
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1280
      qed
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1281
    qed
70
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1282
  qed
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1283
qed
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1284
229
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1285
lemma compile_cn_correct:
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1286
  assumes termi_f: "terminate f (map (\<lambda>g. rec_exec g xs) gs)"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1287
  and f_ind: "\<And>ap arity fp anything.
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1288
  rec_ci f = (ap, arity, fp)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1289
  \<Longrightarrow> {\<lambda>nl. nl = map (\<lambda>g. rec_exec g xs) gs @ 0 \<up> (fp - arity) @ anything} ap
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1290
  {\<lambda>nl. nl = map (\<lambda>g. rec_exec g xs) gs @ rec_exec f (map (\<lambda>g. rec_exec g xs) gs) # 0 \<up> (fp - Suc arity) @ anything}"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1291
  and g_cond: 
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1292
  "\<forall>g\<in>set gs. terminate g xs \<and>
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1293
  (\<forall>x xa xb. rec_ci g = (x, xa, xb) \<longrightarrow>   (\<forall>xc. {\<lambda>nl. nl = xs @ 0 \<up> (xb - xa) @ xc} x {\<lambda>nl. nl = xs @ rec_exec g xs # 0 \<up> (xb - Suc xa) @ xc}))"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1294
  and compile: "rec_ci (Cn n f gs) = (ap, arity, fp)"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1295
  and len: "length xs = n"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1296
  shows "{\<lambda>nl. nl = xs @ 0 \<up> (fp - arity) @ anything} ap {\<lambda>nl. nl = xs @ rec_exec (Cn n f gs) xs # 0 \<up> (fp - Suc arity) @ anything}"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1297
proof(case_tac "rec_ci f")
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1298
  fix fap far ffp
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1299
  assume h: "rec_ci f = (fap, far, ffp)"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1300
  then have f_newind: "\<And> anything .{\<lambda>nl. nl = map (\<lambda>g. rec_exec g xs) gs @ 0 \<up> (ffp - far) @ anything} fap
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1301
    {\<lambda>nl. nl = map (\<lambda>g. rec_exec g xs) gs @ rec_exec f (map (\<lambda>g. rec_exec g xs) gs) # 0 \<up> (ffp - Suc far) @ anything}"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1302
    by(rule_tac f_ind, simp_all)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1303
  thus "{\<lambda>nl. nl = xs @ 0 \<up> (fp - arity) @ anything} ap {\<lambda>nl. nl = xs @ rec_exec (Cn n f gs) xs # 0 \<up> (fp - Suc arity) @ anything}"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1304
    using compile len h termi_f g_cond
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1305
    apply(auto simp: rec_ci.simps abc_comp_commute)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1306
    apply(rule_tac compile_cn_correct', simp_all)
70
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1307
    done
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1308
qed
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1309
229
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1310
lemma [simp]: 
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1311
  "\<lbrakk>length xs = n; ft = max (n+3) (max fft gft)\<rbrakk> 
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1312
 \<Longrightarrow> {\<lambda>nl. nl = xs @ 0 # 0 \<up> (ft - n) @ anything} mv_box n ft 
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1313
       {\<lambda>nl. nl = xs @ 0 # 0 \<up> (ft - n) @ anything}"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1314
using mv_box_correct[of n ft "xs @ 0 # 0 \<up> (ft - n) @ anything"]
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1315
by(auto)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1316
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1317
lemma [simp]: "length xs < max (length xs + 3) (max fft gft)"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1318
by auto
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1319
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1320
lemma save_init_rs: 
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1321
  "\<lbrakk>length xs = n; ft = max (n+3) (max fft gft)\<rbrakk> 
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1322
     \<Longrightarrow>  {\<lambda>nl. nl = xs @ rec_exec f xs # 0 \<up> (ft - n) @ anything} mv_box n (Suc n) 
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1323
       {\<lambda>nl. nl = xs @ 0 # rec_exec f xs # 0 \<up> (ft - Suc n) @ anything}"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1324
using mv_box_correct[of n "Suc n" "xs @ rec_exec f xs # 0 \<up> (ft - n) @ anything"]
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1325
apply(auto simp: list_update_append list_update.simps nth_append split: if_splits)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1326
apply(case_tac "(max (length xs + 3) (max fft gft))", simp_all add: list_update.simps Suc_diff_le)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1327
done
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1328
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1329
lemma [simp]: "n + (2::nat) < max (n + 3) (max fft gft)"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1330
by auto
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1331
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1332
lemma [simp]: "n < max (n + (3::nat)) (max fft gft)"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1333
by auto
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1334
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1335
lemma [simp]:
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1336
  "length xs = n \<Longrightarrow> 
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1337
  {\<lambda>nl. nl = xs @ x # 0 \<up> (max (n + (3::nat)) (max fft gft) - n) @ anything} mv_box n (max (n + 3) (max fft gft))
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1338
  {\<lambda>nl. nl = xs @ 0 \<up> (max (n + 3) (max fft gft) - n) @ x # anything}"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1339
proof -
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1340
  assume h: "length xs = n"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1341
  let ?ft = "max (n+3) (max fft gft)"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1342
  let ?lm = "xs @ x # 0\<up>(?ft - Suc n) @ 0 # anything"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1343
  have g: "?ft > n + 2"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1344
    by simp
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1345
  thm mv_box_correct
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1346
  have a: "{\<lambda> nl. nl = ?lm} mv_box n ?ft {\<lambda> nl. nl = ?lm[?ft := ?lm!n + ?lm!?ft, n := 0]}"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1347
    using h
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1348
    by(rule_tac mv_box_correct, auto)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1349
  have b:"?lm = xs @ x # 0 \<up> (max (n + 3) (max fft gft) - n) @ anything"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1350
    by(case_tac ?ft, simp_all add: Suc_diff_le exp_suc del: replicate_Suc)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1351
  have c: "?lm[?ft := ?lm!n + ?lm!?ft, n := 0] = xs @ 0 \<up> (max (n + 3) (max fft gft) - n) @ x # anything"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1352
    using h g
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1353
    apply(auto simp: nth_append list_update_append split: if_splits)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1354
    using list_update_append[of "x # 0 \<up> (max (length xs + 3) (max fft gft) - Suc (length xs))" "0 # anything"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1355
                                 "max (length xs + 3) (max fft gft) - length xs" "x"]
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1356
    apply(auto simp: if_splits)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1357
    apply(simp add: list_update.simps replicate_Suc[THEN sym] del: replicate_Suc)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1358
    done
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1359
  from a c show "?thesis"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1360
    using h
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1361
    apply(simp)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1362
    using b
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1363
    by simp
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1364
qed
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1365
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1366
lemma [simp]: "max n (Suc n) < Suc (Suc (max (n + 3) (max fft gft) + length anything - Suc 0))"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1367
by arith    
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1368
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1369
lemma [simp]: "Suc n < max (n + 3) (max fft gft)"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1370
by arith
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1371
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1372
lemma [simp]:
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1373
  "length xs = n
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1374
 \<Longrightarrow> {\<lambda>nl. nl = xs @ rec_exec f xs # 0 \<up> (max (n + 3) (max fft gft) - Suc n) @ x # anything} mv_box n (Suc n)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1375
    {\<lambda>nl. nl = xs @ 0 # rec_exec f xs # 0 \<up> (max (n + 3) (max fft gft) - Suc (Suc n)) @ x # anything}"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1376
using mv_box_correct[of n "Suc n" "xs @ rec_exec f xs # 0 \<up> (max (n + 3) (max fft gft) - Suc n) @ x # anything"]
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1377
apply(simp add: nth_append list_update_append list_update.simps)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1378
apply(case_tac "max (n + 3) (max fft gft)", simp_all)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1379
apply(case_tac nat, simp_all add: Suc_diff_le list_update.simps)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1380
done
70
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1381
229
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1382
lemma abc_append_frist_steps_eq_pre: 
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1383
  assumes notfinal: "abc_notfinal (abc_steps_l (0, lm)  A n) A"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1384
  and notnull: "A \<noteq> []"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1385
  shows "abc_steps_l (0, lm) (A @ B) n = abc_steps_l (0, lm) A n"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1386
using notfinal
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1387
proof(induct n)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1388
  case 0
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1389
  thus "?case"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1390
    by(simp add: abc_steps_l.simps)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1391
next
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1392
  case (Suc n)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1393
  have ind: "abc_notfinal (abc_steps_l (0, lm) A n) A \<Longrightarrow> abc_steps_l (0, lm) (A @ B) n = abc_steps_l (0, lm) A n"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1394
    by fact
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1395
  have h: "abc_notfinal (abc_steps_l (0, lm) A (Suc n)) A" by fact
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1396
  then have a: "abc_notfinal (abc_steps_l (0, lm) A n) A"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1397
    by(simp add: notfinal_Suc)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1398
  then have b: "abc_steps_l (0, lm) (A @ B) n = abc_steps_l (0, lm) A n"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1399
    using ind by simp
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1400
  obtain s lm' where c: "abc_steps_l (0, lm) A n = (s, lm')"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1401
    by (metis prod.exhaust)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1402
  then have d: "s < length A \<and> abc_steps_l (0, lm) (A @ B) n = (s, lm')" 
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1403
    using a b by simp
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1404
  thus "?case"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1405
    using c
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1406
    by(simp add: abc_step_red2 abc_fetch.simps abc_step_l.simps nth_append)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1407
qed
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1408
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1409
lemma abc_append_first_step_eq_pre: 
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1410
  "st < length A
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1411
 \<Longrightarrow> abc_step_l (st, lm) (abc_fetch st (A @ B)) = 
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1412
    abc_step_l (st, lm) (abc_fetch st A)"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1413
by(simp add: abc_step_l.simps abc_fetch.simps nth_append)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1414
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1415
lemma abc_append_frist_steps_halt_eq': 
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1416
  assumes final: "abc_steps_l (0, lm) A n = (length A, lm')"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1417
    and notnull: "A \<noteq> []"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1418
  shows "\<exists> n'. abc_steps_l (0, lm) (A @ B) n' = (length A, lm')"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1419
proof -
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1420
  have "\<exists> n'. abc_notfinal (abc_steps_l (0, lm) A n') A \<and> 
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1421
    abc_final (abc_steps_l (0, lm) A (Suc n')) A"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1422
    using assms
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1423
    by(rule_tac n = n in abc_before_final, simp_all)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1424
  then obtain na where a:
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1425
    "abc_notfinal (abc_steps_l (0, lm) A na) A \<and> 
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1426
            abc_final (abc_steps_l (0, lm) A (Suc na)) A" ..
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1427
  obtain sa lma where b: "abc_steps_l (0, lm) A na = (sa, lma)"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1428
    by (metis prod.exhaust)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1429
  then have c: "abc_steps_l (0, lm) (A @ B) na = (sa, lma)"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1430
    using a abc_append_frist_steps_eq_pre[of lm A na B] assms 
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1431
    by simp
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1432
  have d: "sa < length A" using b a by simp
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1433
  then have e: "abc_step_l (sa, lma) (abc_fetch sa (A @ B)) = 
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1434
    abc_step_l (sa, lma) (abc_fetch sa A)"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1435
    by(rule_tac abc_append_first_step_eq_pre)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1436
  from a have "abc_steps_l (0, lm) A (Suc na) = (length A, lm')"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1437
    using final equal_when_halt
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1438
    by(case_tac "abc_steps_l (0, lm) A (Suc na)" , simp)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1439
  then have "abc_steps_l (0, lm) (A @ B) (Suc na) = (length A, lm')"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1440
    using a b c e
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1441
    by(simp add: abc_step_red2)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1442
  thus "?thesis"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1443
    by blast
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1444
qed
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1445
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1446
lemma abc_append_frist_steps_halt_eq: 
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1447
  assumes final: "abc_steps_l (0, lm) A n = (length A, lm')"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1448
  shows "\<exists> n'. abc_steps_l (0, lm) (A @ B) n' = (length A, lm')"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1449
using final
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1450
apply(case_tac "A = []")
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1451
apply(rule_tac x = 0 in exI, simp add: abc_steps_l.simps abc_exec_null)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1452
apply(rule_tac abc_append_frist_steps_halt_eq', simp_all)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1453
done
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1454
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1455
lemma [simp]: "Suc (Suc (max (length xs + 3) (max fft gft) - Suc (Suc (length xs))))
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1456
           = max (length xs + 3) (max fft gft) - (length xs)"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1457
by arith
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1458
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1459
lemma [simp]: "\<lbrakk>ft = max (n + 3) (max fft gft); length xs = n\<rbrakk> \<Longrightarrow>
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1460
     {\<lambda>nl. nl = xs @ (x - Suc y) # rec_exec (Pr n f g) (xs @ [x - Suc y]) # 0 \<up> (ft - Suc (Suc n)) @ Suc y # anything}
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1461
     [Dec ft (length gap + 7)] 
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1462
     {\<lambda>nl. nl = xs @ (x - Suc y) # rec_exec (Pr n f g) (xs @ [x - Suc y]) # 0 \<up> (ft - Suc (Suc n)) @ y # anything}"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1463
apply(simp add: abc_Hoare_halt_def)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1464
apply(rule_tac x = 1 in exI)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1465
apply(auto simp: abc_steps_l.simps abc_step_l.simps abc_fetch.simps nth_append abc_lm_v.simps abc_lm_s.simps list_update_append)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1466
using list_update_length
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1467
[of "(x - Suc y) # rec_exec (Pr (length xs) f g) (xs @ [x - Suc y]) #
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1468
          0 \<up> (max (length xs + 3) (max fft gft) - Suc (Suc (length xs)))" "Suc y" anything y]
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1469
apply(simp)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1470
done
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1471
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1472
lemma adjust_paras': 
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1473
  "length xs = n \<Longrightarrow> {\<lambda>nl. nl = xs @ x # y # anything}  [Inc n] [+] [Dec (Suc n) 2, Goto 0]
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1474
       {\<lambda>nl. nl = xs @ Suc x # 0 # anything}"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1475
proof(rule_tac abc_Hoare_plus_halt)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1476
  assume "length xs = n"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1477
  thus "{\<lambda>nl. nl = xs @ x # y # anything} [Inc n] {\<lambda> nl. nl = xs @ Suc x # y # anything}"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1478
    apply(simp add: abc_Hoare_halt_def)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1479
    apply(rule_tac x = 1 in exI, simp add: abc_steps_l.simps abc_step_l.simps abc_fetch.simps abc_comp.simps
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1480
                                           abc_lm_v.simps abc_lm_s.simps nth_append list_update_append list_update.simps)
70
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1481
    done
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1482
next
229
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1483
  assume h: "length xs = n"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1484
  thus "{\<lambda>nl. nl = xs @ Suc x # y # anything} [Dec (Suc n) 2, Goto 0] {\<lambda>nl. nl = xs @ Suc x # 0 # anything}"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1485
  proof(induct y)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1486
    case 0
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1487
    thus "?case"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1488
      apply(simp add: abc_Hoare_halt_def)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1489
      apply(rule_tac x = 1 in exI, simp add: abc_steps_l.simps abc_step_l.simps abc_fetch.simps abc_comp.simps
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1490
                                           abc_lm_v.simps abc_lm_s.simps nth_append list_update_append list_update.simps)
70
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1491
      done
229
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1492
  next
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1493
    case (Suc y)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1494
    have "length xs = n \<Longrightarrow> 
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1495
      {\<lambda>nl. nl = xs @ Suc x # y # anything} [Dec (Suc n) 2, Goto 0] {\<lambda>nl. nl = xs @ Suc x # 0 # anything}" by fact
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1496
    then obtain stp where 
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1497
      "abc_steps_l (0, xs @ Suc x # y # anything) [Dec (Suc n) 2, Goto 0] stp = (2, xs @ Suc x # 0 # anything)"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1498
      using h
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1499
      apply(auto simp: abc_Hoare_halt_def)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1500
      by(case_tac "abc_steps_l (0, xs @ Suc x # y # anything) [Dec (Suc (length xs)) 2, Goto 0] n",   
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1501
            simp_all add: numeral_2_eq_2)   
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1502
    moreover have "abc_steps_l (0, xs @ Suc x # Suc y # anything) [Dec (Suc n) 2, Goto 0] 2 = 
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1503
                 (0, xs @ Suc x # y # anything)"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1504
      using h
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1505
      by(simp add: abc_steps_l.simps numeral_2_eq_2 abc_step_l.simps abc_fetch.simps
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1506
        abc_lm_v.simps abc_lm_s.simps nth_append list_update_append list_update.simps)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1507
    ultimately show "?case"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1508
      apply(simp add: abc_Hoare_halt_def)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1509
      by(rule_tac x = "2 + stp" in exI, simp only: abc_steps_add, simp)
70
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1510
  qed
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1511
qed
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1512
229
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1513
lemma adjust_paras: 
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1514
  "length xs = n \<Longrightarrow> {\<lambda>nl. nl = xs @ x # y # anything}  [Inc n, Dec (Suc n) 3, Goto (Suc 0)]
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1515
       {\<lambda>nl. nl = xs @ Suc x # 0 # anything}"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1516
using adjust_paras'[of xs n x y anything]
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1517
by(simp add: abc_comp.simps abc_shift.simps numeral_2_eq_2 numeral_3_eq_3)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1518
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1519
lemma [simp]: "\<lbrakk>rec_ci g = (gap, gar, gft); \<forall>y<x. terminate g (xs @ [y, rec_exec (Pr n f g) (xs @ [y])]);
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1520
        length xs = n; Suc y\<le>x\<rbrakk> \<Longrightarrow> gar = Suc (Suc n)"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1521
  apply(erule_tac x = y in allE, simp)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1522
  apply(drule_tac param_pattern, auto)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1523
  done
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1524
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1525
lemma loop_back':  
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1526
  assumes h: "length A = length gap + 4" "length xs = n"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1527
  and le: "y \<ge> x"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1528
  shows "\<exists> stp. abc_steps_l (length A, xs @ m # (y - x) # x # anything) (A @ [Dec (Suc (Suc n)) 0, Inc (Suc n), Goto (length gap + 4)]) stp
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1529
     = (length A, xs @ m # y # 0 # anything)"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1530
  using le
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1531
proof(induct x)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1532
  case 0
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1533
  thus "?case"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1534
    using h
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1535
    by(rule_tac x = 0 in exI,
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1536
    auto simp: abc_steps_l.simps abc_step_l.simps abc_fetch.simps nth_append abc_lm_s.simps abc_lm_v.simps)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1537
next
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1538
  case (Suc x)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1539
  have "x \<le> y \<Longrightarrow> \<exists>stp. abc_steps_l (length A, xs @ m # (y - x) # x # anything) (A @ [Dec (Suc (Suc n)) 0, Inc (Suc n), Goto (length gap + 4)]) stp =
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1540
              (length A, xs @ m # y # 0 # anything)" by fact
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1541
  moreover have "Suc x \<le> y" by fact
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1542
  moreover then have "\<exists> stp. abc_steps_l (length A, xs @ m # (y - Suc x) # Suc x # anything) (A @ [Dec (Suc (Suc n)) 0, Inc (Suc n), Goto (length gap + 4)]) stp
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1543
                = (length A, xs @ m # (y - x) # x # anything)"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1544
    using h
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1545
    apply(rule_tac x = 3 in exI)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1546
    by(simp add: abc_steps_l.simps numeral_3_eq_3 abc_step_l.simps abc_fetch.simps nth_append abc_lm_v.simps abc_lm_s.simps
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1547
                    list_update_append list_update.simps)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1548
  ultimately show "?case"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1549
    apply(auto)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1550
    apply(rule_tac x = "stpa + stp" in exI)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1551
    by(simp add: abc_steps_add)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1552
qed
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1553
70
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1554
229
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1555
lemma loop_back:  
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1556
  assumes h: "length A = length gap + 4" "length xs = n"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1557
  shows "\<exists> stp. abc_steps_l (length A, xs @ m # 0 # x # anything) (A @ [Dec (Suc (Suc n)) 0, Inc (Suc n), Goto (length gap + 4)]) stp
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1558
     = (0, xs @ m # x # 0 # anything)"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1559
using loop_back'[of A gap xs n x x m anything] assms
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1560
apply(auto)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1561
apply(rule_tac x = "stp + 1" in exI)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1562
apply(simp only: abc_steps_add, simp)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1563
apply(simp add: abc_steps_l.simps abc_step_l.simps abc_fetch.simps nth_append abc_lm_v.simps abc_lm_s.simps)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1564
done
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1565
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1566
lemma rec_exec_pr_0_simps: "rec_exec (Pr n f g) (xs @ [0]) = rec_exec f xs"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1567
 by(simp add: rec_exec.simps)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1568
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1569
lemma rec_exec_pr_Suc_simps: "rec_exec (Pr n f g) (xs @ [Suc y])
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1570
          = rec_exec g (xs @ [y, rec_exec (Pr n f g) (xs @ [y])])"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1571
apply(induct y)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1572
apply(simp add: rec_exec.simps)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1573
apply(simp add: rec_exec.simps)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1574
done
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1575
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1576
lemma [simp]: "Suc (max (n + 3) (max fft gft) - Suc (Suc (Suc n))) = max (n + 3) (max fft gft) - Suc (Suc n)"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1577
by arith
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1578
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1579
lemma pr_loop:
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1580
  assumes code: "code = ([Dec (max (n + 3) (max fft gft)) (length gap + 7)] [+] (gap [+] [Inc n, Dec (Suc n) 3, Goto (Suc 0)])) @
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1581
    [Dec (Suc (Suc n)) 0, Inc (Suc n), Goto (length gap + 4)]"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1582
  and len: "length xs = n"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1583
  and g_ind: "\<forall> y<x. (\<forall>anything. {\<lambda>nl. nl = xs @ y # rec_exec (Pr n f g) (xs @ [y]) # 0 \<up> (gft - gar) @ anything} gap
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1584
  {\<lambda>nl. nl = xs @ y # rec_exec (Pr n f g) (xs @ [y]) # rec_exec g (xs @ [y, rec_exec (Pr n f g) (xs @ [y])]) # 0 \<up> (gft - Suc gar) @ anything})"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1585
  and compile_g: "rec_ci g = (gap, gar, gft)"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1586
  and termi_g: "\<forall> y<x. terminate g (xs @ [y, rec_exec (Pr n f g) (xs @ [y])])"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1587
  and ft: "ft = max (n + 3) (max fft gft)"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1588
  and less: "Suc y \<le> x"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1589
  shows 
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1590
  "\<exists>stp. abc_steps_l (0, xs @ (x - Suc y) # rec_exec (Pr n f g) (xs @ [x - Suc y]) # 0 \<up> (ft - Suc (Suc n)) @ Suc y # anything)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1591
  code stp = (0, xs @ (x - y) # rec_exec (Pr n f g) (xs @ [x - y]) # 0 \<up> (ft - Suc (Suc n)) @ y # anything)"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1592
proof -
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1593
  let ?A = "[Dec  ft (length gap + 7)]"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1594
  let ?B = "gap"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1595
  let ?C = "[Inc n, Dec (Suc n) 3, Goto (Suc 0)]"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1596
  let ?D = "[Dec (Suc (Suc n)) 0, Inc (Suc n), Goto (length gap + 4)]"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1597
  have "\<exists> stp. abc_steps_l (0, xs @ (x - Suc y) # rec_exec (Pr n f g) (xs @ [x - Suc y]) # 0 \<up> (ft - Suc (Suc n)) @ Suc y # anything)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1598
            ((?A [+] (?B [+] ?C)) @ ?D) stp = (length (?A [+] (?B [+] ?C)), 
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1599
          xs @ (x - y) # 0 # rec_exec g (xs @ [x - Suc y, rec_exec (Pr n f g) (xs @ [x - Suc y])])
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1600
                  # 0 \<up> (ft - Suc (Suc (Suc n))) @ y # anything)"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1601
  proof -
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1602
    have "\<exists> stp. abc_steps_l (0, xs @ (x - Suc y) # rec_exec (Pr n f g) (xs @ [x - Suc y]) # 0 \<up> (ft - Suc (Suc n)) @ Suc y # anything)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1603
      ((?A [+] (?B [+] ?C))) stp = (length (?A [+] (?B [+] ?C)),  xs @ (x - y) # 0 # 
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1604
      rec_exec g (xs @ [x - Suc y, rec_exec (Pr n f g) (xs @ [x - Suc y])]) # 0 \<up> (ft - Suc (Suc (Suc n))) @ y # anything)"
70
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1605
    proof -
229
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1606
      have "{\<lambda> nl. nl = xs @ (x - Suc y) # rec_exec (Pr n f g) (xs @ [x - Suc y]) # 0 \<up> (ft - Suc (Suc n)) @ Suc y # anything}
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1607
        (?A [+] (?B [+] ?C)) 
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1608
        {\<lambda> nl. nl = xs @ (x - y) # 0 # 
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1609
        rec_exec g (xs @ [x - Suc y, rec_exec (Pr n f g) (xs @ [x - Suc y])]) # 0 \<up> (ft - Suc (Suc (Suc n))) @ y # anything}"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1610
      proof(rule_tac abc_Hoare_plus_halt)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1611
        show "{\<lambda>nl. nl = xs @ (x - Suc y) # rec_exec (Pr n f g) (xs @ [x - Suc y]) # 0 \<up> (ft - Suc (Suc n)) @ Suc y # anything}
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1612
          [Dec ft (length gap + 7)] 
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1613
          {\<lambda>nl. nl = xs @ (x - Suc y) # rec_exec (Pr n f g) (xs @ [x - Suc y]) # 0 \<up> (ft - Suc (Suc n)) @ y # anything}"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1614
          using ft len
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1615
          by(simp)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1616
      next
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1617
        show 
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1618
          "{\<lambda>nl. nl = xs @ (x - Suc y) # rec_exec (Pr n f g) (xs @ [x - Suc y]) # 0 \<up> (ft - Suc (Suc n)) @ y # anything} 
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1619
          ?B [+] ?C
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1620
          {\<lambda>nl. nl = xs @ (x - y) # 0 # rec_exec g (xs @ [x - Suc y, rec_exec (Pr n f g) (xs @ [x - Suc y])]) # 0 \<up> (ft - Suc (Suc (Suc n))) @ y # anything}"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1621
        proof(rule_tac abc_Hoare_plus_halt)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1622
          have a: "gar = Suc (Suc n)" 
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1623
            using compile_g termi_g len less
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1624
            by simp
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1625
          have b: "gft > gar"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1626
            using compile_g
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1627
            by(erule_tac footprint_ge)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1628
          show "{\<lambda>nl. nl = xs @ (x - Suc y) # rec_exec (Pr n f g) (xs @ [x - Suc y]) # 0 \<up> (ft - Suc (Suc n)) @ y # anything} gap 
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1629
                {\<lambda>nl. nl = xs @ (x - Suc y) # rec_exec (Pr n f g) (xs @ [x - Suc y]) # 
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1630
                      rec_exec g (xs @ [x - Suc y, rec_exec (Pr n f g) (xs @ [x - Suc y])]) # 0 \<up> (ft - Suc (Suc (Suc n))) @ y # anything}"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1631
          proof -
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1632
            have 
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1633
              "{\<lambda>nl. nl = xs @ (x - Suc y) # rec_exec (Pr n f g) (xs @ [x - Suc y]) # 0 \<up> (gft - gar) @ 0\<up>(ft - gft) @ y # anything} gap
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1634
              {\<lambda>nl. nl = xs @ (x - Suc y) # rec_exec (Pr n f g) (xs @ [x - Suc y]) # 
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1635
              rec_exec g (xs @ [(x - Suc y), rec_exec (Pr n f g) (xs @ [x - Suc y])]) # 0 \<up> (gft - Suc gar) @ 0\<up>(ft - gft) @ y # anything}"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1636
              using g_ind less by simp
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1637
            thus "?thesis"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1638
              using a b ft
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1639
              by(simp add: replicate_merge_anywhere numeral_3_eq_3)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1640
          qed
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1641
        next
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1642
          show "{\<lambda>nl. nl = xs @ (x - Suc y) #
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1643
                    rec_exec (Pr n f g) (xs @ [x - Suc y]) #
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1644
            rec_exec g (xs @ [x - Suc y, rec_exec (Pr n f g) (xs @ [x - Suc y])]) # 0 \<up> (ft - Suc (Suc (Suc n))) @ y # anything}
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1645
            [Inc n, Dec (Suc n) 3, Goto (Suc 0)]
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1646
            {\<lambda>nl. nl = xs @ (x - y) # 0 # rec_exec g (xs @ [x - Suc y, rec_exec (Pr n f g) 
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1647
                    (xs @ [x - Suc y])]) # 0 \<up> (ft - Suc (Suc (Suc n))) @ y # anything}"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1648
            using len less
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1649
            using adjust_paras[of xs n "x - Suc y" " rec_exec (Pr n f g) (xs @ [x - Suc y])"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1650
              " rec_exec g (xs @ [x - Suc y, rec_exec (Pr n f g) (xs @ [x - Suc y])]) # 
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1651
              0 \<up> (ft - Suc (Suc (Suc n))) @ y # anything"]
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1652
            by(simp add: Suc_diff_Suc)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1653
        qed
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1654
      qed
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1655
      thus "?thesis"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1656
        by(simp add: abc_Hoare_halt_def, auto, rule_tac x = na in exI, case_tac "abc_steps_l (0, xs @ (x - Suc y) # rec_exec (Pr n f g) (xs @ [x - Suc y]) # 
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1657
          0 \<up> (ft - Suc (Suc n)) @ Suc y # anything)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1658
             ([Dec ft (length gap + 7)] [+] (gap [+] [Inc n, Dec (Suc n) 3, Goto (Suc 0)])) na", simp)
70
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1659
    qed
229
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1660
    then obtain stpa where "abc_steps_l (0, xs @ (x - Suc y) # rec_exec (Pr n f g) (xs @ [x - Suc y]) # 0 \<up> (ft - Suc (Suc n)) @ Suc y # anything)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1661
            ((?A [+] (?B [+] ?C))) stpa = (length (?A [+] (?B [+] ?C)), 
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1662
          xs @ (x - y) # 0 # rec_exec g (xs @ [x - Suc y, rec_exec (Pr n f g) (xs @ [x - Suc y])])
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1663
                  # 0 \<up> (ft - Suc (Suc (Suc n))) @ y # anything)" ..
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1664
    thus "?thesis"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1665
      by(erule_tac abc_append_frist_steps_halt_eq)
70
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1666
  qed
229
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1667
  moreover have 
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1668
    "\<exists> stp. abc_steps_l (length (?A [+] (?B [+] ?C)),
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1669
    xs @ (x - y) # 0 # rec_exec g (xs @ [x - Suc y, rec_exec (Pr n f g) (xs @ [x - Suc y])]) # 0 \<up> (ft - Suc (Suc (Suc n))) @ y # anything)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1670
    ((?A [+] (?B [+] ?C)) @ ?D) stp  = (0, xs @ (x - y) # rec_exec g (xs @ [x - Suc y, rec_exec (Pr n f g) (xs @ [x - Suc y])]) # 
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1671
    0 # 0 \<up> (ft - Suc (Suc (Suc n))) @ y # anything)"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1672
    using len
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1673
    by(rule_tac loop_back, simp_all)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1674
  moreover have "rec_exec g (xs @ [x - Suc y, rec_exec (Pr n f g) (xs @ [x - Suc y])]) = rec_exec (Pr n f g) (xs @ [x - y])"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1675
    using less
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1676
    thm rec_exec.simps
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1677
    apply(case_tac "x - y", simp_all add: rec_exec_pr_Suc_simps)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1678
    by(subgoal_tac "nat = x - Suc y", simp, arith)    
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1679
  ultimately show "?thesis"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1680
    using code ft
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1681
    by(auto, rule_tac x = "stp + stpa" in exI, simp add: abc_steps_add replicate_Suc_iff_anywhere del: replicate_Suc)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1682
qed
70
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1683
229
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1684
lemma [simp]: 
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1685
  "length xs = n \<Longrightarrow> abc_lm_s (xs @ x # rec_exec (Pr n f g) (xs @ [x]) # 0 \<up> (max (n + 3) 
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1686
  (max fft gft) - Suc (Suc n)) @ 0 # anything) (max (n + 3) (max fft gft)) 0 =
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1687
    xs @ x # rec_exec (Pr n f g) (xs @ [x]) # 0 \<up> (max (n + 3) (max fft gft) - Suc n) @ anything"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1688
apply(simp add: abc_lm_s.simps)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1689
using list_update_length[of "xs @ x # rec_exec (Pr n f g) (xs @ [x]) # 0 \<up> (max (n + 3) (max fft gft) - Suc (Suc n))"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1690
                        0 anything 0]
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1691
apply(auto simp: Suc_diff_Suc)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1692
apply(simp add: exp_suc[THEN sym] Suc_diff_Suc  del: replicate_Suc)
70
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1693
done
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1694
229
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1695
lemma [simp]:
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1696
  "(xs @ x # rec_exec (Pr (length xs) f g) (xs @ [x]) # 0 \<up> (max (length xs + 3)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1697
  (max fft gft) - Suc (Suc (length xs))) @ 0 # anything) !
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1698
    max (length xs + 3) (max fft gft) = 0"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1699
using nth_append_length[of "xs @ x # rec_exec (Pr (length xs) f g) (xs @ [x]) #
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1700
  0 \<up> (max (length xs + 3) (max fft gft) - Suc (Suc (length xs)))" 0  anything]
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1701
by(simp)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1702
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1703
lemma pr_loop_correct:
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1704
  assumes less: "y \<le> x" 
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1705
  and len: "length xs = n"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1706
  and compile_g: "rec_ci g = (gap, gar, gft)"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1707
  and termi_g: "\<forall> y<x. terminate g (xs @ [y, rec_exec (Pr n f g) (xs @ [y])])"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1708
  and g_ind: "\<forall> y<x. (\<forall>anything. {\<lambda>nl. nl = xs @ y # rec_exec (Pr n f g) (xs @ [y]) # 0 \<up> (gft - gar) @ anything} gap
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1709
  {\<lambda>nl. nl = xs @ y # rec_exec (Pr n f g) (xs @ [y]) # rec_exec g (xs @ [y, rec_exec (Pr n f g) (xs @ [y])]) # 0 \<up> (gft - Suc gar) @ anything})"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1710
  shows "{\<lambda>nl. nl = xs @ (x - y) # rec_exec (Pr n f g) (xs @ [x - y]) # 0 \<up> (max (n + 3) (max fft gft) - Suc (Suc n)) @ y # anything}
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1711
   ([Dec (max (n + 3) (max fft gft)) (length gap + 7)] [+] (gap [+] [Inc n, Dec (Suc n) 3, Goto (Suc 0)])) @ [Dec (Suc (Suc n)) 0, Inc (Suc n), Goto (length gap + 4)]
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1712
   {\<lambda>nl. nl = xs @ x # rec_exec (Pr n f g) (xs @ [x]) # 0 \<up> (max (n + 3) (max fft gft) - Suc n) @ anything}" 
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1713
  using less
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1714
proof(induct y)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1715
  case 0
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1716
  thus "?case"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1717
    using len
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1718
    apply(simp add: abc_Hoare_halt_def)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1719
    apply(rule_tac x = 1 in exI)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1720
    by(auto simp: abc_steps_l.simps abc_step_l.simps abc_fetch.simps 
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1721
      nth_append abc_comp.simps abc_shift.simps, simp add: abc_lm_v.simps)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1722
next
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1723
  case (Suc y)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1724
  let ?ft = "max (n + 3) (max fft gft)"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1725
  let ?C = "[Dec (max (n + 3) (max fft gft)) (length gap + 7)] [+] (gap [+] 
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1726
    [Inc n, Dec (Suc n) 3, Goto (Suc 0)]) @ [Dec (Suc (Suc n)) 0, Inc (Suc n), Goto (length gap + 4)]"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1727
  have ind: "y \<le> x \<Longrightarrow>
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1728
         {\<lambda>nl. nl = xs @ (x - y) # rec_exec (Pr n f g) (xs @ [x - y]) # 0 \<up> (?ft - Suc (Suc n)) @ y # anything}
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1729
         ?C {\<lambda>nl. nl = xs @ x # rec_exec (Pr n f g) (xs @ [x]) # 0 \<up> (?ft - Suc n) @ anything}" by fact 
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1730
  have less: "Suc y \<le> x" by fact
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1731
  have stp1: 
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1732
    "\<exists> stp. abc_steps_l (0, xs @ (x - Suc y) # rec_exec (Pr n f g) (xs @ [x - Suc y]) # 0 \<up> (?ft - Suc (Suc n)) @ Suc y # anything)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1733
    ?C stp  = (0, xs @ (x - y) # rec_exec (Pr n f g) (xs @ [x - y]) # 0 \<up> (?ft - Suc (Suc n)) @ y # anything)"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1734
    using assms less
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1735
    by(rule_tac  pr_loop, auto)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1736
  then obtain stp1 where a:
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1737
    "abc_steps_l (0, xs @ (x - Suc y) # rec_exec (Pr n f g) (xs @ [x - Suc y]) # 0 \<up> (?ft - Suc (Suc n)) @ Suc y # anything)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1738
   ?C stp1 = (0, xs @ (x - y) # rec_exec (Pr n f g) (xs @ [x - y]) # 0 \<up> (?ft - Suc (Suc n)) @ y # anything)" ..
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1739
  moreover have 
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1740
    "\<exists> stp. abc_steps_l (0, xs @ (x - y) # rec_exec (Pr n f g) (xs @ [x - y]) # 0 \<up> (?ft - Suc (Suc n)) @ y # anything)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1741
    ?C stp = (length ?C, xs @ x # rec_exec (Pr n f g) (xs @ [x]) # 0 \<up> (?ft - Suc n) @ anything)"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1742
    using ind less
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1743
    by(auto simp: abc_Hoare_halt_def, case_tac "abc_steps_l (0, xs @ (x - y) # rec_exec (Pr n f g) 
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1744
      (xs @ [x - y]) # 0 \<up> (?ft - Suc (Suc n)) @ y # anything) ?C na", rule_tac x = na in exI, simp)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1745
  then obtain stp2 where b:
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1746
    "abc_steps_l (0, xs @ (x - y) # rec_exec (Pr n f g) (xs @ [x - y]) # 0 \<up> (?ft - Suc (Suc n)) @ y # anything)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1747
    ?C stp2 = (length ?C, xs @ x # rec_exec (Pr n f g) (xs @ [x]) # 0 \<up> (?ft - Suc n) @ anything)" ..
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1748
  from a b show "?case"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1749
    by(simp add: abc_Hoare_halt_def, rule_tac x = "stp1 + stp2" in exI, simp add: abc_steps_add)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1750
qed
70
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1751
229
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1752
lemma compile_pr_correct':
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1753
  assumes termi_g: "\<forall> y<x. terminate g (xs @ [y, rec_exec (Pr n f g) (xs @ [y])])"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1754
  and g_ind: 
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1755
  "\<forall> y<x. (\<forall>anything. {\<lambda>nl. nl = xs @ y # rec_exec (Pr n f g) (xs @ [y]) # 0 \<up> (gft - gar) @ anything} gap
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1756
  {\<lambda>nl. nl = xs @ y # rec_exec (Pr n f g) (xs @ [y]) # rec_exec g (xs @ [y, rec_exec (Pr n f g) (xs @ [y])]) # 0 \<up> (gft - Suc gar) @ anything})"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1757
  and termi_f: "terminate f xs"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1758
  and f_ind: "\<And> anything. {\<lambda>nl. nl = xs @ 0 \<up> (fft - far) @ anything} fap {\<lambda>nl. nl = xs @ rec_exec f xs # 0 \<up> (fft - Suc far) @ anything}"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1759
  and len: "length xs = n"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1760
  and compile1: "rec_ci f = (fap, far, fft)"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1761
  and compile2: "rec_ci g = (gap, gar, gft)"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1762
  shows 
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1763
  "{\<lambda>nl. nl = xs @ x # 0 \<up> (max (n + 3) (max fft gft) - n) @ anything}
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1764
  mv_box n (max (n + 3) (max fft gft)) [+]
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1765
  (fap [+] (mv_box n (Suc n) [+]
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1766
  ([Dec (max (n + 3) (max fft gft)) (length gap + 7)] [+] (gap [+] [Inc n, Dec (Suc n) 3, Goto (Suc 0)]) @
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1767
  [Dec (Suc (Suc n)) 0, Inc (Suc n), Goto (length gap + 4)])))
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1768
  {\<lambda>nl. nl = xs @ x # rec_exec (Pr n f g) (xs @ [x]) # 0 \<up> (max (n + 3) (max fft gft) - Suc n) @ anything}"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1769
proof -
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1770
  let ?ft = "max (n+3) (max fft gft)"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1771
  let ?A = "mv_box n ?ft"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1772
  let ?B = "fap"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1773
  let ?C = "mv_box n (Suc n)"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1774
  let ?D = "[Dec ?ft (length gap + 7)]"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1775
  let ?E = "gap [+] [Inc n, Dec (Suc n) 3, Goto (Suc 0)]"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1776
  let ?F = "[Dec (Suc (Suc n)) 0, Inc (Suc n), Goto (length gap + 4)]"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1777
  let ?P = "\<lambda>nl. nl = xs @ x # 0 \<up> (?ft - n) @ anything"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1778
  let ?S = "\<lambda>nl. nl = xs @ x # rec_exec (Pr n f g) (xs @ [x]) # 0 \<up> (?ft - Suc n) @ anything"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1779
  let ?Q1 = "\<lambda>nl. nl = xs @ 0 \<up> (?ft - n) @  x # anything"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1780
  show "{?P} (?A [+] (?B [+] (?C [+] (?D [+] ?E @ ?F)))) {?S}"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1781
  proof(rule_tac abc_Hoare_plus_halt)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1782
    show "{?P} ?A {?Q1}"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1783
      using len by simp
70
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1784
  next
229
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1785
    let ?Q2 = "\<lambda>nl. nl = xs @ rec_exec f xs # 0 \<up> (?ft - Suc n) @  x # anything"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1786
    have a: "?ft \<ge> fft"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1787
      by arith
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1788
    have b: "far = n"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1789
      using compile1 termi_f len
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1790
      by(drule_tac param_pattern, auto)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1791
    have c: "fft > far"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1792
      using compile1
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1793
      by(simp add: footprint_ge)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1794
    show "{?Q1} (?B [+] (?C [+] (?D [+] ?E @ ?F))) {?S}"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1795
    proof(rule_tac abc_Hoare_plus_halt)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1796
      have "{\<lambda>nl. nl = xs @ 0 \<up> (fft - far) @ 0\<up>(?ft - fft) @ x # anything} fap 
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1797
            {\<lambda>nl. nl = xs @ rec_exec f xs # 0 \<up> (fft - Suc far) @ 0\<up>(?ft - fft) @ x # anything}"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1798
        by(rule_tac f_ind)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1799
      moreover have "fft - far + ?ft - fft = ?ft - far"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1800
        using a b c by arith
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1801
      moreover have "fft - Suc n + ?ft - fft = ?ft - Suc n"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1802
        using a b c by arith
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1803
      ultimately show "{?Q1} ?B {?Q2}"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1804
        using b
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1805
        by(simp add: replicate_merge_anywhere)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1806
    next
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1807
      let ?Q3 = "\<lambda> nl. nl = xs @ 0 # rec_exec f xs # 0\<up>(?ft - Suc (Suc n)) @ x # anything"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1808
      show "{?Q2} (?C [+] (?D [+] ?E @ ?F)) {?S}"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1809
      proof(rule_tac abc_Hoare_plus_halt)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1810
        show "{?Q2} (?C) {?Q3}"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1811
          using mv_box_correct[of n "Suc n" "xs @ rec_exec f xs # 0 \<up> (max (n + 3) (max fft gft) - Suc n) @ x # anything"]
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1812
          using len
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1813
          by(auto)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1814
      next
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1815
        show "{?Q3} (?D [+] ?E @ ?F) {?S}"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1816
          using pr_loop_correct[of x x xs n g  gap gar gft f fft anything] assms
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1817
          by(simp add: rec_exec_pr_0_simps)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1818
      qed
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1819
    qed
70
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1820
  qed
229
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1821
qed 
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1822
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1823
lemma compile_pr_correct:
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1824
  assumes g_ind: "\<forall>y<x. terminate g (xs @ [y, rec_exec (Pr n f g) (xs @ [y])]) \<and>
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1825
  (\<forall>x xa xb. rec_ci g = (x, xa, xb) \<longrightarrow>
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1826
  (\<forall>xc. {\<lambda>nl. nl = xs @ y # rec_exec (Pr n f g) (xs @ [y]) # 0 \<up> (xb - xa) @ xc} x
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1827
  {\<lambda>nl. nl = xs @ y # rec_exec (Pr n f g) (xs @ [y]) # rec_exec g (xs @ [y, rec_exec (Pr n f g) (xs @ [y])]) # 0 \<up> (xb - Suc xa) @ xc}))"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1828
  and termi_f: "terminate f xs"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1829
  and f_ind:
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1830
  "\<And>ap arity fp anything.
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1831
  rec_ci f = (ap, arity, fp) \<Longrightarrow> {\<lambda>nl. nl = xs @ 0 \<up> (fp - arity) @ anything} ap {\<lambda>nl. nl = xs @ rec_exec f xs # 0 \<up> (fp - Suc arity) @ anything}"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1832
  and len: "length xs = n"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1833
  and compile: "rec_ci (Pr n f g) = (ap, arity, fp)"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1834
  shows "{\<lambda>nl. nl = xs @ x # 0 \<up> (fp - arity) @ anything} ap {\<lambda>nl. nl = xs @ x # rec_exec (Pr n f g) (xs @ [x]) # 0 \<up> (fp - Suc arity) @ anything}"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1835
proof(case_tac "rec_ci f", case_tac "rec_ci g")
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1836
  fix fap far fft gap gar gft
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1837
  assume h: "rec_ci f = (fap, far, fft)" "rec_ci g = (gap, gar, gft)"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1838
  have g: 
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1839
    "\<forall>y<x. (terminate g (xs @ [y, rec_exec (Pr n f g) (xs @ [y])]) \<and>
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1840
     (\<forall>anything. {\<lambda>nl. nl = xs @ y # rec_exec (Pr n f g) (xs @ [y]) # 0 \<up> (gft - gar) @ anything} gap
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1841
    {\<lambda>nl. nl = xs @ y # rec_exec (Pr n f g) (xs @ [y]) # rec_exec g (xs @ [y, rec_exec (Pr n f g) (xs @ [y])]) # 0 \<up> (gft - Suc gar) @ anything}))"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1842
    using g_ind h
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1843
    by(auto)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1844
  hence termi_g: "\<forall> y<x. terminate g (xs @ [y, rec_exec (Pr n f g) (xs @ [y])])"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1845
    by simp
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1846
  from g have g_newind: 
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1847
    "\<forall> y<x. (\<forall>anything. {\<lambda>nl. nl = xs @ y # rec_exec (Pr n f g) (xs @ [y]) # 0 \<up> (gft - gar) @ anything} gap
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1848
    {\<lambda>nl. nl = xs @ y # rec_exec (Pr n f g) (xs @ [y]) # rec_exec g (xs @ [y, rec_exec (Pr n f g) (xs @ [y])]) # 0 \<up> (gft - Suc gar) @ anything})"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1849
    by auto
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1850
  have f_newind: "\<And> anything. {\<lambda>nl. nl = xs @ 0 \<up> (fft - far) @ anything} fap {\<lambda>nl. nl = xs @ rec_exec f xs # 0 \<up> (fft - Suc far) @ anything}"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1851
    using h
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1852
    by(rule_tac f_ind, simp)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1853
  show "?thesis"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1854
    using termi_f termi_g h compile
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1855
    apply(simp add: rec_ci.simps abc_comp_commute, auto)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1856
    using g_newind f_newind len
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1857
    by(rule_tac compile_pr_correct', simp_all)
70
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1858
qed
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1859
229
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1860
fun mn_ind_inv ::
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1861
  "nat \<times> nat list \<Rightarrow> nat \<Rightarrow> nat \<Rightarrow> nat \<Rightarrow> nat list \<Rightarrow> nat list \<Rightarrow> bool"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1862
  where
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1863
  "mn_ind_inv (as, lm') ss x rsx suf_lm lm = 
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1864
           (if as = ss then lm' = lm @ x # rsx # suf_lm
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1865
            else if as = ss + 1 then 
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1866
                 \<exists>y. (lm' = lm @ x # y # suf_lm) \<and> y \<le> rsx
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1867
            else if as = ss + 2 then 
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1868
                 \<exists>y. (lm' = lm @ x # y # suf_lm) \<and> y \<le> rsx
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1869
            else if as = ss + 3 then lm' = lm @ x # 0 # suf_lm
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1870
            else if as = ss + 4 then lm' = lm @ Suc x # 0 # suf_lm
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1871
            else if as = 0 then lm' = lm @ Suc x # 0 # suf_lm
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1872
            else False
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1873
)"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1874
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1875
fun mn_stage1 :: "nat \<times> nat list \<Rightarrow> nat \<Rightarrow> nat \<Rightarrow> nat"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1876
  where
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1877
  "mn_stage1 (as, lm) ss n = 
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1878
            (if as = 0 then 0 
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1879
             else if as = ss + 4 then 1
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1880
             else if as = ss + 3 then 2
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1881
             else if as = ss + 2 \<or> as = ss + 1 then 3
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1882
             else if as = ss then 4
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1883
             else 0
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1884
)"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1885
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1886
fun mn_stage2 :: "nat \<times> nat list \<Rightarrow> nat \<Rightarrow> nat \<Rightarrow> nat"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1887
  where
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1888
  "mn_stage2 (as, lm) ss n = 
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1889
            (if as = ss + 1 \<or> as = ss + 2 then (lm ! (Suc n))
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1890
             else 0)"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1891
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1892
fun mn_stage3 :: "nat \<times> nat list \<Rightarrow> nat \<Rightarrow> nat \<Rightarrow> nat"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1893
  where
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1894
  "mn_stage3 (as, lm) ss n = (if as = ss + 2 then 1 else 0)"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1895
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1896
 
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1897
fun mn_measure :: "((nat \<times> nat list) \<times> nat \<times> nat) \<Rightarrow>
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1898
                                                (nat \<times> nat \<times> nat)"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1899
  where
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1900
  "mn_measure ((as, lm), ss, n) = 
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1901
     (mn_stage1 (as, lm) ss n, mn_stage2 (as, lm) ss n,
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1902
                                       mn_stage3 (as, lm) ss n)"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1903
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1904
definition mn_LE :: "(((nat \<times> nat list) \<times> nat \<times> nat) \<times>
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1905
                     ((nat \<times> nat list) \<times> nat \<times> nat)) set"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1906
  where "mn_LE \<equiv> (inv_image lex_triple mn_measure)"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1907
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1908
lemma wf_mn_le[intro]: "wf mn_LE"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1909
by(auto intro:wf_inv_image wf_lex_triple simp: mn_LE_def)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1910
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1911
declare mn_ind_inv.simps[simp del]
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1912
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1913
lemma [simp]: 
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1914
  "0 < rsx \<Longrightarrow> 
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1915
 \<exists>y. (xs @ x # rsx # anything)[Suc (length xs) := rsx - Suc 0] = xs @ x # y # anything \<and> y \<le> rsx"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1916
apply(rule_tac x = "rsx - 1" in exI)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1917
apply(simp add: list_update_append list_update.simps)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1918
done
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1919
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1920
lemma [simp]: 
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1921
  "\<lbrakk>y \<le> rsx; 0 < y\<rbrakk>
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1922
            \<Longrightarrow> \<exists>ya. (xs @ x # y # anything)[Suc (length xs) := y - Suc 0] = xs @ x # ya # anything \<and> ya \<le> rsx"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1923
apply(rule_tac x = "y - 1" in exI)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1924
apply(simp add: list_update_append list_update.simps)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1925
done
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1926
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1927
lemma abc_comp_null[simp]: "(A [+] B = []) = (A = [] \<and> B = [])"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1928
by(auto simp: abc_comp.simps abc_shift.simps)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1929
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1930
lemma rec_ci_not_null[simp]: "(rec_ci f \<noteq> ([], a, b))"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1931
apply(case_tac f, auto simp: rec_ci_z_def rec_ci_s_def rec_ci.simps addition.simps rec_ci_id.simps)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1932
apply(case_tac "rec_ci recf", auto simp: mv_box.simps)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1933
apply(case_tac "rec_ci recf1", case_tac "rec_ci recf2", simp)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1934
apply(case_tac "rec_ci recf", simp)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1935
done
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1936
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1937
lemma mn_correct:
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1938
  assumes compile: "rec_ci rf = (fap, far, fft)"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1939
  and ge: "0 < rsx"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1940
  and len: "length xs = arity"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1941
  and B: "B = [Dec (Suc arity) (length fap + 5), Dec (Suc arity) (length fap + 3), Goto (Suc (length fap)), Inc arity, Goto 0]"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1942
  and f: "f = (\<lambda> stp. (abc_steps_l (length fap, xs @ x # rsx # anything) (fap @ B) stp, (length fap), arity)) "
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1943
  and P: "P =(\<lambda> ((as, lm), ss, arity). as = 0)"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1944
  and Q: "Q = (\<lambda> ((as, lm), ss, arity). mn_ind_inv (as, lm) (length fap) x rsx anything xs)"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1945
  shows "\<exists> stp. P (f stp) \<and> Q (f stp)"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1946
proof(rule_tac halt_lemma2)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1947
  show "wf mn_LE"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1948
    using wf_mn_le by simp
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1949
next
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1950
  show "Q (f 0)"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1951
    by(auto simp: Q f abc_steps_l.simps mn_ind_inv.simps)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1952
next
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1953
  have "fap \<noteq> []"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1954
    using compile by auto
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1955
  thus "\<not> P (f 0)"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1956
    by(auto simp: f P abc_steps_l.simps)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1957
next
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1958
  have "fap \<noteq> []"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1959
    using compile by auto
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1960
  then have "\<And> stp. \<lbrakk>\<not> P (f stp); Q (f stp)\<rbrakk> \<Longrightarrow> Q (f (Suc stp)) \<and> (f (Suc stp), f stp) \<in> mn_LE"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1961
    using ge len
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1962
    apply(case_tac "(abc_steps_l (length fap, xs @ x # rsx # anything) (fap @ B) stp)")
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1963
    apply(simp add: abc_step_red2  B f P Q)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1964
    apply(auto split:if_splits simp add:abc_steps_l.simps  mn_ind_inv.simps abc_steps_zero B abc_fetch.simps nth_append)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1965
    by(auto simp: mn_LE_def lex_triple_def lex_pair_def 
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1966
               abc_step_l.simps abc_steps_l.simps mn_ind_inv.simps
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1967
               abc_lm_v.simps abc_lm_s.simps nth_append abc_fetch.simps
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1968
                split: if_splits)    
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1969
  thus "\<forall>stp. \<not> P (f stp) \<and> Q (f stp) \<longrightarrow> Q (f (Suc stp)) \<and> (f (Suc stp), f stp) \<in> mn_LE"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1970
    by(auto)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1971
qed
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1972
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1973
lemma abc_Hoare_haltE:
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1974
  "{\<lambda> nl. nl = lm1} p {\<lambda> nl. nl = lm2}
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1975
    \<Longrightarrow> \<exists> stp. abc_steps_l (0, lm1) p stp = (length p, lm2)"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1976
apply(auto simp: abc_Hoare_halt_def)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1977
apply(rule_tac x = n in exI)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1978
apply(case_tac "abc_steps_l (0, lm1) p n", auto)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1979
done
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1980
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1981
lemma mn_loop:
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1982
  assumes B:  "B = [Dec (Suc arity) (length fap + 5), Dec (Suc arity) (length fap + 3), Goto (Suc (length fap)), Inc arity, Goto 0]"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1983
  and ft: "ft = max (Suc arity) fft"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1984
  and len: "length xs = arity"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1985
  and far: "far = Suc arity"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1986
  and ind: " (\<forall>xc. ({\<lambda>nl. nl = xs @ x # 0 \<up> (fft - far) @ xc} fap
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1987
    {\<lambda>nl. nl = xs @ x # rec_exec f (xs @ [x]) # 0 \<up> (fft - Suc far) @ xc}))"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1988
  and exec_less: "rec_exec f (xs @ [x]) > 0"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1989
  and compile: "rec_ci f = (fap, far, fft)"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1990
  shows "\<exists> stp > 0. abc_steps_l (0, xs @ x # 0 \<up> (ft - Suc arity) @ anything) (fap @ B) stp =
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1991
    (0, xs @ Suc x # 0 \<up> (ft - Suc arity) @ anything)"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1992
proof -
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1993
  have "\<exists> stp. abc_steps_l (0, xs @ x # 0 \<up> (ft - Suc arity) @ anything) (fap @ B) stp =
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1994
    (length fap, xs @ x # rec_exec f (xs @ [x]) # 0 \<up> (ft - Suc (Suc arity)) @ anything)"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1995
  proof -
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1996
    have "\<exists> stp. abc_steps_l (0, xs @ x # 0 \<up> (ft - Suc arity) @ anything) fap stp =
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1997
      (length fap, xs @ x # rec_exec f (xs @ [x]) # 0 \<up> (ft - Suc (Suc arity)) @ anything)"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1998
    proof -
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  1999
      have "{\<lambda>nl. nl = xs @ x # 0 \<up> (fft - far) @ 0\<up>(ft - fft) @ anything} fap 
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2000
            {\<lambda>nl. nl = xs @ x # rec_exec f (xs @ [x]) # 0 \<up> (fft - Suc far) @ 0\<up>(ft - fft) @ anything}"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2001
        using ind by simp
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2002
      moreover have "fft > far"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2003
        using compile
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2004
        by(erule_tac footprint_ge)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2005
      ultimately show "?thesis"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2006
        using ft far
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2007
        apply(drule_tac abc_Hoare_haltE)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2008
        by(simp add: replicate_merge_anywhere max_absorb2)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2009
    qed
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2010
    then obtain stp where "abc_steps_l (0, xs @ x # 0 \<up> (ft - Suc arity) @ anything) fap stp =
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2011
      (length fap, xs @ x # rec_exec f (xs @ [x]) # 0 \<up> (ft - Suc (Suc arity)) @ anything)" ..
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2012
    thus "?thesis"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2013
      by(erule_tac abc_append_frist_steps_halt_eq)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2014
  qed
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2015
  moreover have 
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2016
    "\<exists> stp > 0. abc_steps_l (length fap, xs @ x # rec_exec f (xs @ [x]) # 0 \<up> (ft - Suc (Suc arity)) @ anything) (fap @ B) stp =
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2017
    (0, xs @ Suc x # 0 # 0 \<up> (ft - Suc (Suc arity)) @ anything)"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2018
    using mn_correct[of f fap far fft "rec_exec f (xs @ [x])" xs arity B
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2019
      "(\<lambda>stp. (abc_steps_l (length fap, xs @ x # rec_exec f (xs @ [x]) # 0 \<up> (ft - Suc (Suc arity)) @ anything) (fap @ B) stp, length fap, arity))"     
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2020
      x "0 \<up> (ft - Suc (Suc arity)) @ anything" "(\<lambda>((as, lm), ss, arity). as = 0)" 
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2021
      "(\<lambda>((as, lm), ss, aritya). mn_ind_inv (as, lm) (length fap) x (rec_exec f (xs @ [x])) (0 \<up> (ft - Suc (Suc arity)) @ anything) xs) "]  
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2022
      B compile  exec_less len
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2023
    apply(subgoal_tac "fap \<noteq> []", auto)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2024
    apply(rule_tac x = stp in exI, auto simp: mn_ind_inv.simps)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2025
    by(case_tac "stp = 0", simp_all add: abc_steps_l.simps)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2026
  moreover have "fft > far"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2027
    using compile
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2028
    by(erule_tac footprint_ge)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2029
  ultimately show "?thesis"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2030
    using ft far
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2031
    apply(auto)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2032
    by(rule_tac x = "stp + stpa" in exI, 
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2033
      simp add: abc_steps_add replicate_Suc[THEN sym] diff_Suc_Suc del: replicate_Suc)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2034
qed
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2035
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2036
lemma mn_loop_correct': 
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2037
  assumes B:  "B = [Dec (Suc arity) (length fap + 5), Dec (Suc arity) (length fap + 3), Goto (Suc (length fap)), Inc arity, Goto 0]"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2038
  and ft: "ft = max (Suc arity) fft"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2039
  and len: "length xs = arity"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2040
  and ind_all: "\<forall>i\<le>x. (\<forall>xc. ({\<lambda>nl. nl = xs @ i # 0 \<up> (fft - far) @ xc} fap
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2041
    {\<lambda>nl. nl = xs @ i # rec_exec f (xs @ [i]) # 0 \<up> (fft - Suc far) @ xc}))"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2042
  and exec_ge: "\<forall> i\<le>x. rec_exec f (xs @ [i]) > 0"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2043
  and compile: "rec_ci f = (fap, far, fft)"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2044
  and far: "far = Suc arity"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2045
  shows "\<exists> stp > x. abc_steps_l (0, xs @ 0 # 0 \<up> (ft - Suc arity) @ anything) (fap @ B) stp = 
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2046
               (0, xs @ Suc x # 0 \<up> (ft - Suc arity) @ anything)"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2047
using ind_all exec_ge
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2048
proof(induct x)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2049
  case 0
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2050
  thus "?case"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2051
    using assms
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2052
    by(rule_tac mn_loop, simp_all)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2053
next
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2054
  case (Suc x)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2055
  have ind': "\<lbrakk>\<forall>i\<le>x. \<forall>xc. {\<lambda>nl. nl = xs @ i # 0 \<up> (fft - far) @ xc} fap {\<lambda>nl. nl = xs @ i # rec_exec f (xs @ [i]) # 0 \<up> (fft - Suc far) @ xc};
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2056
               \<forall>i\<le>x. 0 < rec_exec f (xs @ [i])\<rbrakk> \<Longrightarrow> 
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2057
            \<exists>stp > x. abc_steps_l (0, xs @ 0 # 0 \<up> (ft - Suc arity) @ anything) (fap @ B) stp = (0, xs @ Suc x # 0 \<up> (ft - Suc arity) @ anything)" by fact
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2058
  have exec_ge: "\<forall>i\<le>Suc x. 0 < rec_exec f (xs @ [i])" by fact
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2059
  have ind_all: "\<forall>i\<le>Suc x. \<forall>xc. {\<lambda>nl. nl = xs @ i # 0 \<up> (fft - far) @ xc} fap 
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2060
    {\<lambda>nl. nl = xs @ i # rec_exec f (xs @ [i]) # 0 \<up> (fft - Suc far) @ xc}" by fact
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2061
  have ind: "\<exists>stp > x. abc_steps_l (0, xs @ 0 # 0 \<up> (ft - Suc arity) @ anything) (fap @ B) stp =
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2062
    (0, xs @ Suc x # 0 \<up> (ft - Suc arity) @ anything)" using ind' exec_ge ind_all by simp
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2063
  have stp: "\<exists> stp > 0. abc_steps_l (0, xs @ Suc x # 0 \<up> (ft - Suc arity) @ anything) (fap @ B) stp =
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2064
    (0, xs @ Suc (Suc x) # 0 \<up> (ft - Suc arity) @ anything)"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2065
    using ind_all exec_ge B ft len far compile
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2066
    by(rule_tac mn_loop, simp_all)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2067
  from ind stp show "?case"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2068
    apply(auto)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2069
    by(rule_tac x = "stp + stpa" in exI, simp add: abc_steps_add)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2070
qed
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2071
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2072
lemma mn_loop_correct: 
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2073
  assumes B:  "B = [Dec (Suc arity) (length fap + 5), Dec (Suc arity) (length fap + 3), Goto (Suc (length fap)), Inc arity, Goto 0]"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2074
  and ft: "ft = max (Suc arity) fft"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2075
  and len: "length xs = arity"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2076
  and ind_all: "\<forall>i\<le>x. (\<forall>xc. ({\<lambda>nl. nl = xs @ i # 0 \<up> (fft - far) @ xc} fap
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2077
    {\<lambda>nl. nl = xs @ i # rec_exec f (xs @ [i]) # 0 \<up> (fft - Suc far) @ xc}))"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2078
  and exec_ge: "\<forall> i\<le>x. rec_exec f (xs @ [i]) > 0"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2079
  and compile: "rec_ci f = (fap, far, fft)"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2080
  and far: "far = Suc arity"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2081
  shows "\<exists> stp. abc_steps_l (0, xs @ 0 # 0 \<up> (ft - Suc arity) @ anything) (fap @ B) stp = 
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2082
               (0, xs @ Suc x # 0 \<up> (ft - Suc arity) @ anything)"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2083
proof -
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2084
  have "\<exists>stp>x. abc_steps_l (0, xs @ 0 # 0 \<up> (ft - Suc arity) @ anything) (fap @ B) stp = (0, xs @ Suc x # 0 \<up> (ft - Suc arity) @ anything)"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2085
    using assms
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2086
    by(rule_tac mn_loop_correct', simp_all)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2087
  thus "?thesis"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2088
    by(auto)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2089
qed
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2090
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2091
lemma compile_mn_correct': 
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2092
  assumes B:  "B = [Dec (Suc arity) (length fap + 5), Dec (Suc arity) (length fap + 3), Goto (Suc (length fap)), Inc arity, Goto 0]"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2093
  and ft: "ft = max (Suc arity) fft"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2094
  and len: "length xs = arity"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2095
  and termi_f: "terminate f (xs @ [r])"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2096
  and f_ind: "\<And>anything. {\<lambda>nl. nl = xs @ r # 0 \<up> (fft - far) @ anything} fap 
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2097
        {\<lambda>nl. nl = xs @ r # 0 # 0 \<up> (fft - Suc far) @ anything}"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2098
  and ind_all: "\<forall>i < r. (\<forall>xc. ({\<lambda>nl. nl = xs @ i # 0 \<up> (fft - far) @ xc} fap
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2099
    {\<lambda>nl. nl = xs @ i # rec_exec f (xs @ [i]) # 0 \<up> (fft - Suc far) @ xc}))"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2100
  and exec_less: "\<forall> i<r. rec_exec f (xs @ [i]) > 0"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2101
  and exec: "rec_exec f (xs @ [r]) = 0"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2102
  and compile: "rec_ci f = (fap, far, fft)"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2103
  shows "{\<lambda>nl. nl = xs @ 0 \<up> (max (Suc arity) fft - arity) @ anything}
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2104
    fap @ B
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2105
    {\<lambda>nl. nl = xs @ rec_exec (Mn arity f) xs # 0 \<up> (max (Suc arity) fft - Suc arity) @ anything}"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2106
proof -
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2107
  have a: "far = Suc arity"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2108
    using len compile termi_f
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2109
    by(drule_tac param_pattern, auto)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2110
  have b: "fft > far"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2111
    using compile
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2112
    by(erule_tac footprint_ge)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2113
  have "\<exists> stp. abc_steps_l (0, xs @ 0 # 0 \<up> (ft - Suc arity) @ anything) (fap @ B) stp = 
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2114
    (0, xs @ r # 0 \<up> (ft - Suc arity) @ anything)"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2115
    using assms a
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2116
    apply(case_tac r, rule_tac x = 0 in exI, simp add: abc_steps_l.simps, simp)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2117
    by(rule_tac mn_loop_correct, auto)  
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2118
  moreover have 
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2119
    "\<exists> stp. abc_steps_l (0, xs @ r # 0 \<up> (ft - Suc arity) @ anything) (fap @ B) stp = 
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2120
    (length fap, xs @ r # rec_exec f (xs @ [r]) # 0 \<up> (ft - Suc (Suc arity)) @ anything)"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2121
  proof -
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2122
    have "\<exists> stp. abc_steps_l (0, xs @ r # 0 \<up> (ft - Suc arity) @ anything) fap stp =
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2123
      (length fap, xs @ r # rec_exec f (xs @ [r]) # 0 \<up> (ft - Suc (Suc arity)) @ anything)"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2124
    proof -
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2125
      have "{\<lambda>nl. nl = xs @ r # 0 \<up> (fft - far) @ 0\<up>(ft - fft) @ anything} fap 
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2126
            {\<lambda>nl. nl = xs @ r # rec_exec f (xs @ [r]) # 0 \<up> (fft - Suc far) @ 0\<up>(ft - fft) @ anything}"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2127
        using f_ind exec by simp
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2128
      thus "?thesis"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2129
        using ft a b
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2130
        apply(drule_tac abc_Hoare_haltE)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2131
        by(simp add: replicate_merge_anywhere max_absorb2)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2132
    qed
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2133
    then obtain stp where "abc_steps_l (0, xs @ r # 0 \<up> (ft - Suc arity) @ anything) fap stp =
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2134
      (length fap, xs @ r # rec_exec f (xs @ [r]) # 0 \<up> (ft - Suc (Suc arity)) @ anything)" ..
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2135
    thus "?thesis"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2136
      by(erule_tac abc_append_frist_steps_halt_eq)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2137
  qed
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2138
  moreover have 
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2139
    "\<exists> stp. abc_steps_l (length fap, xs @ r # rec_exec f (xs @ [r]) # 0 \<up> (ft - Suc (Suc arity)) @ anything) (fap @ B) stp = 
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2140
             (length fap + 5, xs @ r # rec_exec f (xs @ [r]) # 0 \<up> (ft - Suc (Suc arity)) @ anything)"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2141
    using ft a b len B exec
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2142
    apply(rule_tac x = 1 in exI, auto)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2143
    by(auto simp: abc_steps_l.simps B abc_step_l.simps 
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2144
      abc_fetch.simps nth_append max_absorb2 abc_lm_v.simps abc_lm_s.simps)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2145
  moreover have "rec_exec (Mn (length xs) f) xs = r"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2146
    using exec exec_less
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2147
    apply(auto simp: rec_exec.simps Least_def)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2148
    thm the_equality
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2149
    apply(rule_tac the_equality, auto)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2150
    apply(metis exec_less less_not_refl3 linorder_not_less)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2151
    by (metis le_neq_implies_less less_not_refl3)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2152
  ultimately show "?thesis"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2153
    using ft a b len B exec
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2154
    apply(auto simp: abc_Hoare_halt_def)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2155
    apply(rule_tac x = "stp + stpa + stpb"  in exI)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2156
    by(simp add: abc_steps_add replicate_Suc_iff_anywhere max_absorb2 Suc_diff_Suc del: replicate_Suc)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2157
qed
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2158
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2159
lemma compile_mn_correct:
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2160
  assumes len: "length xs = n"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2161
  and termi_f: "terminate f (xs @ [r])"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2162
  and f_ind: "\<And>ap arity fp anything. rec_ci f = (ap, arity, fp) \<Longrightarrow> 
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2163
  {\<lambda>nl. nl = xs @ r # 0 \<up> (fp - arity) @ anything} ap {\<lambda>nl. nl = xs @ r # 0 # 0 \<up> (fp - Suc arity) @ anything}"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2164
  and exec: "rec_exec f (xs @ [r]) = 0"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2165
  and ind_all: 
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2166
  "\<forall>i<r. terminate f (xs @ [i]) \<and>
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2167
  (\<forall>x xa xb. rec_ci f = (x, xa, xb) \<longrightarrow> 
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2168
  (\<forall>xc. {\<lambda>nl. nl = xs @ i # 0 \<up> (xb - xa) @ xc} x {\<lambda>nl. nl = xs @ i # rec_exec f (xs @ [i]) # 0 \<up> (xb - Suc xa) @ xc})) \<and>
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2169
  0 < rec_exec f (xs @ [i])"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2170
  and compile: "rec_ci (Mn n f) = (ap, arity, fp)"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2171
  shows "{\<lambda>nl. nl = xs @ 0 \<up> (fp - arity) @ anything} ap 
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2172
  {\<lambda>nl. nl = xs @ rec_exec (Mn n f) xs # 0 \<up> (fp - Suc arity) @ anything}"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2173
proof(case_tac "rec_ci f")
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2174
  fix fap far fft
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2175
  assume h: "rec_ci f = (fap, far, fft)"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2176
  hence f_newind: 
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2177
    "\<And>anything. {\<lambda>nl. nl = xs @ r # 0 \<up> (fft - far) @ anything} fap 
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2178
        {\<lambda>nl. nl = xs @ r # 0 # 0 \<up> (fft - Suc far) @ anything}"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2179
    by(rule_tac f_ind, simp)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2180
  have newind_all: 
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2181
    "\<forall>i < r. (\<forall>xc. ({\<lambda>nl. nl = xs @ i # 0 \<up> (fft - far) @ xc} fap
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2182
    {\<lambda>nl. nl = xs @ i # rec_exec f (xs @ [i]) # 0 \<up> (fft - Suc far) @ xc}))"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2183
    using ind_all h
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2184
    by(auto)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2185
  have all_less: "\<forall> i<r. rec_exec f (xs @ [i]) > 0"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2186
    using ind_all by auto
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2187
  show "?thesis"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2188
    using h compile f_newind newind_all all_less len termi_f exec
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2189
    apply(auto simp: rec_ci.simps)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2190
    by(rule_tac compile_mn_correct', auto)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2191
qed
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2192
    
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2193
lemma recursive_compile_correct:
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2194
   "\<lbrakk>terminate recf args; rec_ci recf = (ap, arity, fp)\<rbrakk>
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2195
  \<Longrightarrow> {\<lambda> nl. nl = args @ 0\<up>(fp - arity) @ anything} ap 
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2196
         {\<lambda> nl. nl = args@ rec_exec recf args # 0\<up>(fp - Suc arity) @ anything}"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2197
apply(induct arbitrary: ap arity fp anything r rule: terminate.induct)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2198
apply(simp_all add: compile_s_correct compile_z_correct compile_id_correct 
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2199
                    compile_cn_correct compile_pr_correct compile_mn_correct)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2200
done
70
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2201
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2202
definition dummy_abc :: "nat \<Rightarrow> abc_inst list"
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2203
where
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2204
"dummy_abc k = [Inc k, Dec k 0, Goto 3]"
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2205
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2206
definition abc_list_crsp:: "nat list \<Rightarrow> nat list \<Rightarrow> bool"
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2207
  where
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2208
  "abc_list_crsp xs ys = (\<exists> n. xs = ys @ 0\<up>n \<or> ys = xs @ 0\<up>n)"
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2209
229
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2210
lemma abc_list_crsp_simp1[intro]: "abc_list_crsp (lm @ 0\<up>m) lm"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2211
by(auto simp: abc_list_crsp_def)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2212
70
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2213
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2214
lemma abc_list_crsp_lm_v: 
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2215
  "abc_list_crsp lma lmb \<Longrightarrow> abc_lm_v lma n = abc_lm_v lmb n"
229
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2216
by(auto simp: abc_list_crsp_def abc_lm_v.simps 
70
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2217
                 nth_append)
229
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2218
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2219
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2220
lemma abc_list_crsp_elim: 
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2221
  "\<lbrakk>abc_list_crsp lma lmb; \<exists> n. lma = lmb @ 0\<up>n \<or> lmb = lma @ 0\<up>n \<Longrightarrow> P \<rbrakk> \<Longrightarrow> P"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2222
by(auto simp: abc_list_crsp_def)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2223
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2224
lemma [simp]: 
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2225
  "\<lbrakk>abc_list_crsp lma lmb; m < length lma; m < length lmb\<rbrakk> \<Longrightarrow>
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2226
          abc_list_crsp (lma[m := n]) (lmb[m := n])"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2227
by(auto simp: abc_list_crsp_def list_update_append)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2228
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2229
lemma [simp]: 
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2230
  "\<lbrakk>abc_list_crsp lma lmb; m < length lma; \<not> m < length lmb\<rbrakk> \<Longrightarrow> 
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2231
  abc_list_crsp (lma[m := n]) (lmb @ 0 \<up> (m - length lmb) @ [n])"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2232
apply(auto simp: abc_list_crsp_def list_update_append)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2233
apply(rule_tac x = "na + length lmb - Suc m" in exI)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2234
apply(rule_tac disjI1)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2235
apply(simp add: upd_conv_take_nth_drop min_absorb1)
70
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2236
done
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2237
229
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2238
lemma [simp]:
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2239
  "\<lbrakk>abc_list_crsp lma lmb; \<not> m < length lma; m < length lmb\<rbrakk> \<Longrightarrow> 
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2240
  abc_list_crsp (lma @ 0 \<up> (m - length lma) @ [n]) (lmb[m := n])"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2241
apply(auto simp: abc_list_crsp_def list_update_append)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2242
apply(rule_tac x = "na + length lma - Suc m" in exI)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2243
apply(rule_tac disjI2)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2244
apply(simp add: upd_conv_take_nth_drop min_absorb1)
70
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2245
done
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2246
229
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2247
lemma [simp]: "\<lbrakk>abc_list_crsp lma lmb; \<not> m < length lma; \<not> m < length lmb\<rbrakk> \<Longrightarrow> 
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2248
  abc_list_crsp (lma @ 0 \<up> (m - length lma) @ [n]) (lmb @ 0 \<up> (m - length lmb) @ [n])"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2249
  by(auto simp: abc_list_crsp_def list_update_append replicate_merge_anywhere)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2250
70
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2251
lemma abc_list_crsp_lm_s: 
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2252
  "abc_list_crsp lma lmb \<Longrightarrow> 
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2253
      abc_list_crsp (abc_lm_s lma m n) (abc_lm_s lmb m n)"
229
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2254
by(auto simp: abc_lm_s.simps)
70
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2255
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2256
lemma abc_list_crsp_step: 
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2257
  "\<lbrakk>abc_list_crsp lma lmb; abc_step_l (aa, lma) i = (a, lma'); 
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2258
    abc_step_l (aa, lmb) i = (a', lmb')\<rbrakk>
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2259
    \<Longrightarrow> a' = a \<and> abc_list_crsp lma' lmb'"
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2260
apply(case_tac i, auto simp: abc_step_l.simps 
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2261
       abc_list_crsp_lm_s abc_list_crsp_lm_v Let_def 
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2262
                       split: abc_inst.splits if_splits)
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2263
done
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2264
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2265
lemma abc_list_crsp_steps: 
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2266
  "\<lbrakk>abc_steps_l (0, lm @ 0\<up>m) aprog stp = (a, lm'); aprog \<noteq> []\<rbrakk> 
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2267
      \<Longrightarrow> \<exists> lma. abc_steps_l (0, lm) aprog stp = (a, lma) \<and> 
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2268
                                          abc_list_crsp lm' lma"
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2269
apply(induct stp arbitrary: a lm', simp add: abc_steps_l.simps, auto)
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2270
apply(case_tac "abc_steps_l (0, lm @ 0\<up>m) aprog stp", 
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2271
      simp add: abc_step_red)
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2272
proof -
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2273
  fix stp a lm' aa b
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2274
  assume ind:
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2275
    "\<And>a lm'. aa = a \<and> b = lm' \<Longrightarrow> 
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2276
     \<exists>lma. abc_steps_l (0, lm) aprog stp = (a, lma) \<and>
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2277
                                          abc_list_crsp lm' lma"
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2278
    and h: "abc_steps_l (0, lm @ 0\<up>m) aprog (Suc stp) = (a, lm')" 
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2279
           "abc_steps_l (0, lm @ 0\<up>m) aprog stp = (aa, b)" 
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2280
           "aprog \<noteq> []"
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2281
  hence g1: "abc_steps_l (0, lm @ 0\<up>m) aprog (Suc stp)
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2282
          = abc_step_l (aa, b) (abc_fetch aa aprog)"
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2283
    apply(rule_tac abc_step_red, simp)
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2284
    done
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2285
  have "\<exists>lma. abc_steps_l (0, lm) aprog stp = (aa, lma) \<and> 
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2286
              abc_list_crsp b lma"
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2287
    apply(rule_tac ind, simp)
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2288
    done
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2289
  from this obtain lma where g2: 
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2290
    "abc_steps_l (0, lm) aprog stp = (aa, lma) \<and> 
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2291
     abc_list_crsp b lma"   ..
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2292
  hence g3: "abc_steps_l (0, lm) aprog (Suc stp)
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2293
          = abc_step_l (aa, lma) (abc_fetch aa aprog)"
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2294
    apply(rule_tac abc_step_red, simp)
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2295
    done
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2296
  show "\<exists>lma. abc_steps_l (0, lm) aprog (Suc stp) = (a, lma) \<and> abc_list_crsp lm' lma"
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2297
    using g1 g2 g3 h
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2298
    apply(auto)
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2299
    apply(case_tac "abc_step_l (aa, b) (abc_fetch aa aprog)",
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2300
          case_tac "abc_step_l (aa, lma) (abc_fetch aa aprog)", simp)
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2301
    apply(rule_tac abc_list_crsp_step, auto)
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2302
    done
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2303
qed
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2304
229
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2305
lemma list_crsp_simp2: "abc_list_crsp (lm1 @ 0\<up>n) lm2 \<Longrightarrow> abc_list_crsp lm1 lm2"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2306
proof(induct n)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2307
  case 0
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2308
  thus "?case"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2309
    by(auto simp: abc_list_crsp_def)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2310
next
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2311
  case (Suc n)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2312
  have ind: "abc_list_crsp (lm1 @ 0 \<up> n) lm2 \<Longrightarrow> abc_list_crsp lm1 lm2" by fact
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2313
  have h: "abc_list_crsp (lm1 @ 0 \<up> Suc n) lm2" by fact
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2314
  then have "abc_list_crsp (lm1 @ 0 \<up> n) lm2"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2315
    apply(auto simp: exp_suc abc_list_crsp_def del: replicate_Suc)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2316
    apply(case_tac n, simp_all add: exp_suc replicate_Suc[THEN sym] del: replicate_Suc, auto)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2317
    apply(rule_tac x = 1 in exI, simp)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2318
    by(rule_tac x = "Suc n" in exI, simp,  simp add: exp_suc replicate_Suc[THEN sym] del: replicate_Suc)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2319
  thus "?case"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2320
    using ind
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2321
    by auto
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2322
qed
70
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2323
229
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2324
lemma recursive_compile_correct_norm': 
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2325
  "\<lbrakk>rec_ci f = (ap, arity, ft);  
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2326
    terminate f args\<rbrakk>
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2327
  \<Longrightarrow> \<exists> stp rl. (abc_steps_l (0, args) ap stp) = (length ap, rl) \<and> abc_list_crsp (args @ [rec_exec f args]) rl"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2328
  using recursive_compile_correct[of f args ap arity ft "[]"]
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2329
apply(auto simp: abc_Hoare_halt_def)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2330
apply(rule_tac x = n in exI)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2331
apply(case_tac "abc_steps_l (0, args @ 0 \<up> (ft - arity)) ap n", auto)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2332
apply(drule_tac abc_list_crsp_steps, auto)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2333
apply(rule_tac list_crsp_simp2, auto)
70
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2334
done
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2335
229
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2336
lemma [simp]:
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2337
  assumes a: "args @ [rec_exec f args] = lm @ 0 \<up> n"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2338
  and b: "length args < length lm"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2339
  shows "\<exists>m. lm = args @ rec_exec f args # 0 \<up> m"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2340
using assms
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2341
apply(case_tac n, simp)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2342
apply(rule_tac x = 0 in exI, simp)
70
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2343
apply(drule_tac length_equal, simp)
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2344
done
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2345
229
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2346
lemma [simp]: 
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2347
"\<lbrakk>args @ [rec_exec f args] = lm @ 0 \<up> n; \<not> length args < length lm\<rbrakk>
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2348
  \<Longrightarrow> \<exists>m. (lm @ 0 \<up> (length args - length lm) @ [Suc 0])[length args := 0] =
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2349
  args @ rec_exec f args # 0 \<up> m"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2350
apply(case_tac n, simp_all add: exp_suc list_update_append list_update.simps del: replicate_Suc)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2351
apply(subgoal_tac "length args = Suc (length lm)", simp)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2352
apply(rule_tac x = "Suc (Suc 0)" in exI, simp)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2353
apply(drule_tac length_equal, simp, auto)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2354
done
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2355
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2356
lemma compile_append_dummy_correct: 
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2357
  assumes compile: "rec_ci f = (ap, ary, fp)"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2358
  and termi: "terminate f args"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2359
  shows "{\<lambda> nl. nl = args} (ap [+] dummy_abc (length args)) {\<lambda> nl. (\<exists> m. nl = args @ rec_exec f args # 0\<up>m)}"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2360
proof(rule_tac abc_Hoare_plus_halt)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2361
  show "{\<lambda>nl. nl = args} ap {\<lambda> nl. abc_list_crsp (args @ [rec_exec f args]) nl}"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2362
    using compile termi recursive_compile_correct_norm'[of f ap ary fp args]
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2363
    apply(auto simp: abc_Hoare_halt_def)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2364
    by(rule_tac x = stp in exI, simp)
70
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2365
next
229
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2366
  show "{abc_list_crsp (args @ [rec_exec f args])} dummy_abc (length args) 
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2367
    {\<lambda>nl. \<exists>m. nl = args @ rec_exec f args # 0 \<up> m}"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2368
    apply(auto simp: dummy_abc_def abc_Hoare_halt_def)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2369
    apply(rule_tac x = 3 in exI)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2370
    by(auto simp: abc_steps_l.simps abc_list_crsp_def abc_step_l.simps numeral_3_eq_3 abc_fetch.simps
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2371
                     abc_lm_v.simps nth_append abc_lm_s.simps)
70
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2372
qed
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2373
229
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2374
lemma cn_merge_gs_split: 
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2375
  "\<lbrakk>i < length gs; rec_ci (gs!i) = (ga, gb, gc)\<rbrakk> \<Longrightarrow> 
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2376
  cn_merge_gs (map rec_ci gs) p =  cn_merge_gs (map rec_ci (take i gs)) p [+] (ga [+] 
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2377
       mv_box gb (p + i)) [+]  cn_merge_gs (map rec_ci (drop (Suc i) gs)) (p + Suc i)"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2378
apply(induct i arbitrary: gs p, case_tac gs, simp, simp)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2379
apply(case_tac gs, simp, case_tac "rec_ci a", 
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2380
       simp add: abc_comp_commute[THEN sym])
70
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2381
done
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2382
229
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2383
lemma cn_unhalt_case:
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2384
  assumes compile1: "rec_ci (Cn n f gs) = (ap, ar, ft) \<and> length args = ar"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2385
  and g: "i < length gs"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2386
  and compile2: "rec_ci (gs!i) = (gap, gar, gft) \<and> gar = length args"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2387
  and g_unhalt: "\<And> anything. {\<lambda> nl. nl = args @ 0\<up>(gft - gar) @ anything} gap \<up>"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2388
  and g_ind: "\<And> apj arj ftj j anything. \<lbrakk>j < i; rec_ci (gs!j) = (apj, arj, ftj)\<rbrakk> 
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2389
  \<Longrightarrow> {\<lambda> nl. nl = args @ 0\<up>(ftj - arj) @ anything} apj {\<lambda> nl. nl = args @ rec_exec (gs!j) args # 0\<up>(ftj - Suc arj) @ anything}"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2390
  and all_termi: "\<forall> j<i. terminate (gs!j) args"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2391
  shows "{\<lambda> nl. nl = args @ 0\<up>(ft - ar) @ anything} ap \<up>"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2392
using compile1
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2393
apply(case_tac "rec_ci f", auto simp: rec_ci.simps abc_comp_commute)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2394
proof(rule_tac abc_Hoare_plus_unhalt1)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2395
  fix fap far fft
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2396
  let ?ft = "max (Suc (length args)) (Max (insert fft ((\<lambda>(aprog, p, n). n) ` rec_ci ` set gs)))"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2397
  let ?Q = "\<lambda>nl. nl = args @ 0\<up> (?ft - length args) @ map (\<lambda>i. rec_exec i args) (take i gs) @ 
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2398
    0\<up>(length gs - i) @ 0\<up> Suc (length args) @ anything"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2399
  have "cn_merge_gs (map rec_ci gs) ?ft = 
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2400
    cn_merge_gs (map rec_ci (take i gs)) ?ft [+] (gap [+] 
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2401
    mv_box gar (?ft + i)) [+]  cn_merge_gs (map rec_ci (drop (Suc i) gs)) (?ft + Suc i)"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2402
    using g compile2 cn_merge_gs_split by simp
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2403
  thus "{\<lambda>nl. nl = args @ 0 # 0 \<up> (?ft + length gs) @ anything} (cn_merge_gs (map rec_ci gs) ?ft) \<up>"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2404
  proof(simp, rule_tac abc_Hoare_plus_unhalt1, rule_tac abc_Hoare_plus_unhalt2, 
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2405
              rule_tac abc_Hoare_plus_unhalt1)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2406
    let ?Q_tmp = "\<lambda>nl. nl = args @ 0\<up> (gft - gar) @ 0\<up>(?ft - (length args) - (gft -gar)) @ map (\<lambda>i. rec_exec i args) (take i gs) @ 
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2407
      0\<up>(length gs - i) @ 0\<up> Suc (length args) @ anything"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2408
    have a: "{?Q_tmp} gap \<up>"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2409
      using g_unhalt[of "0 \<up> (?ft - (length args) - (gft - gar)) @
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2410
        map (\<lambda>i. rec_exec i args) (take i gs) @ 0 \<up> (length gs - i) @ 0 \<up> Suc (length args) @ anything"]
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2411
      by simp
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2412
    moreover have "?ft \<ge> gft"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2413
      using g compile2
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2414
      apply(rule_tac min_max.le_supI2, rule_tac Max_ge, simp, rule_tac insertI2)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2415
      apply(rule_tac  x = "rec_ci (gs ! i)" in image_eqI, simp)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2416
      by(rule_tac x = "gs!i"  in image_eqI, simp, simp)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2417
    then have b:"?Q_tmp = ?Q"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2418
      using compile2
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2419
      apply(rule_tac arg_cong)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2420
      by(simp add: replicate_merge_anywhere)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2421
    thus "{?Q} gap \<up>"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2422
      using a by simp
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2423
  next
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2424
    show "{\<lambda>nl. nl = args @ 0 # 0 \<up> (?ft + length gs) @ anything} 
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2425
      cn_merge_gs (map rec_ci (take i gs)) ?ft
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2426
       {\<lambda>nl. nl = args @ 0 \<up> (?ft - length args) @
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2427
      map (\<lambda>i. rec_exec i args) (take i gs) @ 0 \<up> (length gs - i) @ 0 \<up> Suc (length args) @ anything}"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2428
      using all_termi
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2429
      apply(rule_tac compile_cn_gs_correct', auto simp: set_conv_nth)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2430
      by(drule_tac apj = x and arj = xa and  ftj = xb and j = ia and anything = xc in g_ind, auto)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2431
  qed
70
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2432
qed
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2433
229
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2434
70
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2435
229
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2436
lemma mn_unhalt_case':
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2437
  assumes compile: "rec_ci f = (a, b, c)"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2438
  and all_termi: "\<forall>i. terminate f (args @ [i]) \<and> 0 < rec_exec f (args @ [i])"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2439
  and B: "B = [Dec (Suc (length args)) (length a + 5), Dec (Suc (length args)) (length a + 3), 
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2440
  Goto (Suc (length a)), Inc (length args), Goto 0]"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2441
  shows "{\<lambda>nl. nl = args @ 0 \<up> (max (Suc (length args)) c - length args) @ anything}
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2442
  a @ B \<up>"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2443
proof(rule_tac abc_Hoare_unhaltI, auto)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2444
  fix n
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2445
  have a:  "b = Suc (length args)"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2446
    using all_termi compile
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2447
    apply(erule_tac x = 0 in allE)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2448
    by(auto, drule_tac param_pattern,auto)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2449
  moreover have b: "c > b"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2450
    using compile by(elim footprint_ge)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2451
  ultimately have c: "max (Suc (length args)) c = c" by arith
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2452
  have "\<exists> stp > n. abc_steps_l (0, args @ 0 # 0\<up>(c - Suc (length args)) @ anything) (a @ B) stp
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2453
         = (0, args @ Suc n # 0\<up>(c - Suc (length args)) @ anything)"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2454
    using assms a b c
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2455
  proof(rule_tac mn_loop_correct', auto)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2456
    fix i xc
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2457
    show "{\<lambda>nl. nl = args @ i # 0 \<up> (c - Suc (length args)) @ xc} a 
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2458
      {\<lambda>nl. nl = args @ i # rec_exec f (args @ [i]) # 0 \<up> (c - Suc (Suc (length args))) @ xc}"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2459
      using all_termi recursive_compile_correct[of f "args @ [i]" a b c xc] compile a
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2460
      by(simp)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2461
  qed
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2462
  then obtain stp where d: "stp > n \<and> abc_steps_l (0, args @ 0 # 0\<up>(c - Suc (length args)) @ anything) (a @ B) stp
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2463
         = (0, args @ Suc n # 0\<up>(c - Suc (length args)) @ anything)" ..
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2464
  then obtain d where e: "stp = n + Suc d"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2465
    by (metis add_Suc_right less_iff_Suc_add)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2466
  obtain s nl where f: "abc_steps_l (0, args @ 0 # 0\<up>(c - Suc (length args)) @ anything) (a @ B) n = (s, nl)"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2467
    by (metis prod.exhaust)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2468
  have g: "s < length (a @ B)"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2469
    using d e f
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2470
    apply(rule_tac classical, simp only: abc_steps_add)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2471
    by(simp add: halt_steps2 leI)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2472
  from f g show "abc_notfinal (abc_steps_l (0, args @ 0 \<up> 
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2473
    (max (Suc (length args)) c - length args) @ anything) (a @ B) n) (a @ B)"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2474
    using c b a
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2475
    by(simp add: replicate_Suc_iff_anywhere Suc_diff_Suc del: replicate_Suc)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2476
qed
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2477
    
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2478
lemma mn_unhalt_case: 
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2479
  assumes compile: "rec_ci (Mn n f) = (ap, ar, ft) \<and> length args = ar"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2480
  and all_term: "\<forall> i. terminate f (args @ [i]) \<and> rec_exec f (args @ [i]) > 0"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2481
  shows "{\<lambda> nl. nl = args @ 0\<up>(ft - ar) @ anything} ap \<up> "
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2482
  using assms
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2483
apply(case_tac "rec_ci f", auto simp: rec_ci.simps abc_comp_commute)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2484
by(rule_tac mn_unhalt_case', simp_all)
129
c3832c4963c4 updated recursive
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 126
diff changeset
  2485
c3832c4963c4 updated recursive
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 126
diff changeset
  2486
fun tm_of_rec :: "recf \<Rightarrow> instr list"
c3832c4963c4 updated recursive
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 126
diff changeset
  2487
where "tm_of_rec recf = (let (ap, k, fp) = rec_ci recf in
c3832c4963c4 updated recursive
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 126
diff changeset
  2488
                         let tp = tm_of (ap [+] dummy_abc k) in 
229
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2489
                           tp @ (shift (mopup k) (length tp div 2)))"
129
c3832c4963c4 updated recursive
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 126
diff changeset
  2490
229
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2491
lemma recursive_compile_to_tm_correct1: 
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2492
  assumes  compile: "rec_ci recf = (ap, ary, fp)"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2493
  and termi: " terminate recf args"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2494
  and tp: "tp = tm_of (ap [+] dummy_abc (length args))"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2495
  shows "\<exists> stp m l. steps0 (Suc 0, Bk # Bk # ires, <args> @ Bk\<up>rn)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2496
  (tp @ shift (mopup (length args)) (length tp div 2)) stp = (0, Bk\<up>m @ Bk # Bk # ires, Oc\<up>Suc (rec_exec recf args) @ Bk\<up>l)"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2497
proof -
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2498
  have "{\<lambda>nl. nl = args} ap [+] dummy_abc (length args) {\<lambda>nl. \<exists>m. nl = args @ rec_exec recf args # 0 \<up> m}"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2499
    using compile termi compile
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2500
    by(rule_tac compile_append_dummy_correct, auto)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2501
  then obtain stp m where h: "abc_steps_l (0, args) (ap [+] dummy_abc (length args)) stp = 
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2502
    (length (ap [+] dummy_abc (length args)), args @ rec_exec recf args # 0\<up>m) "
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2503
    apply(simp add: abc_Hoare_halt_def, auto)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2504
    by(case_tac "abc_steps_l (0, args) (ap [+] dummy_abc (length args)) n", auto)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2505
  thus "?thesis"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2506
    using assms tp
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2507
    by(rule_tac  lm = args and stp = stp and am = "args @ rec_exec recf args # 0 \<up> m"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2508
      in compile_correct_halt, auto simp: crsp.simps start_of.simps length_abc_comp abc_lm_v.simps)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2509
qed
70
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2510
126
0b302c0b449a updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 70
diff changeset
  2511
lemma recursive_compile_to_tm_correct2: 
230
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 229
diff changeset
  2512
  assumes termi: " terminate recf args"
229
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2513
  shows "\<exists> stp m l. steps0 (Suc 0, [Bk, Bk], <args>) (tm_of_rec recf) stp = 
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2514
                     (0, Bk\<up>Suc (Suc m), Oc\<up>Suc (rec_exec recf args) @ Bk\<up>l)"
230
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 229
diff changeset
  2515
proof(case_tac "rec_ci recf", simp add: tm_of_rec.simps)
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 229
diff changeset
  2516
  fix ap ar fp
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 229
diff changeset
  2517
  assume "rec_ci recf = (ap, ar, fp)"
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 229
diff changeset
  2518
  thus "\<exists>stp m l. steps0 (Suc 0, [Bk, Bk], <args>) 
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 229
diff changeset
  2519
    (tm_of (ap [+] dummy_abc ar) @ shift (mopup ar) (listsum (layout_of (ap [+] dummy_abc ar)))) stp =
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 229
diff changeset
  2520
    (0, Bk # Bk # Bk \<up> m, Oc # Oc \<up> rec_exec recf args @ Bk \<up> l)"
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 229
diff changeset
  2521
    using recursive_compile_to_tm_correct1[of recf ap ar fp args "tm_of (ap [+] dummy_abc (length args))" "[]" 0]
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 229
diff changeset
  2522
      assms param_pattern[of recf args ap ar fp]
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 229
diff changeset
  2523
    by(simp add: replicate_Suc[THEN sym] replicate_Suc_iff_anywhere del: replicate_Suc tm_of_rec_def, 
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 229
diff changeset
  2524
      simp add: exp_suc del: replicate_Suc)
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 229
diff changeset
  2525
qed
126
0b302c0b449a updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 70
diff changeset
  2526
129
c3832c4963c4 updated recursive
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 126
diff changeset
  2527
lemma recursive_compile_to_tm_correct3: 
230
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 229
diff changeset
  2528
  assumes termi: "terminate recf args"
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 229
diff changeset
  2529
  shows "{\<lambda> tp. tp =([Bk, Bk], <args>)} (tm_of_rec recf) 
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 229
diff changeset
  2530
         {\<lambda> tp. \<exists> k l. tp = (Bk\<up> k, <rec_exec recf args> @ Bk \<up> l)}"
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 229
diff changeset
  2531
using recursive_compile_to_tm_correct2[OF assms]
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 229
diff changeset
  2532
apply(auto simp add: Hoare_halt_def)
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 229
diff changeset
  2533
apply(rule_tac x = stp in exI)
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 229
diff changeset
  2534
apply(auto simp add: tape_of_nat_abv)
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 229
diff changeset
  2535
apply(rule_tac x = "Suc (Suc m)" in exI)
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 229
diff changeset
  2536
apply(simp)
49dcc0b9b0b3 adapted paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 229
diff changeset
  2537
done 
129
c3832c4963c4 updated recursive
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 126
diff changeset
  2538
70
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2539
lemma [simp]:
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2540
  "list_all (\<lambda>(acn, s). s \<le> Suc (Suc (Suc (Suc (Suc (Suc (2 * n))))))) xs \<Longrightarrow>
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2541
  list_all (\<lambda>(acn, s). s \<le> Suc (Suc (Suc (Suc (Suc (Suc (Suc (Suc (2 * n))))))))) xs"
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2542
apply(induct xs, simp, simp)
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2543
apply(case_tac a, simp)
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2544
done
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2545
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2546
lemma shift_append: "shift (xs @ ys) n = shift xs n @ shift ys n"
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2547
apply(simp add: shift.simps)
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2548
done
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2549
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2550
lemma [simp]: "length (shift (mopup n) ss) = 4 * n + 12"
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2551
apply(auto simp: mopup.simps shift_append mopup_b_def)
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2552
done
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2553
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2554
lemma length_tm_even[intro]: "length (tm_of ap) mod 2 = 0"
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2555
apply(simp add: tm_of.simps)
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2556
done
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2557
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2558
lemma [simp]: "k < length ap \<Longrightarrow> tms_of ap ! k  = 
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2559
 ci (layout_of ap) (start_of (layout_of ap) k) (ap ! k)"
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2560
apply(simp add: tms_of.simps tpairs_of.simps)
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2561
done
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2562
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2563
lemma start_of_suc_inc:
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2564
  "\<lbrakk>k < length ap; ap ! k = Inc n\<rbrakk> \<Longrightarrow> start_of (layout_of ap) (Suc k) =
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2565
                        start_of (layout_of ap) k + 2 * n + 9"
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2566
apply(rule_tac start_of_Suc1, auto simp: abc_fetch.simps)
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2567
done
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2568
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2569
lemma start_of_suc_dec:
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2570
  "\<lbrakk>k < length ap; ap ! k = (Dec n e)\<rbrakk> \<Longrightarrow> start_of (layout_of ap) (Suc k) =
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2571
                        start_of (layout_of ap) k + 2 * n + 16"
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2572
apply(rule_tac start_of_Suc2, auto simp: abc_fetch.simps)
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2573
done
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2574
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2575
lemma inc_state_all_le:
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2576
  "\<lbrakk>k < length ap; ap ! k = Inc n; 
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2577
       (a, b) \<in> set (shift (shift tinc_b (2 * n)) 
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2578
                            (start_of (layout_of ap) k - Suc 0))\<rbrakk>
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2579
       \<Longrightarrow> b \<le> start_of (layout_of ap) (length ap)"
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2580
apply(subgoal_tac "b \<le> start_of (layout_of ap) (Suc k)")
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2581
apply(subgoal_tac "start_of (layout_of ap) (Suc k) \<le> start_of (layout_of ap) (length ap) ")
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2582
apply(arith)
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2583
apply(case_tac "Suc k = length ap", simp)
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2584
apply(rule_tac start_of_less, simp)
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2585
apply(auto simp: tinc_b_def shift.simps start_of_suc_inc length_of.simps startof_not0)
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2586
done
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2587
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2588
lemma findnth_le[elim]: 
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2589
  "(a, b) \<in> set (shift (findnth n) (start_of (layout_of ap) k - Suc 0))
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2590
  \<Longrightarrow> b \<le> Suc (start_of (layout_of ap) k + 2 * n)"
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2591
apply(induct n, simp add: findnth.simps shift.simps)
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2592
apply(simp add: findnth.simps shift_append, auto)
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2593
apply(auto simp: shift.simps)
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2594
done
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2595
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2596
lemma findnth_state_all_le1:
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2597
  "\<lbrakk>k < length ap; ap ! k = Inc n;
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2598
  (a, b) \<in> 
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2599
  set (shift (findnth n) (start_of (layout_of ap) k - Suc 0))\<rbrakk> 
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2600
  \<Longrightarrow> b \<le> start_of (layout_of ap) (length ap)"
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2601
apply(subgoal_tac "b \<le> start_of (layout_of ap) (Suc k)")
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2602
apply(subgoal_tac "start_of (layout_of ap) (Suc k) \<le> start_of (layout_of ap) (length ap) ")
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2603
apply(arith)
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2604
apply(case_tac "Suc k = length ap", simp)
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2605
apply(rule_tac start_of_less, simp)
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2606
apply(subgoal_tac "b \<le> start_of (layout_of ap) k + 2*n + 1 \<and> 
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2607
     start_of (layout_of ap) k + 2*n + 1 \<le>  start_of (layout_of ap) (Suc k)", auto)
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2608
apply(auto simp: tinc_b_def shift.simps length_of.simps startof_not0 start_of_suc_inc)
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2609
done
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2610
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2611
lemma start_of_eq: "length ap < as \<Longrightarrow> start_of (layout_of ap) as = start_of (layout_of ap) (length ap)"
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2612
apply(induct as, simp)
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2613
apply(case_tac "length ap < as", simp add: start_of.simps)
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2614
apply(subgoal_tac "as = length ap")
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2615
apply(simp add: start_of.simps)
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2616
apply arith
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2617
done
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2618
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2619
lemma start_of_all_le: "start_of (layout_of ap) as \<le> start_of (layout_of ap) (length ap)"
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2620
apply(subgoal_tac "as > length ap \<or> as = length ap \<or> as < length ap", 
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2621
      auto simp: start_of_eq start_of_less)
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2622
done
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2623
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2624
lemma findnth_state_all_le2: 
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2625
  "\<lbrakk>k < length ap; 
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2626
  ap ! k = Dec n e;
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2627
  (a, b) \<in> set (shift (findnth n) (start_of (layout_of ap) k - Suc 0))\<rbrakk>
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2628
  \<Longrightarrow> b \<le> start_of (layout_of ap) (length ap)"
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2629
apply(subgoal_tac "b \<le> start_of (layout_of ap) k + 2*n + 1 \<and> 
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2630
     start_of (layout_of ap) k + 2*n + 1 \<le>  start_of (layout_of ap) (Suc k) \<and>
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2631
      start_of (layout_of ap) (Suc k) \<le> start_of (layout_of ap) (length ap)", auto)
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2632
apply(subgoal_tac "start_of (layout_of ap) (Suc k) = 
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2633
  start_of  (layout_of ap)  k + 2*n + 16", simp)
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2634
apply(simp add: start_of_suc_dec)
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2635
apply(rule_tac start_of_all_le)
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2636
done
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2637
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2638
lemma dec_state_all_le[simp]:
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2639
  "\<lbrakk>k < length ap; ap ! k = Dec n e; 
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2640
  (a, b) \<in> set (shift (shift tdec_b (2 * n))
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2641
  (start_of (layout_of ap) k - Suc 0))\<rbrakk>
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2642
       \<Longrightarrow> b \<le> start_of (layout_of ap) (length ap)"
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2643
apply(subgoal_tac "2*n + start_of (layout_of ap) k + 16 \<le> start_of (layout_of ap) (length ap) \<and> start_of (layout_of ap) k > 0")
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2644
prefer 2
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2645
apply(subgoal_tac "start_of (layout_of ap) (Suc k) = start_of (layout_of ap) k + 2*n + 16
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2646
                 \<and> start_of (layout_of ap) (Suc k) \<le> start_of (layout_of ap) (length ap)")
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2647
apply(simp add: startof_not0, rule_tac conjI)
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2648
apply(simp add: start_of_suc_dec)
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2649
apply(rule_tac start_of_all_le)
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2650
apply(auto simp: tdec_b_def shift.simps)
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2651
done
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2652
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2653
lemma tms_any_less: 
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2654
  "\<lbrakk>k < length ap; (a, b) \<in> set (tms_of ap ! k)\<rbrakk> \<Longrightarrow> 
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2655
  b \<le> start_of (layout_of ap) (length ap)"
190
f1ecb4a68a54 renamed sete definition to adjust and old special case of adjust to adjust0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 172
diff changeset
  2656
apply(case_tac "ap!k", auto simp: tms_of.simps tpairs_of.simps ci.simps shift_append adjust.simps)
70
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2657
apply(erule_tac findnth_state_all_le1, simp_all)
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2658
apply(erule_tac inc_state_all_le, simp_all)
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2659
apply(erule_tac findnth_state_all_le2, simp_all)
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2660
apply(rule_tac start_of_all_le)
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2661
apply(rule_tac dec_state_all_le, simp_all)
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2662
apply(rule_tac start_of_all_le)
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2663
done
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2664
229
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2665
lemma concat_in: "i < length (concat xs) \<Longrightarrow> 
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2666
  \<exists>k < length xs. concat xs ! i \<in> set (xs ! k)"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2667
apply(induct xs rule: rev_induct, simp, simp)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2668
apply(case_tac "i < length (concat xs)", simp)
70
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2669
apply(erule_tac exE, rule_tac x = k in exI)
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2670
apply(simp add: nth_append)
229
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2671
apply(rule_tac x = "length xs" in exI, simp)
70
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2672
apply(simp add: nth_append)
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2673
done 
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2674
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2675
lemma [simp]: "length (tms_of ap) = length ap"
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2676
apply(simp add: tms_of.simps tpairs_of.simps)
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2677
done
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2678
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2679
declare length_concat[simp]
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2680
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2681
lemma in_tms: "i < length (tm_of ap) \<Longrightarrow> \<exists> k < length ap. (tm_of ap ! i) \<in> set (tms_of ap ! k)"
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2682
apply(simp only: tm_of.simps)
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2683
using concat_in[of i "tms_of ap"]
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2684
apply(auto)
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2685
done
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2686
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2687
lemma all_le_start_of: "list_all (\<lambda>(acn, s). 
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2688
  s \<le> start_of (layout_of ap) (length ap)) (tm_of ap)"
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2689
apply(simp only: list_all_length)
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2690
apply(rule_tac allI, rule_tac impI)
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2691
apply(drule_tac in_tms, auto elim: tms_any_less)
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2692
done
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2693
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2694
lemma length_ci: 
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2695
"\<lbrakk>k < length ap; length (ci ly y (ap ! k)) = 2 * qa\<rbrakk>
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2696
      \<Longrightarrow> layout_of ap ! k = qa"
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2697
apply(case_tac "ap ! k")
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2698
apply(auto simp: layout_of.simps ci.simps 
190
f1ecb4a68a54 renamed sete definition to adjust and old special case of adjust to adjust0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 172
diff changeset
  2699
  length_of.simps tinc_b_def tdec_b_def length_findnth adjust.simps)
70
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2700
done
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2701
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2702
lemma [intro]: "length (ci ly y i) mod 2 = 0"
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2703
apply(case_tac i, auto simp: ci.simps length_findnth
190
f1ecb4a68a54 renamed sete definition to adjust and old special case of adjust to adjust0
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 172
diff changeset
  2704
  tinc_b_def adjust.simps tdec_b_def)
70
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2705
done
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2706
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2707
lemma [intro]: "listsum (map (length \<circ> (\<lambda>(x, y). ci ly x y)) zs) mod 2 = 0"
229
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2708
apply(induct zs rule: rev_induct, simp)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2709
apply(case_tac x, simp)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2710
apply(subgoal_tac "length (ci ly a b) mod 2 = 0")
70
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2711
apply(auto)
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2712
done
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2713
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2714
lemma zip_pre:
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2715
  "(length ys) \<le> length ap \<Longrightarrow>
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2716
  zip ys ap = zip ys (take (length ys) (ap::'a list))"
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2717
proof(induct ys arbitrary: ap, simp, case_tac ap, simp)
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2718
  fix a ys ap aa list
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2719
  assume ind: "\<And>(ap::'a list). length ys \<le> length ap \<Longrightarrow> 
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2720
    zip ys ap = zip ys (take (length ys) ap)"
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2721
  and h: "length (a # ys) \<le> length ap" "(ap::'a list) = aa # (list::'a list)"
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2722
  from h show "zip (a # ys) ap = zip (a # ys) (take (length (a # ys)) ap)"
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2723
    using ind[of list]
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2724
    apply(simp)
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2725
    done
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2726
qed
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2727
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2728
lemma length_start_of_tm: "start_of (layout_of ap) (length ap) = Suc (length (tm_of ap)  div 2)"
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2729
using tpa_states[of "tm_of ap"  "length ap" ap]
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2730
apply(simp add: tm_of.simps)
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2731
done
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2732
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2733
lemma [elim]: "list_all (\<lambda>(acn, s). s \<le> Suc q) xs
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2734
        \<Longrightarrow> list_all (\<lambda>(acn, s). s \<le> q + (2 * n + 6)) xs"
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2735
apply(simp add: list_all_length)
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2736
apply(auto)
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2737
done
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2738
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2739
lemma [simp]: "length mopup_b = 12"
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2740
apply(simp add: mopup_b_def)
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2741
done
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2742
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2743
lemma mp_up_all_le: "list_all  (\<lambda>(acn, s). s \<le> q + (2 * n + 6)) 
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2744
  [(R, Suc (Suc (2 * n + q))), (R, Suc (2 * n + q)), 
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2745
  (L, 5 + 2 * n + q), (W0, Suc (Suc (Suc (2 * n + q)))), (R, 4 + 2 * n + q),
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2746
  (W0, Suc (Suc (Suc (2 * n + q)))), (R, Suc (Suc (2 * n + q))),
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2747
  (W0, Suc (Suc (Suc (2 * n + q)))), (L, 5 + 2 * n + q),
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2748
  (L, 6 + 2 * n + q), (R, 0),  (L, 6 + 2 * n + q)]"
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2749
apply(auto)
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2750
done
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2751
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2752
lemma [simp]: "(a, b) \<in> set (mopup_a n) \<Longrightarrow> b \<le> 2 * n + 6"
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2753
apply(induct n, auto simp: mopup_a.simps)
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2754
done
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2755
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2756
lemma [simp]: "(a, b) \<in> set (shift (mopup n) (listsum (layout_of ap)))
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2757
  \<Longrightarrow> b \<le> (2 * listsum (layout_of ap) + length (mopup n)) div 2"
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2758
apply(auto simp: mopup.simps shift_append shift.simps)
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2759
apply(auto simp: mopup_a.simps mopup_b_def)
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2760
done
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2761
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2762
lemma [intro]: " 2 \<le> 2 * listsum (layout_of ap) + length (mopup n)"
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2763
apply(simp add: mopup.simps)
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2764
done
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2765
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2766
lemma [intro]: " (2 * listsum (layout_of ap) + length (mopup n)) mod 2 = 0"
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2767
apply(auto simp: mopup.simps)
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2768
apply arith
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2769
done
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2770
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2771
lemma [simp]: "b \<le> Suc x
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2772
          \<Longrightarrow> b \<le> (2 * x + length (mopup n)) div 2"
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2773
apply(auto simp: mopup.simps)
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2774
done
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2775
229
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2776
lemma wf_tm_from_abacus: 
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2777
  "tp = tm_of ap \<Longrightarrow> 
70
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2778
    tm_wf (tp @ shift( mopup n) (length tp div 2), 0)"
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2779
  using length_start_of_tm[of ap] all_le_start_of[of ap]
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2780
apply(auto simp: tm_wf.simps List.list_all_iff)
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2781
done
2363eb91d9fd updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  2782
229
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2783
lemma wf_tm_from_recf:
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2784
  assumes compile: "tp = tm_of_rec recf"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2785
  shows "tm_wf0 tp"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2786
proof -
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2787
  obtain a b c where "rec_ci recf = (a, b, c)"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2788
    by (metis prod_cases3)
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2789
  thus "?thesis"
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2790
    using compile
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2791
    using wf_tm_from_abacus[of "tm_of (a [+] dummy_abc b)" "(a [+] dummy_abc b)" b]
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2792
    by simp
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2793
qed
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2794
 
d8e6f0798e23 much simplified version of Recursive.thy
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 204
diff changeset
  2795
end