utm/abacus.thy
changeset 371 48b231495281
parent 370 1ce04eb1c8ad
equal deleted inserted replaced
370:1ce04eb1c8ad 371:48b231495281
     1 header {* 
     1 header {* 
     2   {\em Abacus} (a kind of register machine) 
     2  {\em abacus} a kind of register machine
     3 *}
     3 *}
     4 
     4 
     5 theory abacus
     5 theory abacus
     6 imports Main turing_basic
     6 imports Main turing_basic
     7 begin
     7 begin
   933 apply(simp add: tms_of.simps tpairs_of.simps)
   933 apply(simp add: tms_of.simps tpairs_of.simps)
   934 apply(simp add: tms_of.simps tpairs_of.simps abc_fetch.simps)
   934 apply(simp add: tms_of.simps tpairs_of.simps abc_fetch.simps)
   935 apply(erule_tac t_split, auto simp: tm_of.simps)
   935 apply(erule_tac t_split, auto simp: tm_of.simps)
   936 done
   936 done
   937 
   937 
   938 subsubsection {* The compilation of @{text "Inc n"} *}
   938 (*
       
   939 subsection {* The compilation of @{text "Inc n"} *}
       
   940 *)
   939 
   941 
   940 text {*
   942 text {*
   941   The lemmas in this section lead to the correctness of 
   943   The lemmas in this section lead to the correctness of 
   942   the compilation of @{text "Inc n"} instruction.
   944   the compilation of @{text "Inc n"} instruction.
   943 *}
   945 *}
   944 
   946 
   945 (*****Begin: inc crsp*******)
       
   946 fun at_begin_fst_bwtn :: "inc_inv_t"
   947 fun at_begin_fst_bwtn :: "inc_inv_t"
   947   where
   948   where
   948   "at_begin_fst_bwtn (as, lm) (s, l, r) ires = 
   949   "at_begin_fst_bwtn (as, lm) (s, l, r) ires = 
   949       (\<exists> lm1 tn rn. lm1 = (lm @ (0\<^bsup>tn\<^esup>)) \<and> length lm1 = s \<and> 
   950       (\<exists> lm1 tn rn. lm1 = (lm @ (0\<^bsup>tn\<^esup>)) \<and> length lm1 = s \<and> 
   950           (if lm1 = [] then l = Bk # Bk # ires
   951           (if lm1 = [] then l = Bk # Bk # ires
  2566                                 start_of ly as - Suc 0) stp) ires"
  2567                                 start_of ly as - Suc 0) stp) ires"
  2567 proof -
  2568 proof -
  2568   from inc_crsp_ex_pre [OF layout corresponds inc] show ?thesis .
  2569   from inc_crsp_ex_pre [OF layout corresponds inc] show ?thesis .
  2569 qed
  2570 qed
  2570 
  2571 
  2571 (*******End: inc crsp********)
  2572 (*
  2572 
  2573 subsection {* The compilation of @{text "Dec n e"} *}
  2573 (*******Begin: dec crsp******)
  2574 *)
  2574 
       
  2575 subsubsection {* The compilation of @{text "Dec n e"} *}
       
  2576 
       
  2577 
  2575 
  2578 text {*
  2576 text {*
  2579   The lemmas in this section lead to the correctness of the compilation 
  2577   The lemmas in this section lead to the correctness of the compilation 
  2580   of @{text "Dec n e"} instruction using the same techniques as 
  2578   of @{text "Dec n e"} instruction using the same techniques as 
  2581   @{text "Inc n"}.
  2579   @{text "Inc n"}.
  4832                                        start_of ly as - Suc 0) stp) ires"
  4830                                        start_of ly as - Suc 0) stp) ires"
  4833 proof -
  4831 proof -
  4834   from dec_crsp_ex_pre layout dec correspond  show ?thesis by blast
  4832   from dec_crsp_ex_pre layout dec correspond  show ?thesis by blast
  4835 qed
  4833 qed
  4836 
  4834 
  4837 
  4835 (*
  4838 (*******End: dec crsp********)
  4836 subsection {* Compilation of @{text "Goto n"}*}
  4839 
  4837 *)
  4840 
  4838 
  4841 subsubsection {* Compilation of @{text "Goto n"}*}
       
  4842 
       
  4843 
       
  4844 (*******Begin: goto crsp********)
       
  4845 lemma goto_fetch: 
  4839 lemma goto_fetch: 
  4846      "fetch (ci (layout_of aprog) 
  4840      "fetch (ci (layout_of aprog) 
  4847          (start_of (layout_of aprog) as) (Goto n)) (Suc 0)  b
  4841          (start_of (layout_of aprog) as) (Goto n)) (Suc 0)  b
  4848      = (Nop, start_of (layout_of aprog) n)"
  4842      = (Nop, start_of (layout_of aprog) n)"
  4849 apply(auto simp: ci.simps fetch.simps nth_of.simps 
  4843 apply(auto simp: ci.simps fetch.simps nth_of.simps 
  4878               (t_steps tc (ci (layout_of aprog) (start_of ly as) (Goto n),
  4872               (t_steps tc (ci (layout_of aprog) (start_of ly as) (Goto n),
  4879                                            start_of ly as - Suc 0) stp) ires"
  4873                                            start_of ly as - Suc 0) stp) ires"
  4880 proof -
  4874 proof -
  4881   from goto_crsp_ex_pre and layout goto correspondence show "?thesis" by blast
  4875   from goto_crsp_ex_pre and layout goto correspondence show "?thesis" by blast
  4882 qed
  4876 qed
  4883 (*******End : goto crsp*********)
  4877 
  4884   
  4878 subsection {*
  4885 subsubsection {*
       
  4886   The correctness of the compiler
  4879   The correctness of the compiler
  4887   *}
  4880   *}
  4888 
  4881 
  4889 declare abc_step_l.simps[simp del]
  4882 declare abc_step_l.simps[simp del]
  4890 
  4883 
  5156   shows "(\<exists> n'. crsp_l ly ac' (t_steps tc (tprog, 0) n') ires)"
  5149   shows "(\<exists> n'. crsp_l ly ac' (t_steps tc (tprog, 0) n') ires)"
  5157 proof -
  5150 proof -
  5158   from steps_crsp_pre [OF layout compiled correspond execution] show ?thesis .
  5151   from steps_crsp_pre [OF layout compiled correspond execution] show ?thesis .
  5159 qed
  5152 qed
  5160 
  5153 
  5161 
  5154 subsection {* The Mop-up machine *}
  5162 subsubsection {* The Mop-up machine *}
       
  5163 
  5155 
  5164 fun mop_bef :: "nat \<Rightarrow> tprog"
  5156 fun mop_bef :: "nat \<Rightarrow> tprog"
  5165   where
  5157   where
  5166   "mop_bef 0 = []" |
  5158   "mop_bef 0 = []" |
  5167   "mop_bef (Suc n) = mop_bef n @ 
  5159   "mop_bef (Suc n) = mop_bef n @ 
  5999 apply(simp add: abc_lm_v.simps, auto)
  5991 apply(simp add: abc_lm_v.simps, auto)
  6000 apply(case_tac list, simp_all add: tape_of_nl_abv tape_of_nat_list.simps abc_lm_v.simps) 
  5992 apply(case_tac list, simp_all add: tape_of_nl_abv tape_of_nat_list.simps abc_lm_v.simps) 
  6001 apply(erule_tac x = rn in allE, simp_all)
  5993 apply(erule_tac x = rn in allE, simp_all)
  6002 done
  5994 done
  6003 
  5995 
  6004 (***Begin: mopup stop***)
       
  6005 fun abc_mopup_stage1 :: "t_conf \<Rightarrow> nat \<Rightarrow> nat"
  5996 fun abc_mopup_stage1 :: "t_conf \<Rightarrow> nat \<Rightarrow> nat"
  6006   where
  5997   where
  6007   "abc_mopup_stage1 (s, l, r) n = 
  5998   "abc_mopup_stage1 (s, l, r) n = 
  6008            (if s > 0 \<and> s \<le> 2*n then 6
  5999            (if s > 0 \<and> s \<le> 2*n then 6
  6009             else if s = 2*n + 1 then 4
  6000             else if s = 2*n + 1 then 4
  6105 apply(rule_tac x = na in exI, case_tac "(t_steps (Suc 0, l, r) 
  6096 apply(rule_tac x = na in exI, case_tac "(t_steps (Suc 0, l, r) 
  6106           (mop_bef n @ tshift mp_up (2 * n), 0) na)", simp)
  6097           (mop_bef n @ tshift mp_up (2 * n), 0) na)", simp)
  6107 apply(rule_tac mopup_init, auto)
  6098 apply(rule_tac mopup_init, auto)
  6108 done
  6099 done
  6109 (***End: mopup stop****)
  6100 (***End: mopup stop****)
  6110 (*
       
  6111 lemma mopup_stop_cond: "mopup_inv (0, l, r) lm n ires \<Longrightarrow> 
       
  6112                                      (\<exists>ln rn. ?l = Bk\<^bsup>ln\<^esup> @ Bk # Bk # ?ires \<and> ?r = <abc_lm_v ?lm ?n> @ Bk\<^bsup>rn\<^esup>) "
       
  6113          t_halt_conf (0, l, r) \<and> t_result r = Suc (abc_lm_v lm n)"
       
  6114 apply(simp add: mopup_inv.simps mopup_stop.simps t_halt_conf.simps
       
  6115                 t_result.simps, auto simp: tape_of_nat_abv)
       
  6116 apply(rule_tac x = rn in exI, 
       
  6117       rule_tac x = "Suc (abc_lm_v lm n)" in exI,
       
  6118        simp add: tape_of_nat_abv)
       
  6119 apply(simp add: tape_of_nat_abv  exponent_def)
       
  6120 apply(subgoal_tac "takeWhile (\<lambda>a. a = Oc) 
       
  6121              (replicate (abc_lm_v lm n) Oc @ replicate rn Bk)
       
  6122        = replicate (abc_lm_v lm n) Oc @ takeWhile (\<lambda>a. a = Oc)
       
  6123                                           (replicate rn Bk)", simp)
       
  6124 apply(case_tac rn, simp, simp)
       
  6125 apply(rule takeWhile_append2)
       
  6126 apply(case_tac x, auto)
       
  6127 done
       
  6128 *)
       
  6129 
       
  6130 
  6101 
  6131 lemma mopup_halt_conf_pre: 
  6102 lemma mopup_halt_conf_pre: 
  6132  "\<lbrakk>n < length lm; crsp_l ly (as, lm) (s, l, r) ires\<rbrakk> 
  6103  "\<lbrakk>n < length lm; crsp_l ly (as, lm) (s, l, r) ires\<rbrakk> 
  6133   \<Longrightarrow> \<exists> na. (\<lambda> (s', l', r').  s' = 0 \<and> mopup_stop (s', l', r') lm n ires)
  6104   \<Longrightarrow> \<exists> na. (\<lambda> (s', l', r').  s' = 0 \<and> mopup_stop (s', l', r') lm n ires)
  6134       (t_steps (Suc 0, l, r) 
  6105       (t_steps (Suc 0, l, r) 
  6146 apply(rule_tac mopup_inv_steps, simp, simp)
  6117 apply(rule_tac mopup_inv_steps, simp, simp)
  6147 apply(rule_tac mopup_init, simp, simp)
  6118 apply(rule_tac mopup_init, simp, simp)
  6148 apply(rule_tac mopup_halt, simp, simp)
  6119 apply(rule_tac mopup_halt, simp, simp)
  6149 done
  6120 done
  6150 
  6121 
  6151 thm mopup_stop.simps
       
  6152 
       
  6153 lemma  mopup_halt_conf:
  6122 lemma  mopup_halt_conf:
  6154   assumes len: "n < length lm"
  6123   assumes len: "n < length lm"
  6155   and correspond: "crsp_l ly (as, lm) (s, l, r) ires"
  6124   and correspond: "crsp_l ly (as, lm) (s, l, r) ires"
  6156   shows 
  6125   shows 
  6157   "\<exists> na. (\<lambda> (s', l', r'). ((\<exists>ln rn. s' = 0 \<and> l' = Bk\<^bsup>ln\<^esup> @ Bk # Bk # ires \<and> r' = Oc\<^bsup>Suc (abc_lm_v lm n)\<^esup> @ Bk\<^bsup>rn\<^esup>)))
  6126   "\<exists> na. (\<lambda> (s', l', r'). ((\<exists>ln rn. s' = 0 \<and> l' = Bk\<^bsup>ln\<^esup> @ Bk # Bk # ires
       
  6127                            \<and> r' = Oc\<^bsup>Suc (abc_lm_v lm n)\<^esup> @ Bk\<^bsup>rn\<^esup>)))
  6158              (t_steps (Suc 0, l, r) 
  6128              (t_steps (Suc 0, l, r) 
  6159                   ((mop_bef n @ tshift mp_up (2 * n)), 0) na)"
  6129                   ((mop_bef n @ tshift mp_up (2 * n)), 0) na)"
  6160 using len correspond mopup_halt_conf_pre[of n lm ly as s l r ires]
  6130 using len correspond mopup_halt_conf_pre[of n lm ly as s l r ires]
  6161 apply(simp add: mopup_stop.simps tape_of_nat_abv tape_of_nat_list.simps)
  6131 apply(simp add: mopup_stop.simps tape_of_nat_abv tape_of_nat_list.simps)
  6162 done
  6132 done
  6163 (*********End: mop_up****************************)
  6133 
  6164 
  6134 subsection {* Final results about Abacus machine *}
  6165 
  6135 
  6166 subsubsection {* Final results about Abacus machine *}
       
  6167 
       
  6168 thm mopup_halt
       
  6169 lemma mopup_halt_bef: "\<lbrakk>n < length lm; crsp_l ly (as, lm) (s, l, r) ires\<rbrakk> 
  6136 lemma mopup_halt_bef: "\<lbrakk>n < length lm; crsp_l ly (as, lm) (s, l, r) ires\<rbrakk> 
  6170     \<Longrightarrow> \<exists>stp. (\<lambda>(s, l, r). s \<noteq> 0 \<and> ((\<lambda> (s', l', r'). s' = 0)
  6137     \<Longrightarrow> \<exists>stp. (\<lambda>(s, l, r). s \<noteq> 0 \<and> ((\<lambda> (s', l', r'). s' = 0)
  6171    (t_step (s, l, r) (mop_bef n @ tshift mp_up (2 * n), 0))))
  6138    (t_step (s, l, r) (mop_bef n @ tshift mp_up (2 * n), 0))))
  6172     (t_steps (Suc 0, l, r) (mop_bef n @ tshift mp_up (2 * n), 0) stp)"
  6139     (t_steps (Suc 0, l, r) (mop_bef n @ tshift mp_up (2 * n), 0) stp)"
  6173 apply(insert mopup_halt[of n lm ly as s l r ires], simp, erule_tac exE)
  6140 apply(insert mopup_halt[of n lm ly as s l r ires], simp, erule_tac exE)
  6290 apply(subgoal_tac "start_of (layout_of aprog) (length aprog) > 0", 
  6257 apply(subgoal_tac "start_of (layout_of aprog) (length aprog) > 0", 
  6291       case_tac "start_of (layout_of aprog) (length aprog)", 
  6258       case_tac "start_of (layout_of aprog) (length aprog)", 
  6292       simp, simp)
  6259       simp, simp)
  6293 apply(rule startof_not0, auto)
  6260 apply(rule startof_not0, auto)
  6294 done
  6261 done
  6295 
       
  6296 (*
       
  6297 lemma stop_conf: "mopup_inv (0, aca, bc) am n
       
  6298     \<Longrightarrow> t_halt_conf (0, aca, bc) \<and> t_result bc = Suc (abc_lm_v am n)"
       
  6299 apply(case_tac n, 
       
  6300       auto simp: mopup_inv.simps mopup_stop.simps t_halt_conf.simps 
       
  6301                  t_result.simps tape_of_nl_abv tape_of_nat_abv )
       
  6302 apply(rule_tac x = "rn" in exI, 
       
  6303       rule_tac x = "Suc (abc_lm_v am 0)" in exI, simp) 
       
  6304 apply(subgoal_tac "takeWhile (\<lambda>a. a = Oc) (Oc\<^bsup>abc_lm_v am 0\<^esup> @ Bk\<^bsup>rn\<^esup>)
       
  6305               = Oc\<^bsup>abc_lm_v am 0\<^esup> @ takeWhile (\<lambda>a. a = Oc) (Bk\<^bsup>rn\<^esup>)", simp)
       
  6306 apply(simp add: exponent_def, case_tac rn, simp, simp)
       
  6307 apply(rule_tac takeWhile_append2, simp add: exponent_def)
       
  6308 apply(rule_tac x = rn in exI,
       
  6309       rule_tac x = "Suc (abc_lm_v am (Suc nat))" in exI, simp)
       
  6310 apply(subgoal_tac 
       
  6311  "takeWhile (\<lambda>a. a = Oc) (Oc\<^bsup>abc_lm_v am (Suc nat)\<^esup> @ Bk\<^bsup>rn\<^esup>) = 
       
  6312        Oc\<^bsup>abc_lm_v am (Suc nat)\<^esup> @ takeWhile (\<lambda>a. a = Oc) (Bk\<^bsup>rn\<^esup>)", simp)
       
  6313 apply(simp add: exponent_def, case_tac rn, simp, simp)
       
  6314 apply(rule_tac takeWhile_append2, simp add: exponent_def)
       
  6315 done
       
  6316 *)
       
  6317 
       
  6318 
  6262 
  6319 lemma start_of_out_range: 
  6263 lemma start_of_out_range: 
  6320 "as \<ge> length aprog \<Longrightarrow> 
  6264 "as \<ge> length aprog \<Longrightarrow> 
  6321    start_of (layout_of aprog) as = 
  6265    start_of (layout_of aprog) as = 
  6322              start_of (layout_of aprog) (length aprog)"
  6266              start_of (layout_of aprog) (length aprog)"
  6446   -- {* 
  6390   -- {* 
  6447   After @{text "stp"} steps of execution of the TM composed of @{text "tprog"} and the mopup 
  6391   After @{text "stp"} steps of execution of the TM composed of @{text "tprog"} and the mopup 
  6448   TM @{text "(tMp n (mop_ss - 1))"} will halt and gives rise to a configuration which 
  6392   TM @{text "(tMp n (mop_ss - 1))"} will halt and gives rise to a configuration which 
  6449   only hold the content of memory cell @{text "n"}:
  6393   only hold the content of memory cell @{text "n"}:
  6450   *}
  6394   *}
  6451   "\<exists> stp. (\<lambda> (s, l, r). \<exists> ln rn. s = 0 \<and>  l = Bk\<^bsup>ln\<^esup> @ Bk # Bk # ires \<and> r = Oc\<^bsup>Suc (abc_lm_v am n)\<^esup> @ Bk\<^bsup>rn\<^esup>)
  6395   "\<exists> stp. (\<lambda> (s, l, r). \<exists> ln rn. s = 0 \<and>  l = Bk\<^bsup>ln\<^esup> @ Bk # Bk # ires
       
  6396      \<and> r = Oc\<^bsup>Suc (abc_lm_v am n)\<^esup> @ Bk\<^bsup>rn\<^esup>)
  6452            (t_steps tc (tprog @ (tMp n (mop_ss - 1)), 0) stp)"
  6397            (t_steps tc (tprog @ (tMp n (mop_ss - 1)), 0) stp)"
  6453 proof -
  6398 proof -
  6454   from layout complied correspond halt_state abc_exec rs_len mopup_start
  6399   from layout complied correspond halt_state abc_exec rs_len mopup_start
  6455        and abacus_turing_eq_halt_case_pre [of ly aprog tprog ac tc ires n am stp as mop_ss]
  6400        and abacus_turing_eq_halt_case_pre [of ly aprog tprog ac tc ires n am stp as mop_ss]
  6456   show "?thesis" 
  6401   show "?thesis" 
  6654               (t_steps tc (tprog @ (tMp n (mop_ss - 1)), 0) stp))"
  6599               (t_steps tc (tprog @ (tMp n (mop_ss - 1)), 0) stp))"
  6655   using layout compiled correspond abc_unhalt mopup_start
  6600   using layout compiled correspond abc_unhalt mopup_start
  6656   apply(rule_tac abacus_turing_eq_unhalt_case_pre, auto)
  6601   apply(rule_tac abacus_turing_eq_unhalt_case_pre, auto)
  6657   done
  6602   done
  6658 
  6603 
       
  6604 
  6659 definition abc_list_crsp:: "nat list \<Rightarrow> nat list \<Rightarrow> bool"
  6605 definition abc_list_crsp:: "nat list \<Rightarrow> nat list \<Rightarrow> bool"
  6660   where
  6606   where
  6661   "abc_list_crsp xs ys = (\<exists> n. xs = ys @ 0\<^bsup>n\<^esup> \<or> ys = xs @ 0\<^bsup>n\<^esup>)"
  6607   "abc_list_crsp xs ys = (\<exists> n. xs = ys @ 0\<^bsup>n\<^esup> \<or> ys = xs @ 0\<^bsup>n\<^esup>)"
  6662 lemma [intro]: "abc_list_crsp (lm @ 0\<^bsup>m\<^esup>) lm"
  6608 lemma [intro]: "abc_list_crsp (lm @ 0\<^bsup>m\<^esup>) lm"
  6663 apply(auto simp: abc_list_crsp_def)
  6609 apply(auto simp: abc_list_crsp_def)
  6664 done
  6610 done
  6665 
  6611 
  6666 thm abc_lm_v.simps
       
  6667 lemma abc_list_crsp_lm_v: 
  6612 lemma abc_list_crsp_lm_v: 
  6668   "abc_list_crsp lma lmb \<Longrightarrow> abc_lm_v lma n = abc_lm_v lmb n"
  6613   "abc_list_crsp lma lmb \<Longrightarrow> abc_lm_v lma n = abc_lm_v lmb n"
  6669 apply(auto simp: abc_list_crsp_def abc_lm_v.simps 
  6614 apply(auto simp: abc_list_crsp_def abc_lm_v.simps 
  6670                  nth_append exponent_def)
  6615                  nth_append exponent_def)
  6671 done
  6616 done
  6746 apply(case_tac i, auto simp: abc_step_l.simps 
  6691 apply(case_tac i, auto simp: abc_step_l.simps 
  6747        abc_list_crsp_lm_s abc_list_crsp_lm_v Let_def 
  6692        abc_list_crsp_lm_s abc_list_crsp_lm_v Let_def 
  6748                        split: abc_inst.splits if_splits)
  6693                        split: abc_inst.splits if_splits)
  6749 done
  6694 done
  6750 
  6695 
  6751 thm abc_step_l.simps
       
  6752 
       
  6753 lemma abc_steps_red: 
  6696 lemma abc_steps_red: 
  6754   "abc_steps_l ac aprog stp = (as, am) \<Longrightarrow>
  6697   "abc_steps_l ac aprog stp = (as, am) \<Longrightarrow>
  6755      abc_steps_l ac aprog (Suc stp) = 
  6698      abc_steps_l ac aprog (Suc stp) = 
  6756            abc_step_l (as, am) (abc_fetch as aprog)"
  6699            abc_step_l (as, am) (abc_fetch as aprog)"
  6757 using abc_steps_ind[of ac aprog stp]
  6700 using abc_steps_ind[of ac aprog stp]
  6797           case_tac "abc_step_l (aa, lma) (abc_fetch aa aprog)", simp)
  6740           case_tac "abc_step_l (aa, lma) (abc_fetch aa aprog)", simp)
  6798     apply(rule_tac abc_list_crsp_step, auto)
  6741     apply(rule_tac abc_list_crsp_step, auto)
  6799     done
  6742     done
  6800 qed
  6743 qed
  6801 
  6744 
  6802 text {* Begin: equvilence between steps and t_steps*}
       
  6803 lemma [simp]: "(case ca of [] \<Rightarrow> Bk | Bk # xs \<Rightarrow> Bk | Oc # xs \<Rightarrow> Oc) =
  6745 lemma [simp]: "(case ca of [] \<Rightarrow> Bk | Bk # xs \<Rightarrow> Bk | Oc # xs \<Rightarrow> Oc) =
  6804                 (case ca of [] \<Rightarrow> Bk | x # xs \<Rightarrow> x)"
  6746                 (case ca of [] \<Rightarrow> Bk | x # xs \<Rightarrow> x)"
  6805 by(case_tac ca, simp_all, case_tac a, simp, simp)
  6747 by(case_tac ca, simp_all, case_tac a, simp, simp)
  6806 
       
  6807 text {* needed to interpret*}
       
  6808 
  6748 
  6809 lemma steps_eq: "length t mod 2 = 0 \<Longrightarrow> 
  6749 lemma steps_eq: "length t mod 2 = 0 \<Longrightarrow> 
  6810                     t_steps c (t, 0) stp = steps c t stp"
  6750                     t_steps c (t, 0) stp = steps c t stp"
  6811 apply(induct stp)
  6751 apply(induct stp)
  6812 apply(simp add: steps.simps t_steps.simps)
  6752 apply(simp add: steps.simps t_steps.simps)
  6813 apply(simp add:tstep_red t_steps_ind)
  6753 apply(simp add:tstep_red t_steps_ind)
  6814 apply(case_tac "steps c t stp", simp)
  6754 apply(case_tac "steps c t stp", simp)
  6815 apply(auto simp: t_step.simps tstep.simps)
  6755 apply(auto simp: t_step.simps tstep.simps)
  6816 done
  6756 done
  6817 
       
  6818 text{* end: equvilence between steps and t_steps*}
       
  6819 
  6757 
  6820 lemma crsp_l_start: "crsp_l ly (0, lm) (Suc 0, Bk # Bk # ires, <lm> @ Bk\<^bsup>rn\<^esup>) ires"
  6758 lemma crsp_l_start: "crsp_l ly (0, lm) (Suc 0, Bk # Bk # ires, <lm> @ Bk\<^bsup>rn\<^esup>) ires"
  6821 apply(simp add: crsp_l.simps, auto simp: start_of.simps)
  6759 apply(simp add: crsp_l.simps, auto simp: start_of.simps)
  6822 done
  6760 done
  6823 
  6761 
  6865 apply(rule_tac x = stpa in exI, 
  6803 apply(rule_tac x = stpa in exI, 
  6866        simp add:  exponent_def, auto)
  6804        simp add:  exponent_def, auto)
  6867 done
  6805 done
  6868 
  6806 
  6869 
  6807 
  6870 thm tinres_steps
       
  6871 lemma list_length: "xs = ys \<Longrightarrow> length xs = length ys"
  6808 lemma list_length: "xs = ys \<Longrightarrow> length xs = length ys"
  6872 by simp
  6809 by simp
  6873 lemma [elim]: "tinres (Bk\<^bsup>m\<^esup>) b \<Longrightarrow> \<exists>m. b = Bk\<^bsup>m\<^esup>"
  6810 lemma [elim]: "tinres (Bk\<^bsup>m\<^esup>) b \<Longrightarrow> \<exists>m. b = Bk\<^bsup>m\<^esup>"
  6874 apply(auto simp: tinres_def)
  6811 apply(auto simp: tinres_def)
  6875 apply(rule_tac x = "m-n" in exI, 
  6812 apply(rule_tac x = "m-n" in exI, 
  6901 
  6838 
  6902 
  6839 
  6903 text {*
  6840 text {*
  6904   Main theorem for the case when the original Abacus program does halt.
  6841   Main theorem for the case when the original Abacus program does halt.
  6905 *}
  6842 *}
       
  6843 
  6906 lemma abacus_turing_eq_halt: 
  6844 lemma abacus_turing_eq_halt: 
  6907   assumes layout:
  6845   assumes layout:
  6908   "ly = layout_of aprog"
  6846   "ly = layout_of aprog"
  6909   -- {* There is an Abacus program @{text "aprog"} with layout @{text "ly"}: *}
  6847   -- {* There is an Abacus program @{text "aprog"} with layout @{text "ly"}: *}
  6910   and compiled: "tprog = tm_of aprog"
  6848   and compiled: "tprog = tm_of aprog"
  6950 apply(subgoal_tac 
  6888 apply(subgoal_tac 
  6951    "length (tm_of aprog @ tMp n 
  6889    "length (tm_of aprog @ tMp n 
  6952          (start_of ly (length aprog) - Suc 0)) mod 2 = 0")
  6890          (start_of ly (length aprog) - Suc 0)) mod 2 = 0")
  6953 apply(simp add: steps_eq, auto simp: isS0_def)
  6891 apply(simp add: steps_eq, auto simp: isS0_def)
  6954 done
  6892 done
  6955 (*
  6893 
  6956 lemma abacus_turing_eq_uhalt_pre: 
       
  6957   "\<lbrakk>ly = layout_of aprog; 
       
  6958     tprog = tm_of aprog;
       
  6959     \<forall> stp. ((\<lambda> (as, am). as < length aprog) 
       
  6960                       (abc_steps_l (0, lm) aprog stp));
       
  6961     mop_ss = start_of ly (length aprog)\<rbrakk>
       
  6962   \<Longrightarrow> (\<not> (\<exists> stp. isS0 (steps (Suc 0, [Bk, Bk], <lm>) 
       
  6963                     (tprog @ (tMp n (mop_ss - 1))) stp)))"
       
  6964 apply(drule_tac k = 0 and n = n  in abacus_turing_eq_uhalt', auto)
       
  6965 apply(erule_tac x = stp in allE, erule_tac x = stp in allE)
       
  6966 apply(subgoal_tac "tinres ([Bk]) (Bk\<^bsup>k\<^esup>)")
       
  6967 apply(case_tac "steps (Suc 0, Bk\<^bsup>k\<^esup>, <lm>)
       
  6968       (tm_of aprog @ tMp n (start_of ly (length aprog) - Suc 0)) stp")
       
  6969 apply(case_tac 
       
  6970   "steps (Suc 0, [Bk], <lm>)
       
  6971     (tm_of aprog @ tMp n (start_of ly (length aprog) - Suc 0)) stp")
       
  6972 apply(drule_tac tinres_steps, auto simp: isS0_def)
       
  6973 done
       
  6974 *)
       
  6975 text {*
  6894 text {*
  6976   Main theorem for the case when the original Abacus program does not halt.
  6895   Main theorem for the case when the original Abacus program does not halt.
  6977   *}
  6896   *}
  6978 lemma abacus_turing_eq_uhalt:
  6897 lemma abacus_turing_eq_uhalt:
  6979   assumes layout: 
  6898   assumes layout: 
  6998                     (tprog @ (tMp n (mop_ss - 1))) stp))"
  6917                     (tprog @ (tMp n (mop_ss - 1))) stp))"
  6999   using abacus_turing_eq_uhalt'
  6918   using abacus_turing_eq_uhalt'
  7000         layout compiled abc_unhalt mop_start
  6919         layout compiled abc_unhalt mop_start
  7001   by(auto)
  6920   by(auto)
  7002 
  6921 
  7003 
       
  7004 end
  6922 end
  7005 
  6923