uncomputable.thy
changeset 37 c9b689bb4156
parent 0 aa8656a8dbef
equal deleted inserted replaced
36:4b35e0e0784b 37:c9b689bb4156
    35 text {*
    35 text {*
    36   The following functions are used to expression invariants of {\em Copying} TM.
    36   The following functions are used to expression invariants of {\em Copying} TM.
    37 *}
    37 *}
    38 fun tcopy_F0 :: "nat \<Rightarrow> tape \<Rightarrow> bool"
    38 fun tcopy_F0 :: "nat \<Rightarrow> tape \<Rightarrow> bool"
    39   where
    39   where
    40   "tcopy_F0 x tp = (let (ln, rn) = tp in 
    40   "tcopy_F0 x (l, r) = (\<exists> i. l = Bk\<^bsup>i\<^esup> \<and> r = Oc\<^bsup>x\<^esup> @ Bk # Oc\<^bsup>x\<^esup>)"
    41            list_all isBk ln & rn = replicate x Oc 
       
    42                                    @ [Bk] @ replicate x Oc)"
       
    43 
    41 
    44 fun tcopy_F1 :: "nat \<Rightarrow> tape \<Rightarrow> bool"
    42 fun tcopy_F1 :: "nat \<Rightarrow> tape \<Rightarrow> bool"
    45   where
    43   where
    46    "tcopy_F1 x (ln, rn) = (ln = [] & rn = replicate x Oc)"
    44    "tcopy_F1 x (l, r) = (l = [] \<and> r = Oc\<^bsup>x\<^esup>)"
    47 
    45 
    48 fun tcopy_F2 :: "nat \<Rightarrow> tape \<Rightarrow> bool"
    46 fun tcopy_F2 :: "nat \<Rightarrow> tape \<Rightarrow> bool"
    49   where
    47   where 
    50   "tcopy_F2 0 tp = False" |
    48   "tcopy_F2 x (l, r) = (\<exists> i j. i > 0 \<and> i + j = x \<and> l = Oc\<^bsup>i\<^esup> \<and> r = Oc\<^bsup>j\<^esup>)"
    51   "tcopy_F2 (Suc x) (ln, rn) = (length ln > 0 & 
       
    52              ln @ rn = replicate (Suc x) Oc)"
       
    53 
    49 
    54 fun tcopy_F3 :: "nat \<Rightarrow> tape \<Rightarrow> bool"
    50 fun tcopy_F3 :: "nat \<Rightarrow> tape \<Rightarrow> bool"
    55   where
    51   where
    56   "tcopy_F3 0 tp = False" |
    52   "tcopy_F3 x (l, r) = (x > 0 \<and> l = Bk # Oc\<^bsup>x\<^esup> \<and> tl r = [])"
    57   "tcopy_F3 (Suc x) (ln, rn) = 
       
    58             (ln = Bk # replicate (Suc x) Oc & length rn <= 1)"
       
    59 
    53 
    60 fun tcopy_F4 :: "nat \<Rightarrow> tape \<Rightarrow> bool"
    54 fun tcopy_F4 :: "nat \<Rightarrow> tape \<Rightarrow> bool"
    61   where
    55   where
    62   "tcopy_F4 0 tp = False" | 
    56   "tcopy_F4 x (l, r) = (x > 0 \<and> ((l = Oc\<^bsup>x\<^esup> \<and> r = [Bk, Oc]) \<or> (l = Oc\<^bsup>x - 1\<^esup> \<and> r = [Oc, Bk, Oc])))"
    63   "tcopy_F4 (Suc x) (ln, rn) = 
    57 
    64            ((ln = replicate x Oc & rn = [Oc, Bk, Oc])
    58 fun tcopy_F5_loop :: "nat \<Rightarrow> tape \<Rightarrow> bool"
    65            | (ln = replicate (Suc x) Oc & rn = [Bk, Oc])) "
    59   where
       
    60   "tcopy_F5_loop x (l, r) = 
       
    61        (\<exists> i j. i + j + 1 = x \<and> l = Oc\<^bsup>i\<^esup> \<and> r = Oc # Oc # Bk\<^bsup>j\<^esup> @ Oc\<^bsup>j\<^esup> \<and> j > 0)"
       
    62 
       
    63 fun tcopy_F5_exit :: "nat \<Rightarrow> tape \<Rightarrow> bool"
       
    64   where
       
    65   "tcopy_F5_exit x (l, r) = 
       
    66       (l = [] \<and> r = Bk # Oc # Bk\<^bsup>x\<^esup> @ Oc\<^bsup>x\<^esup> \<and> x > 0 )"
    66 
    67 
    67 fun tcopy_F5 :: "nat \<Rightarrow> tape \<Rightarrow> bool"
    68 fun tcopy_F5 :: "nat \<Rightarrow> tape \<Rightarrow> bool"
    68   where
    69   where
    69   "tcopy_F5 0 tp = False" |
    70   "tcopy_F5 x (l, r) = (tcopy_F5_loop x (l, r) \<or> tcopy_F5_exit x (l, r))"
    70   "tcopy_F5 (Suc x) (ln, rn) = 
       
    71         (if rn = [] then False 
       
    72          else if hd rn = Bk then (ln = [] & 
       
    73                    rn = Bk # (Oc # replicate (Suc x) Bk
       
    74                              @ replicate (Suc x) Oc))
       
    75          else if hd rn = Oc then 
       
    76            (\<exists>n. ln = replicate (x - n) Oc 
       
    77               & rn = Oc # (Oc # replicate n Bk @ replicate n Oc)
       
    78                & n > 0 & n <= x)
       
    79           else False)"
       
    80   
       
    81 
    71 
    82 fun tcopy_F6 :: "nat \<Rightarrow> tape \<Rightarrow> bool"
    72 fun tcopy_F6 :: "nat \<Rightarrow> tape \<Rightarrow> bool"
    83   where
    73   where
    84   "tcopy_F6 0 tp = False" |
    74   "tcopy_F6 x (l, r) = 
    85   "tcopy_F6 (Suc x) (ln, rn) = 
    75        (\<exists> i j any. i + j = x \<and> x > 0 \<and> i > 0 \<and> j > 0 \<and> l = Oc\<^bsup>i\<^esup> \<and> r = any#Bk\<^bsup>j\<^esup> @ Oc\<^bsup>j\<^esup>)"
    86             (\<exists>n. ln = replicate (Suc x -n) Oc 
    76 
    87                      & tl rn = replicate n Bk @ replicate n Oc
       
    88              & n > 0 & n <= x)"
       
    89   
       
    90 fun tcopy_F7 :: "nat \<Rightarrow> tape \<Rightarrow> bool"
    77 fun tcopy_F7 :: "nat \<Rightarrow> tape \<Rightarrow> bool"
    91   where
    78   where
    92   "tcopy_F7 0 tp = False" |
    79   "tcopy_F7 x (l, r) = 
    93   "tcopy_F7 (Suc x) (ln, rn) = 
    80          (\<exists> i j k t. i + j = x \<and> i > 0 \<and> j > 0 \<and>  k + t = Suc j \<and> l = Bk\<^bsup>k\<^esup> @ Oc\<^bsup>i\<^esup> \<and> r = Bk\<^bsup>t\<^esup> @ Oc\<^bsup>j\<^esup>)"
    94             (let lrn = (rev ln) @ rn in 
    81 
    95             (\<exists>n. lrn = replicate ((Suc x) - n) Oc @
       
    96                         replicate (Suc n) Bk @ replicate n Oc
       
    97              & n > 0 & n <= x & 
       
    98                length rn >= n & length rn <= 2 * n ))"
       
    99                  
       
   100 fun tcopy_F8 :: "nat \<Rightarrow> tape \<Rightarrow> bool"
    82 fun tcopy_F8 :: "nat \<Rightarrow> tape \<Rightarrow> bool"
   101   where
    83   where
   102   "tcopy_F8 0 tp = False" |
    84   "tcopy_F8 x (l, r) = 
   103   "tcopy_F8 (Suc x) (ln, rn) = 
    85            (\<exists> i j k t. i + j = x \<and> i > 0 \<and> j > 0 \<and>  k + t = j \<and> l = Oc\<^bsup>k\<^esup> @ Bk\<^bsup>Suc j\<^esup> @ Oc\<^bsup>i\<^esup> \<and> r = Oc\<^bsup>t\<^esup>)"
   104             (let lrn = (rev ln) @ rn in 
    86 
   105             (\<exists>n. lrn = replicate ((Suc x) - n) Oc @ 
    87 fun tcopy_F9_loop :: "nat \<Rightarrow> tape \<Rightarrow> bool"
   106                        replicate (Suc n) Bk @ replicate n Oc
    88 where
   107                & n > 0 & n <= x & length rn < n)) "
    89   "tcopy_F9_loop x (l, r) = 
       
    90           (\<exists> i j k t. i + j = Suc x \<and> i > 0 \<and> j > 0 \<and> k + t = j \<and> t > 0\<and> l = Oc\<^bsup>k\<^esup> @ Bk\<^bsup>j\<^esup> @ Oc\<^bsup>i\<^esup> \<and> r = Oc\<^bsup>t\<^esup>)"
       
    91 
       
    92 fun tcopy_F9_exit :: "nat \<Rightarrow> tape \<Rightarrow> bool"
       
    93   where
       
    94   "tcopy_F9_exit x (l, r) = (\<exists> i j. i + j = Suc x \<and> i > 0 \<and> j > 0 \<and>  l = Bk\<^bsup>j - 1\<^esup> @ Oc\<^bsup>i\<^esup> \<and> r = Bk # Oc\<^bsup>j\<^esup>)"
   108 
    95 
   109 fun tcopy_F9 :: "nat \<Rightarrow> tape \<Rightarrow> bool"
    96 fun tcopy_F9 :: "nat \<Rightarrow> tape \<Rightarrow> bool"
   110   where
    97   where
   111   "tcopy_F9 0 tp = False" | 
    98   "tcopy_F9 x (l, r) = (tcopy_F9_loop x (l, r) \<or> 
   112   "tcopy_F9 (Suc x) (ln, rn) =  
    99                         tcopy_F9_exit x (l, r))"
   113             (let lrn = (rev ln) @ rn in 
   100 
   114             (\<exists>n. lrn = replicate (Suc (Suc x) - n) Oc 
   101 fun tcopy_F10_loop :: "nat \<Rightarrow> tape \<Rightarrow> bool"
   115                             @ replicate n Bk @ replicate n Oc
   102   where
   116              & n > Suc 0 & n <= Suc x & length rn > 0 
   103   "tcopy_F10_loop x (l, r) = 
   117                     & length rn <= Suc n))"
   104      (\<exists> i j k t. i + j = Suc x \<and> i > 0 \<and> k + t + 1 = j \<and> l = Bk\<^bsup>k\<^esup> @ Oc\<^bsup>i\<^esup> \<and> r = Bk\<^bsup>Suc t\<^esup> @ Oc\<^bsup>j\<^esup>)"
       
   105 
       
   106 fun tcopy_F10_exit :: "nat \<Rightarrow> tape \<Rightarrow> bool"
       
   107   where
       
   108   "tcopy_F10_exit x (l, r) = 
       
   109      (\<exists> i j. i + j = x \<and> j > 0 \<and> l =  Oc\<^bsup>i\<^esup> \<and> r = Oc # Bk\<^bsup>j\<^esup> @ Oc\<^bsup>j\<^esup>)"
   118 
   110 
   119 fun tcopy_F10 :: "nat \<Rightarrow> tape \<Rightarrow> bool"
   111 fun tcopy_F10 :: "nat \<Rightarrow> tape \<Rightarrow> bool"
   120   where
   112   where
   121   "tcopy_F10 0 tp = False" |
   113   "tcopy_F10 x (l, r) = (tcopy_F10_loop x (l, r) \<or> tcopy_F10_exit x (l, r))"
   122   "tcopy_F10 (Suc x) (ln, rn) = 
       
   123            (let lrn = (rev ln) @ rn in 
       
   124              (\<exists>n. lrn = replicate (Suc (Suc x) - n) Oc
       
   125                    @ replicate n Bk @ replicate n Oc & n > Suc 0 
       
   126                 & n <= Suc x & length rn > Suc n & 
       
   127                   length rn <= 2*n + 1 ))"
       
   128 
   114 
   129 fun tcopy_F11 :: "nat \<Rightarrow> tape \<Rightarrow> bool"
   115 fun tcopy_F11 :: "nat \<Rightarrow> tape \<Rightarrow> bool"
   130   where
   116   where
   131   "tcopy_F11 0 tp = False" |
   117   "tcopy_F11 x (l, r) = (x > 0 \<and> l = [Bk] \<and> r = Oc # Bk\<^bsup>x\<^esup> @ Oc\<^bsup>x\<^esup>)"
   132   "tcopy_F11 (Suc x) (ln, rn) = 
       
   133             (ln = [Bk] & rn = Oc # replicate (Suc x) Bk 
       
   134                               @ replicate (Suc x) Oc)"
       
   135 
   118 
   136 fun tcopy_F12 :: "nat \<Rightarrow> tape \<Rightarrow> bool"
   119 fun tcopy_F12 :: "nat \<Rightarrow> tape \<Rightarrow> bool"
   137   where
   120   where
   138   "tcopy_F12 0 tp = False" |
   121   "tcopy_F12 x (l, r) = (\<exists> i j. i + j = Suc x \<and> x > 0 \<and> l = Oc\<^bsup>i\<^esup> @ [Bk] \<and> r = Bk\<^bsup>j\<^esup> @ Oc\<^bsup>x\<^esup>)"
   139   "tcopy_F12 (Suc x) (ln, rn) =  
       
   140            (let lrn = ((rev ln) @ rn) in
       
   141            (\<exists>n. n > 0 & n <= Suc (Suc x) 
       
   142          & lrn = Bk # replicate n Oc @ replicate (Suc (Suc x) - n) Bk
       
   143                  @ replicate (Suc x) Oc 
       
   144          & length ln = Suc n))"
       
   145 
   122 
   146 fun tcopy_F13 :: "nat \<Rightarrow> tape \<Rightarrow> bool"
   123 fun tcopy_F13 :: "nat \<Rightarrow> tape \<Rightarrow> bool"
   147   where
   124   where
   148   "tcopy_F13 0 tp = False" |
   125   "tcopy_F13 x (l, r) =
   149   "tcopy_F13 (Suc x) (ln, rn) =  
   126         (\<exists> i j. x > 0 \<and> i + j = x \<and> l = Oc\<^bsup>i\<^esup> @ [Bk] \<and> r = Oc # Bk\<^bsup>j\<^esup> @ Oc\<^bsup>x\<^esup> )"
   150            (let lrn = ((rev ln) @ rn) in
   127 
   151            (\<exists>n. n > Suc 0 & n <= Suc (Suc x) 
       
   152          & lrn = Bk # replicate n Oc @ replicate (Suc (Suc x) - n) Bk
       
   153                  @ replicate (Suc x) Oc
       
   154          & length ln = n))"
       
   155           
       
   156 fun tcopy_F14 :: "nat \<Rightarrow> tape \<Rightarrow> bool"
   128 fun tcopy_F14 :: "nat \<Rightarrow> tape \<Rightarrow> bool"
   157   where
   129   where
   158   "tcopy_F14 0 tp = False" |
   130   "tcopy_F14 x (l, r) = (\<exists> any. x > 0 \<and> l = Oc\<^bsup>x\<^esup> @ [Bk] \<and> r = any#Oc\<^bsup>x\<^esup>)"
   159   "tcopy_F14 (Suc x) (ln, rn) = 
   131 
   160              (ln = replicate (Suc x) Oc @ [Bk] & 
   132 fun tcopy_F15_loop :: "nat \<Rightarrow> tape \<Rightarrow> bool"
   161               tl rn = replicate (Suc x) Oc)"
   133   where
       
   134   "tcopy_F15_loop x (l, r) = 
       
   135          (\<exists> i j. i + j = x \<and> x > 0 \<and> j > 0 \<and> l = Oc\<^bsup>i\<^esup> @ [Bk] \<and> r = Oc\<^bsup>j\<^esup> @ Bk # Oc\<^bsup>x\<^esup>)"
       
   136 
       
   137 fun tcopy_F15_exit :: "nat \<Rightarrow> tape \<Rightarrow> bool"
       
   138   where
       
   139   "tcopy_F15_exit x (l, r) = (x > 0 \<and> l = [] \<and> r = Bk # Oc\<^bsup>x\<^esup> @ Bk # Oc\<^bsup>x\<^esup>)"
   162 
   140 
   163 fun tcopy_F15 :: "nat \<Rightarrow> tape \<Rightarrow> bool"
   141 fun tcopy_F15 :: "nat \<Rightarrow> tape \<Rightarrow> bool"
   164   where
   142   where
   165   "tcopy_F15 0 tp = False" |
   143   "tcopy_F15 x (l, r) = (tcopy_F15_loop x (l, r) \<or>  tcopy_F15_exit x (l, r))"
   166   "tcopy_F15 (Suc x) (ln, rn) = 
       
   167             (let lrn = ((rev ln) @ rn) in
       
   168              lrn = Bk # replicate (Suc x) Oc @ [Bk] @ 
       
   169                    replicate (Suc x) Oc & length ln <= (Suc x))"
       
   170 
   144 
   171 text {*
   145 text {*
   172   The following @{text "inv_tcopy"} is the invariant of the {\em Copying} TM.
   146   The following @{text "inv_tcopy"} is the invariant of the {\em Copying} TM.
   173 *}
   147 *}
   174 fun inv_tcopy :: "nat \<Rightarrow> t_conf \<Rightarrow> bool"
   148 fun inv_tcopy :: "nat \<Rightarrow> t_conf \<Rightarrow> bool"
   206         tcopy_F12.simps [simp del]
   180         tcopy_F12.simps [simp del]
   207         tcopy_F13.simps [simp del]
   181         tcopy_F13.simps [simp del]
   208         tcopy_F14.simps [simp del]
   182         tcopy_F14.simps [simp del]
   209         tcopy_F15.simps [simp del]
   183         tcopy_F15.simps [simp del]
   210 
   184 
   211 lemma list_replicate_Bk[dest]: "list_all isBk list \<Longrightarrow> 
   185 lemma exp_zero_simp: "(a\<^bsup>b\<^esup> = []) = (b = 0)"
   212                             list = replicate (length list) Bk"
   186 apply(auto simp: exponent_def)
   213 apply(induct list)
   187 done
   214 apply(simp+)
   188 
   215 done
   189 lemma exp_zero_simp2: "([] = a\<^bsup>b\<^esup> ) = (b = 0)"
   216 
   190 apply(auto simp: exponent_def)
   217 lemma [simp]: "dropWhile (\<lambda> a. a = b) (replicate x b @ ys) = 
       
   218                   dropWhile (\<lambda> a. a = b) ys"
       
   219 apply(induct x)
       
   220 apply(simp)
       
   221 apply(simp)
       
   222 done
   191 done
   223 
   192 
   224 lemma [elim]: "\<lbrakk>tstep (0, a, b) tcopy = (s, l, r); s \<noteq> 0\<rbrakk> \<Longrightarrow> RR"
   193 lemma [elim]: "\<lbrakk>tstep (0, a, b) tcopy = (s, l, r); s \<noteq> 0\<rbrakk> \<Longrightarrow> RR"
   225 apply(simp add: tstep.simps tcopy_def fetch.simps)
   194 apply(simp add: tstep.simps tcopy_def fetch.simps)
   226 done
   195 done
   298 lemma [elim]: "\<lbrakk>tstep (15, a, b) tcopy = (s, l, r); s \<noteq> 0; s \<noteq> 15\<rbrakk> 
   267 lemma [elim]: "\<lbrakk>tstep (15, a, b) tcopy = (s, l, r); s \<noteq> 0; s \<noteq> 15\<rbrakk> 
   299             \<Longrightarrow> RR"
   268             \<Longrightarrow> RR"
   300 by(simp add: tstep.simps tcopy_def fetch.simps 
   269 by(simp add: tstep.simps tcopy_def fetch.simps 
   301         split: block.splits list.splits)
   270         split: block.splits list.splits)
   302 
   271 
       
   272 (*
   303 lemma min_Suc4: "min (Suc (Suc x)) x = x"
   273 lemma min_Suc4: "min (Suc (Suc x)) x = x"
   304 by auto
   274 by auto
   305 
   275 
   306 lemma takeWhile2replicate: 
   276 lemma takeWhile2replicate: 
   307        "\<exists>n. takeWhile (\<lambda>a. a = b) list = replicate n b"
   277        "\<exists>n. takeWhile (\<lambda>a. a = b) list = replicate n b"
   328 
   298 
   329 lemma replicate_Cons_simp: "b # replicate n b @ xs = 
   299 lemma replicate_Cons_simp: "b # replicate n b @ xs = 
   330                                         replicate n b @ b # xs"
   300                                         replicate n b @ b # xs"
   331 apply(simp)
   301 apply(simp)
   332 done
   302 done
   333 
   303 *)
   334 
   304 
   335 lemma [elim]: "\<lbrakk>tstep (14, b, c) tcopy = (15, ab, ba); 
   305 lemma [elim]: "\<lbrakk>tstep (14, b, c) tcopy = (15, ab, ba); 
   336                 tcopy_F14 x (b, c)\<rbrakk> \<Longrightarrow> tcopy_F15 x (ab, ba)"
   306                 tcopy_F14 x (b, c)\<rbrakk> \<Longrightarrow> tcopy_F15 x (ab, ba)"
   337 apply(case_tac x)
       
   338 apply(auto simp: tstep.simps tcopy_def 
   307 apply(auto simp: tstep.simps tcopy_def 
   339           tcopy_F14.simps tcopy_F15.simps fetch.simps new_tape.simps 
   308           tcopy_F14.simps tcopy_F15.simps fetch.simps new_tape.simps 
   340            split: if_splits list.splits block.splits)
   309            split: if_splits list.splits block.splits)
   341 done
   310 apply(erule_tac [!] x = "x - 1" in allE)
   342 
   311 apply(case_tac [!] x, simp_all add: exp_ind_def exp_zero)
       
   312 apply(erule_tac [!] x = "Suc 0" in allE, simp_all)
       
   313 done
       
   314 
       
   315 (*
   343 lemma dropWhile_drophd: "\<not> p a \<Longrightarrow> 
   316 lemma dropWhile_drophd: "\<not> p a \<Longrightarrow> 
   344       (dropWhile p xs @ (a # as)) = (dropWhile p (xs @ [a]) @ as)"
   317       (dropWhile p xs @ (a # as)) = (dropWhile p (xs @ [a]) @ as)"
   345 apply(induct xs)
   318 apply(induct xs)
   346 apply(auto)
   319 apply(auto)
   347 done
   320 done
   348 
   321 *)
       
   322 (*
   349 lemma dropWhile_append3: "\<lbrakk>\<not> p a; 
   323 lemma dropWhile_append3: "\<lbrakk>\<not> p a; 
   350   listall ((dropWhile p xs) @ [a]) isBk\<rbrakk> \<Longrightarrow> 
   324   listall ((dropWhile p xs) @ [a]) isBk\<rbrakk> \<Longrightarrow> 
   351                listall (dropWhile p (xs @ [a])) isBk"
   325                listall (dropWhile p (xs @ [a])) isBk"
   352 apply(drule_tac p = p and xs = xs and a = a in dropWhile_drophd, simp)
   326 apply(drule_tac p = p and xs = xs and a = a in dropWhile_drophd, simp)
   353 done
   327 done
   362 lemma listall_append: "list_all p (xs @ ys) = 
   336 lemma listall_append: "list_all p (xs @ ys) = 
   363                         (list_all p xs \<and> list_all p ys)"
   337                         (list_all p xs \<and> list_all p ys)"
   364 apply(induct xs)
   338 apply(induct xs)
   365 apply(simp+)
   339 apply(simp+)
   366 done
   340 done
       
   341 *)
       
   342 lemma false_case1:
       
   343   "\<lbrakk>Oc\<^bsup>j\<^esup> @ Bk # Oc\<^bsup>i + j\<^esup> = Oc # list;
       
   344   0 < i; 
       
   345   \<forall>ia. tl (Oc\<^bsup>i\<^esup> @ [Bk]) = Oc\<^bsup>ia\<^esup> @ [Bk] \<longrightarrow> (\<forall>ja. ia + ja = i + j 
       
   346   \<longrightarrow> hd (Oc\<^bsup>i\<^esup> @ [Bk]) # Oc # list \<noteq> Oc\<^bsup>ja\<^esup> @ Bk # Oc\<^bsup>i + j\<^esup>)\<rbrakk>
       
   347   \<Longrightarrow> RR"
       
   348 apply(case_tac i, auto simp: exp_ind_def)
       
   349 apply(erule_tac x = nat in allE, simp add:exp_ind_def)
       
   350 apply(erule_tac x = "Suc j" in allE, simp)
       
   351 done
       
   352 
       
   353 lemma false_case3:"\<forall>ja. ja \<noteq> i \<Longrightarrow> RR"
       
   354 by auto
   367 
   355 
   368 lemma [elim]: "\<lbrakk>tstep (15, b, c) tcopy = (15, ab, ba); 
   356 lemma [elim]: "\<lbrakk>tstep (15, b, c) tcopy = (15, ab, ba); 
   369                 tcopy_F15 x (b, c)\<rbrakk> \<Longrightarrow> tcopy_F15 x (ab, ba)" 
   357                 tcopy_F15 x (b, c)\<rbrakk> \<Longrightarrow> tcopy_F15 x (ab, ba)"
   370 apply(case_tac x)
       
   371 apply(auto simp: tstep.simps tcopy_F15.simps
   358 apply(auto simp: tstep.simps tcopy_F15.simps
   372                  tcopy_def fetch.simps new_tape.simps
   359                  tcopy_def fetch.simps new_tape.simps
   373             split: if_splits list.splits block.splits)
   360             split: if_splits list.splits block.splits elim: false_case1)
   374 apply(case_tac b, simp+)
   361 apply(case_tac [!] i, simp_all add: exp_zero exp_ind_def)
       
   362 apply(erule_tac [!] x = nat in allE, simp_all add: exp_ind_def)
       
   363 apply(auto elim: false_case3)
   375 done
   364 done
   376 
   365 
   377 lemma [elim]: "\<lbrakk>tstep (14, b, c) tcopy = (14, ab, ba); 
   366 lemma [elim]: "\<lbrakk>tstep (14, b, c) tcopy = (14, ab, ba); 
   378                 tcopy_F14 x (b, c)\<rbrakk> \<Longrightarrow> tcopy_F14 x (ab, ba)"
   367                 tcopy_F14 x (b, c)\<rbrakk> \<Longrightarrow> tcopy_F14 x (ab, ba)"
   379 apply(case_tac x)
       
   380 apply(auto simp: tcopy_F14.simps tcopy_def tstep.simps 
   368 apply(auto simp: tcopy_F14.simps tcopy_def tstep.simps 
   381                  tcopy_F14.simps fetch.simps new_tape.simps
   369                  tcopy_F14.simps fetch.simps new_tape.simps
   382            split: if_splits list.splits block.splits)
   370            split: if_splits list.splits block.splits)
   383 done
   371 done
   384 
   372 
   385 lemma [intro]: "list_all isBk (replicate x Bk)"
       
   386 apply(induct x, simp+)
       
   387 done
       
   388 
       
   389 lemma [elim]: "list_all isBk (dropWhile (\<lambda>a. a = Oc) b) \<Longrightarrow> 
       
   390                list_all isBk (dropWhile (\<lambda>a. a = Oc) (tl b))"
       
   391 apply(case_tac b, auto split: if_splits)
       
   392 apply(drule list_replicate_Bk)
       
   393 apply(case_tac "length list", auto)
       
   394 done
       
   395 
       
   396 lemma [elim]: "list_all (\<lambda> a. a = Oc) list \<Longrightarrow> 
       
   397                list = replicate (length list) Oc"
       
   398 apply(induct list)
       
   399 apply(simp+)
       
   400 done
       
   401 
       
   402 lemma append_length:  "\<lbrakk>as @ bs = cs @ ds; length bs = length ds\<rbrakk>
       
   403                     \<Longrightarrow> as = cs & bs = ds"
       
   404 apply(auto)
       
   405 done
       
   406 
       
   407 lemma Suc_elim: "Suc (Suc m) - n = Suc na \<Longrightarrow> Suc m - n = na"
       
   408 apply(simp)
       
   409 done
       
   410 
       
   411 lemma [elim]: "\<lbrakk>0 < n; n \<le> Suc (Suc na);
       
   412   rev b @ Oc # list = 
       
   413          Bk # replicate n Oc @ replicate (Suc (Suc na) - n) Bk @ 
       
   414          Oc # replicate na Oc;
       
   415   length b = Suc n; b \<noteq> []\<rbrakk>
       
   416        \<Longrightarrow> list_all isBk (dropWhile (\<lambda>a. a = Oc) (tl b))"
       
   417 apply(case_tac "rev b", auto)
       
   418 done
       
   419 
       
   420 lemma b_cons_same: "b#bs = replicate x a @ as \<Longrightarrow> a \<noteq> b \<longrightarrow> x = 0"
       
   421 apply(case_tac x, simp+)
       
   422 done
       
   423 
       
   424 lemma tcopy_tmp[elim]: 
       
   425   "\<lbrakk>0 < n; n \<le> Suc (Suc na); 
       
   426   rev b @ Oc # list = 
       
   427     Bk # replicate n Oc @ replicate (Suc (Suc na) - n) Bk 
       
   428     @ Oc # replicate na Oc; length b = Suc n; b \<noteq> []\<rbrakk>
       
   429    \<Longrightarrow> list = replicate na Oc"
       
   430 apply(case_tac "rev b", simp+)
       
   431 apply(auto)
       
   432 apply(frule b_cons_same, auto)
       
   433 done
       
   434 
   373 
   435 lemma [elim]: "\<lbrakk>tstep (12, b, c) tcopy = (14, ab, ba); 
   374 lemma [elim]: "\<lbrakk>tstep (12, b, c) tcopy = (14, ab, ba); 
   436                 tcopy_F12 x (b, c)\<rbrakk> \<Longrightarrow> tcopy_F14 x (ab, ba)" 
   375                 tcopy_F12 x (b, c)\<rbrakk> \<Longrightarrow> tcopy_F14 x (ab, ba)" 
   437 apply(case_tac x)
       
   438 apply(auto simp:tcopy_F12.simps tcopy_F14.simps 
   376 apply(auto simp:tcopy_F12.simps tcopy_F14.simps 
   439                 tcopy_def tstep.simps fetch.simps new_tape.simps 
   377                 tcopy_def tstep.simps fetch.simps new_tape.simps 
   440            split: if_splits list.splits block.splits)
   378            split: if_splits list.splits block.splits)
   441 apply(frule tcopy_tmp, simp+)
   379 apply(case_tac [!] j, simp_all add: exp_zero exp_ind_def)
   442 apply(case_tac n, simp+)
       
   443 apply(case_tac nata, simp+)
       
   444 done
       
   445 
       
   446 lemma replicate_app_Cons: "replicate a b @ b # replicate c b 
       
   447                         = replicate (Suc (a + c)) b"
       
   448 apply(simp)
       
   449 apply(simp add: replicate_app_Cons_same)
       
   450 apply(simp only: replicate_add[THEN sym])
       
   451 done
       
   452 
       
   453 lemma replicate_same_exE_pref: "\<exists>x. bs @ (b # cs) = replicate x y
       
   454                             \<Longrightarrow> (\<exists>n. bs = replicate n y)"
       
   455 apply(induct bs)
       
   456 apply(rule_tac x = 0 in exI, simp)
       
   457 apply(drule impI)
       
   458 apply(erule impE)
       
   459 apply(erule exE, simp+)
       
   460 apply(case_tac x, auto)
       
   461 apply(case_tac x, auto)
       
   462 apply(rule_tac x = "Suc n" in exI, simp+)
       
   463 done
       
   464 
       
   465 lemma replicate_same_exE_inf: "\<exists>x. bs @ (b # cs) = replicate x y \<Longrightarrow> b = y"
       
   466 apply(induct bs, auto)
       
   467 apply(case_tac x, auto)
       
   468 apply(drule impI)
       
   469 apply(erule impE)
       
   470 apply(case_tac x, simp+)
       
   471 done
       
   472 
       
   473 lemma replicate_same_exE_suf: 
       
   474      "\<exists>x. bs @ (b # cs) = replicate x y \<Longrightarrow> \<exists>n. cs = replicate n y"
       
   475 apply(induct bs, auto)
       
   476 apply(case_tac x, simp+)
       
   477 apply(drule impI, erule impE)
       
   478 apply(case_tac x, simp+)
       
   479 done
       
   480 
       
   481 lemma replicate_same_exE: "\<exists>x. bs @ (b # cs) = replicate x y 
       
   482     \<Longrightarrow> (\<exists>n. bs = replicate n y) & (b = y) & (\<exists>m. cs = replicate m y)"
       
   483 apply(rule conjI)
       
   484 apply(drule  replicate_same_exE_pref, simp)
       
   485 apply(rule conjI)
       
   486 apply(drule replicate_same_exE_inf, simp)
       
   487 apply(drule replicate_same_exE_suf, simp)
       
   488 done
       
   489 
       
   490 lemma replicate_same: "bs @ (b # cs) = replicate x y
       
   491     \<Longrightarrow> (\<exists>n. bs = replicate n y) & (b = y) & (\<exists>m. cs = replicate m y)"
       
   492 apply(rule_tac replicate_same_exE)
       
   493 apply(rule_tac x = x in exI)
       
   494 apply(assumption)
       
   495 done
       
   496 
       
   497 lemma [elim]: "\<lbrakk> 0 < n; n \<le> Suc (Suc na);
       
   498     (rev ab @ Bk # list) = Bk # replicate n Oc 
       
   499    @ replicate (Suc (Suc na) - n) Bk @ Oc # replicate na Oc; ab \<noteq> []\<rbrakk>
       
   500     \<Longrightarrow> n \<le> Suc na"
       
   501 apply(rule contrapos_pp, simp+)
       
   502 apply(case_tac "rev ab", simp+)
       
   503 apply(auto)
       
   504 apply(simp only: replicate_app_Cons)
       
   505 apply(drule replicate_same)
       
   506 apply(auto)
       
   507 done
       
   508 
       
   509 
       
   510 lemma [elim]: "\<lbrakk>0 < n; n \<le> Suc (Suc na); 
       
   511    rev ab @ Bk # list = Bk # replicate n Oc @ 
       
   512     replicate (Suc (Suc na) - n) Bk @ Oc # replicate na Oc; 
       
   513    length ab = Suc n; ab \<noteq> []\<rbrakk>
       
   514     \<Longrightarrow> rev ab @ Oc # list = Bk # Oc # replicate n Oc @ 
       
   515                replicate (Suc na - n) Bk @ Oc # replicate na Oc"
       
   516 apply(case_tac "rev ab", simp+)
       
   517 apply(auto)
       
   518 apply(simp only: replicate_Cons_simp)
       
   519 apply(simp)
       
   520 apply(case_tac "Suc (Suc na) - n", simp+)
       
   521 done
   380 done
   522 
   381 
   523 lemma [elim]: "\<lbrakk>tstep (12, b, c) tcopy = (13, ab, ba); 
   382 lemma [elim]: "\<lbrakk>tstep (12, b, c) tcopy = (13, ab, ba); 
   524                 tcopy_F12 x (b, c)\<rbrakk> \<Longrightarrow> tcopy_F13 x (ab, ba)"
   383                 tcopy_F12 x (b, c)\<rbrakk> \<Longrightarrow> tcopy_F13 x (ab, ba)"
   525 apply(case_tac x)
   384 apply(auto simp:tcopy_F12.simps tcopy_F13.simps 
   526 apply(simp_all add:tcopy_F12.simps tcopy_F13.simps 
   385                    tcopy_def tstep.simps fetch.simps new_tape.simps
   527                    tcopy_def tstep.simps fetch.simps new_tape.simps)
   386   split: if_splits list.splits block.splits)
   528 apply(simp split: if_splits list.splits block.splits)
   387 apply(case_tac x, simp_all add: exp_ind_def exp_zero)
   529 apply(auto)
   388 apply(rule_tac [!] x = i in exI, simp_all)
   530 done
   389 apply(rule_tac [!] x = "j - 1" in exI)
   531 
   390 apply(case_tac [!] j, simp_all add: exp_ind_def exp_zero)
       
   391 apply(case_tac x, simp_all add: exp_ind_def exp_zero)
       
   392 done
   532 
   393 
   533 lemma [elim]: "\<lbrakk>tstep (11, b, c) tcopy = (12, ab, ba); 
   394 lemma [elim]: "\<lbrakk>tstep (11, b, c) tcopy = (12, ab, ba); 
   534                 tcopy_F11 x (b, c)\<rbrakk> \<Longrightarrow> tcopy_F12 x (ab, ba)" 
   395                 tcopy_F11 x (b, c)\<rbrakk> \<Longrightarrow> tcopy_F12 x (ab, ba)" 
   535 apply(case_tac x)
       
   536 apply(simp_all add:tcopy_F12.simps tcopy_F11.simps 
   396 apply(simp_all add:tcopy_F12.simps tcopy_F11.simps 
   537                    tcopy_def tstep.simps fetch.simps new_tape.simps)
   397                    tcopy_def tstep.simps fetch.simps new_tape.simps)
   538 apply(auto)
   398 apply(auto)
   539 done
   399 apply(rule_tac x = "Suc 0" in exI, 
   540 
   400   rule_tac x = x in exI, simp add: exp_ind_def exp_zero)
   541 lemma equal_length: "a = b \<Longrightarrow> length a = length b"
   401 done
   542 by(simp)
   402 
   543 
   403 
   544 lemma [elim]: "\<lbrakk>tstep (13, b, c) tcopy = (12, ab, ba); 
   404 lemma [elim]: "\<lbrakk>tstep (13, b, c) tcopy = (12, ab, ba); 
   545                 tcopy_F13 x (b, c)\<rbrakk> \<Longrightarrow> tcopy_F12 x (ab, ba)"
   405                 tcopy_F13 x (b, c)\<rbrakk> \<Longrightarrow> tcopy_F12 x (ab, ba)"
   546 apply(case_tac x)
   406 apply(auto simp:tcopy_F12.simps tcopy_F13.simps 
   547 apply(simp_all add:tcopy_F12.simps tcopy_F13.simps 
   407                    tcopy_def tstep.simps fetch.simps new_tape.simps
   548                    tcopy_def tstep.simps fetch.simps new_tape.simps)
   408   split: if_splits list.splits block.splits)
   549 apply(simp split: if_splits list.splits block.splits)
   409 apply(rule_tac [!] x = "Suc i" in exI, simp_all add: exp_ind_def)
   550 apply(auto)
       
   551 apply(drule equal_length, simp)
       
   552 done
   410 done
   553 
   411 
   554 lemma [elim]: "\<lbrakk>tstep (5, b, c) tcopy = (11, ab, ba); 
   412 lemma [elim]: "\<lbrakk>tstep (5, b, c) tcopy = (11, ab, ba); 
   555                 tcopy_F5 x (b, c)\<rbrakk> \<Longrightarrow> tcopy_F11 x (ab, ba)" 
   413                 tcopy_F5 x (b, c)\<rbrakk> \<Longrightarrow> tcopy_F11 x (ab, ba)"
   556 apply(case_tac x)
       
   557 apply(simp_all add:tcopy_F11.simps tcopy_F5.simps tcopy_def 
   414 apply(simp_all add:tcopy_F11.simps tcopy_F5.simps tcopy_def 
   558                    tstep.simps fetch.simps new_tape.simps)
   415                    tstep.simps fetch.simps new_tape.simps)
   559 apply(simp split: if_splits list.splits block.splits)
   416 apply(simp split: if_splits list.splits block.splits)
   560 done
   417 done
   561 
   418 
   562 lemma less_equal: "\<lbrakk>length xs <= b; \<not> Suc (length xs) <= b\<rbrakk> \<Longrightarrow> 
   419 lemma F10_false: "tcopy_F10 x (b, []) = False"
   563                    length xs = b"
   420 apply(auto simp: tcopy_F10.simps exp_ind_def)
   564 apply(simp)
   421 done
   565 done
   422 
   566 
   423 lemma F10_false2: "tcopy_F10 x ([], Bk # list) = False"
   567 lemma length_cons_same: "\<lbrakk>xs @ b # ys = as @ bs; 
   424 apply(auto simp:tcopy_F10.simps)
   568                  length ys = length bs\<rbrakk> \<Longrightarrow> xs @ [b] = as & ys = bs"
   425 apply(case_tac i, simp_all add: exp_ind_def exp_zero)
   569 apply(drule rev_equal)
   426 done
   570 apply(simp)
   427  
   571 apply(auto)
   428 lemma [simp]: "tcopy_F10_exit x (b, Bk # list) = False"
   572 apply(drule rev_equal, simp)
   429 apply(auto simp: tcopy_F10.simps)
   573 done
   430 done
   574 
   431 
   575 lemma replicate_set_equal: "\<lbrakk> xs @ [a] = replicate n b; a \<noteq> b\<rbrakk> \<Longrightarrow> RR"
   432 declare tcopy_F10_loop.simps[simp del]  tcopy_F10_exit.simps[simp del]
   576 apply(drule rev_equal, simp)
   433 
   577 apply(case_tac n, simp+)
   434 lemma [simp]: "tcopy_F10_loop x (b, [Bk]) = False"
       
   435 apply(auto simp: tcopy_F10_loop.simps)
       
   436 apply(simp add: exp_ind_def)
   578 done
   437 done
   579 
   438 
   580 lemma [elim]: "\<lbrakk>tstep (10, b, c) tcopy = (10, ab, ba); 
   439 lemma [elim]: "\<lbrakk>tstep (10, b, c) tcopy = (10, ab, ba); 
   581                 tcopy_F10 x (b, c)\<rbrakk> \<Longrightarrow> tcopy_F10 x (ab, ba)"
   440                 tcopy_F10 x (b, c)\<rbrakk> \<Longrightarrow> tcopy_F10 x (ab, ba)"
   582 apply(case_tac x)
   441 apply(simp add: tcopy_def tstep.simps fetch.simps 
   583 apply(auto simp:tcopy_F10.simps tcopy_def tstep.simps fetch.simps 
   442                 new_tape.simps exp_ind_def exp_zero_simp exp_zero_simp2 F10_false F10_false2
   584                 new_tape.simps
       
   585            split: if_splits list.splits block.splits)
   443            split: if_splits list.splits block.splits)
   586 apply(rule_tac x = n in exI, auto)
   444 apply(simp add: tcopy_F10.simps del: tcopy_F10_loop.simps  tcopy_F10_exit.simps)
   587 apply(case_tac b, simp+)
   445 apply(case_tac b, simp, case_tac aa)
   588 apply(rule contrapos_pp, simp+)
   446 apply(rule_tac disjI1)
   589 apply(frule less_equal, simp+)
   447 apply(simp only: tcopy_F10_loop.simps)
   590 apply(drule length_cons_same, auto)
   448 apply(erule_tac exE)+
   591 apply(drule replicate_set_equal, simp+)
   449 apply(rule_tac x = i in exI, rule_tac x = j in exI, 
   592 done
   450       rule_tac x = "k - 1" in exI, rule_tac x = "Suc t" in exI, simp)
   593 
   451 apply(case_tac k, simp_all add: exp_ind_def exp_zero)
   594 lemma less_equal2: "\<not> (n::nat) \<le> m \<Longrightarrow> \<exists>x. n = x + m & x > 0"
   452 apply(case_tac i, simp_all add: exp_ind_def exp_zero)
   595 apply(rule_tac x = "n - m" in exI)
   453 apply(rule_tac disjI2)
       
   454 apply(simp only: tcopy_F10_loop.simps tcopy_F10_exit.simps)
       
   455 apply(erule_tac exE)+
       
   456 apply(rule_tac x = "i - 1" in exI, rule_tac x = "j" in exI)
       
   457 apply(case_tac k, simp_all add: exp_ind_def exp_zero)
       
   458 apply(case_tac i, simp_all add: exp_ind_def exp_zero)
   596 apply(auto)
   459 apply(auto)
   597 done
   460 apply(simp add: exp_ind_def)
   598 
   461 done
   599 lemma replicate_tail_length[dest]:
   462 
   600     "\<lbrakk>rev b @ Bk # list = xs @ replicate n Bk @ replicate n Oc\<rbrakk> 
   463 (*
   601  \<Longrightarrow> length list >= n"
   464 lemma false_case4: "\<lbrakk>i + (k + t) = Suc x; 
   602 apply(rule contrapos_pp, simp+)
   465         0 < i;
   603 apply(drule less_equal2, auto)
   466         Bk # list = Oc\<^bsup>t\<^esup>;
   604 apply(drule rev_equal)
   467         \<forall>ia j. ia + j = Suc x \<longrightarrow> ia = 0 \<or> (\<forall>ka. tl (Oc\<^bsup>k\<^esup>) @ Bk\<^bsup>k + t\<^esup> @ Oc\<^bsup>i\<^esup> = Bk\<^bsup>ka\<^esup> @ Oc\<^bsup>ia\<^esup> \<longrightarrow> (\<forall>ta. Suc (ka + ta) = j \<longrightarrow> Oc # Oc\<^bsup>t\<^esup> \<noteq> Bk\<^bsup>Suc ta\<^esup> @ Oc\<^bsup>j\<^esup>));
   605 apply(simp add: replicate_add)
   468         0 < k\<rbrakk>
   606 apply(auto)
   469        \<Longrightarrow> RR"
   607 apply(case_tac x, simp+)
   470 apply(case_tac t, simp_all add: exp_ind_def exp_zero)
   608 done
   471 done
   609 
   472 
       
   473 lemma false_case5: "
       
   474   \<lbrakk>Suc (i + nata) = x;
       
   475    0 < i;
       
   476    \<forall>ia j. ia + j = Suc x \<longrightarrow> ia = 0 \<or> (\<forall>k. Bk\<^bsup>nata\<^esup> @ Oc\<^bsup>i\<^esup> = Bk\<^bsup>k\<^esup> @ Oc\<^bsup>ia\<^esup> \<longrightarrow> (\<forall>t. Suc (k + t) = j \<longrightarrow> Bk # Oc # Oc # Oc\<^bsup>nata\<^esup> \<noteq> Bk\<^bsup>t\<^esup> @ Oc\<^bsup>j\<^esup>))\<rbrakk>
       
   477        \<Longrightarrow> False"
       
   478 apply(erule_tac x = i in allE, simp)
       
   479 apply(erule_tac x = "Suc (Suc nata)" in allE, simp)
       
   480 apply(erule_tac x = nata in allE, simp, simp add: exp_ind_def exp_zero)
       
   481 done
       
   482 
       
   483 lemma false_case6: "\<lbrakk>0 < x; \<forall>i. tl (Oc\<^bsup>x\<^esup>) = Oc\<^bsup>i\<^esup> \<longrightarrow> (\<forall>j. i + j = x \<longrightarrow> j = 0 \<or> [Bk, Oc] \<noteq> Bk\<^bsup>j\<^esup> @ Oc\<^bsup>j\<^esup>)\<rbrakk>
       
   484   \<Longrightarrow> False"
       
   485 apply(erule_tac x = "x - 1" in allE)
       
   486 apply(case_tac x, simp_all add: exp_ind_def exp_zero)
       
   487 apply(erule_tac x = "Suc 0" in allE, simp)
       
   488 done
       
   489 *)
       
   490 
       
   491 lemma [simp]: "tcopy_F9 x ([], b) = False"
       
   492 apply(auto simp: tcopy_F9.simps)
       
   493 apply(case_tac [!] i, simp_all add: exp_ind_def exp_zero)
       
   494 done
       
   495 
       
   496 lemma [simp]: "tcopy_F9 x (b, []) = False"
       
   497 apply(auto simp: tcopy_F9.simps)
       
   498 apply(case_tac [!] t, simp_all add: exp_ind_def exp_zero)
       
   499 done
       
   500 
       
   501 declare tcopy_F9_loop.simps[simp del] tcopy_F9_exit.simps[simp del]
       
   502 lemma [simp]: "tcopy_F9_loop x (b, Bk # list) = False"
       
   503 apply(auto simp: tcopy_F9_loop.simps)
       
   504 apply(case_tac [!] t, simp_all add: exp_ind_def exp_zero)
       
   505 done
   610 
   506 
   611 lemma [elim]: "\<lbrakk>tstep (9, b, c) tcopy = (10, ab, ba); 
   507 lemma [elim]: "\<lbrakk>tstep (9, b, c) tcopy = (10, ab, ba); 
   612                 tcopy_F9 x (b, c)\<rbrakk> \<Longrightarrow> tcopy_F10 x (ab, ba)" 
   508                 tcopy_F9 x (b, c)\<rbrakk> \<Longrightarrow> tcopy_F10 x (ab, ba)"
   613 apply(case_tac x)
   509 apply(auto simp:tcopy_def
   614 apply(auto simp:tcopy_F10.simps tcopy_F9.simps tcopy_def
   510                 tstep.simps fetch.simps new_tape.simps exp_zero_simp
   615                 tstep.simps fetch.simps new_tape.simps 
   511                 exp_zero_simp2 
   616            split: if_splits list.splits block.splits)
   512            split: if_splits list.splits block.splits)
   617 apply(rule_tac x = n in exI, auto)
   513 apply(case_tac "hd b", simp add:tcopy_F9.simps tcopy_F10.simps )
   618 apply(case_tac b, simp+)
   514 apply(simp only: tcopy_F9_exit.simps tcopy_F10_loop.simps)
       
   515 apply(erule_tac exE)+
       
   516 apply(rule_tac x = i in exI, rule_tac x = j in exI, simp)
       
   517 apply(rule_tac x = "j - 2" in exI, simp add: exp_ind_def)
       
   518 apply(case_tac j, simp, simp)
       
   519 apply(case_tac nat, simp_all add: exp_zero exp_ind_def)
       
   520 apply(case_tac x, simp_all add: exp_ind_def exp_zero)
       
   521 apply(simp add: tcopy_F9.simps tcopy_F10.simps)
       
   522 apply(rule_tac disjI2)
       
   523 apply(simp only: tcopy_F10_exit.simps tcopy_F9_exit.simps)
       
   524 apply(erule_tac exE)+
       
   525 apply(simp)
       
   526 apply(case_tac j, simp_all, case_tac nat, simp_all add: exp_ind_def exp_zero)
       
   527 apply(case_tac x, simp_all add: exp_ind_def exp_zero)
       
   528 apply(rule_tac x = nata in exI, rule_tac x = 1 in exI, simp add: exp_ind_def exp_zero)
       
   529 done
       
   530 
       
   531 lemma false_case7:
       
   532   "\<lbrakk>i + (n + t) = x; 0 < i; 0 < t; Oc # list = Oc\<^bsup>t\<^esup>; k = Suc n;
       
   533         \<forall>j. i + j = Suc x \<longrightarrow> (\<forall>k. Oc\<^bsup>n\<^esup> @ Bk # Bk\<^bsup>n + t\<^esup> = Oc\<^bsup>k\<^esup> @ Bk\<^bsup>j\<^esup> \<longrightarrow>
       
   534          (\<forall>ta. k + ta = j \<longrightarrow> ta = 0 \<or> Oc # Oc\<^bsup>t\<^esup> \<noteq> Oc\<^bsup>ta\<^esup>))\<rbrakk>
       
   535        \<Longrightarrow> RR"
       
   536 apply(erule_tac x = "k + t" in allE, simp)
       
   537 apply(erule_tac x = n in allE, simp add: exp_ind_def)
       
   538 apply(erule_tac x = "Suc t" in allE, simp)
       
   539 done
       
   540 
       
   541 lemma false_case8: 
       
   542   "\<lbrakk>i + t = Suc x;
       
   543    0 < i;
       
   544     0 < t; 
       
   545     \<forall>ia j. tl (Bk\<^bsup>t\<^esup> @ Oc\<^bsup>i\<^esup>) = Bk\<^bsup>j - Suc 0\<^esup> @ Oc\<^bsup>ia\<^esup> \<longrightarrow> 
       
   546     ia + j = Suc x \<longrightarrow> ia = 0 \<or> j = 0 \<or> Oc\<^bsup>t\<^esup> \<noteq> Oc\<^bsup>j\<^esup>\<rbrakk> \<Longrightarrow> 
       
   547   RR"
       
   548 apply(erule_tac x = i in allE, simp)
       
   549 apply(erule_tac x = t in allE, simp)
       
   550 apply(case_tac t, simp_all add: exp_ind_def exp_zero)
   619 done
   551 done
   620 
   552 
   621 lemma [elim]: "\<lbrakk>tstep (9, b, c) tcopy = (9, ab, ba); 
   553 lemma [elim]: "\<lbrakk>tstep (9, b, c) tcopy = (9, ab, ba); 
   622                 tcopy_F9 x (b, c)\<rbrakk> \<Longrightarrow> tcopy_F9 x (ab, ba)"
   554                 tcopy_F9 x (b, c)\<rbrakk> \<Longrightarrow> tcopy_F9 x (ab, ba)"
   623 apply(case_tac x)
   555 apply(auto simp: tcopy_F9.simps tcopy_def 
   624 apply(simp_all add: tcopy_F9.simps tcopy_def 
   556                     tstep.simps fetch.simps new_tape.simps exp_zero_simp exp_zero_simp2
   625                     tstep.simps fetch.simps new_tape.simps 
   557                     tcopy_F9_exit.simps tcopy_F9_loop.simps
   626   split: if_splits list.splits block.splits)
   558   split: if_splits list.splits block.splits)
   627 apply(rule_tac x = n in exI, auto)
   559 apply(case_tac [!] k, simp_all add: exp_ind_def exp_zero)
   628 apply(case_tac b, simp+)
   560 apply(erule_tac [!] x = i in allE, simp)
   629 apply(rule contrapos_pp, simp+)
   561 apply(erule_tac false_case7, simp_all)+
   630 apply(drule less_equal, simp+)
   562 apply(case_tac t, simp_all add: exp_zero exp_ind_def)
   631 apply(drule rev_equal, auto)
   563 apply(erule_tac false_case7, simp_all)+
   632 apply(case_tac "length list", simp+)
   564 apply(erule_tac false_case8, simp_all)
   633 done
   565 apply(erule_tac false_case7, simp_all)+
   634 
   566 apply(case_tac t, simp_all add: exp_ind_def exp_zero)
   635 lemma app_cons_app_simp: "xs @ a # bs @ ys = (xs @ [a]) @ bs @ ys"
   567 apply(erule_tac false_case7, simp_all)
   636 apply(simp)
   568 apply(erule_tac false_case8, simp_all)
   637 done
   569 apply(erule_tac false_case7, simp_all)
   638 
   570 done
       
   571  
   639 lemma [elim]: "\<lbrakk>tstep (8, b, c) tcopy = (9, ab, ba); 
   572 lemma [elim]: "\<lbrakk>tstep (8, b, c) tcopy = (9, ab, ba); 
   640                 tcopy_F8 x (b, c)\<rbrakk> \<Longrightarrow> tcopy_F9 x (ab, ba)" 
   573                 tcopy_F8 x (b, c)\<rbrakk> \<Longrightarrow> tcopy_F9 x (ab, ba)"
   641 apply(case_tac x)
       
   642 apply(auto simp:tcopy_F8.simps tcopy_F9.simps tcopy_def 
   574 apply(auto simp:tcopy_F8.simps tcopy_F9.simps tcopy_def 
   643                 tstep.simps fetch.simps new_tape.simps
   575                 tstep.simps fetch.simps new_tape.simps tcopy_F9_loop.simps
       
   576                 tcopy_F9_exit.simps
   644   split: if_splits list.splits block.splits)
   577   split: if_splits list.splits block.splits)
   645 apply(rule_tac x = "Suc n" in exI, auto)
   578 apply(case_tac [!] t, simp_all add: exp_ind_def exp_zero)
   646 apply(rule_tac x = "n" in exI, auto)
   579 apply(rule_tac x = i in exI)
   647 apply(simp only: app_cons_app_simp)
   580 apply(rule_tac x = "Suc k" in exI, simp)
   648 apply(frule replicate_tail_length, simp)
   581 apply(rule_tac x = "k" in exI, simp add: exp_ind_def exp_zero)
   649 done
   582 done
       
   583 
   650 
   584 
   651 lemma [elim]: "\<lbrakk>tstep (8, b, c) tcopy = (8, ab, ba); 
   585 lemma [elim]: "\<lbrakk>tstep (8, b, c) tcopy = (8, ab, ba); 
   652                 tcopy_F8 x (b, c)\<rbrakk> \<Longrightarrow> tcopy_F8 x (ab, ba)"
   586                 tcopy_F8 x (b, c)\<rbrakk> \<Longrightarrow> tcopy_F8 x (ab, ba)"
   653 apply(case_tac x)
   587 apply(auto simp:tcopy_F8.simps tcopy_def tstep.simps 
   654 apply(simp_all add:tcopy_F8.simps tcopy_def tstep.simps 
   588                    fetch.simps new_tape.simps exp_zero_simp exp_zero split: if_splits list.splits 
   655                    fetch.simps new_tape.simps)
   589                    
   656 apply(simp split: if_splits list.splits block.splits)
   590          block.splits)
   657 apply(rule_tac x = "n" in exI, auto)
   591 apply(rule_tac x = i in exI, rule_tac x = "k + t" in exI, simp)
   658 done
   592 apply(rule_tac x = "Suc k" in exI, simp)
   659 
   593 apply(rule_tac x = "t - 1" in exI, simp)
   660 lemma ex_less_more: "\<lbrakk>(x::nat) >= m ; x <= n\<rbrakk> \<Longrightarrow> 
   594 apply(case_tac t, simp_all add: exp_zero exp_ind_def)
   661                         \<exists>y. x = m + y & y <= n - m"
   595 done
   662 by(rule_tac x = "x -m" in exI, auto)
   596 
   663 
       
   664 lemma replicate_split: "x <= n \<Longrightarrow> 
       
   665                       (\<exists>y. replicate n b = replicate (y + x) b)"
       
   666 apply(rule_tac x = "n - x" in exI)
       
   667 apply(simp)
       
   668 done
       
   669 
       
   670 lemma app_app_app_app_simp: "as @ bs @ cs @ ds = 
       
   671                              (as @ bs) @ (cs @ ds)"
       
   672 by simp
       
   673 
       
   674 lemma lengthtailsame_append_elim: 
       
   675      "\<lbrakk>as @ bs = cs @ ds; length bs = length ds\<rbrakk> \<Longrightarrow> bs = ds"
       
   676 apply(simp)
       
   677 done
       
   678 
       
   679 lemma rep_suc: "replicate (Suc n) x = replicate n x @ [x]" 
       
   680 by(induct n, auto)
       
   681 
       
   682 lemma length_append_diff_cons: 
       
   683  "\<lbrakk>b @ x # ba = xs @ replicate m y @ replicate n x; x \<noteq> y; 
       
   684    Suc (length ba) \<le> m + n\<rbrakk>
       
   685   \<Longrightarrow> length ba < n"
       
   686 apply(induct n arbitrary: ba, simp)
       
   687 apply(drule_tac b = y in replicate_split,
       
   688       simp add: replicate_add, erule exE, simp del: replicate.simps)
       
   689 proof -
       
   690   fix ba ya
       
   691   assume h1: 
       
   692      "b @ x # ba = xs @ y # replicate ya y @ replicate (length ba) y" 
       
   693     and h2: "x \<noteq> y"
       
   694   thus "False"  
       
   695     using append_eq_append_conv[of "b @ [x]" 
       
   696             "xs @ y # replicate ya y" "ba" "replicate (length ba) y"]
       
   697     apply(auto)
       
   698     apply(case_tac ya, simp, 
       
   699            simp add: rep_suc del: rep_suc_rev replicate.simps)
       
   700     done
       
   701 next
       
   702   fix n ba
       
   703   assume ind: "\<And>ba. \<lbrakk>b @ x # ba = xs @ replicate m y @ replicate n x;
       
   704                       x \<noteq> y; Suc (length ba) \<le> m + n\<rbrakk> 
       
   705                  \<Longrightarrow> length ba < n"
       
   706     and h1: "b @ x # ba = xs @ replicate m y @ replicate (Suc n) x" 
       
   707     and h2: "x \<noteq> y" and h3: "Suc (length ba) \<le> m + Suc n"
       
   708   show "length ba < Suc n"
       
   709   proof(cases "length ba")
       
   710     case 0 thus "?thesis" by simp
       
   711   next
       
   712     fix nat
       
   713     assume "length ba = Suc nat"
       
   714     hence "\<exists> ys a. ba = ys @ [a]"
       
   715       apply(rule_tac x = "butlast ba" in exI)
       
   716       apply(rule_tac x = "last ba" in exI)
       
   717       using append_butlast_last_id[of ba]
       
   718       apply(case_tac ba, auto)
       
   719       done
       
   720     from this obtain ys where "\<exists> a. ba = ys @ [a]" ..
       
   721     from this obtain a where "ba = ys @ [a]" ..
       
   722     thus "?thesis"
       
   723       using ind[of ys] h1 h2 h3
       
   724       apply(simp del: rep_suc_rev replicate.simps add: rep_suc)
       
   725       done
       
   726   qed
       
   727 qed
       
   728       
       
   729 lemma [elim]: 
       
   730   "\<lbrakk>b @ Oc # ba = xs @ Bk # replicate n Bk @ replicate n Oc;  
       
   731    Suc (length ba) \<le> 2 * n\<rbrakk>
       
   732   \<Longrightarrow> length ba < n"
       
   733   apply(rule_tac length_append_diff_cons[of b Oc ba xs "Suc n" Bk n])
       
   734   apply(simp, simp, simp)
       
   735   done
       
   736 
       
   737 lemma [elim]: "\<lbrakk>tstep (7, b, c) tcopy = (8, ab, ba); 
       
   738                 tcopy_F7 x (b, c)\<rbrakk> \<Longrightarrow> tcopy_F8 x (ab, ba)" 
       
   739 apply(case_tac x)
       
   740 apply(simp_all add:tcopy_F8.simps tcopy_F7.simps 
       
   741                    tcopy_def tstep.simps fetch.simps new_tape.simps)
       
   742 apply(simp split: if_splits list.splits block.splits)
       
   743 apply(rule_tac x = "n" in exI, auto)
       
   744 done
       
   745 
   597 
   746 lemma [elim]: "\<lbrakk>tstep (7, b, c) tcopy = (7, ab, ba); 
   598 lemma [elim]: "\<lbrakk>tstep (7, b, c) tcopy = (7, ab, ba); 
   747                 tcopy_F7 x (b, c)\<rbrakk> \<Longrightarrow> tcopy_F7 x (ab, ba)"
   599                 tcopy_F7 x (b, c)\<rbrakk> \<Longrightarrow> tcopy_F7 x (ab, ba)"
   748 apply(case_tac x)
   600 apply(auto simp:tcopy_F7.simps tcopy_def tstep.simps fetch.simps 
   749 apply(auto simp:tcopy_F7.simps tcopy_def tstep.simps 
   601                 new_tape.simps exp_ind_def exp_zero_simp
   750                 fetch.simps new_tape.simps
   602            split: if_splits list.splits block.splits)
       
   603 apply(rule_tac x = i in exI)
       
   604 apply(rule_tac x = j in exI, simp)
       
   605 apply(rule_tac x = "Suc k" in exI, simp)
       
   606 apply(rule_tac x = "t - 1" in exI)
       
   607 apply(case_tac t, simp_all add: exp_zero exp_ind_def)
       
   608 apply(case_tac j, simp_all add: exp_zero exp_ind_def)
       
   609 done
       
   610 
       
   611 lemma [elim]: "\<lbrakk>tstep (7, b, c) tcopy = (8, ab, ba); 
       
   612                 tcopy_F7 x (b, c)\<rbrakk> \<Longrightarrow> tcopy_F8 x (ab, ba)"
       
   613 apply(auto simp:tcopy_F7.simps tcopy_def tstep.simps tcopy_F8.simps
       
   614                 fetch.simps new_tape.simps exp_zero_simp
   751   split: if_splits list.splits block.splits)
   615   split: if_splits list.splits block.splits)
   752 apply(rule_tac x = "n" in exI, auto)
   616 apply(rule_tac x = i in exI, simp)
   753 apply(simp only: app_cons_app_simp)
   617 apply(rule_tac x =  "Suc 0" in exI, simp add: exp_ind_def exp_zero)
   754 apply(frule replicate_tail_length, simp)
   618 apply(rule_tac x = "j - 1" in exI, simp)
   755 done
   619 apply(case_tac t, simp_all add: exp_ind_def )
   756 
   620 apply(case_tac j, simp_all add: exp_ind_def exp_zero)
   757 lemma Suc_more: "n <= m \<Longrightarrow> Suc m - n = Suc (m - n)"
   621 done
   758 by simp
       
   759 
   622 
   760 lemma [elim]: "\<lbrakk>tstep (6, b, c) tcopy = (7, ab, ba); 
   623 lemma [elim]: "\<lbrakk>tstep (6, b, c) tcopy = (7, ab, ba); 
   761                 tcopy_F6 x (b, c)\<rbrakk> \<Longrightarrow> tcopy_F7 x (ab, ba)" 
   624                 tcopy_F6 x (b, c)\<rbrakk> \<Longrightarrow> tcopy_F7 x (ab, ba)" 
   762 apply(case_tac x)
   625 apply(case_tac x)
   763 apply(auto simp:tcopy_F7.simps tcopy_F6.simps 
   626 apply(auto simp:tcopy_F7.simps tcopy_F6.simps 
   764                 tcopy_def tstep.simps fetch.simps new_tape.simps
   627                 tcopy_def tstep.simps fetch.simps new_tape.simps exp_zero_simp
   765   split: if_splits list.splits block.splits)
   628   split: if_splits list.splits block.splits)
       
   629 apply(case_tac i, simp_all add: exp_ind_def exp_zero)
       
   630 apply(rule_tac x = i in exI, simp)
       
   631 apply(rule_tac x = j in exI, simp)
       
   632 apply(rule_tac x = "Suc 0" in exI, simp add: exp_ind_def exp_zero)
   766 done
   633 done
   767 
   634 
   768 lemma [elim]: "\<lbrakk>tstep (6, b, c) tcopy = (6, ab, ba); 
   635 lemma [elim]: "\<lbrakk>tstep (6, b, c) tcopy = (6, ab, ba); 
   769                 tcopy_F6 x (b, c)\<rbrakk> \<Longrightarrow> tcopy_F6 x (ab, ba)"
   636                 tcopy_F6 x (b, c)\<rbrakk> \<Longrightarrow> tcopy_F6 x (ab, ba)"
   770 apply(case_tac x)
       
   771 apply(auto simp:tcopy_F6.simps tcopy_def tstep.simps 
   637 apply(auto simp:tcopy_F6.simps tcopy_def tstep.simps 
   772                 new_tape.simps fetch.simps
   638                 new_tape.simps fetch.simps
   773   split: if_splits list.splits block.splits)
   639   split: if_splits list.splits block.splits)
   774 done
   640 done
   775 
   641 
   776 lemma [elim]: "\<lbrakk>tstep (5, b, c) tcopy = (6, ab, ba); 
   642 lemma [elim]: "\<lbrakk>tstep (5, b, c) tcopy = (6, ab, ba); 
   777                 tcopy_F5 x (b, c)\<rbrakk> \<Longrightarrow> tcopy_F6 x (ab, ba)" 
   643                 tcopy_F5 x (b, c)\<rbrakk> \<Longrightarrow> tcopy_F6 x (ab, ba)"
   778 apply(case_tac x)
       
   779 apply(auto simp:tcopy_F5.simps tcopy_F6.simps tcopy_def 
   644 apply(auto simp:tcopy_F5.simps tcopy_F6.simps tcopy_def 
   780                 tstep.simps fetch.simps new_tape.simps 
   645                 tstep.simps fetch.simps new_tape.simps exp_zero_simp2
   781   split: if_splits list.splits block.splits)
   646   split: if_splits list.splits block.splits)
   782 apply(rule_tac x = n in exI, simp)
   647 apply(rule_tac x = "Suc 0" in exI, simp add: exp_ind_def exp_zero)
   783 apply(rule_tac x = n in exI, simp)
   648 apply(rule_tac x = "Suc i" in exI, simp add: exp_ind_def)
   784 apply(drule Suc_more, simp)
       
   785 done
       
   786 
       
   787 lemma ex_less_more2: "\<lbrakk>(n::nat) < x ; x <= 2 * n\<rbrakk> \<Longrightarrow> 
       
   788                                \<exists>y. (x = n + y & y <= n)"
       
   789 apply(rule_tac x = "x - n" in exI)
       
   790 apply(auto)
       
   791 done
       
   792 
       
   793 lemma app_app_app_simp: "xs @ ys @ za = (xs @ ys) @ za"
       
   794 apply(simp)
       
   795 done
       
   796 
       
   797 lemma [elim]: "rev xs = replicate n b \<Longrightarrow> xs = replicate n b"
       
   798 using rev_replicate[of n b]
       
   799 thm rev_equal
       
   800 by(drule_tac rev_equal, simp)
       
   801 
       
   802 lemma app_cons_tail_same[dest]: 
       
   803   "\<lbrakk>rev b @ Oc # list = 
       
   804     replicate (Suc (Suc na) - n) Oc @ replicate n Bk @ replicate n Oc;
       
   805   Suc 0 < n; n \<le> Suc na; n < length list; length list \<le> 2 * n; b \<noteq> []\<rbrakk>
       
   806   \<Longrightarrow> list = replicate n Bk @ replicate n Oc 
       
   807            & b = replicate (Suc na - n) Oc"
       
   808 using length_append_diff_cons[of "rev b" Oc list 
       
   809                 "replicate (Suc (Suc na) - n) Oc" n Bk n]
       
   810 apply(case_tac "length list = 2*n", simp)
       
   811 using append_eq_append_conv[of "rev b @ [Oc]" "replicate 
       
   812       (Suc (Suc na) - n) Oc" "list" "replicate n Bk @ replicate n Oc"]
       
   813 apply(case_tac n, simp, simp add: Suc_more rep_suc 
       
   814                              del: rep_suc_rev replicate.simps, auto)
       
   815 done
       
   816 
       
   817 lemma hd_replicate_false1: "\<lbrakk>replicate x Oc \<noteq> [];
       
   818                              hd (replicate x Oc) = Bk\<rbrakk> \<Longrightarrow> RR"
       
   819 apply(case_tac x, auto)
       
   820 done
       
   821 
       
   822 lemma hd_replicate_false2: "\<lbrakk>replicate x Oc \<noteq> [];
       
   823                             hd (replicate x Oc) \<noteq> Oc\<rbrakk> \<Longrightarrow> RR"
       
   824 apply(case_tac x, auto)
       
   825 done
       
   826 
       
   827 lemma Suc_more_less: "\<lbrakk>n \<le> Suc m; n >= m\<rbrakk> \<Longrightarrow> n = m | n = Suc m"
       
   828 apply(auto)
       
   829 done
       
   830 
       
   831 lemma replicate_not_Nil: "replicate x a \<noteq> [] \<Longrightarrow> x > 0"
       
   832 apply(case_tac x, simp+)
       
   833 done
   649 done
   834 
   650 
   835 lemma [elim]: "\<lbrakk>tstep (10, b, c) tcopy = (5, ab, ba); 
   651 lemma [elim]: "\<lbrakk>tstep (10, b, c) tcopy = (5, ab, ba); 
   836                 tcopy_F10 x (b, c)\<rbrakk> \<Longrightarrow> tcopy_F5 x (ab, ba)"
   652                 tcopy_F10 x (b, c)\<rbrakk> \<Longrightarrow> tcopy_F5 x (ab, ba)"
   837 apply(case_tac x)
       
   838 apply(auto simp:tcopy_F5.simps tcopy_F10.simps tcopy_def 
   653 apply(auto simp:tcopy_F5.simps tcopy_F10.simps tcopy_def 
   839                 tstep.simps fetch.simps new_tape.simps
   654                 tstep.simps fetch.simps new_tape.simps exp_zero_simp exp_zero_simp2
   840            split: if_splits list.splits block.splits)
   655                 exp_ind_def tcopy_F10.simps tcopy_F10_loop.simps tcopy_F10_exit.simps
   841 apply(frule app_cons_tail_same, simp+)
   656            split: if_splits list.splits block.splits )
   842 apply(rule_tac x = n in exI, auto)
   657 apply(erule_tac [!] x = "i - 1" in allE)
       
   658 apply(erule_tac [!] x = j in allE, simp_all)
       
   659 apply(case_tac [!] i, simp_all add: exp_ind_def)
   843 done
   660 done
   844 
   661 
   845 lemma [elim]: "\<lbrakk>tstep (4, b, c) tcopy = (5, ab, ba); 
   662 lemma [elim]: "\<lbrakk>tstep (4, b, c) tcopy = (5, ab, ba); 
   846                 tcopy_F4 x (b, c)\<rbrakk> \<Longrightarrow> tcopy_F5 x (ab, ba)" 
   663                 tcopy_F4 x (b, c)\<rbrakk> \<Longrightarrow> tcopy_F5 x (ab, ba)" 
   847 apply(case_tac x)
       
   848 apply(auto simp:tcopy_F5.simps tcopy_F4.simps tcopy_def 
   664 apply(auto simp:tcopy_F5.simps tcopy_F4.simps tcopy_def 
   849                 tstep.simps fetch.simps new_tape.simps
   665                 tstep.simps fetch.simps new_tape.simps exp_zero_simp exp_zero_simp2
   850            split: if_splits list.splits block.splits)
   666            split: if_splits list.splits block.splits)
       
   667 apply(case_tac x, simp, simp add: exp_ind_def exp_zero)
       
   668 apply(erule_tac [!] x = "x - 2" in allE)
       
   669 apply(erule_tac [!] x = "Suc 0" in allE)
       
   670 apply(case_tac [!] x, simp_all add: exp_ind_def exp_zero)
       
   671 apply(case_tac [!] nat, simp_all add: exp_ind_def exp_zero)
   851 done
   672 done
   852 
   673 
   853 lemma [elim]: "\<lbrakk>tstep (3, b, c) tcopy = (4, ab, ba); 
   674 lemma [elim]: "\<lbrakk>tstep (3, b, c) tcopy = (4, ab, ba); 
   854                 tcopy_F3 x (b, c)\<rbrakk> \<Longrightarrow> tcopy_F4 x (ab, ba)"
   675                 tcopy_F3 x (b, c)\<rbrakk> \<Longrightarrow> tcopy_F4 x (ab, ba)"
   855 apply(case_tac x)
       
   856 apply(auto simp:tcopy_F3.simps tcopy_F4.simps 
   676 apply(auto simp:tcopy_F3.simps tcopy_F4.simps 
   857                 tcopy_def tstep.simps fetch.simps new_tape.simps
   677                 tcopy_def tstep.simps fetch.simps new_tape.simps
   858            split: if_splits list.splits block.splits)
   678            split: if_splits list.splits block.splits)
   859 done
   679 done
   860 
   680 
   861 lemma [elim]: "\<lbrakk>tstep (4, b, c) tcopy = (4, ab, ba);
   681 lemma [elim]: "\<lbrakk>tstep (4, b, c) tcopy = (4, ab, ba);
   862                 tcopy_F4 x (b, c)\<rbrakk> \<Longrightarrow> tcopy_F4 x (ab, ba)" 
   682                 tcopy_F4 x (b, c)\<rbrakk> \<Longrightarrow> tcopy_F4 x (ab, ba)" 
   863 apply(case_tac x)
   683 apply(case_tac x)
   864 apply(auto simp:tcopy_F3.simps tcopy_F4.simps 
   684 apply(auto simp:tcopy_F3.simps tcopy_F4.simps 
   865                 tcopy_def tstep.simps fetch.simps new_tape.simps
   685                 tcopy_def tstep.simps fetch.simps new_tape.simps exp_zero_simp exp_zero_simp2 exp_ind_def
   866   split: if_splits list.splits block.splits)
   686   split: if_splits list.splits block.splits)
   867 done
   687 done
   868 
   688 
   869 lemma [elim]: "\<lbrakk>tstep (3, b, c) tcopy = (3, ab, ba); 
   689 lemma [elim]: "\<lbrakk>tstep (3, b, c) tcopy = (3, ab, ba); 
   870                 tcopy_F3 x (b, c)\<rbrakk> \<Longrightarrow> tcopy_F3 x (ab, ba)"
   690                 tcopy_F3 x (b, c)\<rbrakk> \<Longrightarrow> tcopy_F3 x (ab, ba)"
   871 apply(case_tac x)
       
   872 apply(auto simp:tcopy_F3.simps tcopy_F4.simps 
   691 apply(auto simp:tcopy_F3.simps tcopy_F4.simps 
   873                 tcopy_def tstep.simps fetch.simps new_tape.simps 
   692                 tcopy_def tstep.simps fetch.simps new_tape.simps 
   874   split: if_splits list.splits block.splits)
   693   split: if_splits list.splits block.splits)
   875 done
       
   876 
       
   877 lemma replicate_cons_back: "y # replicate x y = replicate (Suc x) y"
       
   878 apply(simp)
       
   879 done
       
   880 
       
   881 lemma replicate_cons_same: "bs @ (b # cs) = y # replicate x y \<Longrightarrow> 
       
   882         (\<exists>n. bs = replicate n y) & (b = y) & (\<exists>m. cs = replicate m y)"
       
   883 apply(simp only: replicate_cons_back)
       
   884 apply(drule_tac replicate_same)
       
   885 apply(simp)
       
   886 done
   694 done
   887 
   695 
   888 lemma [elim]: "\<lbrakk>tstep (2, b, c) tcopy = (3, ab, ba); 
   696 lemma [elim]: "\<lbrakk>tstep (2, b, c) tcopy = (3, ab, ba); 
   889                 tcopy_F2 x (b, c)\<rbrakk> \<Longrightarrow> tcopy_F3 x (ab, ba)" 
   697                 tcopy_F2 x (b, c)\<rbrakk> \<Longrightarrow> tcopy_F3 x (ab, ba)" 
   890 apply(case_tac x)
   698 apply(case_tac x)
   891 apply(auto simp:tcopy_F3.simps tcopy_F2.simps 
   699 apply(auto simp:tcopy_F3.simps tcopy_F2.simps 
   892                 tcopy_def tstep.simps fetch.simps new_tape.simps
   700                 tcopy_def tstep.simps fetch.simps new_tape.simps
       
   701                 exp_zero_simp exp_zero_simp2 exp_zero
   893   split: if_splits list.splits block.splits)
   702   split: if_splits list.splits block.splits)
   894 apply(drule replicate_cons_same, auto)+
   703 apply(case_tac [!] j, simp_all add: exp_zero exp_ind_def)
   895 done
   704 done
   896 
   705 
   897 lemma [elim]: "\<lbrakk>tstep (2, b, c) tcopy = (2, ab, ba); 
   706 lemma [elim]: "\<lbrakk>tstep (2, b, c) tcopy = (2, ab, ba); 
   898                 tcopy_F2 x (b, c)\<rbrakk> \<Longrightarrow> tcopy_F2 x (ab, ba)"
   707                 tcopy_F2 x (b, c)\<rbrakk> \<Longrightarrow> tcopy_F2 x (ab, ba)"
   899 apply(case_tac x)
       
   900 apply(auto simp:tcopy_F3.simps tcopy_F2.simps 
   708 apply(auto simp:tcopy_F3.simps tcopy_F2.simps 
   901                 tcopy_def tstep.simps fetch.simps new_tape.simps
   709                 tcopy_def tstep.simps fetch.simps new_tape.simps 
       
   710                 exp_zero_simp exp_zero_simp2 exp_zero
   902   split: if_splits list.splits block.splits)
   711   split: if_splits list.splits block.splits)
   903 apply(frule replicate_cons_same, auto)
   712 apply(rule_tac x = "Suc i" in exI, simp add: exp_ind_def exp_zero)
   904 apply(simp add: replicate_app_Cons_same)
   713 apply(rule_tac x = "j - 1" in exI, simp)
       
   714 apply(case_tac j, simp_all add: exp_ind_def exp_zero)
   905 done
   715 done
   906 
   716 
   907 lemma [elim]: "\<lbrakk>tstep (Suc 0, b, c) tcopy = (2, ab, ba); 
   717 lemma [elim]: "\<lbrakk>tstep (Suc 0, b, c) tcopy = (2, ab, ba); 
   908                 tcopy_F1 x (b, c)\<rbrakk> \<Longrightarrow> tcopy_F2 x (ab, ba)" 
   718                 tcopy_F1 x (b, c)\<rbrakk> \<Longrightarrow> tcopy_F2 x (ab, ba)"
   909 apply(case_tac x)
   719 apply(auto simp:tcopy_F1.simps tcopy_F2.simps 
   910 apply(simp_all add:tcopy_F2.simps tcopy_F1.simps 
   720                 tcopy_def tstep.simps fetch.simps new_tape.simps 
   911                    tcopy_def tstep.simps fetch.simps new_tape.simps)
   721                 exp_zero_simp exp_zero_simp2 exp_zero
   912 apply(auto)
   722              split: if_splits list.splits block.splits)
       
   723 apply(rule_tac x = "Suc 0" in exI, simp)
       
   724 apply(rule_tac x = "x - 1" in exI, simp)
       
   725 apply(case_tac x, simp_all add: exp_ind_def exp_zero)
   913 done
   726 done
   914 
   727 
   915 lemma [elim]: "\<lbrakk>tstep (Suc 0, b, c) tcopy = (0, ab, ba); 
   728 lemma [elim]: "\<lbrakk>tstep (Suc 0, b, c) tcopy = (0, ab, ba); 
   916                 tcopy_F1 x (b, c)\<rbrakk> \<Longrightarrow> tcopy_F0 x (ab, ba)"
   729                 tcopy_F1 x (b, c)\<rbrakk> \<Longrightarrow> tcopy_F0 x (ab, ba)"
   917 apply(case_tac x)
       
   918 apply(simp_all add:tcopy_F0.simps tcopy_F1.simps 
   730 apply(simp_all add:tcopy_F0.simps tcopy_F1.simps 
   919                    tcopy_def tstep.simps fetch.simps new_tape.simps)
   731                    tcopy_def tstep.simps fetch.simps new_tape.simps
   920 done
   732                    exp_zero_simp exp_zero_simp2 exp_zero
   921 
   733          split: if_splits list.splits block.splits )
   922 lemma ex_less: "Suc x <= y \<Longrightarrow> \<exists>z. y = x + z & z > 0"
   734 apply(case_tac x, simp_all add: exp_ind_def exp_zero, auto)
   923 apply(rule_tac x = "y - x" in exI, auto)
       
   924 done
       
   925 
       
   926 lemma [elim]: "\<lbrakk>xs @ Bk # ba = 
       
   927   Bk # Oc # replicate n Oc @ Bk # Oc # replicate n Oc; 
       
   928   length xs \<le> Suc n; xs \<noteq> []\<rbrakk> \<Longrightarrow> RR"
       
   929 apply(case_tac xs, auto)
       
   930 apply(case_tac list, auto)
       
   931 apply(drule ex_less, auto)
       
   932 apply(simp add: replicate_add)
       
   933 apply(auto)
       
   934 apply(case_tac z, simp+)
       
   935 done
   735 done
   936 
   736 
   937 lemma [elim]: "\<lbrakk>tstep (15, b, c) tcopy = (0, ab, ba); 
   737 lemma [elim]: "\<lbrakk>tstep (15, b, c) tcopy = (0, ab, ba); 
   938                 tcopy_F15 x (b, c)\<rbrakk> \<Longrightarrow> tcopy_F0 x (ab, ba)"
   738                 tcopy_F15 x (b, c)\<rbrakk> \<Longrightarrow> tcopy_F0 x (ab, ba)"
   939 apply(case_tac x)
       
   940 apply(auto simp: tcopy_F15.simps tcopy_F0.simps 
   739 apply(auto simp: tcopy_F15.simps tcopy_F0.simps 
   941                  tcopy_def tstep.simps new_tape.simps fetch.simps
   740                  tcopy_def tstep.simps new_tape.simps fetch.simps
   942            split: if_splits list.splits block.splits)
   741            split: if_splits list.splits block.splits)
   943 done
   742 apply(rule_tac x = "Suc 0" in exI, simp add: exp_ind_def exp_zero)
       
   743 apply(case_tac [!] j, simp_all add: exp_ind_def exp_zero)
       
   744 done
       
   745 
   944 
   746 
   945 lemma [elim]: "\<lbrakk>tstep (0, b, c) tcopy = (0, ab, ba); 
   747 lemma [elim]: "\<lbrakk>tstep (0, b, c) tcopy = (0, ab, ba); 
   946                 tcopy_F0 x (b, c)\<rbrakk> \<Longrightarrow> tcopy_F0 x (ab, ba)" 
   748                 tcopy_F0 x (b, c)\<rbrakk> \<Longrightarrow> tcopy_F0 x (ab, ba)" 
   947 apply(case_tac x)
   749 apply(case_tac x)
   948 apply(simp_all add: tcopy_F0.simps tcopy_def 
   750 apply(simp_all add: tcopy_F0.simps tcopy_def 
   966 
   768 
   967 text {*
   769 text {*
   968   Invariant under mult-step execution.
   770   Invariant under mult-step execution.
   969   *}
   771   *}
   970 lemma inv_tcopy_steps: 
   772 lemma inv_tcopy_steps: 
   971   "inv_tcopy x (steps (Suc 0, [], replicate x Oc) tcopy stp) "
   773   "inv_tcopy x (steps (Suc 0, [], Oc\<^bsup>x\<^esup>) tcopy stp) "
   972 apply(induct stp)
   774 apply(induct stp)
   973 apply(simp add: tstep.simps tcopy_def steps.simps 
   775 apply(simp add: tstep.simps tcopy_def steps.simps 
   974                 tcopy_F1.simps inv_tcopy.simps)
   776                 tcopy_F1.simps inv_tcopy.simps)
   975 apply(drule_tac inv_tcopy_step, simp add: tstep_red)
   777 apply(drule_tac inv_tcopy_step, simp add: tstep_red)
   976 done
   778 done
   977   
   779   
   978 
       
   979 text {*
       
   980   The followng lemmas gives the parital correctness of Copying TM.
       
   981 *}
       
   982 theorem inv_tcopy_rs: 
       
   983   "steps (Suc 0, [], replicate x Oc) tcopy stp = (0, l, r)
       
   984   \<Longrightarrow> \<exists> n. l = replicate n Bk \<and> 
       
   985            r = replicate x Oc @ Bk # replicate x Oc"
       
   986 apply(insert inv_tcopy_steps[of x stp])
       
   987 apply(auto simp: inv_tcopy.simps tcopy_F0.simps isBk.simps)
       
   988 done
       
   989 
       
   990 
   780 
   991 
   781 
   992 
   782 
   993 (*----------halt problem of tcopy----------------------------------------*)
   783 (*----------halt problem of tcopy----------------------------------------*)
   994 
   784 
  1181 apply(simp add: tstep.simps tcopy_def tcopy_LE_def lex_square_def 
   971 apply(simp add: tstep.simps tcopy_def tcopy_LE_def lex_square_def 
  1182  lex_triple_def lex_pair_def tcopy_phase.simps tcopy_stage.simps 
   972  lex_triple_def lex_pair_def tcopy_phase.simps tcopy_stage.simps 
  1183  tcopy_state.simps tcopy_step.simps)
   973  tcopy_state.simps tcopy_step.simps)
  1184 apply(simp split: if_splits list.splits block.splits taction.splits)
   974 apply(simp split: if_splits list.splits block.splits taction.splits)
  1185 apply(auto)
   975 apply(auto)
  1186 apply(case_tac x, simp+)
       
  1187 done
   976 done
  1188 
   977 
  1189 lemma [elim]: "tcopy_F4 x (b, c) \<Longrightarrow> 
   978 lemma [elim]: "tcopy_F4 x (b, c) \<Longrightarrow> 
  1190             (tstep (4, b, c) tcopy, 4, b, c) \<in> tcopy_LE"
   979             (tstep (4, b, c) tcopy, 4, b, c) \<in> tcopy_LE"
  1191 apply(case_tac x, simp)
   980 apply(case_tac x, simp)
  1192 apply(simp add: tcopy_F4.simps tstep.simps tcopy_def tcopy_LE_def 
   981 apply(simp add: tcopy_F4.simps tstep.simps tcopy_def tcopy_LE_def 
  1193  lex_square_def lex_triple_def lex_pair_def tcopy_phase.simps 
   982  lex_square_def lex_triple_def lex_pair_def tcopy_phase.simps 
  1194  tcopy_stage.simps tcopy_state.simps tcopy_step.simps)
   983  tcopy_stage.simps tcopy_state.simps tcopy_step.simps)
  1195 apply(simp split: if_splits list.splits block.splits taction.splits)
   984 apply(simp split: if_splits list.splits block.splits taction.splits)
  1196 apply(auto)
   985 apply(auto simp: exp_ind_def)
  1197 done
   986 done
  1198 
   987 
  1199 lemma[simp]: "takeWhile (\<lambda>a. a = b) (replicate x b @ ys) = 
   988 lemma[simp]: "takeWhile (\<lambda>a. a = b) (replicate x b @ ys) = 
  1200              replicate x b @ (takeWhile (\<lambda>a. a = b) ys)"
   989              replicate x b @ (takeWhile (\<lambda>a. a = b) ys)"
  1201 apply(induct x)
   990 apply(induct x)
  1224                 lex_square_def lex_triple_def lex_pair_def 
  1013                 lex_square_def lex_triple_def lex_pair_def 
  1225                 tcopy_phase.simps)
  1014                 tcopy_phase.simps)
  1226 apply(simp split: if_splits list.splits block.splits taction.splits)
  1015 apply(simp split: if_splits list.splits block.splits taction.splits)
  1227 apply(auto)
  1016 apply(auto)
  1228 apply(simp_all add: tcopy_phase.simps tcopy_stage.simps 
  1017 apply(simp_all add: tcopy_phase.simps tcopy_stage.simps 
  1229                     tcopy_state.simps tcopy_step.simps)
  1018                     tcopy_state.simps tcopy_step.simps exponent_def)
  1230 done
  1019 done
  1231 
  1020 
  1232 lemma [elim]: "tcopy_F7 x (b, c) \<Longrightarrow> 
  1021 lemma [elim]: "tcopy_F7 x (b, c) \<Longrightarrow> 
  1233              (tstep (7, b, c) tcopy, 7, b, c) \<in> tcopy_LE"
  1022              (tstep (7, b, c) tcopy, 7, b, c) \<in> tcopy_LE"
  1234 apply(case_tac x, simp)
  1023 apply(case_tac x, simp)
  1235 apply(simp add: tstep.simps tcopy_def tcopy_LE_def lex_square_def 
  1024 apply(simp add: tstep.simps tcopy_def tcopy_LE_def lex_square_def 
  1236                 lex_triple_def lex_pair_def tcopy_phase.simps)
  1025                 lex_triple_def lex_pair_def tcopy_phase.simps)
  1237 apply(simp split: if_splits list.splits block.splits taction.splits)
  1026 apply(simp split: if_splits list.splits block.splits taction.splits)
  1238 apply(auto)
  1027 apply(auto simp: exp_zero_simp)
  1239 apply(simp_all add: tcopy_phase.simps tcopy_stage.simps 
  1028 apply(simp_all add: tcopy_phase.simps tcopy_stage.simps 
  1240                     tcopy_state.simps tcopy_step.simps)
  1029                     tcopy_state.simps tcopy_step.simps)
  1241 done
  1030 done
  1242 
  1031 
  1243 lemma [elim]: "tcopy_F8 x (b, c) \<Longrightarrow> 
  1032 lemma [elim]: "tcopy_F8 x (b, c) \<Longrightarrow> 
  1244               (tstep (8, b, c) tcopy, 8, b, c) \<in> tcopy_LE"
  1033               (tstep (8, b, c) tcopy, 8, b, c) \<in> tcopy_LE"
  1245 apply(case_tac x, simp)
  1034 apply(case_tac x, simp)
  1246 apply(simp add: tstep.simps tcopy_def tcopy_LE_def lex_square_def 
  1035 apply(simp add: tstep.simps tcopy_def tcopy_LE_def lex_square_def 
  1247                 lex_triple_def lex_pair_def tcopy_phase.simps)
  1036                 lex_triple_def lex_pair_def tcopy_phase.simps)
  1248 apply(simp split: if_splits list.splits block.splits taction.splits)
  1037 apply(simp split: if_splits list.splits block.splits taction.splits)
  1249 apply(auto)
  1038 apply(auto simp: exp_zero_simp)
  1250 apply(simp_all add: tcopy_phase.simps tcopy_stage.simps 
  1039 apply(simp_all add: tcopy_phase.simps tcopy_stage.simps 
  1251                     tcopy_state.simps tcopy_step.simps)
  1040                     tcopy_state.simps tcopy_step.simps exponent_def)
  1252 apply(simp only: app_cons_app_simp, frule replicate_tail_length, simp)
  1041 done
  1253 done
  1042 
       
  1043 lemma rev_equal_rev: "rev a = rev b \<Longrightarrow> a = b"
       
  1044 by simp
  1254 
  1045 
  1255 lemma app_app_app_equal: "xs @ ys @ zs = (xs @ ys) @ zs"
  1046 lemma app_app_app_equal: "xs @ ys @ zs = (xs @ ys) @ zs"
  1256 by simp
  1047 by simp
  1257 
  1048 
  1258 lemma append_cons_assoc: "as @ b # bs = (as @ [b]) @ bs"
  1049 lemma append_cons_assoc: "as @ b # bs = (as @ [b]) @ bs"
  1264                         rev (tl bs) @ hd bs # as = rev bs @ as"
  1055                         rev (tl bs) @ hd bs # as = rev bs @ as"
  1265 apply(rule rev_equal_rev)
  1056 apply(rule rev_equal_rev)
  1266 apply(simp)
  1057 apply(simp)
  1267 done
  1058 done
  1268 
  1059 
       
  1060 lemma[simp]: "takeWhile (\<lambda>a. a = b) (replicate x b @ ys) = 
       
  1061              replicate x b @ (takeWhile (\<lambda>a. a = b) ys)"
       
  1062 apply(induct x)
       
  1063 apply(simp+)
       
  1064 done
       
  1065 
  1269 lemma [elim]: "tcopy_F9 x (b, c) \<Longrightarrow> 
  1066 lemma [elim]: "tcopy_F9 x (b, c) \<Longrightarrow> 
  1270                       (tstep (9, b, c) tcopy, 9, b, c) \<in> tcopy_LE"
  1067                       (tstep (9, b, c) tcopy, 9, b, c) \<in> tcopy_LE"
  1271 apply(case_tac x, simp)
       
  1272 apply(simp add: tstep.simps tcopy_def tcopy_LE_def lex_square_def 
  1068 apply(simp add: tstep.simps tcopy_def tcopy_LE_def lex_square_def 
  1273                 lex_triple_def lex_pair_def tcopy_phase.simps)
  1069                 lex_triple_def lex_pair_def tcopy_phase.simps tcopy_F9.simps
       
  1070                 tcopy_F9_loop.simps tcopy_F9_exit.simps)
  1274 apply(simp split: if_splits list.splits block.splits taction.splits)
  1071 apply(simp split: if_splits list.splits block.splits taction.splits)
  1275 apply(auto)
  1072 apply(auto)
  1276 apply(simp_all add: tcopy_phase.simps tcopy_stage.simps 
  1073 apply(simp_all add: tcopy_phase.simps tcopy_stage.simps  tcopy_F9_loop.simps
  1277                     tcopy_state.simps tcopy_step.simps)
  1074                     tcopy_state.simps tcopy_step.simps tstep.simps exp_zero_simp
  1278 apply(drule_tac bs = b and as = "Bk # list" in rev_tl_hd_merge)
  1075                     exponent_def)
  1279 apply(simp)
  1076 apply(case_tac [1-2] t, simp_all add: rev_tl_hd_merge)
  1280 apply(drule_tac bs = b and as = "Oc # list" in rev_tl_hd_merge)
  1077 apply(case_tac j, simp, simp)
  1281 apply(simp)
  1078 apply(case_tac nat, simp_all)
       
  1079 apply(case_tac nata, simp_all)
  1282 done
  1080 done
  1283 
  1081 
  1284 lemma [elim]: "tcopy_F10 x (b, c) \<Longrightarrow> 
  1082 lemma [elim]: "tcopy_F10 x (b, c) \<Longrightarrow> 
  1285               (tstep (10, b, c) tcopy, 10, b, c) \<in> tcopy_LE"
  1083               (tstep (10, b, c) tcopy, 10, b, c) \<in> tcopy_LE"
  1286 apply(case_tac x, simp)
       
  1287 apply(simp add: tstep.simps tcopy_def tcopy_LE_def lex_square_def 
  1084 apply(simp add: tstep.simps tcopy_def tcopy_LE_def lex_square_def 
  1288                 lex_triple_def lex_pair_def tcopy_phase.simps)
  1085                 lex_triple_def lex_pair_def tcopy_phase.simps tcopy_F10_loop.simps
       
  1086                 tcopy_F10_exit.simps exp_zero_simp)
  1289 apply(simp split: if_splits list.splits block.splits taction.splits)
  1087 apply(simp split: if_splits list.splits block.splits taction.splits)
  1290 apply(auto)
  1088 apply(auto simp: exp_zero_simp)
  1291 apply(simp_all add: tcopy_phase.simps tcopy_stage.simps 
  1089 apply(simp_all add: tcopy_phase.simps tcopy_stage.simps 
  1292                     tcopy_state.simps tcopy_step.simps)
  1090                     tcopy_state.simps tcopy_step.simps exponent_def
  1293 apply(drule_tac bs = b and as = "Bk # list" in rev_tl_hd_merge)
  1091                     rev_tl_hd_merge)
  1294 apply(simp)
  1092 apply(case_tac k, simp_all)
  1295 apply(drule_tac bs = b and as = "Oc # list" in rev_tl_hd_merge)
  1093 apply(case_tac nat, simp_all)
  1296 apply(simp)
       
  1297 done
  1094 done
  1298 
  1095 
  1299 lemma [elim]: "tcopy_F11 x (b, c) \<Longrightarrow> 
  1096 lemma [elim]: "tcopy_F11 x (b, c) \<Longrightarrow> 
  1300               (tstep (11, b, c) tcopy, 11, b, c) \<in> tcopy_LE"
  1097               (tstep (11, b, c) tcopy, 11, b, c) \<in> tcopy_LE"
  1301 apply(case_tac x, simp)
  1098 apply(case_tac x, simp)
  1311                 lex_triple_def lex_pair_def tcopy_phase.simps)
  1108                 lex_triple_def lex_pair_def tcopy_phase.simps)
  1312 apply(simp split: if_splits list.splits block.splits taction.splits)
  1109 apply(simp split: if_splits list.splits block.splits taction.splits)
  1313 apply(auto)
  1110 apply(auto)
  1314 apply(simp_all add: tcopy_phase.simps tcopy_stage.simps 
  1111 apply(simp_all add: tcopy_phase.simps tcopy_stage.simps 
  1315                     tcopy_state.simps tcopy_step.simps)
  1112                     tcopy_state.simps tcopy_step.simps)
       
  1113 apply(simp_all add: exp_ind_def)
  1316 done
  1114 done
  1317 
  1115 
  1318 lemma [elim]: "tcopy_F13 x (b, c) \<Longrightarrow> 
  1116 lemma [elim]: "tcopy_F13 x (b, c) \<Longrightarrow> 
  1319               (tstep (13, b, c) tcopy, 13, b, c) \<in> tcopy_LE"
  1117               (tstep (13, b, c) tcopy, 13, b, c) \<in> tcopy_LE"
  1320 apply(case_tac x, simp)
  1118 apply(case_tac x, simp)
  1322                 lex_triple_def lex_pair_def tcopy_phase.simps)
  1120                 lex_triple_def lex_pair_def tcopy_phase.simps)
  1323 apply(simp split: if_splits list.splits block.splits taction.splits)
  1121 apply(simp split: if_splits list.splits block.splits taction.splits)
  1324 apply(auto)
  1122 apply(auto)
  1325 apply(simp_all add: tcopy_phase.simps tcopy_stage.simps 
  1123 apply(simp_all add: tcopy_phase.simps tcopy_stage.simps 
  1326                     tcopy_state.simps tcopy_step.simps)
  1124                     tcopy_state.simps tcopy_step.simps)
  1327 apply(drule equal_length, simp)+
       
  1328 done
  1125 done
  1329 
  1126 
  1330 lemma [elim]: "tcopy_F14 x (b, c) \<Longrightarrow> 
  1127 lemma [elim]: "tcopy_F14 x (b, c) \<Longrightarrow> 
  1331              (tstep (14, b, c) tcopy, 14, b, c) \<in> tcopy_LE"
  1128              (tstep (14, b, c) tcopy, 14, b, c) \<in> tcopy_LE"
  1332 apply(case_tac x, simp)
  1129 apply(case_tac x, simp)
  1347 apply(auto)
  1144 apply(auto)
  1348 apply(simp_all add: tcopy_phase.simps tcopy_stage.simps 
  1145 apply(simp_all add: tcopy_phase.simps tcopy_stage.simps 
  1349                     tcopy_state.simps tcopy_step.simps)
  1146                     tcopy_state.simps tcopy_step.simps)
  1350 done
  1147 done
  1351 
  1148 
       
  1149 lemma exp_length: "length (a\<^bsup>b\<^esup>) = b"
       
  1150 apply(induct b, simp_all add: exp_zero exp_ind_def)
       
  1151 done
       
  1152 
       
  1153 declare tcopy_F9.simps[simp del] tcopy_F10.simps[simp del]
       
  1154 
       
  1155 lemma length_eq: "xs = ys \<Longrightarrow> length xs = length ys"
       
  1156 by simp
       
  1157 
  1352 lemma tcopy_wf_step:"\<lbrakk>a > 0; inv_tcopy x (a, b, c)\<rbrakk> \<Longrightarrow> 
  1158 lemma tcopy_wf_step:"\<lbrakk>a > 0; inv_tcopy x (a, b, c)\<rbrakk> \<Longrightarrow> 
  1353                      (tstep (a, b, c) tcopy, (a, b, c)) \<in> tcopy_LE"
  1159                      (tstep (a, b, c) tcopy, (a, b, c)) \<in> tcopy_LE"
  1354 apply(simp add:inv_tcopy.simps split: if_splits, auto)
  1160 apply(simp add:inv_tcopy.simps split: if_splits, auto)
  1355 apply(auto simp: tstep.simps tcopy_def  tcopy_LE_def lex_square_def 
  1161 apply(auto simp: tstep.simps tcopy_def  tcopy_LE_def lex_square_def 
  1356                  lex_triple_def lex_pair_def tcopy_phase.simps 
  1162                  lex_triple_def lex_pair_def tcopy_phase.simps 
  1357                  tcopy_stage.simps tcopy_state.simps tcopy_step.simps
  1163                  tcopy_stage.simps tcopy_state.simps tcopy_step.simps
       
  1164                  exp_length exp_zero_simp exponent_def
  1358            split: if_splits list.splits block.splits taction.splits)
  1165            split: if_splits list.splits block.splits taction.splits)
       
  1166 apply(case_tac [!] t, simp_all)
       
  1167 apply(case_tac j, simp_all)
       
  1168 apply(drule_tac length_eq, simp)
  1359 done
  1169 done
  1360 
  1170 
  1361 lemma tcopy_wf: 
  1171 lemma tcopy_wf: 
  1362 "\<forall>n. let nc = steps (Suc 0, [], replicate x Oc) tcopy n in 
  1172 "\<forall>n. let nc = steps (Suc 0, [], Oc\<^bsup>x\<^esup>) tcopy n in 
  1363       let Sucnc = steps (Suc 0, [], replicate x Oc) tcopy (Suc n) in
  1173       let Sucnc = steps (Suc 0, [], Oc\<^bsup>x\<^esup>) tcopy (Suc n) in
  1364   \<not> isS0 nc \<longrightarrow> ((Sucnc, nc) \<in> tcopy_LE)"
  1174   \<not> isS0 nc \<longrightarrow> ((Sucnc, nc) \<in> tcopy_LE)"
  1365 proof(rule allI, case_tac 
  1175 proof(rule allI, case_tac 
  1366    "steps (Suc 0, [], replicate x Oc) tcopy n", auto simp: tstep_red)
  1176    "steps (Suc 0, [], Oc\<^bsup>x\<^esup>) tcopy n", auto simp: tstep_red)
  1367   fix n a b c
  1177   fix n a b c
  1368   assume h: "\<not> isS0 (a, b, c)" 
  1178   assume h: "\<not> isS0 (a, b, c)" 
  1369        "steps (Suc 0, [], replicate x Oc) tcopy n = (a, b, c)"
  1179        "steps (Suc 0, [], Oc\<^bsup>x\<^esup>) tcopy n = (a, b, c)"
  1370   hence  "inv_tcopy x (a, b, c)"
  1180   hence  "inv_tcopy x (a, b, c)"
  1371     using inv_tcopy_steps[of x n] by(simp)
  1181     using inv_tcopy_steps[of x n] by(simp)
  1372   thus "(tstep (a, b, c) tcopy, a, b, c) \<in> tcopy_LE"
  1182   thus "(tstep (a, b, c) tcopy, a, b, c) \<in> tcopy_LE"
  1373     using h
  1183     using h
  1374     by(rule_tac tcopy_wf_step, auto simp: isS0_def)
  1184     by(rule_tac tcopy_wf_step, auto simp: isS0_def)
  1376 
  1186 
  1377 text {*
  1187 text {*
  1378   The termination of Copying TM:
  1188   The termination of Copying TM:
  1379 *}
  1189 *}
  1380 lemma tcopy_halt: 
  1190 lemma tcopy_halt: 
  1381   "\<exists>n. isS0 (steps (Suc 0, [], replicate x Oc) tcopy n)"
  1191   "\<exists>n. isS0 (steps (Suc 0, [], Oc\<^bsup>x\<^esup>) tcopy n)"
  1382 apply(insert halt_lemma 
  1192 apply(insert halt_lemma 
  1383         [of tcopy_LE isS0 "steps (Suc 0, [], replicate x Oc) tcopy"])
  1193         [of tcopy_LE isS0 "steps (Suc 0, [], Oc\<^bsup>x\<^esup>) tcopy"])
  1384 apply(insert tcopy_wf [of x])
  1194 apply(insert tcopy_wf [of x])
  1385 apply(simp only: Let_def)
  1195 apply(simp only: Let_def)
  1386 apply(insert wf_tcopy_le)
  1196 apply(insert wf_tcopy_le)
  1387 apply(simp)
  1197 apply(simp)
  1388 done
  1198 done
  1389 
  1199 
  1390 text {*
  1200 text {*
  1391   The total correntess of Copying TM:
  1201   The total correntess of Copying TM:
  1392 *}
  1202 *}
  1393 theorem tcopy_halt_rs: "\<exists>stp m. 
  1203 theorem tcopy_halt_rs: 
  1394   steps (Suc 0, [], replicate x Oc) tcopy stp = 
  1204   "\<exists>stp m. 
  1395        (0, replicate m Bk, replicate x Oc @ Bk # replicate x Oc)"
  1205    steps (Suc 0, [], Oc\<^bsup>x\<^esup>) tcopy stp = 
       
  1206        (0, Bk\<^bsup>m\<^esup>, Oc\<^bsup>x\<^esup> @ Bk # Oc\<^bsup>x\<^esup>)"
  1396 using tcopy_halt[of x]
  1207 using tcopy_halt[of x]
  1397 proof(erule_tac exE)
  1208 proof(erule_tac exE)
  1398   fix n
  1209   fix n
  1399   assume h: "isS0 (steps (Suc 0, [], replicate x Oc) tcopy n)"
  1210   assume h: "isS0 (steps (Suc 0, [], Oc\<^bsup>x\<^esup>) tcopy n)"
  1400   have "inv_tcopy x (steps (Suc 0, [], replicate x Oc) tcopy n)"
  1211   have "inv_tcopy x (steps (Suc 0, [], Oc\<^bsup>x\<^esup>) tcopy n)"
  1401     using inv_tcopy_steps[of x n] by simp
  1212     using inv_tcopy_steps[of x n] by simp
  1402   thus "?thesis"
  1213   thus "?thesis"
  1403     using h
  1214     using h
  1404     apply(cases "(steps (Suc 0, [], replicate x Oc) tcopy n)", 
  1215     apply(cases "(steps (Suc 0, [], Oc\<^bsup>x\<^esup>) tcopy n)", 
  1405           auto simp: isS0_def inv_tcopy.simps)
  1216           auto simp: isS0_def inv_tcopy.simps)
  1406     apply(rule_tac x = n in exI, auto)
       
  1407     done
  1217     done
  1408 qed
  1218 qed
  1409 
  1219 
  1410 section {*
  1220 section {*
  1411   The {\em Dithering} Turing Machine 
  1221   The {\em Dithering} Turing Machine 
  1503   -- {*
  1313   -- {*
  1504   The following two assumptions specifies that @{text "H"} does solve the Halting problem.
  1314   The following two assumptions specifies that @{text "H"} does solve the Halting problem.
  1505   *}
  1315   *}
  1506   and h_case: 
  1316   and h_case: 
  1507   "\<And> M n. \<lbrakk>(haltP M n)\<rbrakk> \<Longrightarrow> 
  1317   "\<And> M n. \<lbrakk>(haltP M n)\<rbrakk> \<Longrightarrow> 
  1508              \<exists> na nb. (steps (Suc 0, Bk\<^bsup>x\<^esup>, Oc\<^bsup>code M\<^esup> @ Bk # Oc\<^bsup>n\<^esup>) H na = (0, Bk\<^bsup>nb\<^esup>, [Oc]))"
  1318              \<exists> na nb. (steps (Suc 0, [], Oc\<^bsup>code M\<^esup> @ Bk # Oc\<^bsup>n\<^esup>) H na = (0, Bk\<^bsup>nb\<^esup>, [Oc]))"
  1509   and nh_case: 
  1319   and nh_case: 
  1510   "\<And> M n. \<lbrakk>(\<not> haltP M n)\<rbrakk> \<Longrightarrow>
  1320   "\<And> M n. \<lbrakk>(\<not> haltP M n)\<rbrakk> \<Longrightarrow>
  1511              \<exists> na nb. (steps (Suc 0, Bk\<^bsup>x\<^esup>, Oc\<^bsup>code M\<^esup> @ Bk # Oc\<^bsup>n\<^esup>) H na = (0, Bk\<^bsup>nb\<^esup>, [Oc, Oc]))"
  1321              \<exists> na nb. (steps (Suc 0, [],  Oc\<^bsup>code M\<^esup> @ Bk # Oc\<^bsup>n\<^esup>) H na = (0, Bk\<^bsup>nb\<^esup>, [Oc, Oc]))"
  1512 begin
  1322 begin
  1513 
  1323 
  1514 term t_correct
  1324 term t_correct
  1515 declare haltP_def[simp del]
  1325 declare haltP_def[simp del]
  1516 definition tcontra :: "tprog \<Rightarrow> tprog"
  1326 definition tcontra :: "tprog \<Rightarrow> tprog"
  1517   where
  1327   where
  1518   "tcontra h \<equiv> ((tcopy |+| h) |+| dither)"
  1328   "tcontra h \<equiv> ((tcopy |+| h) |+| dither)"
  1519 
  1329 
  1520 lemma [simp]: "a\<^bsup>0\<^esup> = []"
  1330 lemma [simp]: "a\<^bsup>0\<^esup> = []"
  1521   by(simp add: exponent_def)
  1331   by(simp add: exponent_def)
       
  1332 
       
  1333 lemma tinres_ex1:
       
  1334   "tinres (Bk\<^bsup>nb\<^esup>) b \<Longrightarrow> \<exists>nb. b = Bk\<^bsup>nb\<^esup>"
       
  1335 apply(auto simp: tinres_def)
       
  1336 proof -
       
  1337   fix n
       
  1338   assume "Bk\<^bsup>nb\<^esup> = b @ Bk\<^bsup>n\<^esup>"
       
  1339   thus "\<exists>nb. b = Bk\<^bsup>nb\<^esup>"
       
  1340   proof(induct b arbitrary: nb)
       
  1341     show "\<exists>nb. [] = Bk\<^bsup>nb\<^esup>"
       
  1342       by(rule_tac x = 0 in exI, simp add: exp_zero)
       
  1343   next
       
  1344     fix a b nb
       
  1345     assume ind: "\<And>nb. Bk\<^bsup>nb\<^esup> = b @ Bk\<^bsup>n\<^esup> \<Longrightarrow> \<exists>nb. b = Bk\<^bsup>nb\<^esup>"
       
  1346     and h: "Bk\<^bsup>nb\<^esup> = (a # b) @ Bk\<^bsup>n\<^esup>"
       
  1347     from h show "\<exists>nb. a # b = Bk\<^bsup>nb\<^esup>"
       
  1348     proof(case_tac a, case_tac nb, simp_all add: exp_ind_def)
       
  1349       fix nat
       
  1350       assume "Bk\<^bsup>nat\<^esup> = b @ Bk\<^bsup>n\<^esup>"
       
  1351       thus "\<exists>nb. Bk # b = Bk\<^bsup>nb\<^esup>"
       
  1352         using ind[of nat]
       
  1353         apply(auto)
       
  1354         apply(rule_tac x = "Suc nb" in exI, simp add: exp_ind_def)
       
  1355         done
       
  1356     next
       
  1357       assume "Bk\<^bsup>nb\<^esup> = Oc # b @ Bk\<^bsup>n\<^esup>"
       
  1358       thus "\<exists>nb. Oc # b = Bk\<^bsup>nb\<^esup>"
       
  1359         apply(case_tac nb, simp_all add: exp_ind_def)
       
  1360         done
       
  1361     qed
       
  1362   qed
       
  1363 next
       
  1364   fix n
       
  1365   show "\<exists>nba. Bk\<^bsup>nb\<^esup> @ Bk\<^bsup>n\<^esup> = Bk\<^bsup>nba\<^esup>"
       
  1366     apply(rule_tac x = "nb + n" in exI)
       
  1367     apply(simp add: exponent_def replicate_add)
       
  1368     done
       
  1369 qed
       
  1370 
       
  1371 lemma h_newcase: "\<And> M n. \<lbrakk>(haltP M n)\<rbrakk> \<Longrightarrow> 
       
  1372              \<exists> na nb. (steps (Suc 0, Bk\<^bsup>x\<^esup>, Oc\<^bsup>code M\<^esup> @ Bk # Oc\<^bsup>n\<^esup>) H na = (0, Bk\<^bsup>nb\<^esup>, [Oc]))"
       
  1373 proof -
       
  1374   fix M n x
       
  1375   assume "haltP M n"
       
  1376   hence " \<exists> na nb. (steps (Suc 0, [], Oc\<^bsup>code M\<^esup> @ Bk # Oc\<^bsup>n\<^esup>) H na
       
  1377             = (0, Bk\<^bsup>nb\<^esup>, [Oc]))"
       
  1378     apply(erule_tac h_case)
       
  1379     done
       
  1380   from this obtain na nb where 
       
  1381     cond1:"(steps (Suc 0, [], Oc\<^bsup>code M\<^esup> @ Bk # Oc\<^bsup>n\<^esup>) H na
       
  1382             = (0, Bk\<^bsup>nb\<^esup>, [Oc]))" by blast
       
  1383   thus "\<exists> na nb. (steps (Suc 0, Bk\<^bsup>x\<^esup>, Oc\<^bsup>code M\<^esup> @ Bk # Oc\<^bsup>n\<^esup>) H na = (0, Bk\<^bsup>nb\<^esup>, [Oc]))"
       
  1384   proof(rule_tac x = na in exI, case_tac "steps (Suc 0, Bk\<^bsup>x\<^esup>, Oc\<^bsup>code M\<^esup> @ Bk # Oc\<^bsup>n\<^esup>) H na", simp)
       
  1385     fix a b c
       
  1386     assume cond2: "steps (Suc 0, Bk\<^bsup>x\<^esup>, Oc\<^bsup>code M\<^esup> @ Bk # Oc\<^bsup>n\<^esup>) H na = (a, b, c)"
       
  1387     have "tinres (Bk\<^bsup>nb\<^esup>) b \<and> [Oc] = c \<and> 0 = a"
       
  1388     proof(rule_tac tinres_steps)
       
  1389       show "tinres [] (Bk\<^bsup>x\<^esup>)"
       
  1390         apply(simp add: tinres_def)
       
  1391         apply(auto)
       
  1392         done
       
  1393     next
       
  1394       show "(steps (Suc 0, [], Oc\<^bsup>code M\<^esup> @ Bk # Oc\<^bsup>n\<^esup>) H na
       
  1395             = (0, Bk\<^bsup>nb\<^esup>, [Oc]))"
       
  1396         by(simp add: cond1)
       
  1397     next
       
  1398       show "steps (Suc 0, Bk\<^bsup>x\<^esup>, Oc\<^bsup>code M\<^esup> @ Bk # Oc\<^bsup>n\<^esup>) H na = (a, b, c)"
       
  1399         by(simp add: cond2)
       
  1400     qed
       
  1401     thus "a = 0 \<and> (\<exists>nb. b = Bk\<^bsup>nb\<^esup>) \<and> c = [Oc]"
       
  1402       apply(auto simp: tinres_ex1)
       
  1403       done
       
  1404   qed
       
  1405 qed
       
  1406 
       
  1407 lemma nh_newcase: "\<And> M n. \<lbrakk>\<not> (haltP M n)\<rbrakk> \<Longrightarrow> 
       
  1408              \<exists> na nb. (steps (Suc 0, Bk\<^bsup>x\<^esup>, Oc\<^bsup>code M\<^esup> @ Bk # Oc\<^bsup>n\<^esup>) H na = (0, Bk\<^bsup>nb\<^esup>, [Oc, Oc]))"
       
  1409 proof -
       
  1410   fix M n
       
  1411   assume "\<not> haltP M n"
       
  1412   hence "\<exists> na nb. (steps (Suc 0, [], Oc\<^bsup>code M\<^esup> @ Bk # Oc\<^bsup>n\<^esup>) H na
       
  1413             = (0, Bk\<^bsup>nb\<^esup>, [Oc, Oc]))"
       
  1414     apply(erule_tac nh_case)
       
  1415     done
       
  1416   from this obtain na nb where 
       
  1417     cond1: "(steps (Suc 0, [], Oc\<^bsup>code M\<^esup> @ Bk # Oc\<^bsup>n\<^esup>) H na
       
  1418             = (0, Bk\<^bsup>nb\<^esup>, [Oc, Oc]))" by blast
       
  1419   thus "\<exists> na nb. (steps (Suc 0, Bk\<^bsup>x\<^esup>, Oc\<^bsup>code M\<^esup> @ Bk # Oc\<^bsup>n\<^esup>) H na = (0, Bk\<^bsup>nb\<^esup>, [Oc, Oc]))"
       
  1420   proof(rule_tac x = na in exI, case_tac "steps (Suc 0, Bk\<^bsup>x\<^esup>, Oc\<^bsup>code M\<^esup> @ Bk # Oc\<^bsup>n\<^esup>) H na", simp)
       
  1421     fix a b c
       
  1422     assume cond2: "steps (Suc 0, Bk\<^bsup>x\<^esup>, Oc\<^bsup>code M\<^esup> @ Bk # Oc\<^bsup>n\<^esup>) H na = (a, b, c)"
       
  1423     have "tinres (Bk\<^bsup>nb\<^esup>) b \<and> [Oc, Oc] = c \<and> 0 = a"
       
  1424     proof(rule_tac tinres_steps)
       
  1425       show "tinres [] (Bk\<^bsup>x\<^esup>)"
       
  1426         apply(simp add: tinres_def)
       
  1427         apply(auto)
       
  1428         done
       
  1429     next
       
  1430       show "(steps (Suc 0, [], Oc\<^bsup>code M\<^esup> @ Bk # Oc\<^bsup>n\<^esup>) H na
       
  1431             = (0, Bk\<^bsup>nb\<^esup>, [Oc, Oc]))"
       
  1432         by(simp add: cond1)
       
  1433     next
       
  1434       show "steps (Suc 0, Bk\<^bsup>x\<^esup>, Oc\<^bsup>code M\<^esup> @ Bk # Oc\<^bsup>n\<^esup>) H na = (a, b, c)"
       
  1435         by(simp add: cond2)
       
  1436     qed
       
  1437     thus "a = 0 \<and> (\<exists>nb. b = Bk\<^bsup>nb\<^esup>) \<and> c = [Oc, Oc]"
       
  1438       apply(auto simp: tinres_ex1)
       
  1439       done
       
  1440   qed
       
  1441 qed
       
  1442      
  1522 lemma haltP_weaking: 
  1443 lemma haltP_weaking: 
  1523   "haltP (tcontra H) (code (tcontra H)) \<Longrightarrow> 
  1444   "haltP (tcontra H) (code (tcontra H)) \<Longrightarrow> 
  1524     \<exists>stp. isS0 (steps (Suc 0, [], Oc\<^bsup>code (tcontra H)\<^esup>) 
  1445     \<exists>stp. isS0 (steps (Suc 0, [], Oc\<^bsup>code (tcontra H)\<^esup>) 
  1525           ((tcopy |+| H) |+| dither) stp)"
  1446           ((tcopy |+| H) |+| dither) stp)"
  1526   apply(simp add: haltP_def, auto)
  1447   apply(simp add: haltP_def, auto)
  1539   let ?Q2 = "\<lambda> (l, r). (\<exists> nd. l = Bk\<^bsup>nd \<^esup>\<and> r = [Oc])"
  1460   let ?Q2 = "\<lambda> (l, r). (\<exists> nd. l = Bk\<^bsup>nd \<^esup>\<and> r = [Oc])"
  1540   let ?P3 = "\<lambda> tp. False"
  1461   let ?P3 = "\<lambda> tp. False"
  1541   assume h: "haltP (tcontra H) (code (tcontra H))"
  1462   assume h: "haltP (tcontra H) (code (tcontra H))"
  1542   hence h1: "\<And> x. \<exists> na nb. steps (Suc 0, Bk\<^bsup>x\<^esup>, Oc\<^bsup>code (tcontra H)\<^esup> @ Bk # 
  1463   hence h1: "\<And> x. \<exists> na nb. steps (Suc 0, Bk\<^bsup>x\<^esup>, Oc\<^bsup>code (tcontra H)\<^esup> @ Bk # 
  1543                        Oc\<^bsup>code (tcontra H)\<^esup>) H na = (0, Bk\<^bsup>nb\<^esup>, [Oc])"
  1464                        Oc\<^bsup>code (tcontra H)\<^esup>) H na = (0, Bk\<^bsup>nb\<^esup>, [Oc])"
  1544     by(drule_tac x = x in h_case, simp)
  1465     by(drule_tac x = x in h_newcase, simp)
  1545   have "?P1 \<turnstile>-> \<lambda> tp. (\<exists> stp tp'. steps (Suc 0, tp) (tcopy |+| H) stp = (0, tp') \<and> ?Q2 tp')"
  1466   have "?P1 \<turnstile>-> \<lambda> tp. (\<exists> stp tp'. steps (Suc 0, tp) (tcopy |+| H) stp = (0, tp') \<and> ?Q2 tp')"
  1546   proof(rule_tac turing_merge.t_merge_halt[of tcopy H "?P1" "?P2" "?P3" 
  1467   proof(rule_tac turing_merge.t_merge_halt[of tcopy H "?P1" "?P2" "?P3" 
  1547          "?P3" "?Q1" "?Q2"], auto simp: turing_merge_def)
  1468          "?P3" "?Q1" "?Q2"], auto simp: turing_merge_def)
  1548     show "\<exists>stp. case steps (Suc 0, [], Oc\<^bsup>?cn\<^esup>) tcopy stp of (s, tp') \<Rightarrow> 
  1469     show "\<exists>stp. case steps (Suc 0, [], Oc\<^bsup>?cn\<^esup>) tcopy stp of (s, tp') \<Rightarrow> 
  1549                    s = 0 \<and> (case tp' of (l, r) \<Rightarrow> (\<exists>nb. l = Bk\<^bsup>nb\<^esup>) \<and> r = Oc\<^bsup>?cn\<^esup> @ Bk # Oc\<^bsup>?cn\<^esup>)"
  1470                    s = 0 \<and> (case tp' of (l, r) \<Rightarrow> (\<exists>nb. l = Bk\<^bsup>nb\<^esup>) \<and> r = Oc\<^bsup>?cn\<^esup> @ Bk # Oc\<^bsup>?cn\<^esup>)"
  1603 proof -
  1524 proof -
  1604   let ?cn = "code (tcontra H)"
  1525   let ?cn = "code (tcontra H)"
  1605   have h1: "\<And> x. \<exists> na nb. steps (Suc 0, Bk\<^bsup>x\<^esup>, Oc\<^bsup>?cn\<^esup> @ Bk # Oc\<^bsup>?cn\<^esup>)
  1526   have h1: "\<And> x. \<exists> na nb. steps (Suc 0, Bk\<^bsup>x\<^esup>, Oc\<^bsup>?cn\<^esup> @ Bk # Oc\<^bsup>?cn\<^esup>)
  1606                              H na = (0, Bk\<^bsup>nb\<^esup>, [Oc, Oc])"
  1527                              H na = (0, Bk\<^bsup>nb\<^esup>, [Oc, Oc])"
  1607     using uh
  1528     using uh
  1608     by(drule_tac x = x in nh_case, simp)
  1529     by(drule_tac x = x in nh_newcase, simp)
  1609   let ?P1 = "\<lambda> tp. let (l, r) = tp in (l = [] \<and> 
  1530   let ?P1 = "\<lambda> tp. let (l, r) = tp in (l = [] \<and> 
  1610                         (r::block list) = Oc\<^bsup>(?cn)\<^esup>)"
  1531                         (r::block list) = Oc\<^bsup>(?cn)\<^esup>)"
  1611   let ?Q1 = "\<lambda> (l, r).(\<exists> na. l = Bk\<^bsup>na\<^esup> \<and> r = [Oc, Oc])"
  1532   let ?Q1 = "\<lambda> (l, r).(\<exists> na. l = Bk\<^bsup>na\<^esup> \<and> r = [Oc, Oc])"
  1612   let ?P2 = ?Q1
  1533   let ?P2 = ?Q1
  1613   let ?Q2 = ?Q1
  1534   let ?Q2 = ?Q1