thys/UTM.thy
changeset 229 d8e6f0798e23
parent 190 f1ecb4a68a54
child 240 696081f445c2
equal deleted inserted replaced
228:e9ef4ada308b 229:d8e6f0798e23
  1212 
  1212 
  1213 lemma t_twice_len_ge: "Suc 0 \<le> length t_twice div 2"
  1213 lemma t_twice_len_ge: "Suc 0 \<le> length t_twice div 2"
  1214 apply(simp add: t_twice_def mopup.simps t_twice_compile_def)
  1214 apply(simp add: t_twice_def mopup.simps t_twice_compile_def)
  1215 done
  1215 done
  1216 
  1216 
  1217 lemma [intro]: "rec_calc_rel (recf.id (Suc 0) 0) [rs] rs"
       
  1218   apply(rule_tac calc_id, simp_all)
       
  1219   done
       
  1220   
       
  1221 lemma [intro]: "rec_calc_rel (constn 2) [rs] 2"
       
  1222 using prime_rel_exec_eq[of "constn 2" "[rs]" 2]
       
  1223 apply(subgoal_tac "primerec (constn 2) 1", auto)
       
  1224 done
       
  1225 
       
  1226 lemma  [intro]: "rec_calc_rel rec_mult [rs, 2] (2 * rs)"
       
  1227 using prime_rel_exec_eq[of "rec_mult" "[rs, 2]"  "2*rs"]
       
  1228 apply(subgoal_tac "primerec rec_mult (Suc (Suc 0))", auto)
       
  1229 done
       
  1230 
       
  1231 declare start_of.simps[simp del]
  1217 declare start_of.simps[simp del]
       
  1218 
       
  1219 lemma twice_lemma: "rec_exec rec_twice [rs] = 2*rs"
       
  1220 by(auto simp: rec_twice_def rec_exec.simps)
  1232 
  1221 
  1233 lemma t_twice_correct: 
  1222 lemma t_twice_correct: 
  1234   "\<exists>stp ln rn. steps0 (Suc 0, Bk # Bk # ires, Oc\<up>(Suc rs) @ Bk\<up>(n)) 
  1223   "\<exists>stp ln rn. steps0 (Suc 0, Bk # Bk # ires, Oc\<up>(Suc rs) @ Bk\<up>(n)) 
  1235   (tm_of abc_twice @ shift (mopup (Suc 0)) ((length (tm_of abc_twice) div 2))) stp =
  1224   (tm_of abc_twice @ shift (mopup (Suc 0)) ((length (tm_of abc_twice) div 2))) stp =
  1236   (0, Bk\<up>(ln) @ Bk # Bk # ires, Oc\<up>(Suc (2 * rs)) @ Bk\<up>(rn))"
  1225   (0, Bk\<up>(ln) @ Bk # Bk # ires, Oc\<up>(Suc (2 * rs)) @ Bk\<up>(rn))"
  1237 proof(case_tac "rec_ci rec_twice")
  1226 proof(case_tac "rec_ci rec_twice")
  1238   fix a b c
  1227   fix a b c
  1239   assume h: "rec_ci rec_twice = (a, b, c)"
  1228   assume h: "rec_ci rec_twice = (a, b, c)"
  1240   have "\<exists>stp m l. steps0 (Suc 0, Bk # Bk # ires, <[rs]> @ Bk\<up>(n)) (tm_of abc_twice @ shift (mopup 1) 
  1229   have "\<exists>stp m l. steps0 (Suc 0, Bk # Bk # ires, <[rs]> @ Bk\<up>(n)) (tm_of abc_twice @ shift (mopup (length [rs])) 
  1241     (length (tm_of abc_twice) div 2)) stp = (0, Bk\<up>(m) @ Bk # Bk # ires, Oc\<up>(Suc (2*rs)) @ Bk\<up>(l))"
  1230     (length (tm_of abc_twice) div 2)) stp = (0, Bk\<up>(m) @ Bk # Bk # ires, Oc\<up>(Suc (rec_exec rec_twice [rs])) @ Bk\<up>(l))"
  1242   proof(rule_tac recursive_compile_to_tm_correct)
  1231     thm  recursive_compile_to_tm_correct1
       
  1232   proof(rule_tac recursive_compile_to_tm_correct1)
  1243     show "rec_ci rec_twice = (a, b, c)" by (simp add: h)
  1233     show "rec_ci rec_twice = (a, b, c)" by (simp add: h)
  1244   next
  1234   next
  1245     show "rec_calc_rel rec_twice [rs] (2 * rs)"
  1235     show "terminate rec_twice [rs]"
  1246       apply(simp add: rec_twice_def)
  1236       apply(rule_tac primerec_terminate, auto)
  1247       apply(rule_tac rs =  "[rs, 2]" in calc_cn, simp_all)
  1237       apply(simp add: rec_twice_def, auto simp: constn.simps numeral_2_eq_2)
  1248       apply(rule_tac allI, case_tac k, auto)
  1238       by(auto)
  1249       done
       
  1250   next
  1239   next
  1251     show "length [rs] = 1" by simp
  1240     show "tm_of abc_twice = tm_of (a [+] dummy_abc (length [rs]))"
  1252   next	
       
  1253     show "layout_of (a [+] dummy_abc 1) = layout_of (a [+] dummy_abc 1)" by simp
       
  1254   next
       
  1255     show "tm_of abc_twice = tm_of (a [+] dummy_abc 1)"
       
  1256       using h
  1241       using h
  1257       apply(simp add: abc_twice_def)
  1242       by(simp add: abc_twice_def)
  1258       done
       
  1259   qed
  1243   qed
  1260   thus "?thesis"
  1244   thus "?thesis"
  1261     apply(simp add: tape_of_nl_abv tape_of_nat_list.simps tape_of_nat_abv)
  1245     apply(simp add: tape_of_nl_abv tape_of_nat_list.simps tape_of_nat_abv rec_exec.simps twice_lemma)
  1262     done
  1246     done
  1263 qed
  1247 qed
  1264 
  1248 
  1265 declare adjust.simps[simp]
  1249 declare adjust.simps[simp]
  1266 
  1250 
  1384    
  1368    
  1385 declare tm_wf.simps[simp del]
  1369 declare tm_wf.simps[simp del]
  1386 
  1370 
  1387 lemma [simp]: " tm_wf (t_twice_compile, 0)"
  1371 lemma [simp]: " tm_wf (t_twice_compile, 0)"
  1388 apply(simp only: t_twice_compile_def)
  1372 apply(simp only: t_twice_compile_def)
  1389 apply(rule_tac t_compiled_correct)
  1373 apply(rule_tac wf_tm_from_abacus, simp)
  1390 apply(simp_all add: abc_twice_def)
       
  1391 done
  1374 done
  1392 
  1375 
  1393 lemma t_twice_change_term_state:
  1376 lemma t_twice_change_term_state:
  1394   "\<exists> stp ln rn. steps0 (Suc 0, Bk # Bk # ires, Oc\<up>(Suc rs) @ Bk\<up>(n)) t_twice stp
  1377   "\<exists> stp ln rn. steps0 (Suc 0, Bk # Bk # ires, Oc\<up>(Suc rs) @ Bk\<up>(n)) t_twice stp
  1395      = (Suc t_twice_len, Bk\<up>(ln) @ Bk # Bk # ires, Oc\<up>(Suc (2 * rs)) @ Bk\<up>(rn))"
  1378      = (Suc t_twice_len, Bk\<up>(ln) @ Bk # Bk # ires, Oc\<up>(Suc (2 * rs)) @ Bk\<up>(rn))"
  1501     apply(erule_tac exE)
  1484     apply(erule_tac exE)
  1502     apply(simp add: wcode_main_first_part_len)
  1485     apply(simp add: wcode_main_first_part_len)
  1503     apply(rule_tac x = stp in exI, rule_tac x = "ln + lna" in exI, 
  1486     apply(rule_tac x = stp in exI, rule_tac x = "ln + lna" in exI, 
  1504           rule_tac x = rn in exI)
  1487           rule_tac x = rn in exI)
  1505     apply(simp add: t_wcode_main_def)
  1488     apply(simp add: t_wcode_main_def)
  1506     apply(simp add: replicate_Suc[THEN sym] exp_add[THEN sym] del: replicate_Suc)
  1489     apply(simp add: replicate_Suc[THEN sym] replicate_add [THEN sym] del: replicate_Suc)
  1507     done
  1490     done
  1508   from this obtain stpb lnb rnb where stp2: 
  1491   from this obtain stpb lnb rnb where stp2: 
  1509     "steps0 (13, Bk # Bk # Bk\<up>(lna) @ Oc # ires, Oc\<up>(Suc (Suc rs)) @ Bk\<up>(rna)) t_wcode_main stpb =
  1492     "steps0 (13, Bk # Bk # Bk\<up>(lna) @ Oc # ires, Oc\<up>(Suc (Suc rs)) @ Bk\<up>(rna)) t_wcode_main stpb =
  1510     (13 + t_twice_len, Bk # Bk # Bk\<up>(lnb) @ Oc # ires, Oc\<up>(Suc (Suc (Suc (2 *rs)))) @ Bk\<up>(rnb))" by blast
  1493     (13 + t_twice_len, Bk # Bk # Bk\<up>(lnb) @ Oc # ires, Oc\<up>(Suc (Suc (Suc (2 *rs)))) @ Bk\<up>(rnb))" by blast
  1511   have "\<exists>stp ln rn. steps0 (13 + t_twice_len, Bk # Bk # Bk\<up>(lnb) @ Oc # ires,
  1494   have "\<exists>stp ln rn. steps0 (13 + t_twice_len, Bk # Bk # Bk\<up>(lnb) @ Oc # ires,
  2016 
  1999 
  2017 lemma t_fourtimes_len_gr:  "t_fourtimes_len > 0"
  2000 lemma t_fourtimes_len_gr:  "t_fourtimes_len > 0"
  2018 apply(simp add: t_fourtimes_len_def t_fourtimes_def mopup.simps t_fourtimes_compile_def)
  2001 apply(simp add: t_fourtimes_len_def t_fourtimes_def mopup.simps t_fourtimes_compile_def)
  2019 done
  2002 done
  2020 
  2003 
  2021 lemma [intro]: "rec_calc_rel (constn 4) [rs] 4"
  2004 lemma [intro]: "primerec rec_fourtimes (Suc 0)"
  2022 using prime_rel_exec_eq[of "constn 4" "[rs]" 4]
  2005 apply(auto simp: rec_fourtimes_def numeral_4_eq_4 constn.simps)
  2023 apply(subgoal_tac "primerec (constn 4) 1", auto)
  2006 by auto
  2024 done
  2007 
  2025 
  2008 lemma fourtimes_lemma: "rec_exec rec_fourtimes [rs] = 4 * rs"
  2026 lemma [intro]: "rec_calc_rel rec_mult [rs, 4] (4 * rs)"
  2009 by(simp add: rec_exec.simps rec_fourtimes_def)
  2027 using prime_rel_exec_eq[of "rec_mult" "[rs, 4]"  "4*rs"]
  2010 
  2028 apply(subgoal_tac "primerec rec_mult 2", auto simp: numeral_2_eq_2)
       
  2029 done
       
  2030 
  2011 
  2031 lemma t_fourtimes_correct: 
  2012 lemma t_fourtimes_correct: 
  2032   "\<exists>stp ln rn. steps0 (Suc 0, Bk # Bk # ires, Oc\<up>(Suc rs) @ Bk\<up>(n)) 
  2013   "\<exists>stp ln rn. steps0 (Suc 0, Bk # Bk # ires, Oc\<up>(Suc rs) @ Bk\<up>(n)) 
  2033     (tm_of abc_fourtimes @ shift (mopup 1) (length (tm_of abc_fourtimes) div 2)) stp =
  2014     (tm_of abc_fourtimes @ shift (mopup 1) (length (tm_of abc_fourtimes) div 2)) stp =
  2034        (0, Bk\<up>(ln) @ Bk # Bk # ires, Oc\<up>(Suc (4 * rs)) @ Bk\<up>(rn))"
  2015        (0, Bk\<up>(ln) @ Bk # Bk # ires, Oc\<up>(Suc (4 * rs)) @ Bk\<up>(rn))"
  2035 proof(case_tac "rec_ci rec_fourtimes")
  2016 proof(case_tac "rec_ci rec_fourtimes")
  2036   fix a b c
  2017   fix a b c
  2037   assume h: "rec_ci rec_fourtimes = (a, b, c)"
  2018   assume h: "rec_ci rec_fourtimes = (a, b, c)"
  2038   have "\<exists>stp m l. steps0 (Suc 0, Bk # Bk # ires, <[rs]> @ Bk\<up>(n)) (tm_of abc_fourtimes @ shift (mopup 1) 
  2019   have "\<exists>stp m l. steps0 (Suc 0, Bk # Bk # ires, <[rs]> @ Bk\<up>(n)) (tm_of abc_fourtimes @ shift (mopup (length [rs])) 
  2039     (length (tm_of abc_fourtimes) div 2)) stp = (0, Bk\<up>(m) @ Bk # Bk # ires, Oc\<up>(Suc (4*rs)) @ Bk\<up>(l))"
  2020     (length (tm_of abc_fourtimes) div 2)) stp = (0, Bk\<up>(m) @ Bk # Bk # ires, Oc\<up>(Suc (rec_exec rec_fourtimes [rs])) @ Bk\<up>(l))"
  2040   proof(rule_tac recursive_compile_to_tm_correct)
  2021     thm recursive_compile_to_tm_correct1
       
  2022   proof(rule_tac recursive_compile_to_tm_correct1)
  2041     show "rec_ci rec_fourtimes = (a, b, c)" by (simp add: h)
  2023     show "rec_ci rec_fourtimes = (a, b, c)" by (simp add: h)
  2042   next
  2024   next
  2043     show "rec_calc_rel rec_fourtimes [rs] (4 * rs)"
  2025     show "terminate rec_fourtimes [rs]"
  2044       apply(simp add: rec_fourtimes_def)
  2026       apply(rule_tac primerec_terminate)
  2045       apply(rule_tac rs =  "[rs, 4]" in calc_cn, simp_all)
  2027       by auto
  2046       apply(rule_tac allI, case_tac k, auto simp: mult_lemma)
       
  2047       done
       
  2048   next
  2028   next
  2049     show "length [rs] = 1" by simp
  2029     show "tm_of abc_fourtimes = tm_of (a [+] dummy_abc (length [rs]))"
  2050   next	
       
  2051     show "layout_of (a [+] dummy_abc 1) = layout_of (a [+] dummy_abc 1)" by simp
       
  2052   next
       
  2053     show "tm_of abc_fourtimes = tm_of (a [+] dummy_abc 1)"
       
  2054       using h
  2030       using h
  2055       apply(simp add: abc_fourtimes_def)
  2031       by(simp add: abc_fourtimes_def)
  2056       done
       
  2057   qed
  2032   qed
  2058   thus "?thesis"
  2033   thus "?thesis"
  2059     apply(simp add: tape_of_nl_abv tape_of_nat_list.simps tape_of_nat_abv)
  2034     apply(simp add: tape_of_nl_abv tape_of_nat_list.simps tape_of_nat_abv fourtimes_lemma)
  2060     done
  2035     done
  2061 qed
  2036 qed
  2062 
  2037 
  2063 lemma wf_fourtimes[intro]: "tm_wf (t_fourtimes_compile, 0)"
  2038 lemma wf_fourtimes[intro]: "tm_wf (t_fourtimes_compile, 0)"
  2064 apply(simp only: t_fourtimes_compile_def)
  2039 apply(simp only: t_fourtimes_compile_def)
  2065 apply(rule_tac t_compiled_correct)
  2040 apply(rule_tac wf_tm_from_abacus, simp)
  2066 apply(simp_all add: abc_twice_def)
       
  2067 done
  2041 done
  2068 
  2042 
  2069 lemma t_fourtimes_change_term_state:
  2043 lemma t_fourtimes_change_term_state:
  2070   "\<exists> stp ln rn. steps0 (Suc 0, Bk # Bk # ires, Oc\<up>(Suc rs) @ Bk\<up>(n)) t_fourtimes stp
  2044   "\<exists> stp ln rn. steps0 (Suc 0, Bk # Bk # ires, Oc\<up>(Suc rs) @ Bk\<up>(n)) t_fourtimes stp
  2071      = (Suc t_fourtimes_len, Bk\<up>(ln) @ Bk # Bk # ires, Oc\<up>(Suc (4 * rs)) @ Bk\<up>(rn))"
  2045      = (Suc t_fourtimes_len, Bk\<up>(ln) @ Bk # Bk # ires, Oc\<up>(Suc (4 * rs)) @ Bk\<up>(rn))"
  2173 
  2147 
  2174 lemma [simp]: "fetch t_wcode_main (14 + length t_twice div 2 + t_fourtimes_len) Oc
  2148 lemma [simp]: "fetch t_wcode_main (14 + length t_twice div 2 + t_fourtimes_len) Oc
  2175              = (L, Suc 0)" 
  2149              = (L, Suc 0)" 
  2176 apply(subgoal_tac "14 = Suc 13")
  2150 apply(subgoal_tac "14 = Suc 13")
  2177 apply(simp only: fetch.simps add_Suc nth_of.simps t_wcode_main_def)
  2151 apply(simp only: fetch.simps add_Suc nth_of.simps t_wcode_main_def)
  2178 apply(simp add:length_append length_shift Parity.two_times_even_div_two even_twice_len t_fourtimes_len_def)
  2152 apply(simp add:length_append length_shift Parity.two_times_even_div_two even_twice_len t_fourtimes_len_def nth_append)
  2179 by arith
  2153 by arith
  2180 
  2154 
  2181 lemma [simp]: "fetch t_wcode_main (14 + length t_twice div 2 + t_fourtimes_len) Bk
  2155 lemma [simp]: "fetch t_wcode_main (14 + length t_twice div 2 + t_fourtimes_len) Bk
  2182              = (L, Suc 0)"
  2156              = (L, Suc 0)"
  2183 apply(subgoal_tac "14 = Suc 13")
  2157 apply(subgoal_tac "14 = Suc 13")
  2226     apply(erule_tac exE)
  2200     apply(erule_tac exE)
  2227     apply(simp add: t_wcode_main_def)
  2201     apply(simp add: t_wcode_main_def)
  2228     apply(rule_tac x = stp in exI, 
  2202     apply(rule_tac x = stp in exI, 
  2229           rule_tac x = "ln + lna" in exI,
  2203           rule_tac x = "ln + lna" in exI,
  2230           rule_tac x = rn in exI, simp)
  2204           rule_tac x = rn in exI, simp)
  2231     apply(simp add: replicate_Suc[THEN sym] exp_add[THEN sym] del: replicate_Suc)
  2205     apply(simp add: replicate_Suc[THEN sym] replicate_add[THEN sym] del: replicate_Suc)
  2232     done
  2206     done
  2233   from this obtain stpb lnb rnb where stp2:
  2207   from this obtain stpb lnb rnb where stp2:
  2234     "steps0 (t_twice_len + 14, Bk # Bk # Bk\<up>(lna) @ Oc # ires, Oc\<up>(Suc (rs + 1)) @ Bk\<up>(rna))
  2208     "steps0 (t_twice_len + 14, Bk # Bk # Bk\<up>(lna) @ Oc # ires, Oc\<up>(Suc (rs + 1)) @ Bk\<up>(rna))
  2235                      t_wcode_main stpb =
  2209                      t_wcode_main stpb =
  2236        (t_twice_len + 14 + t_fourtimes_len, Bk # Bk # Bk\<up>(lnb) @ Oc # ires,  Oc\<up>(Suc (4*rs + 4)) @ Bk\<up>(rnb))"
  2210        (t_twice_len + 14 + t_fourtimes_len, Bk # Bk # Bk\<up>(lnb) @ Oc # ires,  Oc\<up>(Suc (4*rs + 4)) @ Bk\<up>(rnb))"
  2251     apply(rule_tac x = "stpa + stpb + stpc" in exI,
  2225     apply(rule_tac x = "stpa + stpb + stpc" in exI,
  2252           rule_tac x = lnc in exI, rule_tac x = rnc in exI)
  2226           rule_tac x = lnc in exI, rule_tac x = rnc in exI)
  2253     apply(simp add: steps_add)
  2227     apply(simp add: steps_add)
  2254     done
  2228     done
  2255 qed
  2229 qed
  2256 
       
  2257 (**********************************************************)
       
  2258 
  2230 
  2259 fun wcode_on_left_moving_3_B :: "bin_inv_t"
  2231 fun wcode_on_left_moving_3_B :: "bin_inv_t"
  2260   where
  2232   where
  2261   "wcode_on_left_moving_3_B ires rs (l, r) = 
  2233   "wcode_on_left_moving_3_B ires rs (l, r) = 
  2262        (\<exists> ml mr rn. l = Bk\<up>(ml) @ Oc # Bk # Bk # ires \<and>
  2234        (\<exists> ml mr rn. l = Bk\<up>(ml) @ Oc # Bk # Bk # ires \<and>
  4740 apply(simp add: exp_ind del: replicate_Suc)
  4712 apply(simp add: exp_ind del: replicate_Suc)
  4741 apply(case_tac nat, simp add: exp_ind)
  4713 apply(case_tac nat, simp add: exp_ind)
  4742 apply(rule_tac x = "Suc m" in exI, simp only: exp_ind)
  4714 apply(rule_tac x = "Suc m" in exI, simp only: exp_ind)
  4743 apply(simp only: exp_ind, simp)
  4715 apply(simp only: exp_ind, simp)
  4744 apply(subgoal_tac "m = length la + nata")
  4716 apply(subgoal_tac "m = length la + nata")
  4745 apply(rule_tac x = "m - nata" in exI, simp add: exp_add)
  4717 apply(rule_tac x = "m - nata" in exI, simp add: replicate_add)
  4746 apply(drule_tac length_equal, simp)
  4718 apply(drule_tac length_equal, simp)
  4747 apply(simp only: exp_ind[THEN sym] replicate_Suc[THEN sym] replicate_add[THEN sym])
  4719 apply(simp only: exp_ind[THEN sym] replicate_Suc[THEN sym] replicate_add[THEN sym])
  4748 apply(rule_tac x = "m + Suc (Suc n)" in exI, simp)
  4720 apply(rule_tac x = "m + Suc (Suc n)" in exI, simp)
  4749 done
  4721 done
  4750 
  4722 
  4755   shows "\<exists>stp m n. steps0 (Suc 0, [Bk], <[code tp, bl2wc (<lm>)]> @ Bk\<up>(i)) t_utm stp = 
  4727   shows "\<exists>stp m n. steps0 (Suc 0, [Bk], <[code tp, bl2wc (<lm>)]> @ Bk\<up>(i)) t_utm stp = 
  4756                                                 (0, Bk\<up>(m), Oc\<up>(rs) @ Bk\<up>(n))"
  4728                                                 (0, Bk\<up>(m), Oc\<up>(rs) @ Bk\<up>(n))"
  4757 proof -
  4729 proof -
  4758   obtain ap arity fp where a: "rec_ci rec_F = (ap, arity, fp)"
  4730   obtain ap arity fp where a: "rec_ci rec_F = (ap, arity, fp)"
  4759     by (metis prod_cases3) 
  4731     by (metis prod_cases3) 
  4760   moreover have b: "rec_calc_rel  rec_F [code tp, (bl2wc (<lm>))] (rs - Suc 0)"
  4732   moreover have b: "rec_exec rec_F [code tp, (bl2wc (<lm>))] = (rs - Suc 0)"
  4761     using assms
  4733     using assms
  4762     apply(rule_tac F_correct, simp_all)
  4734     apply(rule_tac F_correct, simp_all)
  4763     done 
  4735     done 
  4764   have "\<exists> stp m l. steps0 (Suc 0, Bk # Bk # [], <[code tp, bl2wc (<lm>)]> @ Bk\<up>i)
  4736   have "\<exists> stp m l. steps0 (Suc 0, Bk # Bk # [], <[code tp, bl2wc (<lm>)]> @ Bk\<up>i)
  4765     (F_tprog @ shift (mopup 2) (length F_tprog div 2)) stp
  4737     (F_tprog @ shift (mopup (length [code tp, bl2wc (<lm>)])) (length F_tprog div 2)) stp
  4766     = (0, Bk\<up>m @ Bk # Bk # [], Oc\<up>Suc (rs - 1) @ Bk\<up>l)"  
  4738     = (0, Bk\<up>m @ Bk # Bk # [], Oc\<up>Suc (rec_exec rec_F [code tp, (bl2wc (<lm>))]) @ Bk\<up>l)"  
  4767   proof(rule_tac recursive_compile_to_tm_correct)
  4739   proof(rule_tac recursive_compile_to_tm_correct1)
  4768     show "rec_ci rec_F = (ap, arity, fp)" using a by simp
  4740     show "rec_ci rec_F = (ap, arity, fp)" using a by simp
  4769   next
  4741   next
  4770     show "rec_calc_rel rec_F [code tp, bl2wc (<lm>)] (rs - 1)"
  4742     show "terminate rec_F [code tp, bl2wc (<lm>)]"
  4771       using b by simp
  4743       using assms
       
  4744       by(rule_tac terminate_F, simp_all)
  4772   next
  4745   next
  4773     show "length [code tp, bl2wc (<lm>)] = 2" by simp
  4746     show "F_tprog = tm_of (ap [+] dummy_abc (length [code tp, bl2wc (<lm>)]))"
  4774   next
       
  4775     show "layout_of (ap [+] dummy_abc 2) = layout_of (ap [+] dummy_abc 2)"
       
  4776       by simp
       
  4777   next
       
  4778     show "F_tprog = tm_of (ap [+] dummy_abc 2)"
       
  4779       using a
  4747       using a
  4780       apply(simp add: F_tprog_def F_aprog_def numeral_2_eq_2)
  4748       apply(simp add: F_tprog_def F_aprog_def numeral_2_eq_2)
  4781       done
  4749       done
  4782   qed
  4750   qed
  4783   then obtain stp m l where 
  4751   then obtain stp m l where 
  4784     "steps0 (Suc 0, Bk # Bk # [], <[code tp, bl2wc (<lm>)]> @ Bk\<up>i)
  4752     "steps0 (Suc 0, Bk # Bk # [], <[code tp, bl2wc (<lm>)]> @ Bk\<up>i)
  4785     (F_tprog @ shift (mopup 2) (length F_tprog div 2)) stp
  4753     (F_tprog @ shift (mopup (length [code tp, (bl2wc (<lm>))])) (length F_tprog div 2)) stp
  4786     = (0, Bk\<up>m @ Bk # Bk # [], Oc\<up>Suc (rs - 1) @ Bk\<up>l)" by blast
  4754     = (0, Bk\<up>m @ Bk # Bk # [], Oc\<up>Suc (rec_exec rec_F [code tp, (bl2wc (<lm>))]) @ Bk\<up>l)" by blast
  4787   hence "\<exists> m. steps0 (Suc 0, [Bk], <[code tp, bl2wc (<lm>)]> @ Bk\<up>i)
  4755   hence "\<exists> m. steps0 (Suc 0, [Bk], <[code tp, bl2wc (<lm>)]> @ Bk\<up>i)
  4788     (F_tprog @ shift (mopup 2) (length F_tprog div 2)) stp
  4756     (F_tprog @ shift (mopup 2) (length F_tprog div 2)) stp
  4789     = (0, Bk\<up>m, Oc\<up>Suc (rs - 1) @ Bk\<up>l)"
  4757     = (0, Bk\<up>m, Oc\<up>Suc (rs - 1) @ Bk\<up>l)"
  4790   proof -
  4758   proof -
  4791     assume g: "steps0 (Suc 0, [Bk, Bk], <[code tp, bl2wc (<lm>)]> @ Bk \<up> i)
  4759     assume g: "steps0 (Suc 0, [Bk, Bk], <[code tp, bl2wc (<lm>)]> @ Bk \<up> i)
  4792       (F_tprog @ shift (mopup 2) (length F_tprog div 2)) stp =
  4760       (F_tprog @ shift (mopup (length [code tp, bl2wc (<lm>)])) (length F_tprog div 2)) stp =
  4793       (0, Bk \<up> m @ [Bk, Bk], Oc \<up> Suc (rs - 1) @ Bk \<up> l)"
  4761       (0, Bk \<up> m @ [Bk, Bk], Oc \<up> Suc ((rec_exec rec_F [code tp, bl2wc (<lm>)])) @ Bk \<up> l)"
  4794    moreover have "tinres [Bk, Bk] [Bk]"
  4762    moreover have "tinres [Bk, Bk] [Bk]"
  4795      apply(auto simp: tinres_def)
  4763      apply(auto simp: tinres_def)
  4796      done
  4764      done
  4797     moreover obtain sa la ra where "steps0 (Suc 0, [Bk], <[code tp, bl2wc (<lm>)]> @ Bk\<up>i)
  4765     moreover obtain sa la ra where "steps0 (Suc 0, [Bk], <[code tp, bl2wc (<lm>)]> @ Bk\<up>i)
  4798     (F_tprog @ shift (mopup 2) (length F_tprog div 2)) stp = (sa, la, ra)"
  4766     (F_tprog @ shift (mopup 2) (length F_tprog div 2)) stp = (sa, la, ra)"
  4799       apply(case_tac "steps0 (Suc 0, [Bk], <[code tp, bl2wc (<lm>)]> @ Bk\<up>i)
  4767       apply(case_tac "steps0 (Suc 0, [Bk], <[code tp, bl2wc (<lm>)]> @ Bk\<up>i)
  4800     (F_tprog @ shift (mopup 2) (length F_tprog div 2)) stp", auto)
  4768     (F_tprog @ shift (mopup 2) (length F_tprog div 2)) stp", auto)
  4801       done
  4769       done
  4802     ultimately show "?thesis"
  4770     ultimately show "?thesis"
  4803       apply(drule_tac tinres_steps1, auto)
  4771       using b
       
  4772       apply(drule_tac la = "Bk\<up>m @ [Bk, Bk]" in tinres_steps1, auto simp: numeral_2_eq_2)
  4804       done
  4773       done
  4805   qed
  4774   qed
  4806   thus "?thesis"
  4775   thus "?thesis"
  4807     apply(auto)
  4776     apply(auto)
  4808     apply(rule_tac x = stp in exI, simp add: t_utm_def)
  4777     apply(rule_tac x = stp in exI, simp add: t_utm_def)
  4817 apply(rule_tac tm_wf_comp, auto)
  4786 apply(rule_tac tm_wf_comp, auto)
  4818 done
  4787 done
  4819       
  4788       
  4820 lemma [intro]: "tm_wf (t_utm, 0)"
  4789 lemma [intro]: "tm_wf (t_utm, 0)"
  4821 apply(simp only: t_utm_def F_tprog_def)
  4790 apply(simp only: t_utm_def F_tprog_def)
  4822 apply(rule_tac t_compiled_correct, auto)
  4791 apply(rule_tac wf_tm_from_abacus, auto)
  4823 done 
  4792 done 
  4824 
  4793 
  4825 lemma UTM_halt_lemma_pre: 
  4794 lemma UTM_halt_lemma_pre: 
  4826   assumes wf_tm: "tm_wf (tp, 0)"
  4795   assumes wf_tm: "tm_wf (tp, 0)"
  4827   and result: "0 < rs"
  4796   and result: "0 < rs"
  4991 done
  4960 done
  4992 
  4961 
  4993 lemma nonstop_true:
  4962 lemma nonstop_true:
  4994   "\<lbrakk>tm_wf (tp, 0);
  4963   "\<lbrakk>tm_wf (tp, 0);
  4995   \<forall> stp. (\<not> TSTD (steps0 (Suc 0, Bk\<up>(l), <lm>) tp stp))\<rbrakk>
  4964   \<forall> stp. (\<not> TSTD (steps0 (Suc 0, Bk\<up>(l), <lm>) tp stp))\<rbrakk>
  4996   \<Longrightarrow> \<forall>y. rec_calc_rel rec_nonstop 
  4965   \<Longrightarrow> \<forall>y. rec_exec rec_nonstop ([code tp, bl2wc (<lm>), y]) =  (Suc 0)"
  4997   ([code tp, bl2wc (<lm>), y]) (Suc 0)"
       
  4998 apply(rule_tac allI, erule_tac x = y in allE)
  4966 apply(rule_tac allI, erule_tac x = y in allE)
  4999 apply(case_tac "steps0 (Suc 0, Bk\<up>(l), <lm>) tp y", simp)
  4967 apply(case_tac "steps0 (Suc 0, Bk\<up>(l), <lm>) tp y", simp)
  5000 apply(rule_tac nonstop_t_uhalt_eq, simp_all)
  4968 apply(rule_tac nonstop_t_uhalt_eq, simp_all)
  5001 done
  4969 done
  5002 
  4970 
  5003 declare ci_cn_para_eq[simp]
  4971 lemma cn_arity:  "rec_ci (Cn n f gs) = (a, b, c) \<Longrightarrow> b = n"
       
  4972 by(case_tac "rec_ci f", simp add: rec_ci.simps)
       
  4973 
       
  4974 lemma mn_arity: "rec_ci (Mn n f) = (a, b, c) \<Longrightarrow> b = n"
       
  4975 by(case_tac "rec_ci f", simp add: rec_ci.simps)
  5004 
  4976 
  5005 lemma F_aprog_uhalt: 
  4977 lemma F_aprog_uhalt: 
  5006   "\<lbrakk>tm_wf (tp,0); 
  4978   assumes wf_tm: "tm_wf (tp,0)"
  5007     \<forall> stp. (\<not> TSTD (steps0 (Suc 0, Bk\<up>(l), <lm>) tp stp)); 
  4979    and unhalt:  "\<forall> stp. (\<not> TSTD (steps0 (Suc 0, Bk\<up>(l), <lm>) tp stp))"
  5008     rec_ci rec_F = (F_ap, rs_pos, a_md)\<rbrakk>
  4980    and compile: "rec_ci rec_F = (F_ap, rs_pos, a_md)"
  5009   \<Longrightarrow> \<forall> stp. case abc_steps_l (0, [code tp, bl2wc (<lm>)] @ 0\<up>(a_md - rs_pos )
  4981  shows "{\<lambda> nl. nl = [code tp, bl2wc (<lm>)] @ 0\<up>(a_md - rs_pos ) @ suflm} (F_ap) \<up>"
  5010                @ suflm) (F_ap) stp of (ss, e) \<Rightarrow> ss < length (F_ap)"
  4982   using compile
  5011 apply(case_tac "rec_ci (Cn (Suc (Suc 0)) rec_right [Cn (Suc (Suc 0)) rec_conf 
  4983 proof(simp only: rec_F_def)
  5012                ([id (Suc (Suc 0)) 0, id (Suc (Suc 0)) (Suc 0), rec_halt])])")
  4984   assume h: "rec_ci (Cn (Suc (Suc 0)) rec_valu [Cn (Suc (Suc 0)) rec_right [Cn (Suc (Suc 0)) 
  5013 apply(simp only: rec_F_def, rule_tac i = 0  and ga = a and gb = b and 
  4985     rec_conf [recf.id (Suc (Suc 0)) 0, recf.id (Suc (Suc 0)) (Suc 0), rec_halt]]]) =
  5014   gc = c in cn_gi_uhalt, simp, simp, simp, simp, simp, simp, simp)
  4986     (F_ap, rs_pos, a_md)"
  5015 apply(simp add: ci_cn_para_eq)
  4987   moreover hence "rs_pos = Suc (Suc 0)"
  5016 apply(case_tac "rec_ci (Cn (Suc (Suc 0)) rec_conf 
  4988     using cn_arity 
  5017   ([id (Suc (Suc 0)) 0, id (Suc (Suc 0)) (Suc 0), rec_halt]))")
  4989     by simp
  5018 apply(rule_tac rf = "(Cn (Suc (Suc 0)) rec_right [Cn (Suc (Suc 0)) rec_conf
  4990   moreover obtain ap1 ar1 ft1 where a: "rec_ci 
  5019               ([id (Suc (Suc 0)) 0, id (Suc (Suc 0)) (Suc 0), rec_halt])])" 
  4991     (Cn (Suc (Suc 0)) rec_right 
  5020            and n = "Suc (Suc 0)" and f = rec_right and 
  4992     [Cn (Suc (Suc 0)) rec_conf [recf.id (Suc (Suc 0)) 0, recf.id (Suc (Suc 0)) (Suc 0), rec_halt]]) = (ap1, ar1, ft1)"
  5021           gs = "[Cn (Suc (Suc 0)) rec_conf 
  4993     by(case_tac "rec_ci (Cn (Suc (Suc 0)) rec_right [Cn (Suc (Suc 0)) 
  5022            ([id (Suc (Suc 0)) 0, id (Suc (Suc 0)) (Suc 0), rec_halt])]"
  4994       rec_conf [recf.id (Suc (Suc 0)) 0, recf.id (Suc (Suc 0)) (Suc 0), rec_halt]])", auto)
  5023            and i = 0 and ga = aa and gb = ba and gc = ca in 
  4995   moreover hence b: "ar1 = Suc (Suc 0)"
  5024           cn_gi_uhalt)
  4996     using cn_arity by simp
  5025 apply(simp, simp, simp, simp, simp, simp, simp, 
  4997   ultimately show "?thesis"
  5026      simp add: ci_cn_para_eq)
  4998   proof(rule_tac i = 0 in cn_unhalt_case, auto)
  5027 apply(case_tac "rec_ci rec_halt")
  4999     fix anything
  5028 apply(rule_tac rf = "(Cn (Suc (Suc 0)) rec_conf 
  5000     obtain ap2 ar2 ft2 where c: 
  5029   ([id (Suc (Suc 0)) 0, id (Suc (Suc 0)) (Suc 0), rec_halt]))" 
  5001       "rec_ci (Cn (Suc (Suc 0)) rec_conf [recf.id (Suc (Suc 0)) 0, recf.id (Suc (Suc 0)) (Suc 0), rec_halt])
  5030   and n = "Suc (Suc 0)" and f = "rec_conf" and 
  5002       = (ap2, ar2, ft2)" 
  5031   gs = "([id (Suc (Suc 0)) 0, id (Suc (Suc 0)) (Suc 0), rec_halt])"  and 
  5003       by(case_tac "rec_ci (Cn (Suc (Suc 0)) rec_conf
  5032   i = "Suc (Suc 0)" and gi = "rec_halt" and ga = ab and gb = bb and
  5004         [recf.id (Suc (Suc 0)) 0, recf.id (Suc (Suc 0)) (Suc 0), rec_halt])", auto)
  5033   gc = cb in cn_gi_uhalt)
  5005     moreover hence d:"ar2 = Suc (Suc 0)"
  5034 apply(simp, simp, simp, simp, simp add: nth_append, simp, 
  5006       using cn_arity by simp
  5035   simp add: nth_append, simp add: rec_halt_def)
  5007     ultimately have "{\<lambda>nl. nl = [code tp, bl2wc (<lm>)] @ 0 \<up> (ft1 - Suc (Suc 0)) @ anything} ap1 \<up>"
  5036 apply(simp only: rec_halt_def)
  5008       using a b c d
  5037 apply(case_tac [!] "rec_ci ((rec_nonstop))")
  5009     proof(rule_tac i = 0 in cn_unhalt_case, auto)
  5038 apply(rule_tac allI, rule_tac impI, simp)
  5010       fix anything
  5039 apply(case_tac j, simp)
  5011       obtain ap3 ar3 ft3 where e: "rec_ci rec_halt = (ap3, ar3, ft3)"
  5040 apply(rule_tac x = "code tp" in exI, rule_tac calc_id, simp, simp, simp, simp)
  5012         by(case_tac "rec_ci rec_halt", auto)
  5041 apply(rule_tac x = "bl2wc (<lm>)" in exI, rule_tac calc_id, simp, simp, simp)
  5013       hence f: "ar3 = Suc (Suc 0)"
  5042 apply(rule_tac rf = "Mn (Suc (Suc 0)) (rec_nonstop)"
  5014         using mn_arity
  5043   and f = "(rec_nonstop)" and n = "Suc (Suc 0)"
  5015         by(simp add: rec_halt_def)
  5044   and  aprog' = ac and rs_pos' =  bc and a_md' = cc in Mn_unhalt)
  5016       have "{\<lambda>nl. nl = [code tp, bl2wc (<lm>)] @ 0 \<up> (ft2 - Suc (Suc 0)) @ anything} ap2 \<up>"
  5045 apply(simp, simp add: rec_halt_def , simp, simp)
  5017         using c d e f
  5046 apply(drule_tac  nonstop_true, simp_all)
  5018       proof(rule_tac i = 2 in cn_unhalt_case, auto simp: rec_halt_def)
  5047 apply(rule_tac allI)
  5019         fix anything
  5048 apply(erule_tac x = y in allE)+
  5020         have "{\<lambda>nl. nl = [code tp, bl2wc (<lm>)] @ 0 \<up> (ft3 - Suc (Suc 0)) @ anything} ap3 \<up>"
  5049 apply(simp)
  5021           using e f
  5050 done
  5022         proof(rule_tac mn_unhalt_case, auto simp: rec_halt_def)
       
  5023           fix i
       
  5024           show "terminate rec_nonstop [code tp, bl2wc (<lm>), i]"
       
  5025             by(rule_tac primerec_terminate, auto)
       
  5026         next
       
  5027           fix i
       
  5028           show "0 < rec_exec rec_nonstop [code tp, bl2wc (<lm>), i]"
       
  5029             using assms
       
  5030             by(drule_tac nonstop_true, auto)
       
  5031         qed
       
  5032         thus "{\<lambda>nl. nl = code tp # bl2wc (<lm>) # 0 \<up> (ft3 - Suc (Suc 0)) @ anything} ap3 \<up>" by simp
       
  5033       next
       
  5034         fix apj arj ftj j  anything
       
  5035         assume "j<2" "rec_ci ([recf.id (Suc (Suc 0)) 0, recf.id (Suc (Suc 0)) (Suc 0), Mn (Suc (Suc 0)) rec_nonstop] ! j) = (apj, arj, ftj)"
       
  5036         hence "{\<lambda>nl. nl = [code tp, bl2wc (<lm>)] @ 0 \<up> (ftj - arj) @ anything} apj
       
  5037           {\<lambda>nl. nl = [code tp, bl2wc (<lm>)] @
       
  5038             rec_exec ([recf.id (Suc (Suc 0)) 0, recf.id (Suc (Suc 0)) (Suc 0), Mn (Suc (Suc 0)) rec_nonstop] ! j) [code tp, bl2wc (<lm>)] # 
       
  5039                0 \<up> (ftj - Suc arj) @ anything}"
       
  5040           apply(rule_tac recursive_compile_correct)
       
  5041           apply(case_tac j, auto)
       
  5042           apply(rule_tac [!] primerec_terminate)
       
  5043           by(auto)
       
  5044         thus "{\<lambda>nl. nl = code tp # bl2wc (<lm>) # 0 \<up> (ftj - arj) @ anything} apj
       
  5045           {\<lambda>nl. nl = code tp # bl2wc (<lm>) # rec_exec ([recf.id (Suc (Suc 0)) 0, recf.id (Suc (Suc 0))
       
  5046           (Suc 0), Mn (Suc (Suc 0)) rec_nonstop] ! j) [code tp, bl2wc (<lm>)] # 0 \<up> (ftj - Suc arj) @ anything}"
       
  5047           by simp
       
  5048       next
       
  5049         fix j
       
  5050         assume "(j::nat) < 2"
       
  5051         thus "terminate ([recf.id (Suc (Suc 0)) 0, recf.id (Suc (Suc 0)) (Suc 0), Mn (Suc (Suc 0)) rec_nonstop] ! j)
       
  5052           [code tp, bl2wc (<lm>)]"
       
  5053           by(case_tac j, auto intro!: primerec_terminate)
       
  5054       qed
       
  5055       thus "{\<lambda>nl. nl = code tp # bl2wc (<lm>) # 0 \<up> (ft2 - Suc (Suc 0)) @ anything} ap2 \<up>"
       
  5056         by simp
       
  5057     qed
       
  5058     thus "{\<lambda>nl. nl = code tp # bl2wc (<lm>) # 0 \<up> (ft1 - Suc (Suc 0)) @ anything} ap1 \<up>" by simp
       
  5059   qed
       
  5060 qed
  5051 
  5061 
  5052 lemma uabc_uhalt': 
  5062 lemma uabc_uhalt': 
  5053   "\<lbrakk>tm_wf (tp, 0);
  5063   "\<lbrakk>tm_wf (tp, 0);
  5054   \<forall> stp. (\<not> TSTD (steps0 (Suc 0, Bk\<up>(l), <lm>) tp stp));
  5064   \<forall> stp. (\<not> TSTD (steps0 (Suc 0, Bk\<up>(l), <lm>) tp stp));
  5055   rec_ci rec_F = (ap, pos, md)\<rbrakk>
  5065   rec_ci rec_F = (ap, pos, md)\<rbrakk>
  5056   \<Longrightarrow> \<forall> stp. case abc_steps_l (0, [code tp, bl2wc (<lm>)]) ap stp of (ss, e)
  5066   \<Longrightarrow> {\<lambda> nl. nl = [code tp, bl2wc (<lm>)]} ap \<up>"
  5057            \<Rightarrow>  ss < length ap"
       
  5058 proof(frule_tac F_ap = ap and rs_pos = pos and a_md = md
  5067 proof(frule_tac F_ap = ap and rs_pos = pos and a_md = md
  5059     and suflm = "[]" in F_aprog_uhalt, auto)
  5068     and suflm = "[]" in F_aprog_uhalt, auto simp: abc_Hoare_unhalt_def, 
  5060   fix stp a b
  5069      case_tac "abc_steps_l (0, [code tp, bl2wc (<lm>)]) ap n", simp)
       
  5070   fix n a b
  5061   assume h: 
  5071   assume h: 
  5062     "\<forall>stp. case abc_steps_l (0, code tp # bl2wc (<lm>) # 0\<up>(md - pos)) ap stp of 
  5072     "\<forall>n. abc_notfinal (abc_steps_l (0, code tp # bl2wc (<lm>) # 0 \<up> (md - pos)) ap n) ap"
  5063     (ss, e) \<Rightarrow> ss < length ap"
  5073     "abc_steps_l (0, [code tp, bl2wc (<lm>)]) ap n = (a, b)" 
  5064     "abc_steps_l (0, [code tp, bl2wc (<lm>)]) ap stp = (a, b)" 
       
  5065     "tm_wf (tp, 0)" 
  5074     "tm_wf (tp, 0)" 
  5066     "rec_ci rec_F = (ap, pos, md)"
  5075     "rec_ci rec_F = (ap, pos, md)"
  5067   moreover have "ap \<noteq> []"
  5076   moreover have a: "ap \<noteq> []"
  5068     using h apply(rule_tac rec_ci_not_null, simp)
  5077     using h rec_ci_not_null[of "rec_F" pos md] by auto
  5069     done
       
  5070   ultimately show "a < length ap"
  5078   ultimately show "a < length ap"
  5071   proof(erule_tac x = stp in allE,
  5079   proof(erule_tac x = n in allE)
  5072   case_tac "abc_steps_l (0, code tp # bl2wc (<lm>) # 0\<up>(md - pos)) ap stp", simp)
  5080     assume g: "abc_notfinal (abc_steps_l (0, code tp # bl2wc (<lm>) # 0 \<up> (md - pos)) ap n) ap"
  5073     fix aa ba
  5081     obtain ss nl where b : "abc_steps_l (0, code tp # bl2wc (<lm>) # 0 \<up> (md - pos)) ap n = (ss, nl)"
  5074     assume g: "aa < length ap" 
  5082       by (metis prod.exhaust)
  5075       "abc_steps_l (0, code tp # bl2wc (<lm>) # 0\<up>(md - pos)) ap stp = (aa, ba)" 
  5083     then have c: "ss < length ap"
  5076       "ap \<noteq> []"
  5084       using g by simp
  5077     thus "?thesis"
  5085     thus "?thesis"
       
  5086       using a b c
  5078       using abc_list_crsp_steps[of "[code tp, bl2wc (<lm>)]"
  5087       using abc_list_crsp_steps[of "[code tp, bl2wc (<lm>)]"
  5079                                    "md - pos" ap stp aa ba] h
  5088                                    "md - pos" ap n ss nl] h
  5080       apply(simp)
  5089       by(simp)
  5081       done
       
  5082   qed
  5090   qed
  5083 qed
  5091 qed
  5084 
  5092 
  5085 lemma uabc_uhalt: 
  5093 lemma uabc_uhalt: 
  5086   "\<lbrakk>tm_wf (tp, 0); 
  5094   "\<lbrakk>tm_wf (tp, 0); 
  5087   \<forall> stp. (\<not> TSTD (steps0 (Suc 0, Bk\<up>(l), <lm>) tp stp))\<rbrakk>
  5095   \<forall> stp. (\<not> TSTD (steps0 (Suc 0, Bk\<up>(l), <lm>) tp stp))\<rbrakk>
  5088   \<Longrightarrow> \<forall> stp. case abc_steps_l (0, [code tp, bl2wc (<lm>)]) F_aprog 
  5096   \<Longrightarrow> {\<lambda> nl. nl = [code tp, bl2wc (<lm>)]} F_aprog \<up> "
  5089        stp of (ss, e) \<Rightarrow> ss < length F_aprog"
       
  5090 apply(case_tac "rec_ci rec_F", simp add: F_aprog_def)
  5097 apply(case_tac "rec_ci rec_F", simp add: F_aprog_def)
  5091 apply(drule_tac ap = a and pos = b and md = c in uabc_uhalt', simp_all)
  5098 apply(drule_tac ap = a and pos = b and md = c in uabc_uhalt', simp_all)
  5092 proof -
  5099 apply(rule_tac abc_Hoare_plus_unhalt1, simp)
  5093   fix a b c
  5100 done
  5094   assume 
       
  5095     "\<forall>stp. case abc_steps_l (0, [code tp, bl2wc (<lm>)]) a stp of (ss, e) 
       
  5096                                                    \<Rightarrow> ss < length a"
       
  5097     "rec_ci rec_F = (a, b, c)"
       
  5098   thus 
       
  5099     "\<forall>stp. case abc_steps_l (0, [code tp, bl2wc (<lm>)]) 
       
  5100     (a [+] dummy_abc (Suc (Suc 0))) stp of (ss, e) \<Rightarrow> 
       
  5101            ss < Suc (Suc (Suc (length a)))"
       
  5102     using abc_append_uhalt1[of a "[code tp, bl2wc (<lm>)]" 
       
  5103       "a [+] dummy_abc (Suc (Suc 0))" "[]" "dummy_abc (Suc (Suc 0))"]  
       
  5104     apply(simp)
       
  5105     done
       
  5106 qed
       
  5107 
  5101 
  5108 lemma tutm_uhalt': 
  5102 lemma tutm_uhalt': 
  5109 assumes tm_wf:  "tm_wf (tp,0)"
  5103 assumes tm_wf:  "tm_wf (tp,0)"
  5110   and unhalt: "\<forall> stp. (\<not> TSTD (steps0 (1, Bk\<up>(l), <lm>) tp stp))"
  5104   and unhalt: "\<forall> stp. (\<not> TSTD (steps0 (1, Bk\<up>(l), <lm>) tp stp))"
  5111   shows "\<forall> stp. \<not> is_final (steps0 (1, [Bk, Bk], <[code tp, bl2wc (<lm>)]>) t_utm stp)"
  5105   shows "\<forall> stp. \<not> is_final (steps0 (1, [Bk, Bk], <[code tp, bl2wc (<lm>)]>) t_utm stp)"
  5112 unfolding t_utm_def
  5106 unfolding t_utm_def
  5113 proof(rule_tac compile_correct_unhalt)
  5107 proof(rule_tac compile_correct_unhalt, auto)
  5114   show "layout_of F_aprog = layout_of F_aprog" by simp
       
  5115 next
       
  5116   show "F_tprog = tm_of F_aprog"
  5108   show "F_tprog = tm_of F_aprog"
  5117     by(simp add:  F_tprog_def)
  5109     by(simp add:  F_tprog_def)
  5118 next
  5110 next
  5119   show "crsp (layout_of F_aprog) (0, [code tp, bl2wc (<lm>)]) (1, [Bk, Bk], <[code tp, bl2wc (<lm>)]>)  []"
  5111   show "crsp (layout_of F_aprog) (0, [code tp, bl2wc (<lm>)]) (Suc 0, [Bk, Bk], <[code tp, bl2wc (<lm>)]>)  []"
  5120     by(auto simp: crsp.simps start_of.simps)
  5112     by(auto simp: crsp.simps start_of.simps)
  5121 next
  5113 next
  5122   show "length F_tprog div 2 = length F_tprog div 2" by simp
  5114   fix stp a b
  5123 next
  5115   show "abc_steps_l (0, [code tp, bl2wc (<lm>)]) F_aprog stp = (a, b) \<Longrightarrow> a < length F_aprog"
  5124   show "\<forall>stp. case abc_steps_l (0, [code tp, bl2wc (<lm>)]) F_aprog stp of (as, am) \<Rightarrow> as < length F_aprog"
       
  5125     using assms
  5116     using assms
  5126     apply(erule_tac uabc_uhalt, simp)
  5117     apply(drule_tac uabc_uhalt, auto simp: abc_Hoare_unhalt_def)
  5127     done
  5118     by(erule_tac x = stp in allE, erule_tac x = stp in allE, simp) 
  5128 qed
  5119 qed
  5129 
  5120 
  5130  
       
  5131 lemma tinres_commute: "tinres r r' \<Longrightarrow> tinres r' r"
  5121 lemma tinres_commute: "tinres r r' \<Longrightarrow> tinres r' r"
  5132 apply(auto simp: tinres_def)
  5122 apply(auto simp: tinres_def)
  5133 done
  5123 done
  5134 
  5124 
  5135 lemma inres_tape:
  5125 lemma inres_tape:
  5164 apply(drule_tac inres_tape, auto)
  5154 apply(drule_tac inres_tape, auto)
  5165 apply(auto simp: tinres_def)
  5155 apply(auto simp: tinres_def)
  5166 apply(case_tac "m > Suc (Suc 0)")
  5156 apply(case_tac "m > Suc (Suc 0)")
  5167 apply(rule_tac x = "m - Suc (Suc 0)" in exI) 
  5157 apply(rule_tac x = "m - Suc (Suc 0)" in exI) 
  5168 apply(case_tac m, simp_all add: , case_tac nat, simp_all add: replicate_Suc)
  5158 apply(case_tac m, simp_all add: , case_tac nat, simp_all add: replicate_Suc)
  5169 apply(rule_tac x = "2 - m" in exI, simp add: exp_add[THEN sym])
  5159 apply(rule_tac x = "2 - m" in exI, simp add: replicate_add[THEN sym])
  5170 apply(simp only: numeral_2_eq_2, simp add: replicate_Suc)
  5160 apply(simp only: numeral_2_eq_2, simp add: replicate_Suc)
  5171 done
  5161 done
  5172 
  5162 
  5173 lemma tutm_uhalt: 
  5163 lemma tutm_uhalt: 
  5174   "\<lbrakk>tm_wf (tp,0);
  5164   "\<lbrakk>tm_wf (tp,0);
  5328   shows "{(\<lambda>tp. tp = ([], <code p # args>))} UTM \<up>"
  5318   shows "{(\<lambda>tp. tp = ([], <code p # args>))} UTM \<up>"
  5329 using UTM_unhalt_lemma[OF assms(1), where i="0"]
  5319 using UTM_unhalt_lemma[OF assms(1), where i="0"]
  5330 using assms(2-3)
  5320 using assms(2-3)
  5331 apply(simp add: tape_of_nat_abv)
  5321 apply(simp add: tape_of_nat_abv)
  5332 done
  5322 done
       
  5323 
  5333 end                               
  5324 end