Paper/Paper.thy
author Christian Urban <christian dot urban at kcl dot ac dot uk>
Mon, 04 Feb 2013 01:17:09 +0000
changeset 112 fea23f9a9d85
parent 111 dfc629cd11de
child 113 8ef94047e6e2
permissions -rw-r--r--
updated
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
6
50880fcda34d added paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
     1
(*<*)
50880fcda34d added paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
     2
theory Paper
111
dfc629cd11de made uncomputable compatible with abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 109
diff changeset
     3
imports "../thys/abacus"
6
50880fcda34d added paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
     4
begin
50880fcda34d added paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
     5
48
559e5c6e5113 updated to ITP and updated directories
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 38
diff changeset
     6
(*
25
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 24
diff changeset
     7
hide_const (open) s 
48
559e5c6e5113 updated to ITP and updated directories
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 38
diff changeset
     8
*)
18
a961c2e4dcea updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 17
diff changeset
     9
109
4635641e77cb updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 107
diff changeset
    10
50
816e84ca16d6 updated turing_basic by Jian
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 49
diff changeset
    11
hide_const (open) Divides.adjust
816e84ca16d6 updated turing_basic by Jian
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 49
diff changeset
    12
32
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 31
diff changeset
    13
abbreviation
48
559e5c6e5113 updated to ITP and updated directories
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 38
diff changeset
    14
  "update2 p a \<equiv> update a p"
34
22e5804b135c updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 33
diff changeset
    15
18
a961c2e4dcea updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 17
diff changeset
    16
consts DUMMY::'a
a961c2e4dcea updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 17
diff changeset
    17
109
4635641e77cb updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 107
diff changeset
    18
4635641e77cb updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 107
diff changeset
    19
(* THEOREMS *)
4635641e77cb updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 107
diff changeset
    20
notation (Rule output)
4635641e77cb updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 107
diff changeset
    21
  "==>"  ("\<^raw:\mbox{}\inferrule{\mbox{>_\<^raw:}}>\<^raw:{\mbox{>_\<^raw:}}>")
4635641e77cb updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 107
diff changeset
    22
4635641e77cb updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 107
diff changeset
    23
syntax (Rule output)
4635641e77cb updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 107
diff changeset
    24
  "_bigimpl" :: "asms \<Rightarrow> prop \<Rightarrow> prop"
4635641e77cb updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 107
diff changeset
    25
  ("\<^raw:\mbox{}\inferrule{>_\<^raw:}>\<^raw:{\mbox{>_\<^raw:}}>")
4635641e77cb updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 107
diff changeset
    26
4635641e77cb updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 107
diff changeset
    27
  "_asms" :: "prop \<Rightarrow> asms \<Rightarrow> asms" 
4635641e77cb updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 107
diff changeset
    28
  ("\<^raw:\mbox{>_\<^raw:}\\>/ _")
4635641e77cb updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 107
diff changeset
    29
4635641e77cb updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 107
diff changeset
    30
  "_asm" :: "prop \<Rightarrow> asms" ("\<^raw:\mbox{>_\<^raw:}>")
4635641e77cb updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 107
diff changeset
    31
4635641e77cb updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 107
diff changeset
    32
notation (Axiom output)
4635641e77cb updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 107
diff changeset
    33
  "Trueprop"  ("\<^raw:\mbox{}\inferrule{\mbox{}}{\mbox{>_\<^raw:}}>")
4635641e77cb updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 107
diff changeset
    34
4635641e77cb updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 107
diff changeset
    35
notation (IfThen output)
4635641e77cb updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 107
diff changeset
    36
  "==>"  ("\<^raw:{\normalsize{}>If\<^raw:\,}> _/ \<^raw:{\normalsize \,>then\<^raw:\,}>/ _.")
4635641e77cb updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 107
diff changeset
    37
syntax (IfThen output)
4635641e77cb updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 107
diff changeset
    38
  "_bigimpl" :: "asms \<Rightarrow> prop \<Rightarrow> prop"
4635641e77cb updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 107
diff changeset
    39
  ("\<^raw:{\normalsize{}>If\<^raw:\,}> _ /\<^raw:{\normalsize \,>then\<^raw:\,}>/ _.")
4635641e77cb updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 107
diff changeset
    40
  "_asms" :: "prop \<Rightarrow> asms \<Rightarrow> asms" ("\<^raw:\mbox{>_\<^raw:}> /\<^raw:{\normalsize \,>and\<^raw:\,}>/ _")
4635641e77cb updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 107
diff changeset
    41
  "_asm" :: "prop \<Rightarrow> asms" ("\<^raw:\mbox{>_\<^raw:}>")
4635641e77cb updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 107
diff changeset
    42
4635641e77cb updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 107
diff changeset
    43
notation (IfThenNoBox output)
4635641e77cb updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 107
diff changeset
    44
  "==>"  ("\<^raw:{\normalsize{}>If\<^raw:\,}> _/ \<^raw:{\normalsize \,>then\<^raw:\,}>/ _.")
4635641e77cb updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 107
diff changeset
    45
syntax (IfThenNoBox output)
4635641e77cb updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 107
diff changeset
    46
  "_bigimpl" :: "asms \<Rightarrow> prop \<Rightarrow> prop"
4635641e77cb updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 107
diff changeset
    47
  ("\<^raw:{\normalsize{}>If\<^raw:\,}> _ /\<^raw:{\normalsize \,>then\<^raw:\,}>/ _.")
4635641e77cb updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 107
diff changeset
    48
  "_asms" :: "prop \<Rightarrow> asms \<Rightarrow> asms" ("_ /\<^raw:{\normalsize \,>and\<^raw:\,}>/ _")
4635641e77cb updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 107
diff changeset
    49
  "_asm" :: "prop \<Rightarrow> asms" ("_")
4635641e77cb updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 107
diff changeset
    50
4635641e77cb updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 107
diff changeset
    51
4635641e77cb updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 107
diff changeset
    52
context uncomputable
4635641e77cb updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 107
diff changeset
    53
begin
4635641e77cb updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 107
diff changeset
    54
18
a961c2e4dcea updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 17
diff changeset
    55
notation (latex output)
100
dfe852aacae6 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 99
diff changeset
    56
  Cons ("_::_" [48,47] 48) and
32
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 31
diff changeset
    57
  set ("") and
18
a961c2e4dcea updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 17
diff changeset
    58
  W0 ("W\<^bsub>\<^raw:\hspace{-2pt}>Bk\<^esub>") and
a961c2e4dcea updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 17
diff changeset
    59
  W1 ("W\<^bsub>\<^raw:\hspace{-2pt}>Oc\<^esub>") and
48
559e5c6e5113 updated to ITP and updated directories
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 38
diff changeset
    60
  update2 ("update") and
63
35fe8fe12e65 small updates
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 61
diff changeset
    61
  tm_wf0 ("wf") and
85
e6f395eccfe7 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 84
diff changeset
    62
  (*is_even ("iseven") and*)
105
2cae8a39803e updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 104
diff changeset
    63
  tcopy_begin ("cbegin") and
2cae8a39803e updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 104
diff changeset
    64
  tcopy_loop ("cloop") and
2cae8a39803e updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 104
diff changeset
    65
  tcopy_end ("cend") and
75
97eaf7514988 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 73
diff changeset
    66
  step0 ("step") and
109
4635641e77cb updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 107
diff changeset
    67
  tcontra ("contra") and
4635641e77cb updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 107
diff changeset
    68
  code_tcontra ("code contra") and
75
97eaf7514988 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 73
diff changeset
    69
  steps0 ("steps") and
81
2e9881578cb2 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 80
diff changeset
    70
  exponent ("_\<^bsup>_\<^esup>") and
105
2cae8a39803e updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 104
diff changeset
    71
  haltP ("halts") and 
37
c9b689bb4156 added new version of uncomputable
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 36
diff changeset
    72
  tcopy ("copy") and 
85
e6f395eccfe7 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 84
diff changeset
    73
  tape_of ("\<langle>_\<rangle>") and 
48
559e5c6e5113 updated to ITP and updated directories
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 38
diff changeset
    74
  tm_comp ("_ \<oplus> _") and 
97
d6f04e3e9894 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 96
diff changeset
    75
  DUMMY  ("\<^raw:\mbox{$\_\!\_\,$}>") and
d6f04e3e9894 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 96
diff changeset
    76
  inv_begin0 ("I\<^isub>0") and
d6f04e3e9894 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 96
diff changeset
    77
  inv_begin1 ("I\<^isub>1") and
d6f04e3e9894 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 96
diff changeset
    78
  inv_begin2 ("I\<^isub>2") and
d6f04e3e9894 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 96
diff changeset
    79
  inv_begin3 ("I\<^isub>3") and
d6f04e3e9894 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 96
diff changeset
    80
  inv_begin4 ("I\<^isub>4") and 
105
2cae8a39803e updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 104
diff changeset
    81
  inv_begin ("I\<^bsub>cbegin\<^esub>") and
2cae8a39803e updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 104
diff changeset
    82
  inv_loop1 ("J\<^isub>1") and
2cae8a39803e updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 104
diff changeset
    83
  inv_loop0 ("J\<^isub>0") and
2cae8a39803e updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 104
diff changeset
    84
  inv_end1 ("K\<^isub>1") and
2cae8a39803e updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 104
diff changeset
    85
  inv_end0 ("K\<^isub>0") and
2cae8a39803e updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 104
diff changeset
    86
  measure_begin_step ("M\<^bsub>cbegin\<^esub>")
97
d6f04e3e9894 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 96
diff changeset
    87
d6f04e3e9894 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 96
diff changeset
    88
 
d6f04e3e9894 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 96
diff changeset
    89
lemma inv_begin_print:
d6f04e3e9894 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 96
diff changeset
    90
  shows "s = 0 \<Longrightarrow> inv_begin n (s, tp) = inv_begin0 n tp" and
d6f04e3e9894 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 96
diff changeset
    91
        "s = 1 \<Longrightarrow> inv_begin n (s, tp) = inv_begin1 n tp" and 
d6f04e3e9894 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 96
diff changeset
    92
        "s = 2 \<Longrightarrow> inv_begin n (s, tp) = inv_begin2 n tp" and 
d6f04e3e9894 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 96
diff changeset
    93
        "s = 3 \<Longrightarrow> inv_begin n (s, tp) = inv_begin3 n tp" and 
d6f04e3e9894 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 96
diff changeset
    94
        "s = 4 \<Longrightarrow> inv_begin n (s, tp) = inv_begin4 n tp" and
d6f04e3e9894 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 96
diff changeset
    95
        "s \<notin> {0,1,2,3,4} \<Longrightarrow> inv_begin n (s, l, r) = False"
d6f04e3e9894 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 96
diff changeset
    96
apply(case_tac [!] tp)
d6f04e3e9894 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 96
diff changeset
    97
by (auto)
d6f04e3e9894 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 96
diff changeset
    98
d6f04e3e9894 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 96
diff changeset
    99
lemma inv1: 
d6f04e3e9894 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 96
diff changeset
   100
  shows "0 < n \<Longrightarrow> inv_begin0 n \<mapsto> inv_loop1 n"
d6f04e3e9894 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 96
diff changeset
   101
unfolding assert_imp_def
d6f04e3e9894 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 96
diff changeset
   102
unfolding inv_loop1.simps inv_begin0.simps
d6f04e3e9894 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 96
diff changeset
   103
apply(auto)
d6f04e3e9894 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 96
diff changeset
   104
apply(rule_tac x="1" in exI)
d6f04e3e9894 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 96
diff changeset
   105
apply(auto simp add: replicate.simps)
d6f04e3e9894 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 96
diff changeset
   106
done
d6f04e3e9894 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 96
diff changeset
   107
d6f04e3e9894 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 96
diff changeset
   108
lemma inv2: 
d6f04e3e9894 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 96
diff changeset
   109
  shows "0 < n \<Longrightarrow> inv_loop0 n = inv_end1 n"
d6f04e3e9894 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 96
diff changeset
   110
apply(rule ext)
d6f04e3e9894 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 96
diff changeset
   111
apply(case_tac x)
d6f04e3e9894 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 96
diff changeset
   112
apply(simp add: inv_end1.simps)
d6f04e3e9894 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 96
diff changeset
   113
done
d6f04e3e9894 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 96
diff changeset
   114
18
a961c2e4dcea updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 17
diff changeset
   115
105
2cae8a39803e updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 104
diff changeset
   116
lemma measure_begin_print:
2cae8a39803e updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 104
diff changeset
   117
  shows "s = 2 \<Longrightarrow> measure_begin_step (s, l, r) = length r" and
2cae8a39803e updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 104
diff changeset
   118
        "s = 3 \<Longrightarrow> measure_begin_step (s, l, r) = (if r = [] \<or> r = [Bk] then 1 else 0)" and
2cae8a39803e updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 104
diff changeset
   119
        "s = 4 \<Longrightarrow> measure_begin_step (s, l, r) = length l" and 
2cae8a39803e updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 104
diff changeset
   120
        "s \<notin> {2,3,4} \<Longrightarrow> measure_begin_step (s, l, r) = 0"
2cae8a39803e updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 104
diff changeset
   121
by (simp_all)
2cae8a39803e updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 104
diff changeset
   122
6
50880fcda34d added paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   123
declare [[show_question_marks = false]]
71
8c7f10b3da7b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 63
diff changeset
   124
85
e6f395eccfe7 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 84
diff changeset
   125
lemma nats2tape:
e6f395eccfe7 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 84
diff changeset
   126
  shows "<([]::nat list)> = []"
97
d6f04e3e9894 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 96
diff changeset
   127
  and "<[n]> = <n>"
d6f04e3e9894 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 96
diff changeset
   128
  and "ns \<noteq> [] \<Longrightarrow> <n#ns> = <(n::nat, ns)>"
d6f04e3e9894 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 96
diff changeset
   129
  and "<(n, m)> = <n> @ [Bk] @ <m>"
d6f04e3e9894 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 96
diff changeset
   130
  and "<[n, m]> = <(n, m)>"
d6f04e3e9894 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 96
diff changeset
   131
  and "<n> = Oc \<up> (n + 1)" 
d6f04e3e9894 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 96
diff changeset
   132
apply(auto simp add: tape_of_nat_pair tape_of_nl_abv tape_of_nat_abv tape_of_nat_list.simps)
85
e6f395eccfe7 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 84
diff changeset
   133
apply(case_tac ns)
97
d6f04e3e9894 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 96
diff changeset
   134
apply(auto simp add: tape_of_nat_pair tape_of_nat_abv)
d6f04e3e9894 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 96
diff changeset
   135
done 
71
8c7f10b3da7b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 63
diff changeset
   136
93
f2bda6ba4952 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 92
diff changeset
   137
lemmas HR1 = 
99
fe7a257bdff4 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 98
diff changeset
   138
  Hoare_plus_halt[where ?S.0="R\<iota>" and ?A="p\<^isub>1" and B="p\<^isub>2"]
93
f2bda6ba4952 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 92
diff changeset
   139
f2bda6ba4952 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 92
diff changeset
   140
lemmas HR2 =
99
fe7a257bdff4 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 98
diff changeset
   141
  Hoare_plus_unhalt[where ?A="p\<^isub>1" and B="p\<^isub>2"]
93
f2bda6ba4952 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 92
diff changeset
   142
97
d6f04e3e9894 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 96
diff changeset
   143
lemma inv_begin01:
d6f04e3e9894 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 96
diff changeset
   144
  assumes "n > 1"
d6f04e3e9894 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 96
diff changeset
   145
  shows "inv_begin0 n (l, r) = (n > 1 \<and> (l, r) = (Oc \<up> (n - 2), [Oc, Oc, Bk, Oc]))"
d6f04e3e9894 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 96
diff changeset
   146
using assms by auto                          
d6f04e3e9894 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 96
diff changeset
   147
d6f04e3e9894 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 96
diff changeset
   148
lemma inv_begin02:
d6f04e3e9894 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 96
diff changeset
   149
  assumes "n = 1"
d6f04e3e9894 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 96
diff changeset
   150
  shows "inv_begin0 n (l, r) = (n = 1 \<and> (l, r) = ([], [Bk, Oc, Bk, Oc]))"
d6f04e3e9894 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 96
diff changeset
   151
using assms by auto
d6f04e3e9894 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 96
diff changeset
   152
109
4635641e77cb updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 107
diff changeset
   153
6
50880fcda34d added paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   154
(*>*)
50880fcda34d added paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   155
50880fcda34d added paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   156
section {* Introduction *}
50880fcda34d added paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   157
50
816e84ca16d6 updated turing_basic by Jian
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 49
diff changeset
   158
816e84ca16d6 updated turing_basic by Jian
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 49
diff changeset
   159
6
50880fcda34d added paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   160
text {*
50880fcda34d added paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   161
49
b388dceee892 shortening a bit the paper and updating various things
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   162
%\noindent
b388dceee892 shortening a bit the paper and updating various things
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   163
%We formalised in earlier work the correctness proofs for two
b388dceee892 shortening a bit the paper and updating various things
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   164
%algorithms in Isabelle/HOL---one about type-checking in
b388dceee892 shortening a bit the paper and updating various things
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   165
%LF~\cite{UrbanCheneyBerghofer11} and another about deciding requests
b388dceee892 shortening a bit the paper and updating various things
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   166
%in access control~\cite{WuZhangUrban12}.  The formalisations
b388dceee892 shortening a bit the paper and updating various things
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   167
%uncovered a gap in the informal correctness proof of the former and
b388dceee892 shortening a bit the paper and updating various things
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   168
%made us realise that important details were left out in the informal
b388dceee892 shortening a bit the paper and updating various things
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   169
%model for the latter. However, in both cases we were unable to
b388dceee892 shortening a bit the paper and updating various things
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   170
%formalise in Isabelle/HOL computability arguments about the
b388dceee892 shortening a bit the paper and updating various things
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   171
%algorithms. 
b388dceee892 shortening a bit the paper and updating various things
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   172
b388dceee892 shortening a bit the paper and updating various things
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   173
8
c216ae455c90 more on the paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 7
diff changeset
   174
\noindent
79
bc54c5e648d7 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 78
diff changeset
   175
Suppose you want to mechanise a proof for whether a predicate @{term
bc54c5e648d7 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 78
diff changeset
   176
P}, say, is decidable or not. Decidability of @{text P} usually
bc54c5e648d7 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 78
diff changeset
   177
amounts to showing whether \mbox{@{term "P \<or> \<not>P"}} holds. But this
bc54c5e648d7 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 78
diff changeset
   178
does \emph{not} work in Isabelle/HOL and other HOL theorem provers,
bc54c5e648d7 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 78
diff changeset
   179
since they are based on classical logic where the law of excluded
bc54c5e648d7 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 78
diff changeset
   180
middle ensures that \mbox{@{term "P \<or> \<not>P"}} is always provable no
bc54c5e648d7 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 78
diff changeset
   181
matter whether @{text P} is constructed by computable means. We hit on
bc54c5e648d7 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 78
diff changeset
   182
this limitation previously when we mechanised the correctness proofs
bc54c5e648d7 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 78
diff changeset
   183
of two algorithms \cite{UrbanCheneyBerghofer11,WuZhangUrban12}, but
109
4635641e77cb updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 107
diff changeset
   184
were unable to formalise arguments about decidability or undecidability.
49
b388dceee892 shortening a bit the paper and updating various things
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   185
b388dceee892 shortening a bit the paper and updating various things
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   186
%The same problem would arise if we had formulated
b388dceee892 shortening a bit the paper and updating various things
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   187
%the algorithms as recursive functions, because internally in
b388dceee892 shortening a bit the paper and updating various things
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   188
%Isabelle/HOL, like in all HOL-based theorem provers, functions are
b388dceee892 shortening a bit the paper and updating various things
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   189
%represented as inductively defined predicates too.
8
c216ae455c90 more on the paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 7
diff changeset
   190
49
b388dceee892 shortening a bit the paper and updating various things
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   191
The only satisfying way out of this problem in a theorem prover based
b388dceee892 shortening a bit the paper and updating various things
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   192
on classical logic is to formalise a theory of computability. Norrish
93
f2bda6ba4952 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 92
diff changeset
   193
provided such a formalisation for HOL4. He choose the
f2bda6ba4952 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 92
diff changeset
   194
$\lambda$-calculus as the starting point for his formalisation because
f2bda6ba4952 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 92
diff changeset
   195
of its ``simplicity'' \cite[Page 297]{Norrish11}.  Part of his
f2bda6ba4952 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 92
diff changeset
   196
formalisation is a clever infrastructure for reducing
f2bda6ba4952 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 92
diff changeset
   197
$\lambda$-terms. He also established the computational equivalence
f2bda6ba4952 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 92
diff changeset
   198
between the $\lambda$-calculus and recursive functions.  Nevertheless
f2bda6ba4952 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 92
diff changeset
   199
he concluded that it would be appealing to have formalisations for
f2bda6ba4952 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 92
diff changeset
   200
more operational models of computations, such as Turing machines or
f2bda6ba4952 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 92
diff changeset
   201
register machines.  One reason is that many proofs in the literature
f2bda6ba4952 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 92
diff changeset
   202
use them.  He noted however that \cite[Page 310]{Norrish11}:
8
c216ae455c90 more on the paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 7
diff changeset
   203
c216ae455c90 more on the paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 7
diff changeset
   204
\begin{quote}
c216ae455c90 more on the paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 7
diff changeset
   205
\it``If register machines are unappealing because of their 
49
b388dceee892 shortening a bit the paper and updating various things
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   206
general fiddliness,\\ Turing machines are an even more 
8
c216ae455c90 more on the paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 7
diff changeset
   207
daunting prospect.''
c216ae455c90 more on the paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 7
diff changeset
   208
\end{quote}
c216ae455c90 more on the paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 7
diff changeset
   209
c216ae455c90 more on the paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 7
diff changeset
   210
\noindent
33
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 32
diff changeset
   211
In this paper we take on this daunting prospect and provide a
13
a7ec585d7f20 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 12
diff changeset
   212
formalisation of Turing machines, as well as abacus machines (a kind
a7ec585d7f20 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 12
diff changeset
   213
of register machines) and recursive functions. To see the difficulties
49
b388dceee892 shortening a bit the paper and updating various things
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   214
involved with this work, one has to understand that Turing machine
80
eb589fa73fc1 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 79
diff changeset
   215
programs can be completely \emph{unstructured}, behaving similar to
eb589fa73fc1 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 79
diff changeset
   216
Basic programs involving the infamous goto \cite{Dijkstra68}. This
eb589fa73fc1 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 79
diff changeset
   217
precludes in the general case a compositional Hoare-style reasoning
eb589fa73fc1 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 79
diff changeset
   218
about Turing programs.  We provide such Hoare-rules for when it
eb589fa73fc1 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 79
diff changeset
   219
\emph{is} possible to reason in a compositional manner (which is
eb589fa73fc1 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 79
diff changeset
   220
fortunately quite often), but also tackle the more complicated case
eb589fa73fc1 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 79
diff changeset
   221
when we translate abacus programs into Turing programs.  This
eb589fa73fc1 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 79
diff changeset
   222
reasoning about concrete Turing machine programs is usually
eb589fa73fc1 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 79
diff changeset
   223
left out in the informal literature, e.g.~\cite{Boolos87}.
12
dd400b5797e1 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 10
diff changeset
   224
49
b388dceee892 shortening a bit the paper and updating various things
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   225
%To see the difficulties
b388dceee892 shortening a bit the paper and updating various things
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   226
%involved with this work, one has to understand that interactive
b388dceee892 shortening a bit the paper and updating various things
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   227
%theorem provers, like Isabelle/HOL, are at their best when the
b388dceee892 shortening a bit the paper and updating various things
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   228
%data-structures at hand are ``structurally'' defined, like lists,
b388dceee892 shortening a bit the paper and updating various things
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   229
%natural numbers, regular expressions, etc. Such data-structures come
b388dceee892 shortening a bit the paper and updating various things
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   230
%with convenient reasoning infrastructures (for example induction
b388dceee892 shortening a bit the paper and updating various things
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   231
%principles, recursion combinators and so on).  But this is \emph{not}
b388dceee892 shortening a bit the paper and updating various things
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   232
%the case with Turing machines (and also not with register machines):
b388dceee892 shortening a bit the paper and updating various things
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   233
%underlying their definitions are sets of states together with 
b388dceee892 shortening a bit the paper and updating various things
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   234
%transition functions, all of which are not structurally defined.  This
b388dceee892 shortening a bit the paper and updating various things
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   235
%means we have to implement our own reasoning infrastructure in order
b388dceee892 shortening a bit the paper and updating various things
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   236
%to prove properties about them. This leads to annoyingly fiddly
b388dceee892 shortening a bit the paper and updating various things
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   237
%formalisations.  We noticed first the difference between both,
b388dceee892 shortening a bit the paper and updating various things
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   238
%structural and non-structural, ``worlds'' when formalising the
b388dceee892 shortening a bit the paper and updating various things
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   239
%Myhill-Nerode theorem, where regular expressions fared much better
b388dceee892 shortening a bit the paper and updating various things
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   240
%than automata \cite{WuZhangUrban11}.  However, with Turing machines
b388dceee892 shortening a bit the paper and updating various things
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   241
%there seems to be no alternative if one wants to formalise the great
b388dceee892 shortening a bit the paper and updating various things
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   242
%many proofs from the literature that use them.  We will analyse one
b388dceee892 shortening a bit the paper and updating various things
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   243
%example---undecidability of Wang's tiling problem---in Section~\ref{Wang}. The
b388dceee892 shortening a bit the paper and updating various things
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   244
%standard proof of this property uses the notion of universal
b388dceee892 shortening a bit the paper and updating various things
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   245
%Turing machines.
b388dceee892 shortening a bit the paper and updating various things
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   246
97
d6f04e3e9894 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 96
diff changeset
   247
We are not the first who formalised Turing machines: we are aware of
d6f04e3e9894 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 96
diff changeset
   248
the work by Asperti and Ricciotti \cite{AspertiRicciotti12}. They
d6f04e3e9894 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 96
diff changeset
   249
describe a complete formalisation of Turing machines in the Matita
d6f04e3e9894 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 96
diff changeset
   250
theorem prover, including a universal Turing machine. However, they do
d6f04e3e9894 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 96
diff changeset
   251
\emph{not} formalise the undecidability of the halting problem since
d6f04e3e9894 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 96
diff changeset
   252
their main focus is complexity, rather than computability theory. They
d6f04e3e9894 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 96
diff changeset
   253
also report that the informal proofs from which they started are not
d6f04e3e9894 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 96
diff changeset
   254
``sufficiently accurate to be directly usable as a guideline for
d6f04e3e9894 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 96
diff changeset
   255
formalization'' \cite[Page 2]{AspertiRicciotti12}. For our
104
01f688735b9b updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 103
diff changeset
   256
formalisation we follow mainly the proofs from the textbook by Boolos
01f688735b9b updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 103
diff changeset
   257
et al \cite{Boolos87} and found that the description there is quite
88
904f9351ab94 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 87
diff changeset
   258
detailed. Some details are left out however: for example, constructing
104
01f688735b9b updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 103
diff changeset
   259
the \emph{copy Turing machine} is left as an excerise to the
01f688735b9b updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 103
diff changeset
   260
reader---a correctness proof is not mentioned at all; also \cite{Boolos87}
01f688735b9b updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 103
diff changeset
   261
only shows how the universal Turing machine is constructed for Turing
01f688735b9b updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 103
diff changeset
   262
machines computing unary functions. We had to figure out a way to
01f688735b9b updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 103
diff changeset
   263
generalise this result to $n$-ary functions. Similarly, when compiling
01f688735b9b updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 103
diff changeset
   264
recursive functions to abacus machines, the textbook again only shows
01f688735b9b updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 103
diff changeset
   265
how it can be done for 2- and 3-ary functions, but in the
01f688735b9b updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 103
diff changeset
   266
formalisation we need arbitrary functions. But the general ideas for
01f688735b9b updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 103
diff changeset
   267
how to do this are clear enough in \cite{Boolos87}.
49
b388dceee892 shortening a bit the paper and updating various things
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   268
%However, one
b388dceee892 shortening a bit the paper and updating various things
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   269
%aspect that is completely left out from the informal description in
b388dceee892 shortening a bit the paper and updating various things
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   270
%\cite{Boolos87}, and similar ones we are aware of, is arguments why certain Turing
b388dceee892 shortening a bit the paper and updating various things
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   271
%machines are correct. We will introduce Hoare-style proof rules
b388dceee892 shortening a bit the paper and updating various things
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   272
%which help us with such correctness arguments of Turing machines.
10
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 9
diff changeset
   273
17
66cebc19ef18 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 16
diff changeset
   274
The main difference between our formalisation and the one by Asperti
66cebc19ef18 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 16
diff changeset
   275
and Ricciotti is that their universal Turing machine uses a different
66cebc19ef18 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 16
diff changeset
   276
alphabet than the machines it simulates. They write \cite[Page
66cebc19ef18 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 16
diff changeset
   277
23]{AspertiRicciotti12}:
10
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 9
diff changeset
   278
15
90bc8cccc218 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 13
diff changeset
   279
\begin{quote}\it
13
a7ec585d7f20 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 12
diff changeset
   280
``In particular, the fact that the universal machine operates with a
a7ec585d7f20 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 12
diff changeset
   281
different alphabet with respect to the machines it simulates is
a7ec585d7f20 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 12
diff changeset
   282
annoying.'' 
a7ec585d7f20 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 12
diff changeset
   283
\end{quote}
6
50880fcda34d added paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   284
15
90bc8cccc218 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 13
diff changeset
   285
\noindent
17
66cebc19ef18 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 16
diff changeset
   286
In this paper we follow the approach by Boolos et al \cite{Boolos87},
66cebc19ef18 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 16
diff changeset
   287
which goes back to Post \cite{Post36}, where all Turing machines
50
816e84ca16d6 updated turing_basic by Jian
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 49
diff changeset
   288
operate on tapes that contain only \emph{blank} or \emph{occupied} cells. 
816e84ca16d6 updated turing_basic by Jian
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 49
diff changeset
   289
Traditionally the content of a cell can be any
18
a961c2e4dcea updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 17
diff changeset
   290
character from a finite alphabet. Although computationally equivalent,
a961c2e4dcea updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 17
diff changeset
   291
the more restrictive notion of Turing machines in \cite{Boolos87} makes
a961c2e4dcea updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 17
diff changeset
   292
the reasoning more uniform. In addition some proofs \emph{about} Turing
34
22e5804b135c updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 33
diff changeset
   293
machines are simpler.  The reason is that one often needs to encode
20
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 19
diff changeset
   294
Turing machines---consequently if the Turing machines are simpler, then the coding
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 19
diff changeset
   295
functions are simpler too. Unfortunately, the restrictiveness also makes
34
22e5804b135c updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 33
diff changeset
   296
it harder to design programs for these Turing machines. In order
38
8f8db701f69f updated contribution section
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 37
diff changeset
   297
to construct a universal Turing machine we therefore do not follow 
34
22e5804b135c updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 33
diff changeset
   298
\cite{AspertiRicciotti12}, instead follow the proof in
75
97eaf7514988 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 73
diff changeset
   299
\cite{Boolos87} by translating abacus machines to Turing machines and in
18
a961c2e4dcea updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 17
diff changeset
   300
turn recursive functions to abacus machines. The universal Turing
20
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 19
diff changeset
   301
machine can then be constructed as a recursive function.
6
50880fcda34d added paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   302
18
a961c2e4dcea updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 17
diff changeset
   303
\smallskip
6
50880fcda34d added paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   304
\noindent
38
8f8db701f69f updated contribution section
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 37
diff changeset
   305
{\bf Contributions:} We formalised in Isabelle/HOL Turing machines following the
8f8db701f69f updated contribution section
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 37
diff changeset
   306
description of Boolos et al \cite{Boolos87} where tapes only have blank or
8f8db701f69f updated contribution section
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 37
diff changeset
   307
occupied cells. We mechanise the undecidability of the halting problem and
8f8db701f69f updated contribution section
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 37
diff changeset
   308
prove the correctness of concrete Turing machines that are needed
8f8db701f69f updated contribution section
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 37
diff changeset
   309
in this proof; such correctness proofs are left out in the informal literature.  
72
49f8e5cf82c5 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 71
diff changeset
   310
For reasoning about Turing machine programs we derive Hoare-rules.
49f8e5cf82c5 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 71
diff changeset
   311
We also construct the universal Turing machine from \cite{Boolos87} by
79
bc54c5e648d7 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 78
diff changeset
   312
translating recursive functions to abacus machines and abacus machines to
38
8f8db701f69f updated contribution section
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 37
diff changeset
   313
Turing machines. Since we have set up in Isabelle/HOL a very general computability
71
8c7f10b3da7b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 63
diff changeset
   314
model and undecidability result, we are able to formalise other
8c7f10b3da7b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 63
diff changeset
   315
results: we describe a proof of the computational equivalence
8c7f10b3da7b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 63
diff changeset
   316
of single-sided Turing machines, which is not given in \cite{Boolos87},
80
eb589fa73fc1 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 79
diff changeset
   317
but needed for example for formalising the undecidability proof of 
eb589fa73fc1 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 79
diff changeset
   318
Wang's tiling problem \cite{Robinson71}.
71
8c7f10b3da7b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 63
diff changeset
   319
%We are not aware of any other
8c7f10b3da7b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 63
diff changeset
   320
%formalisation of a substantial undecidability problem.
6
50880fcda34d added paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   321
*}
50880fcda34d added paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   322
17
66cebc19ef18 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 16
diff changeset
   323
section {* Turing Machines *}
9
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 8
diff changeset
   324
20
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 19
diff changeset
   325
text {* \noindent
50
816e84ca16d6 updated turing_basic by Jian
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 49
diff changeset
   326
  Turing machines can be thought of as having a \emph{head},
18
a961c2e4dcea updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 17
diff changeset
   327
  ``gliding'' over a potentially infinite tape. Boolos et
a961c2e4dcea updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 17
diff changeset
   328
  al~\cite{Boolos87} only consider tapes with cells being either blank
20
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 19
diff changeset
   329
  or occupied, which we represent by a datatype having two
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 19
diff changeset
   330
  constructors, namely @{text Bk} and @{text Oc}.  One way to
18
a961c2e4dcea updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 17
diff changeset
   331
  represent such tapes is to use a pair of lists, written @{term "(l,
75
97eaf7514988 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 73
diff changeset
   332
  r)"}, where @{term l} stands for the tape on the left-hand side of
81
2e9881578cb2 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 80
diff changeset
   333
  the head and @{term r} for the tape on the right-hand side.  We use
2e9881578cb2 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 80
diff changeset
   334
  the notation @{term "Bk \<up> n"} (similarly @{term "Oc \<up> n"}) for lists
88
904f9351ab94 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 87
diff changeset
   335
  composed of @{term n} elements of @{term Bk}s.  We also have the
89
c67e8ed4c865 updated uncomputable
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 88
diff changeset
   336
  convention that the head, abbreviated @{term hd}, of the right list
81
2e9881578cb2 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 80
diff changeset
   337
  is the cell on which the head of the Turing machine currently
2e9881578cb2 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 80
diff changeset
   338
  scannes. This can be pictured as follows:
50
816e84ca16d6 updated turing_basic by Jian
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 49
diff changeset
   339
  %
18
a961c2e4dcea updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 17
diff changeset
   340
  \begin{center}
85
e6f395eccfe7 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 84
diff changeset
   341
  \begin{tikzpicture}[scale=0.9]
18
a961c2e4dcea updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 17
diff changeset
   342
  \draw[very thick] (-3.0,0)   -- ( 3.0,0);
a961c2e4dcea updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 17
diff changeset
   343
  \draw[very thick] (-3.0,0.5) -- ( 3.0,0.5);
a961c2e4dcea updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 17
diff changeset
   344
  \draw[very thick] (-0.25,0)   -- (-0.25,0.5);
a961c2e4dcea updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 17
diff changeset
   345
  \draw[very thick] ( 0.25,0)   -- ( 0.25,0.5);
a961c2e4dcea updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 17
diff changeset
   346
  \draw[very thick] (-0.75,0)   -- (-0.75,0.5);
a961c2e4dcea updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 17
diff changeset
   347
  \draw[very thick] ( 0.75,0)   -- ( 0.75,0.5);
a961c2e4dcea updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 17
diff changeset
   348
  \draw[very thick] (-1.25,0)   -- (-1.25,0.5);
a961c2e4dcea updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 17
diff changeset
   349
  \draw[very thick] ( 1.25,0)   -- ( 1.25,0.5);
a961c2e4dcea updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 17
diff changeset
   350
  \draw[very thick] (-1.75,0)   -- (-1.75,0.5);
a961c2e4dcea updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 17
diff changeset
   351
  \draw[very thick] ( 1.75,0)   -- ( 1.75,0.5);
a961c2e4dcea updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 17
diff changeset
   352
  \draw[rounded corners=1mm] (-0.35,-0.1) rectangle (0.35,0.6);
a961c2e4dcea updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 17
diff changeset
   353
  \draw[fill]     (1.35,0.1) rectangle (1.65,0.4);
a961c2e4dcea updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 17
diff changeset
   354
  \draw[fill]     (0.85,0.1) rectangle (1.15,0.4);
a961c2e4dcea updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 17
diff changeset
   355
  \draw[fill]     (-0.35,0.1) rectangle (-0.65,0.4);
80
eb589fa73fc1 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 79
diff changeset
   356
  \draw[fill]     (-1.65,0.1) rectangle (-1.35,0.4);
18
a961c2e4dcea updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 17
diff changeset
   357
  \draw (-0.25,0.8) -- (-0.25,-0.8);
a961c2e4dcea updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 17
diff changeset
   358
  \draw[<->] (-1.25,-0.7) -- (0.75,-0.7);
85
e6f395eccfe7 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 84
diff changeset
   359
  \node [anchor=base] at (-0.85,-0.5) {\small left list};
e6f395eccfe7 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 84
diff changeset
   360
  \node [anchor=base] at (0.40,-0.5) {\small right list};
18
a961c2e4dcea updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 17
diff changeset
   361
  \node [anchor=base] at (0.1,0.7) {\small head};
a961c2e4dcea updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 17
diff changeset
   362
  \node [anchor=base] at (-2.2,0.2) {\ldots};
a961c2e4dcea updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 17
diff changeset
   363
  \node [anchor=base] at ( 2.3,0.2) {\ldots};
a961c2e4dcea updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 17
diff changeset
   364
  \end{tikzpicture}
a961c2e4dcea updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 17
diff changeset
   365
  \end{center}
17
66cebc19ef18 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 16
diff changeset
   366
  
18
a961c2e4dcea updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 17
diff changeset
   367
  \noindent
a961c2e4dcea updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 17
diff changeset
   368
  Note that by using lists each side of the tape is only finite. The
34
22e5804b135c updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 33
diff changeset
   369
  potential infinity is achieved by adding an appropriate blank or occupied cell 
22e5804b135c updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 33
diff changeset
   370
  whenever the head goes over the ``edge'' of the tape. To 
79
bc54c5e648d7 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 78
diff changeset
   371
  make this formal we define five possible \emph{actions} 
18
a961c2e4dcea updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 17
diff changeset
   372
  the Turing machine can perform:
17
66cebc19ef18 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 16
diff changeset
   373
66cebc19ef18 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 16
diff changeset
   374
  \begin{center}
50
816e84ca16d6 updated turing_basic by Jian
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 49
diff changeset
   375
  \begin{tabular}[t]{@ {}rcl@ {\hspace{2mm}}l}
816e84ca16d6 updated turing_basic by Jian
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 49
diff changeset
   376
  @{text "a"} & $::=$  & @{term "W0"} & (write blank, @{term Bk})\\
816e84ca16d6 updated turing_basic by Jian
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 49
diff changeset
   377
  & $\mid$ & @{term "W1"} & (write occupied, @{term Oc})\\
816e84ca16d6 updated turing_basic by Jian
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 49
diff changeset
   378
  \end{tabular}
816e84ca16d6 updated turing_basic by Jian
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 49
diff changeset
   379
  \begin{tabular}[t]{rcl@ {\hspace{2mm}}l}
816e84ca16d6 updated turing_basic by Jian
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 49
diff changeset
   380
  & $\mid$ & @{term L} & (move left)\\
816e84ca16d6 updated turing_basic by Jian
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 49
diff changeset
   381
  & $\mid$ & @{term R} & (move right)\\
816e84ca16d6 updated turing_basic by Jian
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 49
diff changeset
   382
  \end{tabular}
816e84ca16d6 updated turing_basic by Jian
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 49
diff changeset
   383
  \begin{tabular}[t]{rcl@ {\hspace{2mm}}l@ {}}
816e84ca16d6 updated turing_basic by Jian
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 49
diff changeset
   384
  & $\mid$ & @{term Nop} & (do-nothing operation)\\
18
a961c2e4dcea updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 17
diff changeset
   385
  \end{tabular}
a961c2e4dcea updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 17
diff changeset
   386
  \end{center}
a961c2e4dcea updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 17
diff changeset
   387
a961c2e4dcea updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 17
diff changeset
   388
  \noindent
20
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 19
diff changeset
   389
  We slightly deviate
93
f2bda6ba4952 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 92
diff changeset
   390
  from the presentation in \cite{Boolos87} (and also \cite{AspertiRicciotti12}) 
91
2068654bdf54 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 90
diff changeset
   391
  by using the @{term Nop} operation; however its use
34
22e5804b135c updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 33
diff changeset
   392
  will become important when we formalise halting computations and also universal Turing 
81
2e9881578cb2 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 80
diff changeset
   393
  machines.  Given a tape and an action, we can define the
30
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 29
diff changeset
   394
  following tape updating function:
18
a961c2e4dcea updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 17
diff changeset
   395
a961c2e4dcea updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 17
diff changeset
   396
  \begin{center}
a961c2e4dcea updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 17
diff changeset
   397
  \begin{tabular}{l@ {\hspace{1mm}}c@ {\hspace{1mm}}l}
48
559e5c6e5113 updated to ITP and updated directories
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 38
diff changeset
   398
  @{thm (lhs) update.simps(1)} & @{text "\<equiv>"} & @{thm (rhs) update.simps(1)}\\
559e5c6e5113 updated to ITP and updated directories
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 38
diff changeset
   399
  @{thm (lhs) update.simps(2)} & @{text "\<equiv>"} & @{thm (rhs) update.simps(2)}\\
49
b388dceee892 shortening a bit the paper and updating various things
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   400
  @{thm (lhs) update.simps(3)} & @{text "\<equiv>"} & @{thm (rhs) update.simps(3)}\\
b388dceee892 shortening a bit the paper and updating various things
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   401
  @{thm (lhs) update.simps(4)} & @{text "\<equiv>"} & @{thm (rhs) update.simps(4)}\\
48
559e5c6e5113 updated to ITP and updated directories
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 38
diff changeset
   402
  @{thm (lhs) update.simps(5)} & @{text "\<equiv>"} & @{thm (rhs) update.simps(5)}\\
17
66cebc19ef18 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 16
diff changeset
   403
  \end{tabular}
66cebc19ef18 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 16
diff changeset
   404
  \end{center}
66cebc19ef18 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 16
diff changeset
   405
18
a961c2e4dcea updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 17
diff changeset
   406
  \noindent
89
c67e8ed4c865 updated uncomputable
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 88
diff changeset
   407
  The first two clauses replace the head of the right list
37
c9b689bb4156 added new version of uncomputable
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 36
diff changeset
   408
  with a new @{term Bk} or @{term Oc}, respectively. To see that
30
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 29
diff changeset
   409
  these two clauses make sense in case where @{text r} is the empty
50
816e84ca16d6 updated turing_basic by Jian
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 49
diff changeset
   410
  list, one has to know that the tail function, @{term tl}, is defined
18
a961c2e4dcea updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 17
diff changeset
   411
  such that @{term "tl [] == []"} holds. The third clause 
30
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 29
diff changeset
   412
  implements the move of the head one step to the left: we need
22
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 21
diff changeset
   413
  to test if the left-list @{term l} is empty; if yes, then we just prepend a 
89
c67e8ed4c865 updated uncomputable
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 88
diff changeset
   414
  blank cell to the right list; otherwise we have to remove the
c67e8ed4c865 updated uncomputable
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 88
diff changeset
   415
  head from the left-list and prepend it to the right list. Similarly
34
22e5804b135c updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 33
diff changeset
   416
  in the fourth clause for a right move action. The @{term Nop} operation
50
816e84ca16d6 updated turing_basic by Jian
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 49
diff changeset
   417
  leaves the the tape unchanged.
18
a961c2e4dcea updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 17
diff changeset
   418
49
b388dceee892 shortening a bit the paper and updating various things
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   419
  %Note that our treatment of the tape is rather ``unsymmetric''---we
89
c67e8ed4c865 updated uncomputable
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 88
diff changeset
   420
  %have the convention that the head of the right list is where the
49
b388dceee892 shortening a bit the paper and updating various things
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   421
  %head is currently positioned. Asperti and Ricciotti
b388dceee892 shortening a bit the paper and updating various things
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   422
  %\cite{AspertiRicciotti12} also considered such a representation, but
b388dceee892 shortening a bit the paper and updating various things
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   423
  %dismiss it as it complicates their definition for \emph{tape
b388dceee892 shortening a bit the paper and updating various things
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   424
  %equality}. The reason is that moving the head one step to
b388dceee892 shortening a bit the paper and updating various things
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   425
  %the left and then back to the right might change the tape (in case
b388dceee892 shortening a bit the paper and updating various things
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   426
  %of going over the ``edge''). Therefore they distinguish four types
b388dceee892 shortening a bit the paper and updating various things
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   427
  %of tapes: one where the tape is empty; another where the head
b388dceee892 shortening a bit the paper and updating various things
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   428
  %is on the left edge, respectively right edge, and in the middle
b388dceee892 shortening a bit the paper and updating various things
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   429
  %of the tape. The reading, writing and moving of the tape is then
b388dceee892 shortening a bit the paper and updating various things
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   430
  %defined in terms of these four cases.  In this way they can keep the
b388dceee892 shortening a bit the paper and updating various things
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   431
  %tape in a ``normalised'' form, and thus making a left-move followed
b388dceee892 shortening a bit the paper and updating various things
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   432
  %by a right-move being the identity on tapes. Since we are not using
b388dceee892 shortening a bit the paper and updating various things
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   433
  %the notion of tape equality, we can get away with the unsymmetric
b388dceee892 shortening a bit the paper and updating various things
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   434
  %definition above, and by using the @{term update} function
b388dceee892 shortening a bit the paper and updating various things
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   435
  %cover uniformly all cases including corner cases.
18
a961c2e4dcea updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 17
diff changeset
   436
50
816e84ca16d6 updated turing_basic by Jian
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 49
diff changeset
   437
  Next we need to define the \emph{states} of a Turing machine.  
816e84ca16d6 updated turing_basic by Jian
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 49
diff changeset
   438
  %Given
816e84ca16d6 updated turing_basic by Jian
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 49
diff changeset
   439
  %how little is usually said about how to represent them in informal
816e84ca16d6 updated turing_basic by Jian
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 49
diff changeset
   440
  %presentations, it might be surprising that in a theorem prover we
816e84ca16d6 updated turing_basic by Jian
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 49
diff changeset
   441
  %have to select carefully a representation. If we use the naive
816e84ca16d6 updated turing_basic by Jian
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 49
diff changeset
   442
  %representation where a Turing machine consists of a finite set of
816e84ca16d6 updated turing_basic by Jian
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 49
diff changeset
   443
  %states, then we will have difficulties composing two Turing
816e84ca16d6 updated turing_basic by Jian
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 49
diff changeset
   444
  %machines: we would need to combine two finite sets of states,
816e84ca16d6 updated turing_basic by Jian
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 49
diff changeset
   445
  %possibly renaming states apart whenever both machines share
816e84ca16d6 updated turing_basic by Jian
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 49
diff changeset
   446
  %states.\footnote{The usual disjoint union operation in Isabelle/HOL
816e84ca16d6 updated turing_basic by Jian
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 49
diff changeset
   447
  %cannot be used as it does not preserve types.} This renaming can be
816e84ca16d6 updated turing_basic by Jian
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 49
diff changeset
   448
  %quite cumbersome to reason about. 
73
a673539f2f75 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 72
diff changeset
   449
  We follow the choice made in \cite{AspertiRicciotti12} 
81
2e9881578cb2 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 80
diff changeset
   450
  by representing a state with a natural number and the states in a Turing
73
a673539f2f75 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 72
diff changeset
   451
  machine program by the initial segment of natural numbers starting from @{text 0}.
71
8c7f10b3da7b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 63
diff changeset
   452
  In doing so we can compose two Turing machine programs by
34
22e5804b135c updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 33
diff changeset
   453
  shifting the states of one by an appropriate amount to a higher
71
8c7f10b3da7b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 63
diff changeset
   454
  segment and adjusting some ``next states'' in the other. 
18
a961c2e4dcea updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 17
diff changeset
   455
63
35fe8fe12e65 small updates
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 61
diff changeset
   456
  An \emph{instruction} of a Turing machine is a pair consisting of 
30
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 29
diff changeset
   457
  an action and a natural number (the next state). A \emph{program} @{term p} of a Turing
34
22e5804b135c updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 33
diff changeset
   458
  machine is then a list of such pairs. Using as an example the following Turing machine
22e5804b135c updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 33
diff changeset
   459
  program, which consists of four instructions
81
2e9881578cb2 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 80
diff changeset
   460
  %
34
22e5804b135c updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 33
diff changeset
   461
  \begin{equation}
30
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 29
diff changeset
   462
  \begin{tikzpicture}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 29
diff changeset
   463
  \node [anchor=base] at (0,0) {@{thm dither_def}};
73
a673539f2f75 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 72
diff changeset
   464
  \node [anchor=west] at (-1.5,-0.64) 
a673539f2f75 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 72
diff changeset
   465
  {$\underbrace{\hspace{21mm}}_{\text{\begin{tabular}{@ {}l@ {}}1st state\\[-2mm] 
a673539f2f75 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 72
diff changeset
   466
  = starting state\end{tabular}}}$};
a673539f2f75 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 72
diff changeset
   467
  
30
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 29
diff changeset
   468
  \node [anchor=west] at ( 1.1,-0.42) {$\underbrace{\hspace{17mm}}_{\text{2nd state}}$};
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 29
diff changeset
   469
  \node [anchor=west] at (-1.5,0.65) {$\overbrace{\hspace{10mm}}^{\text{@{term Bk}-case}}$};
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 29
diff changeset
   470
  \node [anchor=west] at (-0.1,0.65) {$\overbrace{\hspace{6mm}}^{\text{@{term Oc}-case}}$};
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 29
diff changeset
   471
  \end{tikzpicture}
34
22e5804b135c updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 33
diff changeset
   472
  \label{dither}
22e5804b135c updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 33
diff changeset
   473
  \end{equation}
81
2e9881578cb2 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 80
diff changeset
   474
  %
29
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 28
diff changeset
   475
  \noindent
34
22e5804b135c updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 33
diff changeset
   476
  the reader can see we have organised our Turing machine programs so
79
bc54c5e648d7 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 78
diff changeset
   477
  that segments of two belong to a state. The first component of such a
34
22e5804b135c updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 33
diff changeset
   478
  segment determines what action should be taken and which next state
22e5804b135c updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 33
diff changeset
   479
  should be transitioned to in case the head reads a @{term Bk};
30
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 29
diff changeset
   480
  similarly the second component determines what should be done in
34
22e5804b135c updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 33
diff changeset
   481
  case of reading @{term Oc}. We have the convention that the first
22e5804b135c updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 33
diff changeset
   482
  state is always the \emph{starting state} of the Turing machine.
50
816e84ca16d6 updated turing_basic by Jian
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 49
diff changeset
   483
  The @{text 0}-state is special in that it will be used as the
34
22e5804b135c updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 33
diff changeset
   484
  ``halting state''.  There are no instructions for the @{text
22e5804b135c updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 33
diff changeset
   485
  0}-state, but it will always perform a @{term Nop}-operation and
22e5804b135c updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 33
diff changeset
   486
  remain in the @{text 0}-state.  Unlike Asperti and Riccioti
22e5804b135c updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 33
diff changeset
   487
  \cite{AspertiRicciotti12}, we have chosen a very concrete
22e5804b135c updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 33
diff changeset
   488
  representation for programs, because when constructing a universal
22e5804b135c updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 33
diff changeset
   489
  Turing machine, we need to define a coding function for programs.
81
2e9881578cb2 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 80
diff changeset
   490
  This can be directly done for our programs-as-lists, but is
2e9881578cb2 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 80
diff changeset
   491
  slightly more difficult for the functions used by Asperti and Ricciotti.
34
22e5804b135c updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 33
diff changeset
   492
29
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 28
diff changeset
   493
  Given a program @{term p}, a state
30
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 29
diff changeset
   494
  and the cell being read by the head, we need to fetch
22
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 21
diff changeset
   495
  the corresponding instruction from the program. For this we define 
18
a961c2e4dcea updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 17
diff changeset
   496
  the function @{term fetch}
a961c2e4dcea updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 17
diff changeset
   497
 
71
8c7f10b3da7b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 63
diff changeset
   498
  \begin{equation}\label{fetch}
8c7f10b3da7b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 63
diff changeset
   499
  \mbox{\begin{tabular}{l@ {\hspace{1mm}}c@ {\hspace{1mm}}l}
48
559e5c6e5113 updated to ITP and updated directories
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 38
diff changeset
   500
  \multicolumn{3}{l}{@{thm fetch.simps(1)[where b=DUMMY]}}\\
49
b388dceee892 shortening a bit the paper and updating various things
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   501
  @{thm (lhs) fetch.simps(2)} & @{text "\<equiv>"} & @{text "case nth_of p (2 * s) of"}\\
50
816e84ca16d6 updated turing_basic by Jian
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 49
diff changeset
   502
  \multicolumn{3}{@ {\hspace{4cm}}l}{@{text "None \<Rightarrow> (Nop, 0) | Some i \<Rightarrow> i"}}\\
49
b388dceee892 shortening a bit the paper and updating various things
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 48
diff changeset
   503
  @{thm (lhs) fetch.simps(3)} & @{text "\<equiv>"} & @{text "case nth_of p (2 * s + 1) of"}\\
50
816e84ca16d6 updated turing_basic by Jian
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 49
diff changeset
   504
  \multicolumn{3}{@ {\hspace{4cm}}l}{@{text "None \<Rightarrow> (Nop, 0) | Some i \<Rightarrow> i"}}
71
8c7f10b3da7b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 63
diff changeset
   505
  \end{tabular}}
8c7f10b3da7b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 63
diff changeset
   506
  \end{equation}
18
a961c2e4dcea updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 17
diff changeset
   507
30
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 29
diff changeset
   508
  \noindent
32
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 31
diff changeset
   509
  In this definition the function @{term nth_of} returns the @{text n}th element
34
22e5804b135c updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 33
diff changeset
   510
  from a list, provided it exists (@{term Some}-case), or if it does not, it
22e5804b135c updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 33
diff changeset
   511
  returns the default action @{term Nop} and the default state @{text 0} 
97
d6f04e3e9894 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 96
diff changeset
   512
  (@{term None}-case). We often have to restrict Turing machine programs 
71
8c7f10b3da7b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 63
diff changeset
   513
  to be well-formed: a program @{term p} is \emph{well-formed} if it 
8c7f10b3da7b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 63
diff changeset
   514
  satisfies the following three properties:
33
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 32
diff changeset
   515
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 32
diff changeset
   516
  \begin{center}
71
8c7f10b3da7b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 63
diff changeset
   517
  @{thm tm_wf.simps[where p="p" and off="0::nat", simplified, THEN eq_reflection]}
33
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 32
diff changeset
   518
  \end{center}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 32
diff changeset
   519
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 32
diff changeset
   520
  \noindent
75
97eaf7514988 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 73
diff changeset
   521
  The first states that @{text p} must have at least an instruction for the starting 
33
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 32
diff changeset
   522
  state; the second that @{text p} has a @{term Bk} and @{term Oc} instruction for every 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 32
diff changeset
   523
  state, and the third that every next-state is one of the states mentioned in
34
22e5804b135c updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 33
diff changeset
   524
  the program or being the @{text 0}-state.
22
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 21
diff changeset
   525
72
49f8e5cf82c5 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 71
diff changeset
   526
  We need to be able to sequentially compose Turing machine programs. Given our
49f8e5cf82c5 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 71
diff changeset
   527
  concrete representation, this is relatively straightforward, if
49f8e5cf82c5 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 71
diff changeset
   528
  slightly fiddly. We use the following two auxiliary functions:
49f8e5cf82c5 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 71
diff changeset
   529
49f8e5cf82c5 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 71
diff changeset
   530
  \begin{center}
49f8e5cf82c5 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 71
diff changeset
   531
  \begin{tabular}{@ {}l@ {\hspace{1mm}}c@ {\hspace{1mm}}l@ {}}
49f8e5cf82c5 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 71
diff changeset
   532
  @{thm (lhs) shift.simps} @{text "\<equiv>"} @{thm (rhs) shift.simps}\\
49f8e5cf82c5 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 71
diff changeset
   533
  @{thm (lhs) adjust.simps} @{text "\<equiv>"} @{thm (rhs) adjust.simps}\\
49f8e5cf82c5 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 71
diff changeset
   534
  \end{tabular}
49f8e5cf82c5 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 71
diff changeset
   535
  \end{center}
49f8e5cf82c5 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 71
diff changeset
   536
49f8e5cf82c5 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 71
diff changeset
   537
  \noindent
49f8e5cf82c5 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 71
diff changeset
   538
  The first adds @{text n} to all states, exept the @{text 0}-state,
49f8e5cf82c5 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 71
diff changeset
   539
  thus moving all ``regular'' states to the segment starting at @{text
49f8e5cf82c5 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 71
diff changeset
   540
  n}; the second adds @{term "Suc(length p div 2)"} to the @{text
49f8e5cf82c5 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 71
diff changeset
   541
  0}-state, thus redirecting all references to the ``halting state''
49f8e5cf82c5 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 71
diff changeset
   542
  to the first state after the program @{text p}.  With these two
49f8e5cf82c5 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 71
diff changeset
   543
  functions in place, we can define the \emph{sequential composition}
79
bc54c5e648d7 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 78
diff changeset
   544
  of two Turing machine programs @{text "p\<^isub>1"} and @{text "p\<^isub>2"} as
72
49f8e5cf82c5 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 71
diff changeset
   545
49f8e5cf82c5 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 71
diff changeset
   546
  \begin{center}
49f8e5cf82c5 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 71
diff changeset
   547
  @{thm tm_comp.simps[where ?p1.0="p\<^isub>1" and ?p2.0="p\<^isub>2", THEN eq_reflection]}
49f8e5cf82c5 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 71
diff changeset
   548
  \end{center}
49f8e5cf82c5 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 71
diff changeset
   549
49f8e5cf82c5 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 71
diff changeset
   550
  \noindent
49f8e5cf82c5 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 71
diff changeset
   551
  %This means @{text "p\<^isub>1"} is executed first. Whenever it originally
49f8e5cf82c5 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 71
diff changeset
   552
  %transitioned to the @{text 0}-state, it will in the composed program transition to the starting
49f8e5cf82c5 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 71
diff changeset
   553
  %state of @{text "p\<^isub>2"} instead. All the states of @{text "p\<^isub>2"}
49f8e5cf82c5 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 71
diff changeset
   554
  %have been shifted in order to make sure that the states of the composed 
49f8e5cf82c5 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 71
diff changeset
   555
  %program @{text "p\<^isub>1 \<oplus> p\<^isub>2"} still only ``occupy'' 
49f8e5cf82c5 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 71
diff changeset
   556
  %an initial segment of the natural numbers.
49f8e5cf82c5 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 71
diff changeset
   557
49f8e5cf82c5 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 71
diff changeset
   558
  A \emph{configuration} @{term c} of a Turing machine is a state
49f8e5cf82c5 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 71
diff changeset
   559
  together with a tape. This is written as @{text "(s, (l, r))"}.  We
73
a673539f2f75 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 72
diff changeset
   560
  say a configuration \emph{is final} if @{term "s = (0::nat)"} and we
72
49f8e5cf82c5 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 71
diff changeset
   561
  say a predicate @{text P} \emph{holds for} a configuration if @{text
79
bc54c5e648d7 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 78
diff changeset
   562
  "P"} holds for the tape @{text "(l, r)"}.  If we have a configuration and a program, we can
72
49f8e5cf82c5 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 71
diff changeset
   563
  calculate what the next configuration is by fetching the appropriate
49f8e5cf82c5 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 71
diff changeset
   564
  action and next state from the program, and by updating the state
49f8e5cf82c5 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 71
diff changeset
   565
  and tape accordingly.  This single step of execution is defined as
49f8e5cf82c5 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 71
diff changeset
   566
  the function @{term step}
22
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 21
diff changeset
   567
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 21
diff changeset
   568
  \begin{center}
63
35fe8fe12e65 small updates
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 61
diff changeset
   569
  \begin{tabular}{l@ {\hspace{1mm}}c@ {\hspace{1mm}}l}
35fe8fe12e65 small updates
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 61
diff changeset
   570
  @{text "step (s, (l, r)) p"} & @{text "\<equiv>"} & @{text "let (a, s') = fetch p s (read r)"}\\
35fe8fe12e65 small updates
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 61
diff changeset
   571
  & & @{text "in (s', update (l, r) a)"}
30
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 29
diff changeset
   572
  \end{tabular}
24
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 23
diff changeset
   573
  \end{center}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 23
diff changeset
   574
32
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 31
diff changeset
   575
  \noindent
104
01f688735b9b updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 103
diff changeset
   576
  where @{term "read r"} returns the head of the list @{text r}, or if
01f688735b9b updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 103
diff changeset
   577
  @{text r} is empty it returns @{term Bk}.  It is impossible in
01f688735b9b updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 103
diff changeset
   578
  Isabelle/HOL to lift the @{term step}-function in order to realise a
01f688735b9b updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 103
diff changeset
   579
  general evaluation function for Turing machines programs. The reason
01f688735b9b updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 103
diff changeset
   580
  is that functions in HOL-based provers need to be terminating, and
01f688735b9b updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 103
diff changeset
   581
  clearly there are programs that are not. We can however define a
01f688735b9b updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 103
diff changeset
   582
  recursive evaluation function that performs exactly @{text n} steps:
24
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 23
diff changeset
   583
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 23
diff changeset
   584
  \begin{center}
30
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 29
diff changeset
   585
  \begin{tabular}{l@ {\hspace{1mm}}c@ {\hspace{1mm}}l}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 29
diff changeset
   586
  @{thm (lhs) steps.simps(1)} & @{text "\<equiv>"} & @{thm (rhs) steps.simps(1)}\\
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 29
diff changeset
   587
  @{thm (lhs) steps.simps(2)} & @{text "\<equiv>"} & @{thm (rhs) steps.simps(2)}\\
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 29
diff changeset
   588
  \end{tabular}
22
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 21
diff changeset
   589
  \end{center}
18
a961c2e4dcea updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 17
diff changeset
   590
73
a673539f2f75 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 72
diff changeset
   591
  \noindent Recall our definition of @{term fetch} (shown in
a673539f2f75 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 72
diff changeset
   592
  \eqref{fetch}) with the default value for the @{text 0}-state. In
a673539f2f75 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 72
diff changeset
   593
  case a Turing program takes according to the usual textbook
109
4635641e77cb updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 107
diff changeset
   594
  definition, say \cite{Boolos87}, less than @{text n} steps before it
73
a673539f2f75 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 72
diff changeset
   595
  halts, then in our setting the @{term steps}-evaluation does not
a673539f2f75 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 72
diff changeset
   596
  actually halt, but rather transitions to the @{text 0}-state (the
a673539f2f75 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 72
diff changeset
   597
  final state) and remains there performing @{text Nop}-actions until
91
2068654bdf54 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 90
diff changeset
   598
  @{text n} is reached. 
73
a673539f2f75 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 72
diff changeset
   599
  
a673539f2f75 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 72
diff changeset
   600
  \begin{figure}[t]
a673539f2f75 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 72
diff changeset
   601
  \begin{center}
85
e6f395eccfe7 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 84
diff changeset
   602
  \begin{tabular}{@ {}c@ {\hspace{3mm}}c@ {\hspace{3mm}}c}
87
cf6e89b5f702 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 86
diff changeset
   603
  \begin{tabular}[t]{@ {}l@ {}}
92
b9d0dd18c81e updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 91
diff changeset
   604
  @{thm (lhs) tcopy_begin_def} @{text "\<equiv>"}\\
87
cf6e89b5f702 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 86
diff changeset
   605
  \hspace{2mm}@{text "["}@{text "(W\<^bsub>Bk\<^esub>, 0), (R, 2), (R, 3),"}\\
cf6e89b5f702 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 86
diff changeset
   606
  \hspace{2mm}\phantom{@{text "["}}@{text "(R, 2), (W1, 3), (L, 4),"}\\
cf6e89b5f702 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 86
diff changeset
   607
  \hspace{2mm}\phantom{@{text "["}}@{text "(L, 4), (L, 0)"}@{text "]"} 
cf6e89b5f702 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 86
diff changeset
   608
  \end{tabular}
cf6e89b5f702 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 86
diff changeset
   609
  &
cf6e89b5f702 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 86
diff changeset
   610
  \begin{tabular}[t]{@ {}l@ {}}
cf6e89b5f702 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 86
diff changeset
   611
  @{thm (lhs) tcopy_loop_def} @{text "\<equiv>"}\\
cf6e89b5f702 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 86
diff changeset
   612
  \hspace{2mm}@{text "["}@{text "(R, 0), (R, 2), (R, 3),"}\\
cf6e89b5f702 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 86
diff changeset
   613
  \hspace{2mm}\phantom{@{text "["}}@{text "(W\<^bsub>Bk\<^esub>, 2), (R, 3), (R, 4),"}\\
cf6e89b5f702 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 86
diff changeset
   614
  \hspace{2mm}\phantom{@{text "["}}@{text "(W\<^bsub>Oc\<^esub>, 5), (R, 4), (L, 6),"}\\
cf6e89b5f702 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 86
diff changeset
   615
  \hspace{2mm}\phantom{@{text "["}}@{text "(L, 5), (L, 6), (L, 1)"}@{text "]"} 
85
e6f395eccfe7 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 84
diff changeset
   616
  \end{tabular}
e6f395eccfe7 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 84
diff changeset
   617
  &
87
cf6e89b5f702 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 86
diff changeset
   618
  \begin{tabular}[t]{@ {}l@ {}}
cf6e89b5f702 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 86
diff changeset
   619
  @{thm (lhs) tcopy_end_def} @{text "\<equiv>"}\\
cf6e89b5f702 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 86
diff changeset
   620
  \hspace{2mm}@{text "["}@{text "(L, 0), (R, 2), (W\<^bsub>Oc\<^esub>, 3),"}\\
cf6e89b5f702 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 86
diff changeset
   621
  \hspace{2mm}\phantom{@{text "["}}@{text "(L, 4), (R, 2), (R, 2),"}\\
cf6e89b5f702 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 86
diff changeset
   622
  \hspace{2mm}\phantom{@{text "["}}@{text "(L, 5), (W\<^bsub>Bk\<^esub>, 4), (R, 0),"}\\
cf6e89b5f702 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 86
diff changeset
   623
  \hspace{2mm}\phantom{@{text "["}}@{text "(L, 5)"}@{text "]"} 
85
e6f395eccfe7 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 84
diff changeset
   624
  \end{tabular}
87
cf6e89b5f702 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 86
diff changeset
   625
  \end{tabular}\\[2mm]
cf6e89b5f702 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 86
diff changeset
   626
cf6e89b5f702 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 86
diff changeset
   627
  \begin{tikzpicture}[scale=0.7]
cf6e89b5f702 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 86
diff changeset
   628
  \node [anchor=base] at (2.2,0.1) {\small$\Rightarrow$};
cf6e89b5f702 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 86
diff changeset
   629
  \node [anchor=base] at (5.6,0.1) {\small$\Rightarrow$};
cf6e89b5f702 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 86
diff changeset
   630
  \node [anchor=base] at (10.5,0.1) {\small$\Rightarrow$};
98
860f05037c36 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 97
diff changeset
   631
  \node [anchor=base] at (2.2,-0.6) {\small$\overbrace{@{term "tcopy_begin"}}^{}$};
88
904f9351ab94 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 87
diff changeset
   632
  \node [anchor=base] at (5.6,-0.6) {\small$\overbrace{@{term "tcopy_loop"}}^{}$};
904f9351ab94 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 87
diff changeset
   633
  \node [anchor=base] at (10.5,-0.6) {\small$\overbrace{@{term "tcopy_end"}}^{}$};
87
cf6e89b5f702 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 86
diff changeset
   634
cf6e89b5f702 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 86
diff changeset
   635
cf6e89b5f702 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 86
diff changeset
   636
  \begin{scope}[shift={(0.5,0)}]
cf6e89b5f702 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 86
diff changeset
   637
  \draw[very thick] (-0.25,0)   -- ( 1.25,0);
cf6e89b5f702 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 86
diff changeset
   638
  \draw[very thick] (-0.25,0.5) -- ( 1.25,0.5);
cf6e89b5f702 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 86
diff changeset
   639
  \draw[very thick] (-0.25,0)   -- (-0.25,0.5);
cf6e89b5f702 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 86
diff changeset
   640
  \draw[very thick] ( 0.25,0)   -- ( 0.25,0.5);
cf6e89b5f702 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 86
diff changeset
   641
  \draw[very thick] ( 0.75,0)   -- ( 0.75,0.5);
cf6e89b5f702 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 86
diff changeset
   642
  \draw[very thick] ( 1.25,0)   -- ( 1.25,0.5);
cf6e89b5f702 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 86
diff changeset
   643
  \draw[rounded corners=1mm] (-0.35,-0.1) rectangle (0.35,0.6);
cf6e89b5f702 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 86
diff changeset
   644
  \draw[fill]     (-0.15,0.1) rectangle (0.15,0.4);
cf6e89b5f702 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 86
diff changeset
   645
  \draw[fill]     ( 0.35,0.1) rectangle (0.65,0.4);
cf6e89b5f702 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 86
diff changeset
   646
  \draw[fill]     ( 0.85,0.1) rectangle (1.15,0.4);
cf6e89b5f702 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 86
diff changeset
   647
  \end{scope}
cf6e89b5f702 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 86
diff changeset
   648
cf6e89b5f702 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 86
diff changeset
   649
  \begin{scope}[shift={(2.9,0)}]
cf6e89b5f702 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 86
diff changeset
   650
  \draw[very thick] (-0.25,0)   -- ( 2.25,0);
cf6e89b5f702 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 86
diff changeset
   651
  \draw[very thick] (-0.25,0.5) -- ( 2.25,0.5);
cf6e89b5f702 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 86
diff changeset
   652
  \draw[very thick] (-0.25,0)   -- (-0.25,0.5);
cf6e89b5f702 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 86
diff changeset
   653
  \draw[very thick] ( 0.25,0)   -- ( 0.25,0.5);
cf6e89b5f702 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 86
diff changeset
   654
  \draw[very thick] ( 0.75,0)   -- ( 0.75,0.5);
cf6e89b5f702 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 86
diff changeset
   655
  \draw[very thick] ( 1.25,0)   -- ( 1.25,0.5);
cf6e89b5f702 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 86
diff changeset
   656
  \draw[very thick] ( 1.75,0)   -- ( 1.75,0.5);
cf6e89b5f702 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 86
diff changeset
   657
  \draw[very thick] ( 2.25,0)   -- ( 2.25,0.5);
cf6e89b5f702 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 86
diff changeset
   658
  \draw[rounded corners=1mm] (0.15,-0.1) rectangle (0.85,0.6);
cf6e89b5f702 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 86
diff changeset
   659
  \draw[fill]     (-0.15,0.1) rectangle (0.15,0.4);
cf6e89b5f702 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 86
diff changeset
   660
  \draw[fill]     ( 0.35,0.1) rectangle (0.65,0.4);
cf6e89b5f702 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 86
diff changeset
   661
  \draw[fill]     ( 0.85,0.1) rectangle (1.15,0.4);
cf6e89b5f702 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 86
diff changeset
   662
  \draw[fill]     ( 1.85,0.1) rectangle (2.15,0.4);
cf6e89b5f702 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 86
diff changeset
   663
  \end{scope}
cf6e89b5f702 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 86
diff changeset
   664
cf6e89b5f702 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 86
diff changeset
   665
  \begin{scope}[shift={(6.8,0)}]
cf6e89b5f702 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 86
diff changeset
   666
  \draw[very thick] (-0.75,0)   -- ( 3.25,0);
cf6e89b5f702 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 86
diff changeset
   667
  \draw[very thick] (-0.75,0.5) -- ( 3.25,0.5);
cf6e89b5f702 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 86
diff changeset
   668
  \draw[very thick] (-0.75,0)   -- (-0.75,0.5);
cf6e89b5f702 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 86
diff changeset
   669
  \draw[very thick] (-0.25,0)   -- (-0.25,0.5);
cf6e89b5f702 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 86
diff changeset
   670
  \draw[very thick] ( 0.25,0)   -- ( 0.25,0.5);
cf6e89b5f702 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 86
diff changeset
   671
  \draw[very thick] ( 0.75,0)   -- ( 0.75,0.5);
cf6e89b5f702 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 86
diff changeset
   672
  \draw[very thick] ( 1.25,0)   -- ( 1.25,0.5);
cf6e89b5f702 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 86
diff changeset
   673
  \draw[very thick] ( 1.75,0)   -- ( 1.75,0.5);
cf6e89b5f702 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 86
diff changeset
   674
  \draw[very thick] ( 2.25,0)   -- ( 2.25,0.5);
cf6e89b5f702 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 86
diff changeset
   675
  \draw[very thick] ( 2.75,0)   -- ( 2.75,0.5);
cf6e89b5f702 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 86
diff changeset
   676
  \draw[very thick] ( 3.25,0)   -- ( 3.25,0.5);
cf6e89b5f702 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 86
diff changeset
   677
  \draw[rounded corners=1mm] (-0.35,-0.1) rectangle (0.35,0.6);
cf6e89b5f702 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 86
diff changeset
   678
  \draw[fill]     (-0.15,0.1) rectangle (0.15,0.4);
cf6e89b5f702 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 86
diff changeset
   679
  \draw[fill]     ( 2.35,0.1) rectangle (2.65,0.4);
cf6e89b5f702 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 86
diff changeset
   680
  \draw[fill]     ( 2.85,0.1) rectangle (3.15,0.4);
cf6e89b5f702 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 86
diff changeset
   681
  \draw[fill]     ( 1.85,0.1) rectangle (2.15,0.4);
cf6e89b5f702 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 86
diff changeset
   682
  \end{scope}
cf6e89b5f702 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 86
diff changeset
   683
cf6e89b5f702 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 86
diff changeset
   684
  \begin{scope}[shift={(11.7,0)}]
cf6e89b5f702 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 86
diff changeset
   685
  \draw[very thick] (-0.75,0)   -- ( 3.25,0);
cf6e89b5f702 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 86
diff changeset
   686
  \draw[very thick] (-0.75,0.5) -- ( 3.25,0.5);
cf6e89b5f702 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 86
diff changeset
   687
  \draw[very thick] (-0.75,0)   -- (-0.75,0.5);
cf6e89b5f702 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 86
diff changeset
   688
  \draw[very thick] (-0.25,0)   -- (-0.25,0.5);
cf6e89b5f702 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 86
diff changeset
   689
  \draw[very thick] ( 0.25,0)   -- ( 0.25,0.5);
cf6e89b5f702 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 86
diff changeset
   690
  \draw[very thick] ( 0.75,0)   -- ( 0.75,0.5);
cf6e89b5f702 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 86
diff changeset
   691
  \draw[very thick] ( 1.25,0)   -- ( 1.25,0.5);
cf6e89b5f702 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 86
diff changeset
   692
  \draw[very thick] ( 1.75,0)   -- ( 1.75,0.5);
cf6e89b5f702 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 86
diff changeset
   693
  \draw[very thick] ( 2.25,0)   -- ( 2.25,0.5);
cf6e89b5f702 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 86
diff changeset
   694
  \draw[very thick] ( 2.75,0)   -- ( 2.75,0.5);
cf6e89b5f702 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 86
diff changeset
   695
  \draw[very thick] ( 3.25,0)   -- ( 3.25,0.5);
cf6e89b5f702 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 86
diff changeset
   696
  \draw[rounded corners=1mm] (-0.35,-0.1) rectangle (0.35,0.6);
cf6e89b5f702 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 86
diff changeset
   697
  \draw[fill]     (-0.15,0.1) rectangle (0.15,0.4);
cf6e89b5f702 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 86
diff changeset
   698
  \draw[fill]     ( 2.35,0.1) rectangle (2.65,0.4);
cf6e89b5f702 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 86
diff changeset
   699
  \draw[fill]     ( 2.85,0.1) rectangle (3.15,0.4);
cf6e89b5f702 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 86
diff changeset
   700
  \draw[fill]     ( 1.85,0.1) rectangle (2.15,0.4);
cf6e89b5f702 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 86
diff changeset
   701
  \draw[fill]     ( 0.35,0.1) rectangle (0.65,0.4);
cf6e89b5f702 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 86
diff changeset
   702
  \draw[fill]     ( 0.85,0.1) rectangle (1.15,0.4);
cf6e89b5f702 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 86
diff changeset
   703
  \end{scope}
cf6e89b5f702 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 86
diff changeset
   704
  \end{tikzpicture}\\[-8mm]\mbox{} 
73
a673539f2f75 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 72
diff changeset
   705
  \end{center}
94
aeaf1374dc67 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   706
  \caption{The three components of the \emph{copy Turing machine} (above). If started 
97
d6f04e3e9894 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 96
diff changeset
   707
  (below) with the tape @{term "([], <(2::nat)>)"} the first machine appends @{term "[Bk, Oc]"} at 
87
cf6e89b5f702 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 86
diff changeset
   708
  the end of the right tape; the second then ``moves'' all @{term Oc}s except the 
cf6e89b5f702 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 86
diff changeset
   709
  first from the beginning of the tape to the end; the third ``refills'' the original 
97
d6f04e3e9894 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 96
diff changeset
   710
  block of @{term "Oc"}s. The resulting tape is @{term "([Bk], <(2::nat, 2::nat)>)"}.}
87
cf6e89b5f702 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 86
diff changeset
   711
  \label{copy}
73
a673539f2f75 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 72
diff changeset
   712
  \end{figure}
a673539f2f75 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 72
diff changeset
   713
87
cf6e89b5f702 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 86
diff changeset
   714
104
01f688735b9b updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 103
diff changeset
   715
  We often need to restrict tapes to be in standard form, which means 
81
2e9881578cb2 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 80
diff changeset
   716
  the left list of the tape is either empty or only contains @{text "Bk"}s, and 
2e9881578cb2 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 80
diff changeset
   717
  the right list contains some ``clusters'' of @{text "Oc"}s separted by single 
97
d6f04e3e9894 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 96
diff changeset
   718
  blanks. To make this formal we define the following overloaded function
104
01f688735b9b updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 103
diff changeset
   719
  encoding natural numbers into lists of @{term "Oc"}s and @{term Bk}s.
81
2e9881578cb2 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 80
diff changeset
   720
  
2e9881578cb2 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 80
diff changeset
   721
  \begin{center}
97
d6f04e3e9894 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 96
diff changeset
   722
  \begin{tabular}[t]{@ {}l@ {\hspace{1mm}}c@ {\hspace{1mm}}l@ {}}
d6f04e3e9894 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 96
diff changeset
   723
  @{thm (lhs) nats2tape(6)} & @{text "\<equiv>"} & @{thm (rhs) nats2tape(6)}\\
d6f04e3e9894 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 96
diff changeset
   724
  @{thm (lhs) nats2tape(4)} & @{text "\<equiv>"} & @{thm (rhs) nats2tape(4)}\\
d6f04e3e9894 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 96
diff changeset
   725
  \end{tabular}\hspace{6mm}
d6f04e3e9894 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 96
diff changeset
   726
  \begin{tabular}[t]{@ {}l@ {\hspace{1mm}}c@ {\hspace{1mm}}l@ {}}
85
e6f395eccfe7 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 84
diff changeset
   727
  @{thm (lhs) nats2tape(1)} & @{text "\<equiv>"} & @{thm (rhs) nats2tape(1)}\\
e6f395eccfe7 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 84
diff changeset
   728
  @{thm (lhs) nats2tape(2)} & @{text "\<equiv>"} & @{thm (rhs) nats2tape(2)}\\
e6f395eccfe7 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 84
diff changeset
   729
  @{thm (lhs) nats2tape(3)} & @{text "\<equiv>"} & @{thm (rhs) nats2tape(3)}
84
4c8325c64dab updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 81
diff changeset
   730
  \end{tabular}
81
2e9881578cb2 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 80
diff changeset
   731
  \end{center}
2e9881578cb2 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 80
diff changeset
   732
2e9881578cb2 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 80
diff changeset
   733
  \noindent
104
01f688735b9b updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 103
diff changeset
   734
  A \emph{standard tape} is then of the form @{text "(Bk\<^isup>l,\<langle>[n\<^isub>1,...,n\<^isub>m]\<rangle>)"} for some @{text l} 
84
4c8325c64dab updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 81
diff changeset
   735
  and @{text "n\<^isub>i"}. Note that the head in a standard tape ``points'' to the 
94
aeaf1374dc67 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   736
  leftmost @{term "Oc"} on the tape. Note also that the natural number @{text 0} 
aeaf1374dc67 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   737
  is represented by a single filled cell on a standard tape, @{text 1} by two filled cells and so on.
79
bc54c5e648d7 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 78
diff changeset
   738
104
01f688735b9b updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 103
diff changeset
   739
  Before we can prove the undecidability of the halting problem for
01f688735b9b updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 103
diff changeset
   740
  our Turing machines working on standard tapes, we have to analyse
01f688735b9b updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 103
diff changeset
   741
  two concrete Turing machine programs and establish that they are
01f688735b9b updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 103
diff changeset
   742
  correct---that means they are ``doing what they are supposed to be
01f688735b9b updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 103
diff changeset
   743
  doing''.  Such correctness proofs are usually left out in the
01f688735b9b updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 103
diff changeset
   744
  informal literature, for example \cite{Boolos87}.  The first program
01f688735b9b updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 103
diff changeset
   745
  we need to prove correct is the @{term dither} program shown in
01f688735b9b updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 103
diff changeset
   746
  \eqref{dither} and the second program is @{term "tcopy"} defined as
73
a673539f2f75 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 72
diff changeset
   747
91
2068654bdf54 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 90
diff changeset
   748
  \begin{equation}
2068654bdf54 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 90
diff changeset
   749
  \mbox{\begin{tabular}{@ {}l@ {\hspace{1mm}}c@ {\hspace{1mm}}l@ {}}
73
a673539f2f75 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 72
diff changeset
   750
  @{thm (lhs) tcopy_def} & @{text "\<equiv>"} & @{thm (rhs) tcopy_def}
91
2068654bdf54 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 90
diff changeset
   751
  \end{tabular}}\label{tcopy}
2068654bdf54 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 90
diff changeset
   752
  \end{equation}
73
a673539f2f75 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 72
diff changeset
   753
32
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 31
diff changeset
   754
  \noindent
102
cdef5b1072fe updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 100
diff changeset
   755
  whose three components are given in Figure~\ref{copy}. For our
cdef5b1072fe updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 100
diff changeset
   756
  correctness proofs, we introduce the notion of total correctness
cdef5b1072fe updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 100
diff changeset
   757
  defined in terms of \emph{Hoare-triples}, written @{term "{P} p
cdef5b1072fe updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 100
diff changeset
   758
  {Q}"}.  They implement the idea that a program @{term
cdef5b1072fe updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 100
diff changeset
   759
  p} started in state @{term "1::nat"} with a tape satisfying @{term
cdef5b1072fe updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 100
diff changeset
   760
  P} will after some @{text n} steps halt (have transitioned into the
cdef5b1072fe updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 100
diff changeset
   761
  halting state) with a tape satisfying @{term Q}. This idea is very
104
01f688735b9b updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 103
diff changeset
   762
  similar to the notion of \emph{realisability} in \cite{AspertiRicciotti12}. We
102
cdef5b1072fe updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 100
diff changeset
   763
  also have \emph{Hoare-pairs} of the form @{term "{P} p \<up>"}
cdef5b1072fe updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 100
diff changeset
   764
  implementing the case that a program @{term p} started with a tape
cdef5b1072fe updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 100
diff changeset
   765
  satisfying @{term P} will loop (never transition into the halting
cdef5b1072fe updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 100
diff changeset
   766
  state). Both notion are formally defined as
34
22e5804b135c updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 33
diff changeset
   767
22e5804b135c updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 33
diff changeset
   768
  \begin{center}
76
04399b471108 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 75
diff changeset
   769
  \begin{tabular}{@ {}c@ {\hspace{4mm}}c@ {}}
04399b471108 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 75
diff changeset
   770
  \begin{tabular}[t]{@ {}l@ {}}
80
eb589fa73fc1 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 79
diff changeset
   771
  \colorbox{mygrey}{@{thm (lhs) Hoare_halt_def}} @{text "\<equiv>"}\\[1mm]
76
04399b471108 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 75
diff changeset
   772
  \hspace{5mm}@{text "\<forall>"} @{term "(l, r)"}.\\
04399b471108 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 75
diff changeset
   773
  \hspace{7mm}if @{term "P (l, r)"} holds then\\
04399b471108 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 75
diff changeset
   774
  \hspace{7mm}@{text "\<exists>"} @{term n}. such that\\
04399b471108 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 75
diff changeset
   775
  \hspace{7mm}@{text "is_final (steps (1, (l, r)) p n)"} \hspace{1mm}@{text "\<and>"}\\
04399b471108 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 75
diff changeset
   776
  \hspace{7mm}@{text "Q holds_for (steps (1, (l, r)) p n)"}
04399b471108 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 75
diff changeset
   777
  \end{tabular} &
04399b471108 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 75
diff changeset
   778
  \begin{tabular}[t]{@ {}l@ {}}
80
eb589fa73fc1 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 79
diff changeset
   779
  \colorbox{mygrey}{@{thm (lhs) Hoare_unhalt_def}} @{text "\<equiv>"}\\[1mm]
76
04399b471108 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 75
diff changeset
   780
  \hspace{5mm}@{text "\<forall>"} @{term "(l, r)"}.\\ 
04399b471108 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 75
diff changeset
   781
  \hspace{7mm}if @{term "P (l, r)"} holds then\\
04399b471108 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 75
diff changeset
   782
  \hspace{7mm}@{text "\<forall>"} @{term n}. @{text "\<not> is_final (steps (1, (l, r)) p n)"}
04399b471108 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 75
diff changeset
   783
  \end{tabular}
04399b471108 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 75
diff changeset
   784
  \end{tabular}
04399b471108 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 75
diff changeset
   785
  \end{center}
04399b471108 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 75
diff changeset
   786
  
04399b471108 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 75
diff changeset
   787
  \noindent
102
cdef5b1072fe updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 100
diff changeset
   788
  For our Hoare-triples we can easily prove the following Hoare-consequence rule
99
fe7a257bdff4 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 98
diff changeset
   789
fe7a257bdff4 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 98
diff changeset
   790
  \begin{equation}
fe7a257bdff4 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 98
diff changeset
   791
  @{thm[mode=Rule] Hoare_consequence}
fe7a257bdff4 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 98
diff changeset
   792
  \end{equation}
fe7a257bdff4 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 98
diff changeset
   793
104
01f688735b9b updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 103
diff changeset
   794
  \noindent
01f688735b9b updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 103
diff changeset
   795
  where
01f688735b9b updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 103
diff changeset
   796
  @{term "P' \<mapsto> P"} stands for the fact that for all tapes @{term "tp"},
109
4635641e77cb updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 107
diff changeset
   797
  @{term "P' tp"} implies @{term "P tp"} (similarly for @{text "Q"} and @{text "Q'"}).
99
fe7a257bdff4 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 98
diff changeset
   798
90
d2f4b775cd15 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 89
diff changeset
   799
  Like Asperti and Ricciotti with their notion of realisability, we
93
f2bda6ba4952 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 92
diff changeset
   800
  have set up our Hoare-rules so that we can deal explicitly
90
d2f4b775cd15 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 89
diff changeset
   801
  with total correctness and non-terminantion, rather than have
d2f4b775cd15 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 89
diff changeset
   802
  notions for partial correctness and termination. Although the latter
d2f4b775cd15 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 89
diff changeset
   803
  would allow us to reason more uniformly (only using Hoare-triples),
96
bd320b5365e2 updated uncomputable
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 94
diff changeset
   804
  we prefer our definitions because we can derive below some simple
90
d2f4b775cd15 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 89
diff changeset
   805
  Hoare-rules for sequentially composed Turing programs.  In this way
93
f2bda6ba4952 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 92
diff changeset
   806
  we can reason about the correctness of @{term "tcopy_begin"}, for
90
d2f4b775cd15 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 89
diff changeset
   807
  example, completely separately from @{term "tcopy_loop"} and @{term
d2f4b775cd15 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 89
diff changeset
   808
  "tcopy_end"}.
d2f4b775cd15 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 89
diff changeset
   809
102
cdef5b1072fe updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 100
diff changeset
   810
  It is realatively straightforward to prove that the Turing program 
90
d2f4b775cd15 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 89
diff changeset
   811
  @{term "dither"} shown in \eqref{dither} is correct. This program
d2f4b775cd15 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 89
diff changeset
   812
  should be the ``identity'' when started with a standard tape representing 
102
cdef5b1072fe updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 100
diff changeset
   813
  @{text "1"} but loops when started with @{text 0} instead, as pictured 
94
aeaf1374dc67 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   814
  below.
90
d2f4b775cd15 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 89
diff changeset
   815
76
04399b471108 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 75
diff changeset
   816
80
eb589fa73fc1 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 79
diff changeset
   817
  \begin{center}
81
2e9881578cb2 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 80
diff changeset
   818
  \begin{tabular}{l@ {\hspace{3mm}}lcl}
2e9881578cb2 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 80
diff changeset
   819
  & \multicolumn{1}{c}{start tape}\\[1mm]
90
d2f4b775cd15 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 89
diff changeset
   820
  \raisebox{2mm}{halting case:} &
d2f4b775cd15 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 89
diff changeset
   821
  \begin{tikzpicture}[scale=0.8]
80
eb589fa73fc1 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 79
diff changeset
   822
  \draw[very thick] (-2,0)   -- ( 0.75,0);
eb589fa73fc1 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 79
diff changeset
   823
  \draw[very thick] (-2,0.5) -- ( 0.75,0.5);
eb589fa73fc1 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 79
diff changeset
   824
  \draw[very thick] (-0.25,0)   -- (-0.25,0.5);
eb589fa73fc1 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 79
diff changeset
   825
  \draw[very thick] ( 0.25,0)   -- ( 0.25,0.5);
eb589fa73fc1 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 79
diff changeset
   826
  \draw[very thick] (-0.75,0)   -- (-0.75,0.5);
eb589fa73fc1 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 79
diff changeset
   827
  \draw[very thick] ( 0.75,0)   -- ( 0.75,0.5);
eb589fa73fc1 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 79
diff changeset
   828
  \draw[very thick] (-1.25,0)   -- (-1.25,0.5);
eb589fa73fc1 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 79
diff changeset
   829
  \draw[rounded corners=1mm] (-0.35,-0.1) rectangle (0.35,0.6);
eb589fa73fc1 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 79
diff changeset
   830
  \draw[fill]     (-0.15,0.1) rectangle (0.15,0.4);
eb589fa73fc1 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 79
diff changeset
   831
  \draw[fill]     ( 0.35,0.1) rectangle (0.65,0.4);
eb589fa73fc1 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 79
diff changeset
   832
  \node [anchor=base] at (-1.7,0.2) {\ldots};
eb589fa73fc1 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 79
diff changeset
   833
  \end{tikzpicture} 
90
d2f4b775cd15 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 89
diff changeset
   834
  & \raisebox{2mm}{$\;\;\large\Rightarrow\;\;$} &
d2f4b775cd15 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 89
diff changeset
   835
  \begin{tikzpicture}[scale=0.8]
80
eb589fa73fc1 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 79
diff changeset
   836
  \draw[very thick] (-2,0)   -- ( 0.75,0);
eb589fa73fc1 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 79
diff changeset
   837
  \draw[very thick] (-2,0.5) -- ( 0.75,0.5);
eb589fa73fc1 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 79
diff changeset
   838
  \draw[very thick] (-0.25,0)   -- (-0.25,0.5);
eb589fa73fc1 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 79
diff changeset
   839
  \draw[very thick] ( 0.25,0)   -- ( 0.25,0.5);
eb589fa73fc1 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 79
diff changeset
   840
  \draw[very thick] (-0.75,0)   -- (-0.75,0.5);
eb589fa73fc1 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 79
diff changeset
   841
  \draw[very thick] ( 0.75,0)   -- ( 0.75,0.5);
eb589fa73fc1 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 79
diff changeset
   842
  \draw[very thick] (-1.25,0)   -- (-1.25,0.5);
eb589fa73fc1 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 79
diff changeset
   843
  \draw[rounded corners=1mm] (-0.35,-0.1) rectangle (0.35,0.6);
eb589fa73fc1 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 79
diff changeset
   844
  \draw[fill]     (-0.15,0.1) rectangle (0.15,0.4);
eb589fa73fc1 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 79
diff changeset
   845
  \draw[fill]     ( 0.35,0.1) rectangle (0.65,0.4);
eb589fa73fc1 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 79
diff changeset
   846
  \node [anchor=base] at (-1.7,0.2) {\ldots};
eb589fa73fc1 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 79
diff changeset
   847
  \end{tikzpicture}\\
eb589fa73fc1 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 79
diff changeset
   848
90
d2f4b775cd15 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 89
diff changeset
   849
  \raisebox{2mm}{non-halting case:} &
d2f4b775cd15 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 89
diff changeset
   850
  \begin{tikzpicture}[scale=0.8]
80
eb589fa73fc1 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 79
diff changeset
   851
  \draw[very thick] (-2,0)   -- ( 0.25,0);
eb589fa73fc1 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 79
diff changeset
   852
  \draw[very thick] (-2,0.5) -- ( 0.25,0.5);
eb589fa73fc1 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 79
diff changeset
   853
  \draw[very thick] (-0.25,0)   -- (-0.25,0.5);
eb589fa73fc1 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 79
diff changeset
   854
  \draw[very thick] ( 0.25,0)   -- ( 0.25,0.5);
eb589fa73fc1 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 79
diff changeset
   855
  \draw[very thick] (-0.75,0)   -- (-0.75,0.5);
eb589fa73fc1 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 79
diff changeset
   856
  \draw[very thick] (-1.25,0)   -- (-1.25,0.5);
eb589fa73fc1 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 79
diff changeset
   857
  \draw[rounded corners=1mm] (-0.35,-0.1) rectangle (0.35,0.6);
eb589fa73fc1 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 79
diff changeset
   858
  \draw[fill]     (-0.15,0.1) rectangle (0.15,0.4);
eb589fa73fc1 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 79
diff changeset
   859
  \node [anchor=base] at (-1.7,0.2) {\ldots};
eb589fa73fc1 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 79
diff changeset
   860
  \end{tikzpicture} 
90
d2f4b775cd15 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 89
diff changeset
   861
  & \raisebox{2mm}{$\;\;\large\Rightarrow\;\;$} &
d2f4b775cd15 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 89
diff changeset
   862
  \raisebox{2mm}{loops}
80
eb589fa73fc1 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 79
diff changeset
   863
  \end{tabular}
eb589fa73fc1 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 79
diff changeset
   864
  \end{center}
eb589fa73fc1 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 79
diff changeset
   865
90
d2f4b775cd15 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 89
diff changeset
   866
  \noindent
91
2068654bdf54 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 90
diff changeset
   867
  We can prove the following Hoare-statements:
90
d2f4b775cd15 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 89
diff changeset
   868
 
76
04399b471108 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 75
diff changeset
   869
  \begin{center}
04399b471108 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 75
diff changeset
   870
  \begin{tabular}{l}
04399b471108 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 75
diff changeset
   871
  @{thm dither_halts}\\
04399b471108 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 75
diff changeset
   872
  @{thm dither_loops}
04399b471108 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 75
diff changeset
   873
  \end{tabular}
34
22e5804b135c updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 33
diff changeset
   874
  \end{center}
22e5804b135c updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 33
diff changeset
   875
77
04e5850818c8 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 76
diff changeset
   876
  \noindent
102
cdef5b1072fe updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 100
diff changeset
   877
  The first is by a simple calculation. The second is by an induction on the
91
2068654bdf54 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 90
diff changeset
   878
  number of steps we can perform starting from the input tape.
75
97eaf7514988 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 73
diff changeset
   879
96
bd320b5365e2 updated uncomputable
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 94
diff changeset
   880
  The program @{term tcopy} defined in \eqref{tcopy} has 15 states;
104
01f688735b9b updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 103
diff changeset
   881
  its purpose is to produce the standard tape @{term "(Bks, <(n,
01f688735b9b updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 103
diff changeset
   882
  n::nat)>)"} when started with @{term "(Bks, <(n::nat)>)"}, that is
96
bd320b5365e2 updated uncomputable
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 94
diff changeset
   883
  making a copy of a value on the tape.  Reasoning about this program
bd320b5365e2 updated uncomputable
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 94
diff changeset
   884
  is substantially harder than about @{term dither}. To ease the
97
d6f04e3e9894 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 96
diff changeset
   885
  burden, we derive the following two Hoare-rules for sequentially
96
bd320b5365e2 updated uncomputable
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 94
diff changeset
   886
  composed programs.
75
97eaf7514988 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 73
diff changeset
   887
91
2068654bdf54 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 90
diff changeset
   888
  \begin{center}
94
aeaf1374dc67 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   889
  \begin{tabular}{@ {\hspace{-10mm}}c@ {\hspace{14mm}}c@ {}}
aeaf1374dc67 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   890
  $\inferrule*[Right=@{thm (prem 3) HR1}]
aeaf1374dc67 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   891
  {@{thm (prem 1) HR1} \\ @{thm (prem 2) HR1}}
93
f2bda6ba4952 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 92
diff changeset
   892
  {@{thm (concl) HR1}}
f2bda6ba4952 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 92
diff changeset
   893
  $ &
f2bda6ba4952 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 92
diff changeset
   894
  $
94
aeaf1374dc67 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   895
  \inferrule*[Right=@{thm (prem 3) HR2}]
aeaf1374dc67 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   896
  {@{thm (prem 1) HR2} \\ @{thm (prem 2) HR2}}
93
f2bda6ba4952 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 92
diff changeset
   897
  {@{thm (concl) HR2}}
f2bda6ba4952 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 92
diff changeset
   898
  $
91
2068654bdf54 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 90
diff changeset
   899
  \end{tabular}
2068654bdf54 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 90
diff changeset
   900
  \end{center}
93
f2bda6ba4952 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 92
diff changeset
   901
91
2068654bdf54 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 90
diff changeset
   902
  \noindent
93
f2bda6ba4952 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 92
diff changeset
   903
  The first corresponds to the usual Hoare-rule for composition of two
102
cdef5b1072fe updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 100
diff changeset
   904
  terminating programs. The second rule gives the conditions for when
cdef5b1072fe updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 100
diff changeset
   905
  the first program terminates generating a tape for which the second
cdef5b1072fe updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 100
diff changeset
   906
  program loops.  The side-conditions about @{thm (prem 3) HR2} are
cdef5b1072fe updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 100
diff changeset
   907
  needed in order to ensure that the redirection of the halting and
107
c2a7a99bf554 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 106
diff changeset
   908
  initial state in @{term "p\<^isub>1"} and @{term "p\<^isub>2"}, respectively, match
c2a7a99bf554 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 106
diff changeset
   909
  up correctly.  These Hoare-rules allow us to prove the correctness
c2a7a99bf554 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 106
diff changeset
   910
  of @{term tcopy} by considering the correctness of the components
c2a7a99bf554 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 106
diff changeset
   911
  @{term "tcopy_begin"}, @{term "tcopy_loop"} and @{term "tcopy_end"}
c2a7a99bf554 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 106
diff changeset
   912
  in isolation. This simplifies the reasoning considerably, for
c2a7a99bf554 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 106
diff changeset
   913
  example when designing decreasing measures for proving the termination
c2a7a99bf554 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 106
diff changeset
   914
  of the programs.  We will show the details for the program @{term
c2a7a99bf554 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 106
diff changeset
   915
  "tcopy_begin"}. For the two other programs we refer the reader to
c2a7a99bf554 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 106
diff changeset
   916
  our formalisation.
93
f2bda6ba4952 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 92
diff changeset
   917
107
c2a7a99bf554 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 106
diff changeset
   918
  Given the invariants @{term "inv_begin0"},\ldots,
c2a7a99bf554 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 106
diff changeset
   919
  @{term "inv_begin4"} shown in Figure~\ref{invbegin}, which
c2a7a99bf554 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 106
diff changeset
   920
  correspond to each state of @{term tcopy_begin}, we define the
103
294576baaeed updated theories
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 102
diff changeset
   921
  following invariant for the whole @{term tcopy_begin} program:
93
f2bda6ba4952 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 92
diff changeset
   922
104
01f688735b9b updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 103
diff changeset
   923
  \begin{figure}[t]
97
d6f04e3e9894 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 96
diff changeset
   924
  \begin{center}
105
2cae8a39803e updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 104
diff changeset
   925
  \begin{tabular}{@ {}lcl@ {\hspace{-0.5cm}}l@ {}}
2cae8a39803e updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 104
diff changeset
   926
  \hline
97
d6f04e3e9894 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 96
diff changeset
   927
  @{thm (lhs) inv_begin1.simps} & @{text "\<equiv>"} & @{thm (rhs) inv_begin1.simps} & (starting state)\\
d6f04e3e9894 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 96
diff changeset
   928
  @{thm (lhs) inv_begin2.simps} & @{text "\<equiv>"} & @{thm (rhs) inv_begin2.simps}\\
d6f04e3e9894 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 96
diff changeset
   929
  @{thm (lhs) inv_begin3.simps} & @{text "\<equiv>"} & @{thm (rhs) inv_begin3.simps}\\
100
dfe852aacae6 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 99
diff changeset
   930
  @{thm (lhs) inv_begin4.simps} & @{text "\<equiv>"} & @{thm (rhs) inv_begin4.simps}\\
105
2cae8a39803e updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 104
diff changeset
   931
  @{thm (lhs) inv_begin0.simps} & @{text "\<equiv>"} & @{thm (rhs) inv_begin01} @{text "\<or>"}& (halting state)\\
2cae8a39803e updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 104
diff changeset
   932
                                &             & @{thm (rhs) inv_begin02}\smallskip \\
2cae8a39803e updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 104
diff changeset
   933
   \hline
100
dfe852aacae6 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 99
diff changeset
   934
  @{thm (lhs) inv_loop1.simps} & @{text "\<equiv>"} & @{thm (rhs) inv_loop1_loop.simps} @{text "\<or>"}\\
105
2cae8a39803e updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 104
diff changeset
   935
                               &             & @{thm (rhs) inv_loop1_exit.simps} & (starting state)\\
2cae8a39803e updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 104
diff changeset
   936
  @{thm (lhs) inv_loop0.simps} & @{text "\<equiv>"} & @{thm (rhs) inv_loop0.simps}& (halting state)\smallskip\\
2cae8a39803e updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 104
diff changeset
   937
   \hline
2cae8a39803e updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 104
diff changeset
   938
  @{thm (lhs) inv_end1.simps} & @{text "\<equiv>"} & @{thm (rhs) inv_end1.simps} & (starting state)\\
2cae8a39803e updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 104
diff changeset
   939
  @{thm (lhs) inv_end0.simps} & @{text "\<equiv>"} & @{thm (rhs) inv_end0.simps} & (halting state)\smallskip\\
2cae8a39803e updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 104
diff changeset
   940
  \hline
97
d6f04e3e9894 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 96
diff changeset
   941
  \end{tabular}
d6f04e3e9894 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 96
diff changeset
   942
  \end{center}
106
c3155e9e4f63 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 105
diff changeset
   943
  \caption{The invariants @{term inv_begin0},\ldots,@{term inv_begin4} are for the states of 
c3155e9e4f63 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 105
diff changeset
   944
  @{term tcopy_begin}. Below, the invariants only for the starting and halting states of
c3155e9e4f63 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 105
diff changeset
   945
  @{term tcopy_loop} and @{term tcopy_end} are shown. In each invariant the parameter 
c3155e9e4f63 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 105
diff changeset
   946
  @{term n} stands for the number
105
2cae8a39803e updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 104
diff changeset
   947
  of @{term Oc}s with which the Turing machine is started.}\label{invbegin}
97
d6f04e3e9894 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 96
diff changeset
   948
  \end{figure}
96
bd320b5365e2 updated uncomputable
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 94
diff changeset
   949
bd320b5365e2 updated uncomputable
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 94
diff changeset
   950
  \begin{center}
97
d6f04e3e9894 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 96
diff changeset
   951
  \begin{tabular}{rcl}
d6f04e3e9894 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 96
diff changeset
   952
  @{thm (lhs) inv_begin.simps} & @{text "\<equiv>"} & 
d6f04e3e9894 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 96
diff changeset
   953
  @{text "if"} @{thm (prem 1) inv_begin_print(1)} @{text then} @{thm (rhs) inv_begin_print(1)}\\
d6f04e3e9894 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 96
diff changeset
   954
  & & @{text else} @{text "if"} @{thm (prem 1) inv_begin_print(2)} @{text then} @{thm (rhs) inv_begin_print(2)} \\
d6f04e3e9894 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 96
diff changeset
   955
 & & @{text else} @{text "if"} @{thm (prem 1) inv_begin_print(3)} @{text then} @{thm (rhs) inv_begin_print(3)}\\
d6f04e3e9894 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 96
diff changeset
   956
  & & @{text else} @{text "if"} @{thm (prem 1) inv_begin_print(4)} @{text then} @{thm (rhs) inv_begin_print(4)}\\
d6f04e3e9894 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 96
diff changeset
   957
   & & @{text else} @{text "if"} @{thm (prem 1) inv_begin_print(5)} @{text then} @{thm (rhs) inv_begin_print(5)}\\
d6f04e3e9894 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 96
diff changeset
   958
  & & @{text else} @{thm (rhs) inv_begin_print(6)}
d6f04e3e9894 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 96
diff changeset
   959
  \end{tabular}
d6f04e3e9894 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 96
diff changeset
   960
  \end{center}
d6f04e3e9894 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 96
diff changeset
   961
d6f04e3e9894 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 96
diff changeset
   962
  \noindent
102
cdef5b1072fe updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 100
diff changeset
   963
  This invariant depends on @{term n} representing the number of
104
01f688735b9b updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 103
diff changeset
   964
  @{term Oc}s (or encoded number) on the tape. It is not hard (26
01f688735b9b updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 103
diff changeset
   965
  lines of automated proof script) to show that for @{term "n >
105
2cae8a39803e updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 104
diff changeset
   966
  (0::nat)"} this invariant is preserved under the computation rules
2cae8a39803e updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 104
diff changeset
   967
  @{term step} and @{term steps}. This gives us partial correctness
2cae8a39803e updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 104
diff changeset
   968
  for @{term "tcopy_begin"}. 
97
d6f04e3e9894 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 96
diff changeset
   969
105
2cae8a39803e updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 104
diff changeset
   970
  We next need to show that @{term "tcopy_begin"} terminates. For this
2cae8a39803e updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 104
diff changeset
   971
  we introduce lexicographically ordered pairs @{term "(n, m)"}
106
c3155e9e4f63 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 105
diff changeset
   972
  derived from configurations @{text "(s, (l, r))"}: @{text n} is
c3155e9e4f63 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 105
diff changeset
   973
  the state @{text s}, but ordered according to how @{term tcopy_begin} executes
c3155e9e4f63 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 105
diff changeset
   974
  them, that is @{text "1 > 2 > 3 > 4 > 0"}; in order to have
c3155e9e4f63 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 105
diff changeset
   975
  a strictly decreasing meansure, @{term m} takes the data on the tape into
107
c2a7a99bf554 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 106
diff changeset
   976
  account and is calculated according to the following measure function:
97
d6f04e3e9894 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 96
diff changeset
   977
d6f04e3e9894 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 96
diff changeset
   978
  \begin{center}
105
2cae8a39803e updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 104
diff changeset
   979
  \begin{tabular}{rcl}
2cae8a39803e updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 104
diff changeset
   980
  @{term measure_begin_step}@{text "(s, (l, r))"} & @{text "\<equiv>"} & 
2cae8a39803e updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 104
diff changeset
   981
  @{text "if"} @{thm (prem 1) measure_begin_print(1)} @{text then} @{thm (rhs) measure_begin_print(1)}\\
106
c3155e9e4f63 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 105
diff changeset
   982
  & & @{text else} @{text "if"} @{thm (prem 1) measure_begin_print(2)} @{text then} 
c3155e9e4f63 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 105
diff changeset
   983
  @{text "("}@{thm (rhs) measure_begin_print(2)}@{text ")"} \\
105
2cae8a39803e updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 104
diff changeset
   984
 & & @{text else} @{text "if"} @{thm (prem 1) measure_begin_print(3)} @{text then} @{thm (rhs) measure_begin_print(3)}\\
2cae8a39803e updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 104
diff changeset
   985
  & & @{text else} @{thm (rhs) measure_begin_print(4)}\\
2cae8a39803e updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 104
diff changeset
   986
  \end{tabular}
2cae8a39803e updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 104
diff changeset
   987
  \end{center}
2cae8a39803e updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 104
diff changeset
   988
  
2cae8a39803e updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 104
diff changeset
   989
  \noindent
2cae8a39803e updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 104
diff changeset
   990
  With this in place, we can show that for every starting tape of the
2cae8a39803e updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 104
diff changeset
   991
  form @{term "([], Oc \<up> n)"} with @{term "n > (0::nat)"}, the Turing
107
c2a7a99bf554 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 106
diff changeset
   992
  machine @{term "tcopy_begin"} will eventually halt (the measure
c2a7a99bf554 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 106
diff changeset
   993
  decreases in each step). Taking this and the partial correctness
c2a7a99bf554 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 106
diff changeset
   994
  proof together, we obtain the left-most Hoare-triple for @{term tcopy_begin}:
105
2cae8a39803e updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 104
diff changeset
   995
   
2cae8a39803e updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 104
diff changeset
   996
2cae8a39803e updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 104
diff changeset
   997
  \begin{center}
2cae8a39803e updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 104
diff changeset
   998
  @{thm (concl) begin_correct}\hspace{6mm}
2cae8a39803e updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 104
diff changeset
   999
  @{thm (concl) loop_correct}\hspace{6mm}
2cae8a39803e updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 104
diff changeset
  1000
  @{thm (concl) end_correct}
96
bd320b5365e2 updated uncomputable
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 94
diff changeset
  1001
  \end{center}
36
4b35e0e0784b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 35
diff changeset
  1002
105
2cae8a39803e updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 104
diff changeset
  1003
  \noindent 
107
c2a7a99bf554 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 106
diff changeset
  1004
  where we assume @{text "0 < n"} (similar resoning is needed for
109
4635641e77cb updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 107
diff changeset
  1005
  the Hoare-triples for @{term tcopy_loop} and @{term tcopy_end}). Since the invariant of
107
c2a7a99bf554 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 106
diff changeset
  1006
  the halting state of @{term tcopy_begin} implies the invariant of
c2a7a99bf554 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 106
diff changeset
  1007
  the starting state of @{term tcopy_loop}, that is @{term "inv_begin0
c2a7a99bf554 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 106
diff changeset
  1008
  n \<mapsto> inv_loop1 n"} holds, and also @{term "inv_loop0 n = inv_end1
109
4635641e77cb updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 107
diff changeset
  1009
  n"}, we can derive the following Hoare-triple for the correctness 
107
c2a7a99bf554 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 106
diff changeset
  1010
  of @{term tcopy}:
24
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 23
diff changeset
  1011
105
2cae8a39803e updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 104
diff changeset
  1012
  \begin{center}
2cae8a39803e updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 104
diff changeset
  1013
  @{thm tcopy_correct}
2cae8a39803e updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 104
diff changeset
  1014
  \end{center}
2cae8a39803e updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 104
diff changeset
  1015
107
c2a7a99bf554 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 106
diff changeset
  1016
  \noindent
c2a7a99bf554 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 106
diff changeset
  1017
  That means if we start with a tape of the form @{term "([], <n::nat>)"} then 
109
4635641e77cb updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 107
diff changeset
  1018
  @{term tcopy} will halt with the tape \mbox{@{term "([Bk], <(n::nat, n::nat)>)"}}, as desired.
107
c2a7a99bf554 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 106
diff changeset
  1019
105
2cae8a39803e updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 104
diff changeset
  1020
  Finally, we are in the position to prove the undecidability of the halting problem.
2cae8a39803e updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 104
diff changeset
  1021
  A program @{term p} started with a standard tape containing the (encoded) numbers
2cae8a39803e updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 104
diff changeset
  1022
  @{term ns} will \emph{halt} with a standard tape containging a single (encoded) 
2cae8a39803e updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 104
diff changeset
  1023
  number is defined as
24
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 23
diff changeset
  1024
93
f2bda6ba4952 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 92
diff changeset
  1025
  \begin{center}
99
fe7a257bdff4 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 98
diff changeset
  1026
  @{thm haltP_def}
93
f2bda6ba4952 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 92
diff changeset
  1027
  \end{center}
f2bda6ba4952 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 92
diff changeset
  1028
105
2cae8a39803e updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 104
diff changeset
  1029
  \noindent
107
c2a7a99bf554 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 106
diff changeset
  1030
  This roughly means we considering only Turing machine programs
c2a7a99bf554 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 106
diff changeset
  1031
  representing functions that take some numbers as input and produce a
c2a7a99bf554 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 106
diff changeset
  1032
  single number as output. For undecidability, the property we are
c2a7a99bf554 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 106
diff changeset
  1033
  proving is that there is no Turing machine that can decide in
c2a7a99bf554 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 106
diff changeset
  1034
  general whether a Turing machine program halts (answer either @{text
c2a7a99bf554 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 106
diff changeset
  1035
  0} for halting and @{text 1} for looping). Given our correctness
c2a7a99bf554 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 106
diff changeset
  1036
  proofs for @{term dither} and @{term tcopy} shown above, this
109
4635641e77cb updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 107
diff changeset
  1037
  non-existence is now relatively straightforward to establish. We first
107
c2a7a99bf554 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 106
diff changeset
  1038
  assume there is a coding function, written @{term "code M"}, which
c2a7a99bf554 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 106
diff changeset
  1039
  represents a Turing machine @{term "M"} as a natural number.  No
c2a7a99bf554 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 106
diff changeset
  1040
  further assumptions are made about this coding function. Suppose a
c2a7a99bf554 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 106
diff changeset
  1041
  Turing machine @{term H} exists such that if started with the
c2a7a99bf554 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 106
diff changeset
  1042
  standard tape @{term "([Bk], <(code M, ns)>)"} returns @{text 0},
c2a7a99bf554 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 106
diff changeset
  1043
  respectively @{text 1}, depending on whether @{text M} halts when
c2a7a99bf554 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 106
diff changeset
  1044
  started with the input tape containing @{term "<ns>"}.  This
109
4635641e77cb updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 107
diff changeset
  1045
  assumption is formalised as follows---for all @{term M} and all lists of
4635641e77cb updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 107
diff changeset
  1046
  natural numbers @{term ns}:
106
c3155e9e4f63 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 105
diff changeset
  1047
105
2cae8a39803e updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 104
diff changeset
  1048
  \begin{center}
2cae8a39803e updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 104
diff changeset
  1049
  \begin{tabular}{r}
93
f2bda6ba4952 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 92
diff changeset
  1050
  @{thm (prem 2) uncomputable.h_case} implies
105
2cae8a39803e updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 104
diff changeset
  1051
  @{thm (concl) uncomputable.h_case}\\
93
f2bda6ba4952 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 92
diff changeset
  1052
  
f2bda6ba4952 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 92
diff changeset
  1053
  @{thm (prem 2) uncomputable.nh_case} implies
f2bda6ba4952 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 92
diff changeset
  1054
  @{thm (concl) uncomputable.nh_case}
105
2cae8a39803e updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 104
diff changeset
  1055
  \end{tabular}
2cae8a39803e updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 104
diff changeset
  1056
  \end{center}
93
f2bda6ba4952 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 92
diff changeset
  1057
105
2cae8a39803e updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 104
diff changeset
  1058
  \noindent
2cae8a39803e updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 104
diff changeset
  1059
  The contradiction can be derived using the following Turing machine
93
f2bda6ba4952 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 92
diff changeset
  1060
f2bda6ba4952 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 92
diff changeset
  1061
  \begin{center}
109
4635641e77cb updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 107
diff changeset
  1062
  @{thm tcontra_def}
4635641e77cb updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 107
diff changeset
  1063
  \end{center}
4635641e77cb updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 107
diff changeset
  1064
4635641e77cb updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 107
diff changeset
  1065
  \noindent
4635641e77cb updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 107
diff changeset
  1066
  Suppose @{thm (prem 1) "tcontra_halt"}. Given the invariants on the 
4635641e77cb updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 107
diff changeset
  1067
  left, we can derive the following Hoare-pair for @{term tcontra} on the right.
4635641e77cb updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 107
diff changeset
  1068
4635641e77cb updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 107
diff changeset
  1069
  \begin{center}\small
4635641e77cb updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 107
diff changeset
  1070
  \begin{tabular}{@ {}c@ {\hspace{-10mm}}c@ {}}
4635641e77cb updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 107
diff changeset
  1071
  \begin{tabular}[t]{@ {}l@ {}}
4635641e77cb updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 107
diff changeset
  1072
  @{term "P\<^isub>1 \<equiv> \<lambda>tp. tp = ([]::cell list, <code_tcontra>)"}\\
4635641e77cb updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 107
diff changeset
  1073
  @{term "P\<^isub>2 \<equiv> \<lambda>tp. tp = ([Bk], <(code_tcontra, code_tcontra)>)"}\\
4635641e77cb updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 107
diff changeset
  1074
  @{term "P\<^isub>3 \<equiv> \<lambda>tp. \<exists>k. tp = (Bk \<up> k, <0::nat>)"}
4635641e77cb updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 107
diff changeset
  1075
  \end{tabular}
4635641e77cb updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 107
diff changeset
  1076
  &
4635641e77cb updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 107
diff changeset
  1077
  \begin{tabular}[b]{@ {}l@ {}}
4635641e77cb updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 107
diff changeset
  1078
  \raisebox{-20mm}{$\inferrule*{
4635641e77cb updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 107
diff changeset
  1079
    \inferrule*{@{term "{P\<^isub>1} tcopy {P\<^isub>2}"} \\ @{term "{P\<^isub>2} H {P\<^isub>3}"}}
4635641e77cb updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 107
diff changeset
  1080
    {@{term "{P\<^isub>1} (tcopy |+| H) {P\<^isub>3}"}}
4635641e77cb updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 107
diff changeset
  1081
    \\ @{term "{P\<^isub>3} dither \<up>"}
4635641e77cb updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 107
diff changeset
  1082
   }
4635641e77cb updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 107
diff changeset
  1083
   {@{term "{P\<^isub>1} tcontra \<up>"}}
4635641e77cb updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 107
diff changeset
  1084
  $}
4635641e77cb updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 107
diff changeset
  1085
  \end{tabular}
4635641e77cb updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 107
diff changeset
  1086
  \end{tabular}
93
f2bda6ba4952 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 92
diff changeset
  1087
  \end{center}
f2bda6ba4952 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 92
diff changeset
  1088
105
2cae8a39803e updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 104
diff changeset
  1089
  \noindent
109
4635641e77cb updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 107
diff changeset
  1090
  This Hoare-pair contradicts our assumption that @{term tcontra} started
4635641e77cb updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 107
diff changeset
  1091
  with @{term "<(code tcontra)>"} halts.
4635641e77cb updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 107
diff changeset
  1092
4635641e77cb updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 107
diff changeset
  1093
  Suppose @{thm (prem 1) "tcontra_unhalt"}. Again given the invariants on the 
4635641e77cb updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 107
diff changeset
  1094
  left, we can derive the Hoare-triple for @{term tcontra} on the right.
93
f2bda6ba4952 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 92
diff changeset
  1095
109
4635641e77cb updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 107
diff changeset
  1096
  \begin{center}\small
4635641e77cb updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 107
diff changeset
  1097
  \begin{tabular}{@ {}c@ {\hspace{-17mm}}c@ {}}
4635641e77cb updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 107
diff changeset
  1098
  \begin{tabular}[t]{@ {}l@ {}}
4635641e77cb updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 107
diff changeset
  1099
  @{term "Q\<^isub>1 \<equiv> \<lambda>tp. tp = ([]::cell list, <code_tcontra>)"}\\
4635641e77cb updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 107
diff changeset
  1100
  @{term "Q\<^isub>2 \<equiv> \<lambda>tp. tp = ([Bk], <(code_tcontra, code_tcontra)>)"}\\
4635641e77cb updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 107
diff changeset
  1101
  @{term "Q\<^isub>3 \<equiv> \<lambda>tp. \<exists>k. tp = (Bk \<up> k, <1::nat>)"}
4635641e77cb updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 107
diff changeset
  1102
  \end{tabular}
4635641e77cb updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 107
diff changeset
  1103
  &
4635641e77cb updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 107
diff changeset
  1104
  \begin{tabular}[t]{@ {}l@ {}}
4635641e77cb updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 107
diff changeset
  1105
  \raisebox{-20mm}{$\inferrule*{
4635641e77cb updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 107
diff changeset
  1106
    \inferrule*{@{term "{Q\<^isub>1} tcopy {Q\<^isub>2}"} \\ @{term "{Q\<^isub>2} H {Q\<^isub>3}"}}
4635641e77cb updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 107
diff changeset
  1107
    {@{term "{Q\<^isub>1} (tcopy |+| H) {Q\<^isub>3}"}}
4635641e77cb updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 107
diff changeset
  1108
    \\ @{term "{Q\<^isub>3} dither {Q\<^isub>3}"}
93
f2bda6ba4952 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 92
diff changeset
  1109
   }
109
4635641e77cb updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 107
diff changeset
  1110
   {@{term "{Q\<^isub>1} tcontra {Q\<^isub>3}"}}
4635641e77cb updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 107
diff changeset
  1111
  $}
4635641e77cb updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 107
diff changeset
  1112
  \end{tabular}
4635641e77cb updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 107
diff changeset
  1113
  \end{tabular}
93
f2bda6ba4952 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 92
diff changeset
  1114
  \end{center}
f2bda6ba4952 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 92
diff changeset
  1115
109
4635641e77cb updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 107
diff changeset
  1116
  \noindent
4635641e77cb updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 107
diff changeset
  1117
  This time the Hoare-triple states that @{term tcontra} terminates 
4635641e77cb updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 107
diff changeset
  1118
  with the ``output'' @{term "<(1::nat)>"}. In both case we come
4635641e77cb updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 107
diff changeset
  1119
  to an contradiction, which means we have to abondon our assumption 
112
fea23f9a9d85 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 111
diff changeset
  1120
  that there exists a Turing machine @{term H} which can in general decide 
109
4635641e77cb updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 107
diff changeset
  1121
  whether Turing machines terminate.
9
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 8
diff changeset
  1122
*}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 8
diff changeset
  1123
63
35fe8fe12e65 small updates
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 61
diff changeset
  1124
17
66cebc19ef18 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 16
diff changeset
  1125
section {* Abacus Machines *}
66cebc19ef18 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 16
diff changeset
  1126
25
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 24
diff changeset
  1127
text {*
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 24
diff changeset
  1128
  \noindent
112
fea23f9a9d85 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 111
diff changeset
  1129
  Boolos et al \cite{Boolos87} use abacus machines as a stepping stone
fea23f9a9d85 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 111
diff changeset
  1130
  for making it less laborious to write Turing machine
fea23f9a9d85 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 111
diff changeset
  1131
  programs. Abacus machines operate over a set of registers $R_0$,
fea23f9a9d85 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 111
diff changeset
  1132
  $R_1$, \ldots{} each being able to hold an arbitrary large natural
fea23f9a9d85 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 111
diff changeset
  1133
  number.  We use natural numbers to refer to registers, but also to
fea23f9a9d85 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 111
diff changeset
  1134
  refer to \emph{statements} of abacus programs. Statements are given
fea23f9a9d85 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 111
diff changeset
  1135
  by the datatype
25
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 24
diff changeset
  1136
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 24
diff changeset
  1137
  \begin{center}
111
dfc629cd11de made uncomputable compatible with abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 109
diff changeset
  1138
  \begin{tabular}{rcl@ {\hspace{10mm}}l}
27
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 26
diff changeset
  1139
  @{text "o"} & $::=$  & @{term "Inc R\<iota>"} & increment register $R$ by one\\
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 26
diff changeset
  1140
  & $\mid$ & @{term "Dec R\<iota> o\<iota>"} & if content of $R$ is non-zero,\\
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 26
diff changeset
  1141
  & & & then decrement it by one\\
111
dfc629cd11de made uncomputable compatible with abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 109
diff changeset
  1142
  & & & otherwise jump to statement $o$\\
dfc629cd11de made uncomputable compatible with abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 109
diff changeset
  1143
  & $\mid$ & @{term "Goto o\<iota>"} & jump to statement $o$
25
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 24
diff changeset
  1144
  \end{tabular}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 24
diff changeset
  1145
  \end{center}
27
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 26
diff changeset
  1146
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 26
diff changeset
  1147
  \noindent
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 26
diff changeset
  1148
  A \emph{program} of an abacus machine is a list of such
111
dfc629cd11de made uncomputable compatible with abacus
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 109
diff changeset
  1149
  statements. For example the program clearing the register
112
fea23f9a9d85 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 111
diff changeset
  1150
  $R$ (setting it to @{term "(0::nat)"}) can be defined as follows:
27
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 26
diff changeset
  1151
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 26
diff changeset
  1152
  \begin{center}
112
fea23f9a9d85 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 111
diff changeset
  1153
  @{thm clear.simps[where n="R\<iota>" and e="o\<iota>", THEN eq_reflection]}
27
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 26
diff changeset
  1154
  \end{center}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 26
diff changeset
  1155
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 26
diff changeset
  1156
  \noindent
73
a673539f2f75 updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 72
diff changeset
  1157
  The second opcode @{term "Goto 0"} in this program means we 
112
fea23f9a9d85 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 111
diff changeset
  1158
  jump back to the first statement, namely @{text "Dec R o"}.
27
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 26
diff changeset
  1159
  The \emph{memory} $m$ of an abacus machine holding the values
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 26
diff changeset
  1160
  of the registers is represented as a list of natural numbers.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 26
diff changeset
  1161
  We have a lookup function for this memory, written @{term "abc_lm_v m R\<iota>"},
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 26
diff changeset
  1162
  which looks up the content of register $R$; if $R$
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 26
diff changeset
  1163
  is not in this list, then we return 0. Similarly we
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 26
diff changeset
  1164
  have a setting function, written @{term "abc_lm_s m R\<iota> n"}, which
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 26
diff changeset
  1165
  sets the value of $R$ to $n$, and if $R$ was not yet in $m$
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 26
diff changeset
  1166
  it pads it approriately with 0s.
29
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 28
diff changeset
  1167
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 28
diff changeset
  1168
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 28
diff changeset
  1169
  Abacus machine halts when it jumps out of range.
25
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 24
diff changeset
  1170
*}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 24
diff changeset
  1171
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 24
diff changeset
  1172
17
66cebc19ef18 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 16
diff changeset
  1173
section {* Recursive Functions *}
7
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 6
diff changeset
  1174
13
a7ec585d7f20 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 12
diff changeset
  1175
section {* Wang Tiles\label{Wang} *}
7
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 6
diff changeset
  1176
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 6
diff changeset
  1177
text {*
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 6
diff changeset
  1178
  Used in texture mapings - graphics
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 6
diff changeset
  1179
*}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 6
diff changeset
  1180
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 6
diff changeset
  1181
6
50880fcda34d added paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1182
section {* Related Work *}
50880fcda34d added paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1183
50880fcda34d added paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1184
text {*
17
66cebc19ef18 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 16
diff changeset
  1185
  The most closely related work is by Norrish \cite{Norrish11}, and Asperti and 
66cebc19ef18 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 16
diff changeset
  1186
  Ricciotti \cite{AspertiRicciotti12}. Norrish bases his approach on 
6
50880fcda34d added paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1187
  lambda-terms. For this he introduced a clever rewriting technology
50880fcda34d added paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1188
  based on combinators and de-Bruijn indices for
50880fcda34d added paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1189
  rewriting modulo $\beta$-equivalence (to keep it manageable)
71
8c7f10b3da7b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 63
diff changeset
  1190
8c7f10b3da7b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 63
diff changeset
  1191
8c7f10b3da7b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 63
diff changeset
  1192
  
8c7f10b3da7b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 63
diff changeset
  1193
  Given some input tape @{text "(l\<^isub>i,r\<^isub>i)"}, we can define when a program 
8c7f10b3da7b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 63
diff changeset
  1194
  @{term p} generates a specific  output tape @{text "(l\<^isub>o,r\<^isub>o)"}
8c7f10b3da7b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 63
diff changeset
  1195
8c7f10b3da7b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 63
diff changeset
  1196
  \begin{center}
8c7f10b3da7b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 63
diff changeset
  1197
  \begin{tabular}{l}
8c7f10b3da7b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 63
diff changeset
  1198
  @{term "runs p (l\<^isub>i, r\<^isub>i) (l\<^isub>o,r\<^isub>o)"} @{text "\<equiv>"}\\
8c7f10b3da7b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 63
diff changeset
  1199
  \hspace{6mm}@{text "\<exists>n. nsteps (1, (l\<^isub>i,r\<^isub>i)) p n = (0, (l\<^isub>o,r\<^isub>o))"}
8c7f10b3da7b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 63
diff changeset
  1200
  \end{tabular}
8c7f10b3da7b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 63
diff changeset
  1201
  \end{center}
8c7f10b3da7b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 63
diff changeset
  1202
8c7f10b3da7b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 63
diff changeset
  1203
  \noindent
8c7f10b3da7b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 63
diff changeset
  1204
  where @{text 1} stands for the starting state and @{text 0} for our final state.
8c7f10b3da7b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 63
diff changeset
  1205
  A program @{text p} with input tape @{term "(l\<^isub>i, r\<^isub>i)"} \emph{halts} iff
8c7f10b3da7b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 63
diff changeset
  1206
8c7f10b3da7b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 63
diff changeset
  1207
  \begin{center}
8c7f10b3da7b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 63
diff changeset
  1208
  @{term "halts p (l\<^isub>i, r\<^isub>i) \<equiv>
8c7f10b3da7b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 63
diff changeset
  1209
  \<exists>l\<^isub>o r\<^isub>o. runs p (l\<^isub>i, r\<^isub>i) (l\<^isub>o,r\<^isub>o)"}
8c7f10b3da7b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 63
diff changeset
  1210
  \end{center}
8c7f10b3da7b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 63
diff changeset
  1211
8c7f10b3da7b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 63
diff changeset
  1212
  \noindent
8c7f10b3da7b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 63
diff changeset
  1213
  Later on we need to consider specific Turing machines that 
8c7f10b3da7b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 63
diff changeset
  1214
  start with a tape in standard form and halt the computation
8c7f10b3da7b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 63
diff changeset
  1215
  in standard form. To define a tape in standard form, it is
8c7f10b3da7b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 63
diff changeset
  1216
  useful to have an operation %@{ term "tape_of_nat_list DUMMY"} 
8c7f10b3da7b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 63
diff changeset
  1217
  that translates lists of natural numbers into tapes. 
8c7f10b3da7b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 63
diff changeset
  1218
8c7f10b3da7b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 63
diff changeset
  1219
  
8c7f10b3da7b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 63
diff changeset
  1220
  \begin{center}
8c7f10b3da7b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 63
diff changeset
  1221
  \begin{tabular}{l@ {\hspace{1mm}}c@ {\hspace{1mm}}l}
8c7f10b3da7b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 63
diff changeset
  1222
  %@ { thm (lhs) tape_of_nat_list_def2(1)} & @{text "\<equiv>"} & @ { thm (rhs) tape_of_nat_list_def2(1)}\\
8c7f10b3da7b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 63
diff changeset
  1223
  %@ { thm (lhs) tape_of_nat_list_def2(2)} & @{text "\<equiv>"} & @ { thm (rhs) tape_of_nat_list_def2(2)}\\
8c7f10b3da7b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 63
diff changeset
  1224
  %@ { thm (lhs) tape_of_nat_list_def2(3)} & @{text "\<equiv>"} & @ { thm (rhs) tape_of_nat_list_def2(3)}\\
8c7f10b3da7b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 63
diff changeset
  1225
  \end{tabular}
8c7f10b3da7b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 63
diff changeset
  1226
  \end{center}
8c7f10b3da7b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 63
diff changeset
  1227
8c7f10b3da7b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 63
diff changeset
  1228
  
8c7f10b3da7b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 63
diff changeset
  1229
 By this we mean
8c7f10b3da7b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 63
diff changeset
  1230
8c7f10b3da7b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 63
diff changeset
  1231
  \begin{center}
8c7f10b3da7b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 63
diff changeset
  1232
  %@ {thm haltP_def2[where p="p" and n="n", THEN eq_reflection]}
8c7f10b3da7b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 63
diff changeset
  1233
  \end{center}
8c7f10b3da7b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 63
diff changeset
  1234
8c7f10b3da7b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 63
diff changeset
  1235
  \noindent
8c7f10b3da7b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 63
diff changeset
  1236
  This means the Turing machine starts with a tape containg @{text n} @{term Oc}s
8c7f10b3da7b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 63
diff changeset
  1237
  and the head pointing to the first one; the Turing machine
8c7f10b3da7b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 63
diff changeset
  1238
  halts with a tape consisting of some @{term Bk}s, followed by a 
8c7f10b3da7b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 63
diff changeset
  1239
  ``cluster'' of @{term Oc}s and after that by some @{term Bk}s.
8c7f10b3da7b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 63
diff changeset
  1240
  The head in the output is pointing again at the first @{term Oc}.
8c7f10b3da7b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 63
diff changeset
  1241
  The intuitive meaning of this definition is to start the Turing machine with a
8c7f10b3da7b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 63
diff changeset
  1242
  tape corresponding to a value @{term n} and producing
8c7f10b3da7b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 63
diff changeset
  1243
  a new tape corresponding to the value @{term l} (the number of @{term Oc}s
8c7f10b3da7b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 63
diff changeset
  1244
  clustered on the output tape).
8c7f10b3da7b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 63
diff changeset
  1245
109
4635641e77cb updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 107
diff changeset
  1246
4635641e77cb updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 107
diff changeset
  1247
  
4635641e77cb updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 107
diff changeset
  1248
  Magnus: invariants -- Section 5.4.5 on page 75.
6
50880fcda34d added paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1249
*}
50880fcda34d added paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1250
50880fcda34d added paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1251
50880fcda34d added paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1252
(*
50880fcda34d added paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1253
Questions:
50880fcda34d added paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1254
50880fcda34d added paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1255
Can this be done: Ackerman function is not primitive 
50880fcda34d added paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1256
recursive (Nora Szasz)
50880fcda34d added paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1257
50880fcda34d added paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1258
Tape is represented as two lists (finite - usually infinite tape)?
50880fcda34d added paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1259
50880fcda34d added paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1260
*)
50880fcda34d added paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1261
50880fcda34d added paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1262
50880fcda34d added paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1263
(*<*)
50880fcda34d added paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1264
end
109
4635641e77cb updated paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 107
diff changeset
  1265
end
6
50880fcda34d added paper
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1266
(*>*)