thys/UTM.thy
changeset 139 7cb94089324e
parent 133 ca7fb6848715
child 145 38d8e0e37b7d
equal deleted inserted replaced
138:7fa1b8e88d76 139:7cb94089324e
  1233   thus "?thesis"
  1233   thus "?thesis"
  1234     apply(simp add: tape_of_nl_abv tape_of_nat_list.simps tape_of_nat_abv)
  1234     apply(simp add: tape_of_nl_abv tape_of_nat_list.simps tape_of_nat_abv)
  1235     done
  1235     done
  1236 qed
  1236 qed
  1237 
  1237 
       
  1238 declare adjust.simps[simp]
  1238 
  1239 
  1239 lemma adjust_fetch0: 
  1240 lemma adjust_fetch0: 
  1240   "\<lbrakk>0 < a; a \<le> length ap div 2;  fetch ap a b = (aa, 0)\<rbrakk>
  1241   "\<lbrakk>0 < a; a \<le> length ap div 2;  fetch ap a b = (aa, 0)\<rbrakk>
  1241   \<Longrightarrow> fetch (adjust ap) a b = (aa, Suc (length ap div 2))"
  1242   \<Longrightarrow> fetch (adjust ap) a b = (aa, Suc (length ap div 2))"
  1242 apply(case_tac b, auto simp: fetch.simps nth_of.simps nth_map
  1243 apply(case_tac b, auto simp: fetch.simps nth_of.simps nth_map
  1249  \<Longrightarrow>  fetch (turing_basic.adjust ap) st b = (aa, ns)"
  1250  \<Longrightarrow>  fetch (turing_basic.adjust ap) st b = (aa, ns)"
  1250  apply(case_tac b, auto simp: fetch.simps nth_of.simps nth_map
  1251  apply(case_tac b, auto simp: fetch.simps nth_of.simps nth_map
  1251                        split: if_splits)
  1252                        split: if_splits)
  1252 apply(case_tac [!] st, auto simp: fetch.simps nth_of.simps)
  1253 apply(case_tac [!] st, auto simp: fetch.simps nth_of.simps)
  1253 done
  1254 done
       
  1255 
       
  1256 declare adjust.simps[simp del]
  1254 
  1257 
  1255 lemma adjust_step_eq: 
  1258 lemma adjust_step_eq: 
  1256   assumes exec: "step0 (st,l,r) ap = (st', l', r')"
  1259   assumes exec: "step0 (st,l,r) ap = (st', l', r')"
  1257   and wf_tm: "tm_wf (ap, 0)"
  1260   and wf_tm: "tm_wf (ap, 0)"
  1258   and notfinal: "st' > 0"
  1261   and notfinal: "st' > 0"
  1264     by(case_tac st, simp_all add: step.simps fetch.simps)
  1267     by(case_tac st, simp_all add: step.simps fetch.simps)
  1265   moreover hence "st \<le> (length ap) div 2"
  1268   moreover hence "st \<le> (length ap) div 2"
  1266     using assms
  1269     using assms
  1267     apply(case_tac "st \<le> (length ap) div 2", simp)
  1270     apply(case_tac "st \<le> (length ap) div 2", simp)
  1268     apply(case_tac st, auto simp: step.simps fetch.simps)
  1271     apply(case_tac st, auto simp: step.simps fetch.simps)
  1269     apply(case_tac "read r", simp_all add: fetch.simps nth_of.simps)
  1272     apply(case_tac "read r", simp_all add: fetch.simps 
  1270     done   
  1273       nth_of.simps adjust.simps tm_wf.simps split: if_splits)
       
  1274     apply(auto simp: mod_ex2)
       
  1275     done    
  1271   ultimately have "fetch (adjust ap) st (read r) = fetch ap st (read r)"
  1276   ultimately have "fetch (adjust ap) st (read r) = fetch ap st (read r)"
  1272     using assms
  1277     using assms
  1273     apply(case_tac "fetch ap st (read r)")
  1278     apply(case_tac "fetch ap st (read r)")
  1274     apply(drule_tac adjust_fetch_norm, simp_all)
  1279     apply(drule_tac adjust_fetch_norm, simp_all)
  1275     apply(simp add: step.simps)
  1280     apply(simp add: step.simps)
  2023       using h
  2028       using h
  2024       apply(simp add: abc_fourtimes_def)
  2029       apply(simp add: abc_fourtimes_def)
  2025       done
  2030       done
  2026   qed
  2031   qed
  2027   thus "?thesis"
  2032   thus "?thesis"
  2028     apply(simp add: tape_of_nl_abv tape_of_nat_list.simps)
  2033     apply(simp add: tape_of_nl_abv tape_of_nat_list.simps tape_of_nat_abv)
  2029     done
  2034     done
  2030 qed
  2035 qed
  2031 
  2036 
  2032 lemma wf_fourtimes[intro]: "tm_wf (t_fourtimes_compile, 0)"
  2037 lemma wf_fourtimes[intro]: "tm_wf (t_fourtimes_compile, 0)"
  2033 apply(simp only: t_fourtimes_compile_def)
  2038 apply(simp only: t_fourtimes_compile_def)
  2955 done
  2960 done
  2956 
  2961 
  2957 lemma [simp]: "\<lbrakk>wprepare_add_one m lm (b, Bk # list)\<rbrakk> \<Longrightarrow> list \<noteq> []"
  2962 lemma [simp]: "\<lbrakk>wprepare_add_one m lm (b, Bk # list)\<rbrakk> \<Longrightarrow> list \<noteq> []"
  2958 apply(simp only: wprepare_invs)
  2963 apply(simp only: wprepare_invs)
  2959 apply(case_tac lm, simp_all add: tape_of_nl_abv 
  2964 apply(case_tac lm, simp_all add: tape_of_nl_abv 
  2960                          tape_of_nat_list.simps, auto)
  2965                          tape_of_nat_list.simps tape_of_nat_abv, auto)
  2961 done
  2966 done
  2962     
  2967     
  2963 lemma [simp]: "\<lbrakk>lm \<noteq> [];  wprepare_goto_first_end m lm (b, Bk # list)\<rbrakk> \<Longrightarrow> list \<noteq> []"
  2968 lemma [simp]: "\<lbrakk>lm \<noteq> [];  wprepare_goto_first_end m lm (b, Bk # list)\<rbrakk> \<Longrightarrow> list \<noteq> []"
  2964 apply(simp only: wprepare_invs, auto)
  2969 apply(simp only: wprepare_invs, auto)
  2965 apply(case_tac mr, simp_all)
  2970 apply(case_tac mr, simp_all)
  2978 done
  2983 done
  2979 
  2984 
  2980 lemma [simp]: "\<lbrakk>lm \<noteq> [];  wprepare_goto_start_pos m lm (b, Bk # list)\<rbrakk> \<Longrightarrow> list \<noteq> []"
  2985 lemma [simp]: "\<lbrakk>lm \<noteq> [];  wprepare_goto_start_pos m lm (b, Bk # list)\<rbrakk> \<Longrightarrow> list \<noteq> []"
  2981 apply(simp only: wprepare_invs, auto)
  2986 apply(simp only: wprepare_invs, auto)
  2982 apply(case_tac lm, simp, case_tac list)
  2987 apply(case_tac lm, simp, case_tac list)
  2983 apply(simp_all add: tape_of_nl_abv tape_of_nat_list.simps)
  2988 apply(simp_all add: tape_of_nl_abv tape_of_nat_list.simps tape_of_nat_abv)
  2984 done
  2989 done
  2985 
  2990 
  2986 lemma [simp]: "\<lbrakk>lm \<noteq> [];  wprepare_goto_start_pos m lm (b, Bk # list)\<rbrakk> \<Longrightarrow> b \<noteq> []"
  2991 lemma [simp]: "\<lbrakk>lm \<noteq> [];  wprepare_goto_start_pos m lm (b, Bk # list)\<rbrakk> \<Longrightarrow> b \<noteq> []"
  2987 apply(simp only: wprepare_invs)
  2992 apply(simp only: wprepare_invs)
  2988 apply(auto)
  2993 apply(auto)
  3053 lemma tape_of_nl_false1:
  3058 lemma tape_of_nl_false1:
  3054   "lm \<noteq> [] \<Longrightarrow> rev b @ [Bk] \<noteq> Bk\<up>(ln) @ Oc # Oc\<up>(m) @ Bk # Bk # <lm::nat list>"
  3059   "lm \<noteq> [] \<Longrightarrow> rev b @ [Bk] \<noteq> Bk\<up>(ln) @ Oc # Oc\<up>(m) @ Bk # Bk # <lm::nat list>"
  3055 apply(auto)
  3060 apply(auto)
  3056 apply(drule_tac rev_equal_iff, simp add: tape_of_nl_rev)
  3061 apply(drule_tac rev_equal_iff, simp add: tape_of_nl_rev)
  3057 apply(case_tac "rev lm")
  3062 apply(case_tac "rev lm")
  3058 apply(case_tac [2] list, auto simp: tape_of_nl_abv tape_of_nat_list.simps )
  3063 apply(case_tac [2] list, auto simp: tape_of_nl_abv tape_of_nat_list.simps tape_of_nat_abv)
  3059 done
  3064 done
  3060 
  3065 
  3061 lemma [simp]: "wprepare_loop_start_in_middle m lm (b, [Bk]) = False"
  3066 lemma [simp]: "wprepare_loop_start_in_middle m lm (b, [Bk]) = False"
  3062 apply(simp add: wprepare_loop_start_in_middle.simps, auto)
  3067 apply(simp add: wprepare_loop_start_in_middle.simps, auto)
  3063 apply(case_tac mr, simp_all add: )
  3068 apply(case_tac mr, simp_all add: )
  3086 
  3091 
  3087 lemma [simp]: "wprepare_loop_start_on_rightmost m lm (b, Bk # a # lista)
  3092 lemma [simp]: "wprepare_loop_start_on_rightmost m lm (b, Bk # a # lista)
  3088  \<Longrightarrow> wprepare_loop_goon_in_middle m lm (Bk # b, a # lista) = False"
  3093  \<Longrightarrow> wprepare_loop_goon_in_middle m lm (Bk # b, a # lista) = False"
  3089 apply(auto simp: wprepare_loop_start_on_rightmost.simps
  3094 apply(auto simp: wprepare_loop_start_on_rightmost.simps
  3090                  wprepare_loop_goon_in_middle.simps)
  3095                  wprepare_loop_goon_in_middle.simps)
  3091 apply(case_tac [!] mr, simp_all)
       
  3092 done
  3096 done
  3093 
  3097 
  3094 lemma [simp]: "\<lbrakk>lm \<noteq> []; wprepare_loop_start_on_rightmost m lm (b, Bk # a # lista)\<rbrakk>
  3098 lemma [simp]: "\<lbrakk>lm \<noteq> []; wprepare_loop_start_on_rightmost m lm (b, Bk # a # lista)\<rbrakk>
  3095     \<Longrightarrow> wprepare_loop_goon_on_rightmost m lm (Bk # b, a # lista)"
  3099     \<Longrightarrow> wprepare_loop_goon_on_rightmost m lm (Bk # b, a # lista)"
  3096 apply(simp only: wprepare_loop_start_on_rightmost.simps
  3100 apply(simp only: wprepare_loop_start_on_rightmost.simps
  3121 apply(rule_tac x = rn in exI, simp)
  3125 apply(rule_tac x = rn in exI, simp)
  3122 apply(case_tac mr, simp_all add: )
  3126 apply(case_tac mr, simp_all add: )
  3123 apply(case_tac lm1, simp)
  3127 apply(case_tac lm1, simp)
  3124 apply(rule_tac x = "Suc aa" in exI, simp)
  3128 apply(rule_tac x = "Suc aa" in exI, simp)
  3125 apply(rule_tac x = list in exI)
  3129 apply(rule_tac x = list in exI)
  3126 apply(case_tac list, simp_all add: tape_of_nl_abv tape_of_nat_list.simps)
  3130 apply(case_tac list, simp_all add: tape_of_nl_abv tape_of_nat_list.simps tape_of_nat_abv)
  3127 done
  3131 done
  3128 
  3132 
  3129 lemma [simp]: "\<lbrakk>lm \<noteq> []; wprepare_loop_start m lm (b, Bk # a # lista)\<rbrakk> \<Longrightarrow> 
  3133 lemma [simp]: "\<lbrakk>lm \<noteq> []; wprepare_loop_start m lm (b, Bk # a # lista)\<rbrakk> \<Longrightarrow> 
  3130   wprepare_loop_goon m lm (Bk # b, a # lista)"
  3134   wprepare_loop_goon m lm (Bk # b, a # lista)"
  3131 apply(simp add: wprepare_loop_start.simps 
  3135 apply(simp add: wprepare_loop_start.simps 
  3186 done
  3190 done
  3187 
  3191 
  3188 lemma [simp]: "wprepare_loop_goon_on_rightmost m lm (b, Oc # list) = False"
  3192 lemma [simp]: "wprepare_loop_goon_on_rightmost m lm (b, Oc # list) = False"
  3189 apply(simp add: wprepare_loop_goon_on_rightmost.simps)
  3193 apply(simp add: wprepare_loop_goon_on_rightmost.simps)
  3190 done
  3194 done
       
  3195 
  3191 lemma wprepare_loop1: "\<lbrakk>rev b @ Oc\<up>(mr) =  Oc\<up>(Suc m) @ Bk # Bk # <lm>; 
  3196 lemma wprepare_loop1: "\<lbrakk>rev b @ Oc\<up>(mr) =  Oc\<up>(Suc m) @ Bk # Bk # <lm>; 
  3192          b \<noteq> []; 0 < mr; Oc # list = Oc\<up>(mr) @ Bk\<up>(rn)\<rbrakk>
  3197          b \<noteq> []; 0 < mr; Oc # list = Oc\<up>(mr) @ Bk\<up>(rn)\<rbrakk>
  3193        \<Longrightarrow> wprepare_loop_start_on_rightmost m lm (Oc # b, list)"
  3198        \<Longrightarrow> wprepare_loop_start_on_rightmost m lm (Oc # b, list)"
  3194 apply(simp add: wprepare_loop_start_on_rightmost.simps)
  3199 apply(simp add: wprepare_loop_start_on_rightmost.simps)
  3195 apply(rule_tac x = rn in exI, simp)
  3200 apply(rule_tac x = rn in exI, simp)
  3467                            r =  Bk # Oc # Bk\<up>(ln) @ Bk # Bk # Oc\<up>(bl_bin (<args>)) @ Bk\<up>(rn)))"
  3472                            r =  Bk # Oc # Bk\<up>(ln) @ Bk # Bk # Oc\<up>(bl_bin (<args>)) @ Bk\<up>(rn)))"
  3468   let ?P3 = "\<lambda> tp. False"
  3473   let ?P3 = "\<lambda> tp. False"
  3469   assume h: "args \<noteq> []"
  3474   assume h: "args \<noteq> []"
  3470   have "{?P1} t_wcode_prepare |+| t_wcode_main {?Q2}"
  3475   have "{?P1} t_wcode_prepare |+| t_wcode_main {?Q2}"
  3471   proof(rule_tac Hoare_plus_halt)
  3476   proof(rule_tac Hoare_plus_halt)
  3472     show "?Q1 \<mapsto> ?P2"
       
  3473       by(simp add: assert_imp_def)
       
  3474   next
       
  3475     show "tm_wf (t_wcode_prepare, 0)"
       
  3476       by auto
       
  3477   next
       
  3478     show "{?P1} t_wcode_prepare {?Q1}"
  3477     show "{?P1} t_wcode_prepare {?Q1}"
  3479     proof(rule_tac HoareI, auto)
  3478     proof(rule_tac Hoare_haltI, auto)
  3480       show "\<exists>n. is_final (steps0 (Suc 0, [], <m # args>) t_wcode_prepare n) \<and>
  3479       show "\<exists>n. is_final (steps0 (Suc 0, [], <m # args>) t_wcode_prepare n) \<and>
  3481         wprepare_stop m args holds_for steps0 (Suc 0, [], <m # args>) t_wcode_prepare n"
  3480         wprepare_stop m args holds_for steps0 (Suc 0, [], <m # args>) t_wcode_prepare n"
  3482         using wprepare_correctness[of args m] h
  3481         using wprepare_correctness[of args m] h
  3483         apply(auto)
  3482         apply(auto)
  3484         apply(rule_tac x = n in exI, simp add: wprepare_inv.simps)
  3483         apply(rule_tac x = n in exI, simp add: wprepare_inv.simps)
  3485         done
  3484         done
  3486     qed
  3485     qed
  3487   next
  3486   next
  3488     show "{?P2} t_wcode_main {?Q2}"
  3487     show "{?P2} t_wcode_main {?Q2}"
  3489     proof(rule_tac HoareI, auto)
  3488     proof(rule_tac Hoare_haltI, auto)
  3490       fix l r
  3489       fix l r
  3491       assume "wprepare_stop m args (l, r)"
  3490       assume "wprepare_stop m args (l, r)"
  3492       thus "\<exists>n. is_final (steps0 (Suc 0, l, r) t_wcode_main n) \<and>
  3491       thus "\<exists>n. is_final (steps0 (Suc 0, l, r) t_wcode_main n) \<and>
  3493               (\<lambda>(l, r). l = Bk # Oc # Oc \<up> m \<and> (\<exists>ln rn. r = Bk # Oc # Bk \<up> ln @ 
  3492               (\<lambda>(l, r). l = Bk # Oc # Oc \<up> m \<and> (\<exists>ln rn. r = Bk # Oc # Bk \<up> ln @ 
  3494         Bk # Bk # Oc \<up> bl_bin (<args>) @ Bk \<up> rn)) holds_for steps0 (Suc 0, l, r) t_wcode_main n"
  3493         Bk # Bk # Oc \<up> bl_bin (<args>) @ Bk \<up> rn)) holds_for steps0 (Suc 0, l, r) t_wcode_main n"
  3503           apply(auto simp: tape_of_nl_rev)
  3502           apply(auto simp: tape_of_nl_rev)
  3504           apply(rule_tac x = stp in exI, auto)
  3503           apply(rule_tac x = stp in exI, auto)
  3505           done
  3504           done
  3506       qed
  3505       qed
  3507     qed
  3506     qed
       
  3507   next
       
  3508     show "tm_wf0 t_wcode_prepare"
       
  3509       by auto
  3508   qed
  3510   qed
  3509   thus "?thesis"
  3511   thus "?thesis"
  3510     apply(auto simp: Hoare_def)
  3512     apply(auto simp: Hoare_halt_def)
  3511     apply(rule_tac x = n in exI)
  3513     apply(rule_tac x = n in exI)
  3512     apply(case_tac "(steps0 (Suc 0, [], <m # args>)
  3514     apply(case_tac "(steps0 (Suc 0, [], <m # args>)
  3513       (turing_basic.adjust t_wcode_prepare @ shift t_wcode_main (length t_wcode_prepare div 2)) n)")
  3515       (turing_basic.adjust t_wcode_prepare @ shift t_wcode_main (length t_wcode_prepare div 2)) n)")
  3514     apply(auto simp: tm_comp.simps)
  3516     apply(auto simp: tm_comp.simps)
  3515     done
  3517     done
  3516 qed
  3518 qed
       
  3519 
       
  3520 definition tinres :: "cell list \<Rightarrow> cell list \<Rightarrow> bool"
       
  3521   where
       
  3522   "tinres xs ys = (\<exists>n. xs = ys @ Bk \<up> n \<or> ys = xs @ Bk \<up> n)"
  3517    
  3523    
  3518 lemma [simp]:  "tinres r r' \<Longrightarrow> 
  3524 lemma [simp]:  "tinres r r' \<Longrightarrow> 
  3519   fetch t ss (read r) = 
  3525   fetch t ss (read r) = 
  3520   fetch t ss (read r')"
  3526   fetch t ss (read r')"
  3521 apply(simp add: fetch.simps, auto split: if_splits simp: tinres_def)
  3527 apply(simp add: fetch.simps, auto split: if_splits simp: tinres_def)
  3647 done
  3653 done
  3648 
  3654 
  3649 lemma [simp]: "fetch t_wcode_adjust (Suc (Suc (Suc (Suc 0)))) Oc = (L, 5)"
  3655 lemma [simp]: "fetch t_wcode_adjust (Suc (Suc (Suc (Suc 0)))) Oc = (L, 5)"
  3650 apply(simp add: fetch.simps t_wcode_adjust_def nth_of.simps numeral_4_eq_4)
  3656 apply(simp add: fetch.simps t_wcode_adjust_def nth_of.simps numeral_4_eq_4)
  3651 done
  3657 done
  3652 
       
  3653 thm numeral_5_eq_5
       
  3654 
  3658 
  3655 lemma [simp]: "fetch t_wcode_adjust 5 Oc = (W0, 5)"
  3659 lemma [simp]: "fetch t_wcode_adjust 5 Oc = (W0, 5)"
  3656 apply(simp only: fetch.simps t_wcode_adjust_def nth_of.simps numeral_5_eq_5, simp)
  3660 apply(simp only: fetch.simps t_wcode_adjust_def nth_of.simps numeral_5_eq_5, simp)
  3657 done
  3661 done
  3658 
  3662 
  4531   assume h: "args \<noteq> []"
  4535   assume h: "args \<noteq> []"
  4532   hence a: "bl_bin (<args>) > 0"
  4536   hence a: "bl_bin (<args>) > 0"
  4533     using h by simp
  4537     using h by simp
  4534   hence "{?P1} (t_wcode_prepare |+| t_wcode_main) |+| t_wcode_adjust {?Q2}"
  4538   hence "{?P1} (t_wcode_prepare |+| t_wcode_main) |+| t_wcode_adjust {?Q2}"
  4535   proof(rule_tac Hoare_plus_halt)
  4539   proof(rule_tac Hoare_plus_halt)
  4536     show "?Q1 \<mapsto> ?P2"
       
  4537       by(simp add: assert_imp_def)
       
  4538   next
  4540   next
  4539     show "tm_wf (t_wcode_prepare |+| t_wcode_main, 0)"
  4541     show "tm_wf (t_wcode_prepare |+| t_wcode_main, 0)"
  4540       apply(rule_tac tm_wf_comp, auto)
  4542       apply(rule_tac tm_wf_comp, auto)
  4541       done
  4543       done
  4542   next
  4544   next
  4543     show "{?P1} t_wcode_prepare |+| t_wcode_main {?Q1}"
  4545     show "{?P1} t_wcode_prepare |+| t_wcode_main {?Q1}"
  4544     proof(rule_tac HoareI, auto)
  4546     proof(rule_tac Hoare_haltI, auto)
  4545       show 
  4547       show 
  4546         "\<exists>n. is_final (steps0 (Suc 0, [], <m # args>) (t_wcode_prepare |+| t_wcode_main) n) \<and>
  4548         "\<exists>n. is_final (steps0 (Suc 0, [], <m # args>) (t_wcode_prepare |+| t_wcode_main) n) \<and>
  4547         (\<lambda>(l, r). l = Bk # Oc # Oc \<up> m \<and>
  4549         (\<lambda>(l, r). l = Bk # Oc # Oc \<up> m \<and>
  4548         (\<exists>ln rn. r = Bk # Oc # Bk \<up> ln @ Bk # Bk # Oc \<up> bl_bin (<args>) @ Bk \<up> rn))
  4550         (\<exists>ln rn. r = Bk # Oc # Bk \<up> ln @ Bk # Bk # Oc \<up> bl_bin (<args>) @ Bk \<up> rn))
  4549         holds_for steps0 (Suc 0, [], <m # args>) (t_wcode_prepare |+| t_wcode_main) n"
  4551         holds_for steps0 (Suc 0, [], <m # args>) (t_wcode_prepare |+| t_wcode_main) n"
  4553         apply(rule_tac x = ln in exI, auto)
  4555         apply(rule_tac x = ln in exI, auto)
  4554         done
  4556         done
  4555     qed
  4557     qed
  4556   next
  4558   next
  4557     show "{?P2} t_wcode_adjust {?Q2}"
  4559     show "{?P2} t_wcode_adjust {?Q2}"
  4558     proof(rule_tac HoareI, auto del: replicate_Suc)
  4560     proof(rule_tac Hoare_haltI, auto del: replicate_Suc)
  4559       fix ln rn
  4561       fix ln rn
  4560       show "\<exists>n. is_final (steps0 (Suc 0, Bk # Oc # Oc \<up> m, 
  4562       show "\<exists>n. is_final (steps0 (Suc 0, Bk # Oc # Oc \<up> m, 
  4561         Bk # Oc # Bk \<up> ln @ Bk # Bk # Oc \<up> bl_bin (<args>) @ Bk \<up> rn) t_wcode_adjust n) \<and>
  4563         Bk # Oc # Bk \<up> ln @ Bk # Bk # Oc \<up> bl_bin (<args>) @ Bk \<up> rn) t_wcode_adjust n) \<and>
  4562         wadjust_stop m (bl_bin (<args>) - Suc 0) holds_for steps0
  4564         wadjust_stop m (bl_bin (<args>) - Suc 0) holds_for steps0
  4563         (Suc 0, Bk # Oc # Oc \<up> m, Bk # Oc # Bk \<up> ln @ Bk # Bk # Oc \<up> bl_bin (<args>) @ Bk \<up> rn) t_wcode_adjust n"
  4565         (Suc 0, Bk # Oc # Oc \<up> m, Bk # Oc # Bk \<up> ln @ Bk # Bk # Oc \<up> bl_bin (<args>) @ Bk \<up> rn) t_wcode_adjust n"
  4568         apply(case_tac "bl_bin (<args>)", simp, simp del: replicate_Suc add: exp_ind wadjust_inv.simps)
  4570         apply(case_tac "bl_bin (<args>)", simp, simp del: replicate_Suc add: exp_ind wadjust_inv.simps)
  4569         done
  4571         done
  4570     qed
  4572     qed
  4571   qed
  4573   qed
  4572   thus "?thesis"
  4574   thus "?thesis"
  4573     apply(simp add: Hoare_def, auto)
  4575     apply(simp add: Hoare_halt_def, auto)
  4574     apply(case_tac "(steps0 (Suc 0, [], <(m::nat) # args>) 
  4576     apply(case_tac "(steps0 (Suc 0, [], <(m::nat) # args>) 
  4575       ((t_wcode_prepare |+| t_wcode_main) |+| t_wcode_adjust) n)")
  4577       ((t_wcode_prepare |+| t_wcode_main) |+| t_wcode_adjust) n)")
  4576     apply(rule_tac x = n in exI, auto simp: wadjust_stop.simps)
  4578     apply(rule_tac x = n in exI, auto simp: wadjust_stop.simps)
  4577     using a
  4579     using a
  4578     apply(case_tac "bl_bin (<args>)", simp_all)
  4580     apply(case_tac "bl_bin (<args>)", simp_all)
  4601 lemma wcode_lemma: 
  4603 lemma wcode_lemma: 
  4602   "args \<noteq> [] \<Longrightarrow> 
  4604   "args \<noteq> [] \<Longrightarrow> 
  4603   \<exists> stp ln rn. steps0 (Suc 0, [], <m # args>)  (t_wcode) stp = 
  4605   \<exists> stp ln rn. steps0 (Suc 0, [], <m # args>)  (t_wcode) stp = 
  4604               (0,  [Bk],  <[m ,bl_bin (<args>)]> @ Bk\<up>(rn))"
  4606               (0,  [Bk],  <[m ,bl_bin (<args>)]> @ Bk\<up>(rn))"
  4605 using wcode_lemma_1[of args m]
  4607 using wcode_lemma_1[of args m]
  4606 apply(simp add: t_wcode_def tape_of_nl_abv tape_of_nat_list.simps)
  4608 apply(simp add: t_wcode_def tape_of_nl_abv tape_of_nat_list.simps tape_of_nat_abv)
  4607 done
  4609 done
  4608 
  4610 
  4609 section {* The universal TM *}
  4611 section {* The universal TM *}
  4610 
  4612 
  4611 text {*
  4613 text {*
  4874 done
  4876 done
  4875       
  4877       
  4876 lemma [intro]: "tm_wf (t_utm, 0)"
  4878 lemma [intro]: "tm_wf (t_utm, 0)"
  4877 apply(simp only: t_utm_def F_tprog_def)
  4879 apply(simp only: t_utm_def F_tprog_def)
  4878 apply(rule_tac t_compiled_correct, auto)
  4880 apply(rule_tac t_compiled_correct, auto)
  4879 done   
  4881 done 
  4880 
  4882 
  4881 lemma UTM_halt_lemma_pre: 
  4883 lemma UTM_halt_lemma_pre: 
  4882   assumes wf_tm: "tm_wf (tp, 0)"
  4884   assumes wf_tm: "tm_wf (tp, 0)"
  4883   and result: "0 < rs"
  4885   and result: "0 < rs"
  4884   and args: "args \<noteq> []"
  4886   and args: "args \<noteq> []"
  4892     (\<exists> rn. r = Oc\<up>(Suc (code tp)) @ Bk # Oc\<up>(Suc (bl_bin (<args>))) @ Bk\<up>(rn)))"
  4894     (\<exists> rn. r = Oc\<up>(Suc (code tp)) @ Bk # Oc\<up>(Suc (bl_bin (<args>))) @ Bk\<up>(rn)))"
  4893   let ?P2 = ?Q1
  4895   let ?P2 = ?Q1
  4894   let ?P3 = "\<lambda> (l, r). False"
  4896   let ?P3 = "\<lambda> (l, r). False"
  4895   have "{?P1} (t_wcode |+| t_utm) {?Q2}"
  4897   have "{?P1} (t_wcode |+| t_utm) {?Q2}"
  4896   proof(rule_tac Hoare_plus_halt)
  4898   proof(rule_tac Hoare_plus_halt)
  4897     show "?Q1 \<mapsto> ?P2"
       
  4898       by(simp add: assert_imp_def)
       
  4899   next
       
  4900     show "tm_wf (t_wcode, 0)" by auto
  4899     show "tm_wf (t_wcode, 0)" by auto
  4901   next
  4900   next
  4902     show "{?P1} t_wcode {?Q1}"
  4901     show "{?P1} t_wcode {?Q1}"
  4903       apply(rule_tac HoareI, auto)
  4902       apply(rule_tac Hoare_haltI, auto)
  4904       using wcode_lemma_1[of args "code tp"] args
  4903       using wcode_lemma_1[of args "code tp"] args
  4905       apply(auto)
  4904       apply(auto)
  4906       apply(rule_tac x = stp in exI, simp)
  4905       apply(rule_tac x = stp in exI, simp)
  4907       done
  4906       done
  4908   next
  4907   next
  4909     show "{?P2} t_utm {?Q2}"
  4908     show "{?P2} t_utm {?Q2}"
  4910     proof(rule_tac HoareI, auto)
  4909     proof(rule_tac Hoare_haltI, auto)
  4911       fix rn
  4910       fix rn
  4912       show "\<exists>n. is_final (steps0 (Suc 0, [Bk], Oc # Oc \<up> code tp @ Bk # Oc # Oc \<up> bl_bin (<args>) @ Bk \<up> rn) t_utm n) \<and>
  4911       show "\<exists>n. is_final (steps0 (Suc 0, [Bk], Oc # Oc \<up> code tp @ Bk # Oc # Oc \<up> bl_bin (<args>) @ Bk \<up> rn) t_utm n) \<and>
  4913         (\<lambda>(l, r). (\<exists>ln. l = Bk \<up> ln) \<and>
  4912         (\<lambda>(l, r). (\<exists>ln. l = Bk \<up> ln) \<and>
  4914         (\<exists>rn. r = Oc \<up> rs @ Bk \<up> rn)) holds_for steps0 (Suc 0, [Bk],
  4913         (\<exists>rn. r = Oc \<up> rs @ Bk \<up> rn)) holds_for steps0 (Suc 0, [Bk],
  4915         Oc # Oc \<up> code tp @ Bk # Oc # Oc \<up> bl_bin (<args>) @ Bk \<up> rn) t_utm n"
  4914         Oc # Oc \<up> code tp @ Bk # Oc # Oc \<up> bl_bin (<args>) @ Bk \<up> rn) t_utm n"
  4916         using t_utm_halt_eq[of tp i "args" stp m rs k rn] assms
  4915         using t_utm_halt_eq[of tp i "args" stp m rs k rn] assms
  4917       apply(auto simp: bin_wc_eq)
  4916       apply(auto simp: bin_wc_eq)
  4918       apply(rule_tac x = stpa in exI, simp add: tape_of_nl_abv)
  4917       apply(rule_tac x = stpa in exI, simp add: tape_of_nl_abv tape_of_nat_abv)
  4919       done
  4918       done
  4920     qed
  4919     qed
  4921   qed
  4920   qed
  4922   thus "?thesis"
  4921   thus "?thesis"
  4923     apply(auto simp: Hoare_def UTM_pre_def)
  4922     apply(auto simp: Hoare_halt_def UTM_pre_def)
  4924     apply(case_tac "steps0 (Suc 0, [], <code tp # args>) (t_wcode |+| t_utm) n")
  4923     apply(case_tac "steps0 (Suc 0, [], <code tp # args>) (t_wcode |+| t_utm) n")
  4925     apply(rule_tac x = n in exI, simp)
  4924     apply(rule_tac x = n in exI, simp)
  4926     done
  4925     done
  4927 qed
  4926 qed
  4928 
  4927 
  5257   let ?Q1 = "\<lambda> (l, r). (l = [Bk] \<and>
  5256   let ?Q1 = "\<lambda> (l, r). (l = [Bk] \<and>
  5258              (\<exists> rn. r = Oc\<up>(Suc (code tp)) @ Bk # Oc\<up>(Suc (bl_bin (<args>))) @ Bk\<up>(rn)))"
  5257              (\<exists> rn. r = Oc\<up>(Suc (code tp)) @ Bk # Oc\<up>(Suc (bl_bin (<args>))) @ Bk\<up>(rn)))"
  5259   let ?P2 = ?Q1
  5258   let ?P2 = ?Q1
  5260   have "{?P1} (t_wcode |+| t_utm) \<up>"
  5259   have "{?P1} (t_wcode |+| t_utm) \<up>"
  5261   proof(rule_tac Hoare_plus_unhalt)
  5260   proof(rule_tac Hoare_plus_unhalt)
  5262     show "?Q1 \<mapsto> ?P2"
       
  5263       by(simp add: assert_imp_def)
       
  5264   next
       
  5265     show "tm_wf (t_wcode, 0)" by auto
  5261     show "tm_wf (t_wcode, 0)" by auto
  5266   next
  5262   next
  5267     show "{?P1} t_wcode {?Q1}"
  5263     show "{?P1} t_wcode {?Q1}"
  5268       apply(rule_tac HoareI, auto)
  5264       apply(rule_tac Hoare_haltI, auto)
  5269       using wcode_lemma_1[of args "code tp"] args
  5265       using wcode_lemma_1[of args "code tp"] args
  5270       apply(auto)
  5266       apply(auto)
  5271       apply(rule_tac x = stp in exI, simp)
  5267       apply(rule_tac x = stp in exI, simp)
  5272       done
  5268       done
  5273   next
  5269   next
  5274     show "{?P2} t_utm \<up>"
  5270     show "{?P2} t_utm \<up>"
  5275     proof(rule_tac Hoare_unhalt_I, auto)
  5271     proof(rule_tac Hoare_unhaltI, auto)
  5276       fix n rn
  5272       fix n rn
  5277       assume h: "is_final (steps0 (Suc 0, [Bk], Oc \<up> Suc (code tp) @ Bk # Oc \<up> Suc (bl_bin (<args>)) @ Bk \<up> rn) t_utm n)"
  5273       assume h: "is_final (steps0 (Suc 0, [Bk], Oc \<up> Suc (code tp) @ Bk # Oc \<up> Suc (bl_bin (<args>)) @ Bk \<up> rn) t_utm n)"
  5278       have "\<forall> stp. \<not> is_final (steps0 (Suc 0, Bk\<up>(Suc 0), <[code tp, bl2wc (<args>)]> @ Bk\<up>(rn)) t_utm stp)"
  5274       have "\<forall> stp. \<not> is_final (steps0 (Suc 0, Bk\<up>(Suc 0), <[code tp, bl2wc (<args>)]> @ Bk\<up>(rn)) t_utm stp)"
  5279         using assms
  5275         using assms
  5280         apply(rule_tac tutm_uhalt, simp_all)
  5276         apply(rule_tac tutm_uhalt, simp_all)
  5281         done
  5277         done
  5282       thus "False"
  5278       thus "False"
  5283         using h
  5279         using h
  5284         apply(erule_tac x = n in allE)
  5280         apply(erule_tac x = n in allE)
  5285         apply(simp add: tape_of_nl_abv bin_wc_eq)
  5281         apply(simp add: tape_of_nl_abv bin_wc_eq tape_of_nat_abv)
  5286         done
  5282         done
  5287     qed
  5283     qed
  5288   qed
  5284   qed
  5289   thus "?thesis"
  5285   thus "?thesis"
  5290     apply(simp add: Hoare_unhalt_def UTM_pre_def)
  5286     apply(simp add: Hoare_unhalt_def UTM_pre_def)