7 in terms of recursive functions. This @{text "rec_F"} is essentially an |
7 in terms of recursive functions. This @{text "rec_F"} is essentially an |
8 interpreter of Turing Machines. Once the correctness of @{text "rec_F"} is established, |
8 interpreter of Turing Machines. Once the correctness of @{text "rec_F"} is established, |
9 UTM can easil be obtained by compling @{text "rec_F"} into the corresponding Turing Machine. |
9 UTM can easil be obtained by compling @{text "rec_F"} into the corresponding Turing Machine. |
10 *} |
10 *} |
11 |
11 |
12 |
12 section {* Univeral Function *} |
13 section {* The construction of component functions *} |
13 |
|
14 subsection {* The construction of component functions *} |
14 |
15 |
15 text {* |
16 text {* |
16 This section constructs a set of component functions used to construct @{text "rec_F"}. |
17 This section constructs a set of component functions used to construct @{text "rec_F"}. |
17 *} |
18 *} |
18 |
19 |
124 @{text "get_fstn_args n (Suc k)"} returns |
125 @{text "get_fstn_args n (Suc k)"} returns |
125 @{text "[id n 0, id n 1, id n 2, \<dots>, id n k]"}, |
126 @{text "[id n 0, id n 1, id n 2, \<dots>, id n k]"}, |
126 the effect of which is to take out the first @{text "Suc k"} |
127 the effect of which is to take out the first @{text "Suc k"} |
127 arguments out of the @{text "n"} input arguments. |
128 arguments out of the @{text "n"} input arguments. |
128 *} |
129 *} |
129 (* get_fstn_args *) |
130 |
130 fun get_fstn_args :: "nat \<Rightarrow> nat \<Rightarrow> recf list" |
131 fun get_fstn_args :: "nat \<Rightarrow> nat \<Rightarrow> recf list" |
131 where |
132 where |
132 "get_fstn_args n 0 = []" |
133 "get_fstn_args n 0 = []" |
133 | "get_fstn_args n (Suc y) = get_fstn_args n y @ [id n y]" |
134 | "get_fstn_args n (Suc y) = get_fstn_args n y @ [id n y]" |
134 |
135 |
339 |
340 |
340 declare rec_exec.simps[simp del] get_fstn_args.simps[simp del] |
341 declare rec_exec.simps[simp del] get_fstn_args.simps[simp del] |
341 arity.simps[simp del] Sigma.simps[simp del] |
342 arity.simps[simp del] Sigma.simps[simp del] |
342 rec_sigma.simps[simp del] |
343 rec_sigma.simps[simp del] |
343 |
344 |
344 |
|
345 section {* Properties of @{text rec_sigma} *} |
|
346 |
|
347 lemma [simp]: "arity z = 1" |
345 lemma [simp]: "arity z = 1" |
348 by(simp add: arity.simps) |
346 by(simp add: arity.simps) |
349 |
347 |
350 lemma rec_pr_0_simp_rewrite: " |
348 lemma rec_pr_0_simp_rewrite: " |
351 rec_exec (Pr n f g) (xs @ [0]) = rec_exec f xs" |
349 rec_exec (Pr n f g) (xs @ [0]) = rec_exec f xs" |
363 |
361 |
364 lemma rec_pr_Suc_simp_rewrite_single_param: |
362 lemma rec_pr_Suc_simp_rewrite_single_param: |
365 "rec_exec (Pr n f g) ([Suc x]) = |
363 "rec_exec (Pr n f g) ([Suc x]) = |
366 rec_exec g ([x] @ [rec_exec (Pr n f g) ([x])])" |
364 rec_exec g ([x] @ [rec_exec (Pr n f g) ([x])])" |
367 by(simp add: rec_exec.simps) |
365 by(simp add: rec_exec.simps) |
368 |
|
369 thm Sigma.simps |
|
370 |
366 |
371 lemma Sigma_0_simp_rewrite_single_param: |
367 lemma Sigma_0_simp_rewrite_single_param: |
372 "Sigma f [0] = f [0]" |
368 "Sigma f [0] = f [0]" |
373 by(simp add: Sigma.simps) |
369 by(simp add: Sigma.simps) |
374 |
370 |
1413 apply(case_tac rcs, simp, simp) |
1409 apply(case_tac rcs, simp, simp) |
1414 apply(case_tac "rec_exec aa xs = 0") |
1410 apply(case_tac "rec_exec aa xs = 0") |
1415 apply(case_tac [!] "zip rgs list = []", simp) |
1411 apply(case_tac [!] "zip rgs list = []", simp) |
1416 apply(subgoal_tac "rgs = [] \<and> list = []", simp add: Embranch.simps rec_exec.simps rec_embranch.simps) |
1412 apply(subgoal_tac "rgs = [] \<and> list = []", simp add: Embranch.simps rec_exec.simps rec_embranch.simps) |
1417 apply(rule_tac zip_null_iff, simp, simp, simp) |
1413 apply(rule_tac zip_null_iff, simp, simp, simp) |
1418 thm Embranch.simps |
|
1419 proof - |
1414 proof - |
1420 fix aa list |
1415 fix aa list |
1421 assume g: |
1416 assume g: |
1422 "Suc (length rgs) = n" "Suc (length list) = n" |
1417 "Suc (length rgs) = n" "Suc (length list) = n" |
1423 "\<exists>i<n. rec_exec ((aa # list) ! i) xs = Suc 0 \<and> |
1418 "\<exists>i<n. rec_exec ((aa # list) ! i) xs = Suc 0 \<and> |
1563 rec_all (Cn 1 rec_minus [id 1 0, constn 1]) |
1558 rec_all (Cn 1 rec_minus [id 1 0, constn 1]) |
1564 (rec_all (Cn 2 rec_minus [id 2 0, Cn 2 (constn 1) |
1559 (rec_all (Cn 2 rec_minus [id 2 0, Cn 2 (constn 1) |
1565 [id 2 0]]) (Cn 3 rec_noteq |
1560 [id 2 0]]) (Cn 3 rec_noteq |
1566 [Cn 3 rec_mult [id 3 1, id 3 2], id 3 0]))]" |
1561 [Cn 3 rec_mult [id 3 1, id 3 2], id 3 0]))]" |
1567 |
1562 |
1568 (* |
|
1569 lemma prime_lemma1: |
|
1570 "(rec_exec rec_prime [x] = Suc 0) \<or> |
|
1571 (rec_exec rec_prime [x] = 0)" |
|
1572 apply(auto simp: rec_exec.simps rec_prime_def) |
|
1573 done |
|
1574 *) |
|
1575 declare numeral_2_eq_2[simp del] numeral_3_eq_3[simp del] |
1563 declare numeral_2_eq_2[simp del] numeral_3_eq_3[simp del] |
1576 |
1564 |
1577 lemma exec_tmp: |
1565 lemma exec_tmp: |
1578 "rec_exec (rec_all (Cn 2 rec_minus [recf.id 2 0, Cn 2 (constn (Suc 0)) [recf.id 2 0]]) |
1566 "rec_exec (rec_all (Cn 2 rec_minus [recf.id 2 0, Cn 2 (constn (Suc 0)) [recf.id 2 0]]) |
1579 (Cn 3 rec_noteq [Cn 3 rec_mult [recf.id 3 (Suc 0), recf.id 3 2], recf.id 3 0])) [x, k] = |
1567 (Cn 3 rec_noteq [Cn 3 rec_mult [recf.id 3 (Suc 0), recf.id 3 2], recf.id 3 0])) [x, k] = |
1886 *} |
1873 *} |
1887 lemma pi_lemma: "rec_exec rec_pi [x] = Pi x" |
1874 lemma pi_lemma: "rec_exec rec_pi [x] = Pi x" |
1888 apply(simp add: rec_pi_def rec_exec.simps pi_dummy_lemma) |
1875 apply(simp add: rec_pi_def rec_exec.simps pi_dummy_lemma) |
1889 done |
1876 done |
1890 |
1877 |
1891 text{*follows: lemmas for lo*} |
|
1892 fun loR :: "nat list \<Rightarrow> bool" |
1878 fun loR :: "nat list \<Rightarrow> bool" |
1893 where |
1879 where |
1894 "loR [x, y, u] = (x mod (y^u) = 0)" |
1880 "loR [x, y, u] = (x mod (y^u) = 0)" |
1895 |
1881 |
1896 declare loR.simps[simp del] |
1882 declare loR.simps[simp del] |
2173 The correctness of @{text "rec_entry"}. |
2159 The correctness of @{text "rec_entry"}. |
2174 *} |
2160 *} |
2175 lemma entry_lemma: "rec_exec rec_entry [str, i] = Entry str i" |
2161 lemma entry_lemma: "rec_exec rec_entry [str, i] = Entry str i" |
2176 by(simp add: rec_entry_def rec_exec.simps lo_lemma pi_lemma) |
2162 by(simp add: rec_entry_def rec_exec.simps lo_lemma pi_lemma) |
2177 |
2163 |
2178 section {* The construction of @{text "F"} *} |
2164 |
|
2165 subsection {* The construction of F *} |
2179 |
2166 |
2180 text {* |
2167 text {* |
2181 Using the auxilliary functions obtained in last section, |
2168 Using the auxilliary functions obtained in last section, |
2182 we are going to contruct the function @{text "F"}, |
2169 we are going to contruct the function @{text "F"}, |
2183 which is an interpreter of Turing Machines. |
2170 which is an interpreter of Turing Machines. |
2458 apply(case_tac "a = 3", rule_tac x = "2" in exI) |
2445 apply(case_tac "a = 3", rule_tac x = "2" in exI) |
2459 prefer 2 |
2446 prefer 2 |
2460 apply(case_tac "a > 3", rule_tac x = "3" in exI, auto) |
2447 apply(case_tac "a > 3", rule_tac x = "3" in exI, auto) |
2461 apply(auto simp: rec_exec.simps) |
2448 apply(auto simp: rec_exec.simps) |
2462 apply(erule_tac [!] Suc_Suc_Suc_Suc_induct, auto simp: rec_exec.simps) |
2449 apply(erule_tac [!] Suc_Suc_Suc_Suc_induct, auto simp: rec_exec.simps) |
2463 done(* |
2450 done |
2464 have "Embranch (zip (map rec_exec ?rgs) (map (\<lambda>r args. 0 < rec_exec r args) ?rrs)) [p, r, a] |
|
2465 = Embranch (zip ?gs ?rs) [p, r, a]" |
|
2466 apply(simp add)*) |
|
2467 have k2: "Embranch (zip (map rec_exec ?rgs) (map (\<lambda>r args. 0 < rec_exec r args) ?rrs)) [p, r, a] = newleft p r a" |
2451 have k2: "Embranch (zip (map rec_exec ?rgs) (map (\<lambda>r args. 0 < rec_exec r args) ?rrs)) [p, r, a] = newleft p r a" |
2468 apply(simp add: Embranch.simps) |
2452 apply(simp add: Embranch.simps) |
2469 apply(simp add: rec_exec.simps) |
2453 apply(simp add: rec_exec.simps) |
2470 apply(auto simp: newleft.simps rec_newleft0_def rec_exec.simps |
2454 apply(auto simp: newleft.simps rec_newleft0_def rec_exec.simps |
2471 rec_newleft1_def rec_newleft2_def rec_newleft3_def) |
2455 rec_newleft1_def rec_newleft2_def rec_newleft3_def) |
2611 The correctness of @{text "actn"}. |
2595 The correctness of @{text "actn"}. |
2612 *} |
2596 *} |
2613 lemma actn_lemma: "rec_exec rec_actn [m, q, r] = actn m q r" |
2597 lemma actn_lemma: "rec_exec rec_actn [m, q, r] = actn m q r" |
2614 by(auto simp: rec_actn_def rec_exec.simps entry_lemma scan_lemma) |
2598 by(auto simp: rec_actn_def rec_exec.simps entry_lemma scan_lemma) |
2615 |
2599 |
2616 (* Stop point *) |
|
2617 |
|
2618 fun newstat :: "nat \<Rightarrow> nat \<Rightarrow> nat \<Rightarrow> nat" |
2600 fun newstat :: "nat \<Rightarrow> nat \<Rightarrow> nat \<Rightarrow> nat" |
2619 where |
2601 where |
2620 "newstat m q r = (if q \<noteq> 0 then Entry m (4*(q - 1) + 2*scan r + 1) |
2602 "newstat m q r = (if q \<noteq> 0 then Entry m (4*(q - 1) + 2*scan r + 1) |
2621 else 0)" |
2603 else 0)" |
2622 |
2604 |
2917 lemma nstd_lemma: "rec_exec rec_NSTD [c] = nstd c" |
2899 lemma nstd_lemma: "rec_exec rec_NSTD [c] = nstd c" |
2918 using NSTD_lemma1 |
2900 using NSTD_lemma1 |
2919 apply(simp add: NSTD_lemma2, auto) |
2901 apply(simp add: NSTD_lemma2, auto) |
2920 done |
2902 done |
2921 |
2903 |
2922 text {* GGGGGGGGGGGGGGGGGGGGGGG *} |
|
2923 |
|
2924 text{* |
2904 text{* |
2925 @{text "nonstep m r t"} means afer @{text "t"} steps of execution, the TM coded by @{text "m"} |
2905 @{text "nonstep m r t"} means afer @{text "t"} steps of execution, the TM coded by @{text "m"} |
2926 is not at a stardard final configuration. |
2906 is not at a stardard final configuration. |
2927 *} |
2907 *} |
2928 fun nonstop :: "nat \<Rightarrow> nat \<Rightarrow> nat \<Rightarrow> nat" |
2908 fun nonstop :: "nat \<Rightarrow> nat \<Rightarrow> nat \<Rightarrow> nat" |
2954 definition rec_halt :: "recf" |
2934 definition rec_halt :: "recf" |
2955 where |
2935 where |
2956 "rec_halt = Mn (Suc (Suc 0)) (rec_nonstop)" |
2936 "rec_halt = Mn (Suc (Suc 0)) (rec_nonstop)" |
2957 |
2937 |
2958 declare nonstop.simps[simp del] |
2938 declare nonstop.simps[simp del] |
2959 |
|
2960 (* when mn, use rec_calc_rel instead of rec_exec*) |
|
2961 |
2939 |
2962 lemma primerec_not0: "primerec f n \<Longrightarrow> n > 0" |
2940 lemma primerec_not0: "primerec f n \<Longrightarrow> n > 0" |
2963 by(induct f n rule: primerec.induct, auto) |
2941 by(induct f n rule: primerec.induct, auto) |
2964 |
2942 |
2965 lemma [elim]: "primerec f 0 \<Longrightarrow> RR" |
2943 lemma [elim]: "primerec f 0 \<Longrightarrow> RR" |
3492 using h |
3470 using h |
3493 apply(erule_tac x = "ysb ! (Suc (Suc 0))" in allE, simp) |
3471 apply(erule_tac x = "ysb ! (Suc (Suc 0))" in allE, simp) |
3494 done |
3472 done |
3495 qed |
3473 qed |
3496 |
3474 |
3497 section {* Coding function of TMs *} |
3475 |
|
3476 subsection {* Coding function of TMs *} |
3498 |
3477 |
3499 text {* |
3478 text {* |
3500 The purpose of this section is to get the coding function of Turing Machine, which is |
3479 The purpose of this section is to get the coding function of Turing Machine, which is |
3501 going to be named @{text "code"}. |
3480 going to be named @{text "code"}. |
3502 *} |
3481 *} |
3560 fun code :: "tprog \<Rightarrow> nat" |
3539 fun code :: "tprog \<Rightarrow> nat" |
3561 where |
3540 where |
3562 "code tp = (let nl = modify_tprog tp in |
3541 "code tp = (let nl = modify_tprog tp in |
3563 godel_code nl)" |
3542 godel_code nl)" |
3564 |
3543 |
3565 section {* Relating interperter functions to the execution of TMs *} |
3544 subsection {* Relating interperter functions to the execution of TMs *} |
3566 |
3545 |
3567 lemma [simp]: "bl2wc [] = 0" by(simp add: bl2wc.simps bl2nat.simps) |
3546 lemma [simp]: "bl2wc [] = 0" by(simp add: bl2wc.simps bl2nat.simps) |
3568 term trpl |
3547 term trpl |
3569 |
3548 |
3570 lemma [simp]: "\<lbrakk>fetch tp 0 b = (nact, ns)\<rbrakk> \<Longrightarrow> action_map nact = 4" |
3549 lemma [simp]: "\<lbrakk>fetch tp 0 b = (nact, ns)\<rbrakk> \<Longrightarrow> action_map nact = 4" |
3571 apply(simp add: fetch.simps) |
3550 apply(simp add: fetch.simps) |
3572 done |
3551 done |
3573 |
3552 |
3574 thm entry_lemma |
|
3575 lemma Pi_gr_1[simp]: "Pi n > Suc 0" |
3553 lemma Pi_gr_1[simp]: "Pi n > Suc 0" |
3576 proof(induct n, auto simp: Pi.simps Np.simps) |
3554 proof(induct n, auto simp: Pi.simps Np.simps) |
3577 fix n |
3555 fix n |
3578 let ?setx = "{y. y \<le> Suc (Pi n!) \<and> Pi n < y \<and> Prime y}" |
3556 let ?setx = "{y. y \<le> Suc (Pi n!) \<and> Pi n < y \<and> Prime y}" |
3579 have "finite ?setx" by auto |
3557 have "finite ?setx" by auto |
3976 lemma godel_code_get_nth: |
3954 lemma godel_code_get_nth: |
3977 "i < length nl \<Longrightarrow> |
3955 "i < length nl \<Longrightarrow> |
3978 Max {u. Pi (Suc i) ^ u dvd godel_code nl} = nl ! i" |
3956 Max {u. Pi (Suc i) ^ u dvd godel_code nl} = nl ! i" |
3979 by(simp add: godel_code.simps godel_code'_get_nth) |
3957 by(simp add: godel_code.simps godel_code'_get_nth) |
3980 |
3958 |
3981 thm trpl.simps |
|
3982 |
|
3983 lemma "trpl l st r = godel_code' [l, st, r] 0" |
3959 lemma "trpl l st r = godel_code' [l, st, r] 0" |
3984 apply(simp add: trpl.simps godel_code'.simps) |
3960 apply(simp add: trpl.simps godel_code'.simps) |
3985 done |
3961 done |
3986 |
3962 |
3987 lemma mod_dvd_simp: "(x mod y = (0::nat)) = (y dvd x)" |
3963 lemma mod_dvd_simp: "(x mod y = (0::nat)) = (y dvd x)" |
4216 qed |
4192 qed |
4217 hence |
4193 hence |
4218 "Entry (godel_code (modify_tprog tp))?i = |
4194 "Entry (godel_code (modify_tprog tp))?i = |
4219 (modify_tprog tp) ! ?i" |
4195 (modify_tprog tp) ! ?i" |
4220 by(erule_tac godel_decode) |
4196 by(erule_tac godel_decode) |
4221 thm modify_tprog.simps |
4197 moreover have |
4222 moreover have |
|
4223 "modify_tprog tp ! ?i = |
4198 "modify_tprog tp ! ?i = |
4224 action_map (fst (tp ! (2 * (st - Suc 0) + r mod 2)))" |
4199 action_map (fst (tp ! (2 * (st - Suc 0) + r mod 2)))" |
4225 apply(rule_tac modify_tprog_fetch_action) |
4200 apply(rule_tac modify_tprog_fetch_action) |
4226 using h |
4201 using h |
4227 by(auto) |
4202 by(auto) |
4305 by(auto) |
4280 by(auto) |
4306 qed |
4281 qed |
4307 hence "Entry (godel_code (modify_tprog tp)) (?i) = |
4282 hence "Entry (godel_code (modify_tprog tp)) (?i) = |
4308 (modify_tprog tp) ! ?i" |
4283 (modify_tprog tp) ! ?i" |
4309 by(erule_tac godel_decode) |
4284 by(erule_tac godel_decode) |
4310 thm modify_tprog.simps |
4285 moreover have |
4311 moreover have |
|
4312 "modify_tprog tp ! ?i = |
4286 "modify_tprog tp ! ?i = |
4313 (snd (tp ! (2 * (st - Suc 0) + r mod 2)))" |
4287 (snd (tp ! (2 * (st - Suc 0) + r mod 2)))" |
4314 apply(rule_tac modify_tprog_fetch_state) |
4288 apply(rule_tac modify_tprog_fetch_state) |
4315 using h |
4289 using h |
4316 by(auto) |
4290 by(auto) |
4604 apply(simp add: conf_lemma) |
4578 apply(simp add: conf_lemma) |
4605 done |
4579 done |
4606 moreover hence |
4580 moreover hence |
4607 "trpl_code (tstep (a, b, c) tp) = |
4581 "trpl_code (tstep (a, b, c) tp) = |
4608 rec_exec rec_newconf [code tp, trpl_code (a, b, c)]" |
4582 rec_exec rec_newconf [code tp, trpl_code (a, b, c)]" |
4609 thm rec_t_eq_step |
|
4610 apply(rule_tac rec_t_eq_step) |
4583 apply(rule_tac rec_t_eq_step) |
4611 using h g |
4584 using h g |
4612 apply(simp add: s_keep) |
4585 apply(simp add: s_keep) |
4613 done |
4586 done |
4614 ultimately show |
4587 ultimately show |
4781 qed |
4754 qed |
4782 qed |
4755 qed |
4783 qed |
4756 qed |
4784 qed |
4757 qed |
4785 |
4758 |
4786 (* |
|
4787 lemma halt_steps_ex: |
|
4788 "\<lbrakk>steps (Suc 0, Bk\<^bsup>l\<^esup>, <lm>) tp stp = (0, Bk\<^bsup>m\<^esup>, Oc\<^bsup>rs\<^esup> @ Bk\<^bsup>n\<^esup>); |
|
4789 lm \<noteq> []; turing_basic.t_correct tp; 0<rs\<rbrakk> \<Longrightarrow> |
|
4790 \<exists> t. rec_calc_rel (rec_halt (length lm)) (code tp # lm) t" |
|
4791 apply(drule_tac halt_least_step, auto) |
|
4792 apply(rule_tac x = stp in exI) |
|
4793 apply(simp add: halt_lemma nonstop_lemma) |
|
4794 apply(auto) |
|
4795 done*) |
|
4796 thm loR.simps |
|
4797 |
|
4798 lemma conf_trpl_ex: "\<exists> p q r. conf m (bl2wc (<lm>)) stp = trpl p q r" |
4759 lemma conf_trpl_ex: "\<exists> p q r. conf m (bl2wc (<lm>)) stp = trpl p q r" |
4799 apply(induct stp, auto simp: conf.simps inpt.simps trpl.simps |
4760 apply(induct stp, auto simp: conf.simps inpt.simps trpl.simps |
4800 newconf.simps) |
4761 newconf.simps) |
4801 apply(rule_tac x = 0 in exI, rule_tac x = 1 in exI, |
4762 apply(rule_tac x = 0 in exI, rule_tac x = 1 in exI, |
4802 rule_tac x = "bl2wc (<lm>)" in exI) |
4763 rule_tac x = "bl2wc (<lm>)" in exI) |