thys2/UF_Rec.thy
author Christian Urban <christian dot urban at kcl dot ac dot uk>
Fri, 24 May 2013 15:43:10 +0100
changeset 260 1e45b5b6482a
parent 259 4524c5edcafb
child 261 ca1fe315cb0a
permissions -rwxr-xr-x
added definitions and proofs for right-std and left-std tapes
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
246
e113420a2fce separated recursive functions and UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
     1
theory UF_Rec
258
32c5e8d1f6ff added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
     2
imports Recs Turing2
246
e113420a2fce separated recursive functions and UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
     3
begin
e113420a2fce separated recursive functions and UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
     4
258
32c5e8d1f6ff added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
     5
section {* Coding of Turing Machines and tapes*}
246
e113420a2fce separated recursive functions and UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
     6
258
32c5e8d1f6ff added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
     7
text {*
32c5e8d1f6ff added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
     8
  The purpose of this section is to construct the coding function of Turing 
32c5e8d1f6ff added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
     9
  Machine, which is going to be named @{text "code"}. *}
32c5e8d1f6ff added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
    10
32c5e8d1f6ff added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
    11
text {* Encoding of actions as numbers *}
32c5e8d1f6ff added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
    12
32c5e8d1f6ff added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
    13
fun action_num :: "action \<Rightarrow> nat"
32c5e8d1f6ff added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
    14
  where
32c5e8d1f6ff added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
    15
  "action_num W0 = 0"
32c5e8d1f6ff added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
    16
| "action_num W1 = 1"
32c5e8d1f6ff added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
    17
| "action_num L  = 2"
32c5e8d1f6ff added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
    18
| "action_num R  = 3"
32c5e8d1f6ff added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
    19
| "action_num Nop = 4"
32c5e8d1f6ff added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
    20
32c5e8d1f6ff added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
    21
fun cell_num :: "cell \<Rightarrow> nat" where
32c5e8d1f6ff added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
    22
  "cell_num Bk = 0"
32c5e8d1f6ff added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
    23
| "cell_num Oc = 1"
32c5e8d1f6ff added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
    24
32c5e8d1f6ff added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
    25
fun code_tp :: "cell list \<Rightarrow> nat list"
32c5e8d1f6ff added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
    26
  where
32c5e8d1f6ff added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
    27
  "code_tp [] = []"
32c5e8d1f6ff added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
    28
| "code_tp (c # tp) = (cell_num c) # code_tp tp"
32c5e8d1f6ff added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
    29
32c5e8d1f6ff added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
    30
fun Code_tp where
32c5e8d1f6ff added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
    31
  "Code_tp tp = lenc (code_tp tp)"
32c5e8d1f6ff added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
    32
260
1e45b5b6482a added definitions and proofs for right-std and left-std tapes
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 259
diff changeset
    33
lemma code_tp_length [simp]:
1e45b5b6482a added definitions and proofs for right-std and left-std tapes
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 259
diff changeset
    34
  "length (code_tp tp) = length tp"
1e45b5b6482a added definitions and proofs for right-std and left-std tapes
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 259
diff changeset
    35
by (induct tp) (simp_all)
1e45b5b6482a added definitions and proofs for right-std and left-std tapes
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 259
diff changeset
    36
1e45b5b6482a added definitions and proofs for right-std and left-std tapes
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 259
diff changeset
    37
lemma code_tp_nth [simp]:
1e45b5b6482a added definitions and proofs for right-std and left-std tapes
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 259
diff changeset
    38
  "n < length tp \<Longrightarrow> (code_tp tp) ! n = cell_num (tp ! n)"
1e45b5b6482a added definitions and proofs for right-std and left-std tapes
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 259
diff changeset
    39
apply(induct n arbitrary: tp) 
1e45b5b6482a added definitions and proofs for right-std and left-std tapes
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 259
diff changeset
    40
apply(simp_all)
1e45b5b6482a added definitions and proofs for right-std and left-std tapes
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 259
diff changeset
    41
apply(case_tac [!] tp)
1e45b5b6482a added definitions and proofs for right-std and left-std tapes
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 259
diff changeset
    42
apply(simp_all)
1e45b5b6482a added definitions and proofs for right-std and left-std tapes
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 259
diff changeset
    43
done
1e45b5b6482a added definitions and proofs for right-std and left-std tapes
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 259
diff changeset
    44
258
32c5e8d1f6ff added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
    45
fun Code_conf where
32c5e8d1f6ff added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
    46
  "Code_conf (s, l, r) = (s, Code_tp l, Code_tp r)"
32c5e8d1f6ff added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
    47
32c5e8d1f6ff added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
    48
fun code_instr :: "instr \<Rightarrow> nat" where
32c5e8d1f6ff added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
    49
  "code_instr i = penc (action_num (fst i)) (snd i)"
32c5e8d1f6ff added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
    50
  
32c5e8d1f6ff added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
    51
fun Code_instr :: "instr \<times> instr \<Rightarrow> nat" where
32c5e8d1f6ff added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
    52
  "Code_instr i = penc (code_instr (fst i)) (code_instr (snd i))"
32c5e8d1f6ff added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
    53
32c5e8d1f6ff added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
    54
fun code_tprog :: "tprog \<Rightarrow> nat list"
32c5e8d1f6ff added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
    55
  where
32c5e8d1f6ff added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
    56
  "code_tprog [] =  []"
32c5e8d1f6ff added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
    57
| "code_tprog (i # tm) = Code_instr i # code_tprog tm"
32c5e8d1f6ff added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
    58
32c5e8d1f6ff added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
    59
lemma code_tprog_length [simp]:
32c5e8d1f6ff added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
    60
  "length (code_tprog tp) = length tp"
32c5e8d1f6ff added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
    61
by (induct tp) (simp_all)
32c5e8d1f6ff added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
    62
32c5e8d1f6ff added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
    63
lemma code_tprog_nth [simp]:
32c5e8d1f6ff added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
    64
  "n < length tp \<Longrightarrow> (code_tprog tp) ! n = Code_instr (tp ! n)"
32c5e8d1f6ff added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
    65
by (induct tp arbitrary: n) (simp_all add: nth_Cons')
32c5e8d1f6ff added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
    66
32c5e8d1f6ff added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
    67
fun Code_tprog :: "tprog \<Rightarrow> nat"
32c5e8d1f6ff added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
    68
  where 
32c5e8d1f6ff added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
    69
  "Code_tprog tm = lenc (code_tprog tm)"
246
e113420a2fce separated recursive functions and UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    70
250
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
    71
section {* Universal Function in HOL *}
246
e113420a2fce separated recursive functions and UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    72
258
32c5e8d1f6ff added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
    73
259
4524c5edcafb moved new theries into a separate directory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 258
diff changeset
    74
text {* Reading and writing the encoded tape *}
246
e113420a2fce separated recursive functions and UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    75
259
4524c5edcafb moved new theries into a separate directory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 258
diff changeset
    76
fun Read where
4524c5edcafb moved new theries into a separate directory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 258
diff changeset
    77
  "Read tp = ldec tp 0"
250
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
    78
258
32c5e8d1f6ff added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
    79
fun Write where
259
4524c5edcafb moved new theries into a separate directory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 258
diff changeset
    80
  "Write n tp = penc (Suc n) (pdec2 tp)"
246
e113420a2fce separated recursive functions and UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    81
258
32c5e8d1f6ff added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
    82
text {* 
32c5e8d1f6ff added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
    83
  The @{text Newleft} and @{text Newright} functions on page 91 of B book. 
32c5e8d1f6ff added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
    84
  They calculate the new left and right tape (@{text p} and @{text r}) according 
32c5e8d1f6ff added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
    85
  to an action @{text a}.
32c5e8d1f6ff added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
    86
*}
246
e113420a2fce separated recursive functions and UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    87
e113420a2fce separated recursive functions and UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    88
fun Newleft :: "nat \<Rightarrow> nat \<Rightarrow> nat \<Rightarrow> nat"
e113420a2fce separated recursive functions and UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    89
  where
259
4524c5edcafb moved new theries into a separate directory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 258
diff changeset
    90
  "Newleft l r a = (if a = 0 then l else 
4524c5edcafb moved new theries into a separate directory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 258
diff changeset
    91
                    if a = 1 then l else 
4524c5edcafb moved new theries into a separate directory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 258
diff changeset
    92
                    if a = 2 then pdec2 l else 
4524c5edcafb moved new theries into a separate directory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 258
diff changeset
    93
                    if a = 3 then penc (Suc (Read r)) l
4524c5edcafb moved new theries into a separate directory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 258
diff changeset
    94
                    else l)"
246
e113420a2fce separated recursive functions and UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    95
e113420a2fce separated recursive functions and UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    96
fun Newright :: "nat \<Rightarrow> nat \<Rightarrow> nat \<Rightarrow> nat"
e113420a2fce separated recursive functions and UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    97
  where
259
4524c5edcafb moved new theries into a separate directory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 258
diff changeset
    98
  "Newright l r a  = (if a = 0 then Write 0 r
258
32c5e8d1f6ff added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
    99
                      else if a = 1 then Write 1 r
259
4524c5edcafb moved new theries into a separate directory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 258
diff changeset
   100
                      else if a = 2 then penc (Suc (Read l)) r
258
32c5e8d1f6ff added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
   101
                      else if a = 3 then pdec2 r
246
e113420a2fce separated recursive functions and UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   102
                      else r)"
e113420a2fce separated recursive functions and UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   103
e113420a2fce separated recursive functions and UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   104
text {*
e113420a2fce separated recursive functions and UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   105
  The @{text "Actn"} function given on page 92 of B book, which is used to 
e113420a2fce separated recursive functions and UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   106
  fetch Turing Machine intructions. In @{text "Actn m q r"}, @{text "m"} is 
258
32c5e8d1f6ff added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
   107
  the code of the Turing Machine, @{text "q"} is the current state of 
32c5e8d1f6ff added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
   108
  Turing Machine, and @{text "r"} is the scanned cell of is the right tape. 
32c5e8d1f6ff added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
   109
*}
32c5e8d1f6ff added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
   110
32c5e8d1f6ff added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
   111
fun actn :: "nat \<Rightarrow> nat \<Rightarrow> nat" where
32c5e8d1f6ff added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
   112
  "actn n 0 = pdec1 (pdec1 n)"
32c5e8d1f6ff added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
   113
| "actn n _ = pdec1 (pdec2 n)"
250
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   114
246
e113420a2fce separated recursive functions and UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   115
fun Actn :: "nat \<Rightarrow> nat \<Rightarrow> nat \<Rightarrow> nat"
e113420a2fce separated recursive functions and UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   116
  where
259
4524c5edcafb moved new theries into a separate directory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 258
diff changeset
   117
  "Actn m q r = (if q \<noteq> 0 \<and> within m (q - 1) then (actn (ldec m (q - 1)) r) else 4)"
258
32c5e8d1f6ff added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
   118
259
4524c5edcafb moved new theries into a separate directory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 258
diff changeset
   119
fun newstate :: "nat \<Rightarrow> nat \<Rightarrow> nat" where
4524c5edcafb moved new theries into a separate directory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 258
diff changeset
   120
  "newstate n 0 = pdec2 (pdec1 n)"
4524c5edcafb moved new theries into a separate directory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 258
diff changeset
   121
| "newstate n _ = pdec2 (pdec2 n)"
246
e113420a2fce separated recursive functions and UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   122
259
4524c5edcafb moved new theries into a separate directory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 258
diff changeset
   123
fun Newstate :: "nat \<Rightarrow> nat \<Rightarrow> nat \<Rightarrow> nat"
246
e113420a2fce separated recursive functions and UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   124
  where
259
4524c5edcafb moved new theries into a separate directory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 258
diff changeset
   125
  "Newstate m q r = (if q \<noteq> 0 then (newstate (ldec m (q - 1)) r) else 0)"
246
e113420a2fce separated recursive functions and UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   126
258
32c5e8d1f6ff added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
   127
fun Conf :: "nat \<times> (nat \<times> nat) \<Rightarrow> nat"
246
e113420a2fce separated recursive functions and UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   128
  where
258
32c5e8d1f6ff added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
   129
  "Conf (q, (l, r)) = lenc [q, l, r]"
32c5e8d1f6ff added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
   130
259
4524c5edcafb moved new theries into a separate directory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 258
diff changeset
   131
fun State where
4524c5edcafb moved new theries into a separate directory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 258
diff changeset
   132
  "State cf = ldec cf 0"
246
e113420a2fce separated recursive functions and UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   133
e113420a2fce separated recursive functions and UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   134
fun Left where
259
4524c5edcafb moved new theries into a separate directory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 258
diff changeset
   135
  "Left cf = ldec cf 1"
246
e113420a2fce separated recursive functions and UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   136
e113420a2fce separated recursive functions and UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   137
fun Right where
259
4524c5edcafb moved new theries into a separate directory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 258
diff changeset
   138
  "Right cf = ldec cf 2"
246
e113420a2fce separated recursive functions and UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   139
259
4524c5edcafb moved new theries into a separate directory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 258
diff changeset
   140
fun Step :: "nat \<Rightarrow> nat \<Rightarrow> nat"
246
e113420a2fce separated recursive functions and UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   141
  where
259
4524c5edcafb moved new theries into a separate directory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 258
diff changeset
   142
  "Step cf m = Conf (Newstate m (State cf) (Read (Right cf)), 
4524c5edcafb moved new theries into a separate directory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 258
diff changeset
   143
                    (Newleft (Left cf) (Right cf) (Actn m (State cf) (Read (Right cf))),
4524c5edcafb moved new theries into a separate directory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 258
diff changeset
   144
                     Newright (Left cf) (Right cf) (Actn m (State cf) (Read (Right cf)))))"
246
e113420a2fce separated recursive functions and UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   145
e113420a2fce separated recursive functions and UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   146
text {*
259
4524c5edcafb moved new theries into a separate directory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 258
diff changeset
   147
  @{text "Steps cf m k"} computes the TM configuration after @{text "k"} steps of execution
4524c5edcafb moved new theries into a separate directory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 258
diff changeset
   148
  of TM coded as @{text "m"}. 
4524c5edcafb moved new theries into a separate directory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 258
diff changeset
   149
*}
250
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   150
258
32c5e8d1f6ff added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
   151
fun Steps :: "nat \<Rightarrow> nat \<Rightarrow> nat \<Rightarrow> nat"
246
e113420a2fce separated recursive functions and UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   152
  where
258
32c5e8d1f6ff added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
   153
  "Steps cf p 0  = cf"
259
4524c5edcafb moved new theries into a separate directory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 258
diff changeset
   154
| "Steps cf p (Suc n) = Steps (Step cf p) p n"
246
e113420a2fce separated recursive functions and UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   155
e113420a2fce separated recursive functions and UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   156
text {*
259
4524c5edcafb moved new theries into a separate directory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 258
diff changeset
   157
  Decoding tapes into binary or stroke numbers.
4524c5edcafb moved new theries into a separate directory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 258
diff changeset
   158
*}
4524c5edcafb moved new theries into a separate directory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 258
diff changeset
   159
4524c5edcafb moved new theries into a separate directory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 258
diff changeset
   160
definition Binnum :: "nat \<Rightarrow> nat"
4524c5edcafb moved new theries into a separate directory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 258
diff changeset
   161
  where
4524c5edcafb moved new theries into a separate directory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 258
diff changeset
   162
  "Binnum z \<equiv> (\<Sum>i < enclen z. ldec z i * 2 ^ i)"
4524c5edcafb moved new theries into a separate directory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 258
diff changeset
   163
4524c5edcafb moved new theries into a separate directory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 258
diff changeset
   164
definition Stknum :: "nat \<Rightarrow> nat"
4524c5edcafb moved new theries into a separate directory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 258
diff changeset
   165
  where
4524c5edcafb moved new theries into a separate directory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 258
diff changeset
   166
  "Stknum z \<equiv> (\<Sum>i < enclen z. ldec z i) - 1"
4524c5edcafb moved new theries into a separate directory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 258
diff changeset
   167
260
1e45b5b6482a added definitions and proofs for right-std and left-std tapes
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 259
diff changeset
   168
1e45b5b6482a added definitions and proofs for right-std and left-std tapes
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 259
diff changeset
   169
definition
1e45b5b6482a added definitions and proofs for right-std and left-std tapes
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 259
diff changeset
   170
  "right_std z \<equiv> (\<exists>i \<le> enclen z. (\<forall>j < i. ldec z j = 1) \<and> (\<forall>j < enclen z - i. ldec z (i + j) = 0))"
1e45b5b6482a added definitions and proofs for right-std and left-std tapes
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 259
diff changeset
   171
1e45b5b6482a added definitions and proofs for right-std and left-std tapes
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 259
diff changeset
   172
definition
1e45b5b6482a added definitions and proofs for right-std and left-std tapes
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 259
diff changeset
   173
  "left_std z \<equiv> (\<forall>j < enclen z. ldec z j = 0)"
250
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   174
260
1e45b5b6482a added definitions and proofs for right-std and left-std tapes
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 259
diff changeset
   175
lemma ww:
1e45b5b6482a added definitions and proofs for right-std and left-std tapes
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 259
diff changeset
   176
 "(\<exists>k l. tp = Oc \<up> k @ Bk \<up> l) \<longleftrightarrow> 
1e45b5b6482a added definitions and proofs for right-std and left-std tapes
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 259
diff changeset
   177
  (\<exists>i\<le>length tp. (\<forall>j < i. tp ! j = Oc) \<and> (\<forall>j < length tp - i. tp ! (i + j) = Bk))"
1e45b5b6482a added definitions and proofs for right-std and left-std tapes
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 259
diff changeset
   178
apply(rule iffI)
1e45b5b6482a added definitions and proofs for right-std and left-std tapes
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 259
diff changeset
   179
apply(erule exE)+
1e45b5b6482a added definitions and proofs for right-std and left-std tapes
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 259
diff changeset
   180
apply(simp)
1e45b5b6482a added definitions and proofs for right-std and left-std tapes
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 259
diff changeset
   181
apply(rule_tac x="k" in exI)
1e45b5b6482a added definitions and proofs for right-std and left-std tapes
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 259
diff changeset
   182
apply(auto)[1]
1e45b5b6482a added definitions and proofs for right-std and left-std tapes
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 259
diff changeset
   183
apply(simp add: nth_append)
1e45b5b6482a added definitions and proofs for right-std and left-std tapes
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 259
diff changeset
   184
apply(simp add: nth_append)
1e45b5b6482a added definitions and proofs for right-std and left-std tapes
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 259
diff changeset
   185
apply(erule exE)
1e45b5b6482a added definitions and proofs for right-std and left-std tapes
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 259
diff changeset
   186
apply(rule_tac x="i" in exI)
1e45b5b6482a added definitions and proofs for right-std and left-std tapes
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 259
diff changeset
   187
apply(rule_tac x="length tp - i" in exI)
1e45b5b6482a added definitions and proofs for right-std and left-std tapes
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 259
diff changeset
   188
apply(auto)
1e45b5b6482a added definitions and proofs for right-std and left-std tapes
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 259
diff changeset
   189
apply(rule sym)
1e45b5b6482a added definitions and proofs for right-std and left-std tapes
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 259
diff changeset
   190
apply(subst append_eq_conv_conj)
1e45b5b6482a added definitions and proofs for right-std and left-std tapes
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 259
diff changeset
   191
apply(simp)
1e45b5b6482a added definitions and proofs for right-std and left-std tapes
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 259
diff changeset
   192
apply(rule conjI)
1e45b5b6482a added definitions and proofs for right-std and left-std tapes
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 259
diff changeset
   193
apply (smt length_replicate length_take nth_equalityI nth_replicate nth_take)
1e45b5b6482a added definitions and proofs for right-std and left-std tapes
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 259
diff changeset
   194
by (smt length_drop length_replicate nth_drop nth_equalityI nth_replicate)
1e45b5b6482a added definitions and proofs for right-std and left-std tapes
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 259
diff changeset
   195
1e45b5b6482a added definitions and proofs for right-std and left-std tapes
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 259
diff changeset
   196
lemma right_std:
1e45b5b6482a added definitions and proofs for right-std and left-std tapes
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 259
diff changeset
   197
  "(\<exists>k l. tp = Oc \<up> k @ Bk \<up> l) \<longleftrightarrow> right_std (Code_tp tp)"
1e45b5b6482a added definitions and proofs for right-std and left-std tapes
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 259
diff changeset
   198
apply(simp add: right_std_def)
1e45b5b6482a added definitions and proofs for right-std and left-std tapes
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 259
diff changeset
   199
apply(simp only: list_encode_inverse)
1e45b5b6482a added definitions and proofs for right-std and left-std tapes
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 259
diff changeset
   200
apply(simp)
1e45b5b6482a added definitions and proofs for right-std and left-std tapes
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 259
diff changeset
   201
apply(simp add: ww)
1e45b5b6482a added definitions and proofs for right-std and left-std tapes
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 259
diff changeset
   202
apply(auto)
1e45b5b6482a added definitions and proofs for right-std and left-std tapes
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 259
diff changeset
   203
apply(rule_tac x="i" in exI)
1e45b5b6482a added definitions and proofs for right-std and left-std tapes
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 259
diff changeset
   204
apply(simp)
1e45b5b6482a added definitions and proofs for right-std and left-std tapes
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 259
diff changeset
   205
apply(rule conjI)
1e45b5b6482a added definitions and proofs for right-std and left-std tapes
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 259
diff changeset
   206
apply (metis Suc_eq_plus1 Suc_neq_Zero cell_num.cases cell_num.simps(1) leD less_trans linorder_neqE_nat)
1e45b5b6482a added definitions and proofs for right-std and left-std tapes
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 259
diff changeset
   207
apply(auto)
1e45b5b6482a added definitions and proofs for right-std and left-std tapes
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 259
diff changeset
   208
by (metis One_nat_def cell_num.cases cell_num.simps(2) less_diff_conv n_not_Suc_n nat_add_commute)
1e45b5b6482a added definitions and proofs for right-std and left-std tapes
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 259
diff changeset
   209
1e45b5b6482a added definitions and proofs for right-std and left-std tapes
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 259
diff changeset
   210
lemma left_std:
1e45b5b6482a added definitions and proofs for right-std and left-std tapes
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 259
diff changeset
   211
  "(\<exists>k. tp = Bk \<up> k) \<longleftrightarrow> left_std (Code_tp tp)"
1e45b5b6482a added definitions and proofs for right-std and left-std tapes
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 259
diff changeset
   212
apply(simp add: left_std_def)
1e45b5b6482a added definitions and proofs for right-std and left-std tapes
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 259
diff changeset
   213
apply(simp only: list_encode_inverse)
1e45b5b6482a added definitions and proofs for right-std and left-std tapes
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 259
diff changeset
   214
apply(simp)
1e45b5b6482a added definitions and proofs for right-std and left-std tapes
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 259
diff changeset
   215
apply(auto)
1e45b5b6482a added definitions and proofs for right-std and left-std tapes
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 259
diff changeset
   216
apply(rule_tac x="length tp" in exI)
259
4524c5edcafb moved new theries into a separate directory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 258
diff changeset
   217
apply(induct tp)
4524c5edcafb moved new theries into a separate directory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 258
diff changeset
   218
apply(simp)
4524c5edcafb moved new theries into a separate directory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 258
diff changeset
   219
apply(simp)
260
1e45b5b6482a added definitions and proofs for right-std and left-std tapes
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 259
diff changeset
   220
apply(auto)
1e45b5b6482a added definitions and proofs for right-std and left-std tapes
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 259
diff changeset
   221
apply(case_tac a)
1e45b5b6482a added definitions and proofs for right-std and left-std tapes
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 259
diff changeset
   222
apply(auto)
259
4524c5edcafb moved new theries into a separate directory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 258
diff changeset
   223
apply(case_tac a)
260
1e45b5b6482a added definitions and proofs for right-std and left-std tapes
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 259
diff changeset
   224
apply(auto)
1e45b5b6482a added definitions and proofs for right-std and left-std tapes
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 259
diff changeset
   225
by (metis Suc_less_eq nth_Cons_Suc)
259
4524c5edcafb moved new theries into a separate directory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 258
diff changeset
   226
4524c5edcafb moved new theries into a separate directory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 258
diff changeset
   227
4524c5edcafb moved new theries into a separate directory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 258
diff changeset
   228
text {*
4524c5edcafb moved new theries into a separate directory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 258
diff changeset
   229
  @{text "Std cf"} returns true, if the  configuration  @{text "cf"} 
4524c5edcafb moved new theries into a separate directory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 258
diff changeset
   230
  is a stardard tape. 
4524c5edcafb moved new theries into a separate directory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 258
diff changeset
   231
*}
4524c5edcafb moved new theries into a separate directory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 258
diff changeset
   232
4524c5edcafb moved new theries into a separate directory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 258
diff changeset
   233
fun Std :: "nat \<Rightarrow> bool"
246
e113420a2fce separated recursive functions and UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   234
  where
260
1e45b5b6482a added definitions and proofs for right-std and left-std tapes
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 259
diff changeset
   235
  "Std cf = (left_std (Left cf) \<and> right_std (Right cf))"
246
e113420a2fce separated recursive functions and UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   236
e113420a2fce separated recursive functions and UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   237
text{* 
259
4524c5edcafb moved new theries into a separate directory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 258
diff changeset
   238
  @{text "Nostop m cf k"} means that afer @{text k} steps of 
4524c5edcafb moved new theries into a separate directory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 258
diff changeset
   239
  execution the TM coded by @{text m} and started in configuration
4524c5edcafb moved new theries into a separate directory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 258
diff changeset
   240
  @{text cf} is not at a stardard final configuration. *}
4524c5edcafb moved new theries into a separate directory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 258
diff changeset
   241
4524c5edcafb moved new theries into a separate directory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 258
diff changeset
   242
fun Final :: "nat \<Rightarrow> bool"
4524c5edcafb moved new theries into a separate directory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 258
diff changeset
   243
  where
4524c5edcafb moved new theries into a separate directory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 258
diff changeset
   244
    "Final cf = (State cf = 0)"
250
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   245
246
e113420a2fce separated recursive functions and UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   246
fun Nostop :: "nat \<Rightarrow> nat \<Rightarrow> nat \<Rightarrow> bool"
e113420a2fce separated recursive functions and UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   247
  where
259
4524c5edcafb moved new theries into a separate directory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 258
diff changeset
   248
  "Nostop m cf k = (Final (Steps cf m k) \<and> \<not> Std (Steps cf m k))"
246
e113420a2fce separated recursive functions and UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   249
e113420a2fce separated recursive functions and UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   250
text{*
259
4524c5edcafb moved new theries into a separate directory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 258
diff changeset
   251
  @{text "Halt"} is the function calculating the steps a TM needs to 
4524c5edcafb moved new theries into a separate directory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 258
diff changeset
   252
  execute before reaching a stardard final configuration. This recursive 
4524c5edcafb moved new theries into a separate directory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 258
diff changeset
   253
  function is the only one that uses unbounded minimization. So it is the 
4524c5edcafb moved new theries into a separate directory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 258
diff changeset
   254
  only non-primitive recursive function needs to be used in the construction 
4524c5edcafb moved new theries into a separate directory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 258
diff changeset
   255
  of the universal function @{text "UF"}. 
258
32c5e8d1f6ff added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
   256
*}
246
e113420a2fce separated recursive functions and UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   257
250
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   258
fun Halt :: "nat \<Rightarrow> nat \<Rightarrow> nat"
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   259
  where
259
4524c5edcafb moved new theries into a separate directory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 258
diff changeset
   260
  "Halt m cf = (LEAST k. \<not> Nostop m cf k)"
250
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   261
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   262
fun UF :: "nat \<Rightarrow> nat \<Rightarrow> nat"
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   263
  where
259
4524c5edcafb moved new theries into a separate directory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 258
diff changeset
   264
  "UF m cf = Stknum (Right (Steps m cf (Halt m cf)))"
258
32c5e8d1f6ff added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
   265
32c5e8d1f6ff added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
   266
section {* The UF can simulate Turing machines *}
32c5e8d1f6ff added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
   267
32c5e8d1f6ff added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
   268
lemma Update_left_simulate:
32c5e8d1f6ff added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
   269
  shows "Newleft (Code_tp l) (Code_tp r) (action_num a) = Code_tp (fst (update a (l, r)))"
32c5e8d1f6ff added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
   270
apply(induct a)
32c5e8d1f6ff added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
   271
apply(simp_all)
32c5e8d1f6ff added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
   272
apply(case_tac l)
32c5e8d1f6ff added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
   273
apply(simp_all)
32c5e8d1f6ff added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
   274
apply(case_tac r)
32c5e8d1f6ff added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
   275
apply(simp_all)
32c5e8d1f6ff added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
   276
done
32c5e8d1f6ff added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
   277
32c5e8d1f6ff added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
   278
lemma Update_right_simulate:
32c5e8d1f6ff added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
   279
  shows "Newright (Code_tp l) (Code_tp r) (action_num a) = Code_tp (snd (update a (l, r)))"
32c5e8d1f6ff added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
   280
apply(induct a)
32c5e8d1f6ff added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
   281
apply(simp_all)
32c5e8d1f6ff added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
   282
apply(case_tac r)
32c5e8d1f6ff added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
   283
apply(simp_all)
32c5e8d1f6ff added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
   284
apply(case_tac r)
32c5e8d1f6ff added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
   285
apply(simp_all)
32c5e8d1f6ff added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
   286
apply(case_tac l)
32c5e8d1f6ff added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
   287
apply(simp_all)
32c5e8d1f6ff added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
   288
apply(case_tac r)
32c5e8d1f6ff added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
   289
apply(simp_all)
32c5e8d1f6ff added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
   290
done
32c5e8d1f6ff added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
   291
32c5e8d1f6ff added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
   292
lemma Fetch_state_simulate:
259
4524c5edcafb moved new theries into a separate directory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 258
diff changeset
   293
  "tm_wf tp \<Longrightarrow> Newstate (Code_tprog tp) st (cell_num c) = snd (fetch tp st c)"
258
32c5e8d1f6ff added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
   294
apply(induct tp st c rule: fetch.induct)
32c5e8d1f6ff added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
   295
apply(simp_all add: list_encode_inverse split: cell.split)
32c5e8d1f6ff added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
   296
done
32c5e8d1f6ff added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
   297
32c5e8d1f6ff added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
   298
lemma Fetch_action_simulate:
259
4524c5edcafb moved new theries into a separate directory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 258
diff changeset
   299
  "tm_wf tp \<Longrightarrow> Actn (Code_tprog tp) st (cell_num c) = action_num (fst (fetch tp st c))"
258
32c5e8d1f6ff added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
   300
apply(induct tp st c rule: fetch.induct)
32c5e8d1f6ff added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
   301
apply(simp_all add: list_encode_inverse split: cell.split)
32c5e8d1f6ff added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
   302
done
32c5e8d1f6ff added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
   303
259
4524c5edcafb moved new theries into a separate directory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 258
diff changeset
   304
lemma Read_simulate:
4524c5edcafb moved new theries into a separate directory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 258
diff changeset
   305
  "Read (Code_tp tp) = cell_num (read tp)"
258
32c5e8d1f6ff added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
   306
apply(case_tac tp)
32c5e8d1f6ff added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
   307
apply(simp_all)
32c5e8d1f6ff added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
   308
done
32c5e8d1f6ff added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
   309
32c5e8d1f6ff added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
   310
lemma misc:
32c5e8d1f6ff added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
   311
  "2 < (3::nat)"
32c5e8d1f6ff added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
   312
  "1 < (3::nat)"
32c5e8d1f6ff added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
   313
  "0 < (3::nat)" 
32c5e8d1f6ff added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
   314
  "length [x] = 1"
32c5e8d1f6ff added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
   315
  "length [x, y] = 2"
32c5e8d1f6ff added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
   316
  "length [x, y , z] = 3"
32c5e8d1f6ff added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
   317
  "[x, y, z] ! 0 = x"
32c5e8d1f6ff added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
   318
  "[x, y, z] ! 1 = y"
32c5e8d1f6ff added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
   319
  "[x, y, z] ! 2 = z"
32c5e8d1f6ff added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
   320
apply(simp_all)
32c5e8d1f6ff added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
   321
done
32c5e8d1f6ff added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
   322
259
4524c5edcafb moved new theries into a separate directory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 258
diff changeset
   323
lemma Step_simulate:
4524c5edcafb moved new theries into a separate directory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 258
diff changeset
   324
  assumes "tm_wf tp"
4524c5edcafb moved new theries into a separate directory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 258
diff changeset
   325
  shows "Step (Conf (Code_conf (st, l, r))) (Code_tprog tp) = Conf (Code_conf (step (st, l, r) tp))"
258
32c5e8d1f6ff added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
   326
apply(subst step.simps) 
32c5e8d1f6ff added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
   327
apply(simp only: Let_def)
259
4524c5edcafb moved new theries into a separate directory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 258
diff changeset
   328
apply(subst Step.simps)
258
32c5e8d1f6ff added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
   329
apply(simp only: Conf.simps Code_conf.simps Right.simps Left.simps)
32c5e8d1f6ff added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
   330
apply(simp only: list_encode_inverse)
32c5e8d1f6ff added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
   331
apply(simp only: misc if_True Code_tp.simps)
32c5e8d1f6ff added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
   332
apply(simp only: prod_case_beta) 
32c5e8d1f6ff added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
   333
apply(subst Fetch_state_simulate[OF assms, symmetric])
259
4524c5edcafb moved new theries into a separate directory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 258
diff changeset
   334
apply(simp only: State.simps)
258
32c5e8d1f6ff added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
   335
apply(simp only: list_encode_inverse)
32c5e8d1f6ff added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
   336
apply(simp only: misc if_True)
259
4524c5edcafb moved new theries into a separate directory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 258
diff changeset
   337
apply(simp only: Read_simulate[simplified Code_tp.simps])
258
32c5e8d1f6ff added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
   338
apply(simp only: Fetch_action_simulate[OF assms])
32c5e8d1f6ff added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
   339
apply(simp only: Update_left_simulate[simplified Code_tp.simps])
32c5e8d1f6ff added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
   340
apply(simp only: Update_right_simulate[simplified Code_tp.simps])
32c5e8d1f6ff added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
   341
apply(case_tac "update (fst (fetch tp st (read r))) (l, r)")
32c5e8d1f6ff added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
   342
apply(simp only: Code_conf.simps)
32c5e8d1f6ff added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
   343
apply(simp only: Conf.simps)
32c5e8d1f6ff added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
   344
apply(simp)
32c5e8d1f6ff added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
   345
done
32c5e8d1f6ff added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
   346
259
4524c5edcafb moved new theries into a separate directory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 258
diff changeset
   347
lemma Steps_simulate:
4524c5edcafb moved new theries into a separate directory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 258
diff changeset
   348
  assumes "tm_wf tp" 
258
32c5e8d1f6ff added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
   349
  shows "Steps (Conf (Code_conf cf)) (Code_tprog tp) n = Conf (Code_conf (steps cf tp n))"
32c5e8d1f6ff added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
   350
apply(induct n arbitrary: cf) 
32c5e8d1f6ff added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
   351
apply(simp)
32c5e8d1f6ff added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
   352
apply(simp only: Steps.simps steps.simps)
32c5e8d1f6ff added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
   353
apply(case_tac cf)
32c5e8d1f6ff added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
   354
apply(simp only: )
259
4524c5edcafb moved new theries into a separate directory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 258
diff changeset
   355
apply(subst Step_simulate)
258
32c5e8d1f6ff added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
   356
apply(rule assms)
32c5e8d1f6ff added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
   357
apply(drule_tac x="step (a, b, c) tp" in meta_spec)
32c5e8d1f6ff added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
   358
apply(simp)
250
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   359
done
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   360
259
4524c5edcafb moved new theries into a separate directory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 258
diff changeset
   361
lemma Final_simulate:
4524c5edcafb moved new theries into a separate directory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 258
diff changeset
   362
  "Final (Conf (Code_conf cf)) = is_final cf"
4524c5edcafb moved new theries into a separate directory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 258
diff changeset
   363
by (case_tac cf) (simp)
246
e113420a2fce separated recursive functions and UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   364
259
4524c5edcafb moved new theries into a separate directory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 258
diff changeset
   365
lemma Std_simulate:
4524c5edcafb moved new theries into a separate directory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 258
diff changeset
   366
  "Std (Conf (Code_conf cf)) = std_tape (snd cf)" 
4524c5edcafb moved new theries into a separate directory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 258
diff changeset
   367
apply(case_tac cf)
260
1e45b5b6482a added definitions and proofs for right-std and left-std tapes
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 259
diff changeset
   368
apply(simp only: )
1e45b5b6482a added definitions and proofs for right-std and left-std tapes
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 259
diff changeset
   369
apply(simp only: std_tape_def)
1e45b5b6482a added definitions and proofs for right-std and left-std tapes
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 259
diff changeset
   370
apply(rule trans)
1e45b5b6482a added definitions and proofs for right-std and left-std tapes
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 259
diff changeset
   371
defer
1e45b5b6482a added definitions and proofs for right-std and left-std tapes
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 259
diff changeset
   372
apply(simp)
1e45b5b6482a added definitions and proofs for right-std and left-std tapes
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 259
diff changeset
   373
apply(subst Std.simps)
1e45b5b6482a added definitions and proofs for right-std and left-std tapes
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 259
diff changeset
   374
apply(simp only: Left.simps Right.simps)
1e45b5b6482a added definitions and proofs for right-std and left-std tapes
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 259
diff changeset
   375
apply(simp only: Code_conf.simps)
1e45b5b6482a added definitions and proofs for right-std and left-std tapes
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 259
diff changeset
   376
apply(simp only: Conf.simps)
1e45b5b6482a added definitions and proofs for right-std and left-std tapes
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 259
diff changeset
   377
apply(simp only: list_encode_inverse)
1e45b5b6482a added definitions and proofs for right-std and left-std tapes
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 259
diff changeset
   378
apply(simp only: misc if_True)
1e45b5b6482a added definitions and proofs for right-std and left-std tapes
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 259
diff changeset
   379
apply(simp only: Binnum_simulate)
259
4524c5edcafb moved new theries into a separate directory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 258
diff changeset
   380
apply(simp add: std_tape_def del: Std.simps)
4524c5edcafb moved new theries into a separate directory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 258
diff changeset
   381
apply(subst Std.simps)
246
e113420a2fce separated recursive functions and UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   382
259
4524c5edcafb moved new theries into a separate directory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 258
diff changeset
   383
(* UNTIL HERE *)
246
e113420a2fce separated recursive functions and UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   384
250
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   385
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   386
section {* Universal Function as Recursive Functions *}
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   387
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   388
definition 
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   389
  "rec_entry = CN rec_lo [Id 2 0, CN rec_pi [CN S [Id 2 1]]]"
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   390
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   391
fun rec_listsum2 :: "nat \<Rightarrow> nat \<Rightarrow> recf"
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   392
  where
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   393
  "rec_listsum2 vl 0 = CN Z [Id vl 0]"
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   394
| "rec_listsum2 vl (Suc n) = CN rec_add [rec_listsum2 vl n, Id vl n]"
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   395
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   396
fun rec_strt' :: "nat \<Rightarrow> nat \<Rightarrow> recf"
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   397
  where
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   398
  "rec_strt' xs 0 = Z"
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   399
| "rec_strt' xs (Suc n) = 
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   400
      (let dbound = CN rec_add [rec_listsum2 xs n, constn n] in
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   401
       let t1 = CN rec_power [constn 2, dbound] in
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   402
       let t2 = CN rec_power [constn 2, CN rec_add [Id xs n, dbound]] in
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   403
       CN rec_add [rec_strt' xs n, CN rec_minus [t2, t1]])"
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   404
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   405
fun rec_map :: "recf \<Rightarrow> nat \<Rightarrow> recf list"
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   406
  where
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   407
  "rec_map rf vl = map (\<lambda>i. CN rf [Id vl i]) [0..<vl]"
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   408
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   409
fun rec_strt :: "nat \<Rightarrow> recf"
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   410
  where
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   411
  "rec_strt xs = CN (rec_strt' xs xs) (rec_map S xs)"
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   412
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   413
definition 
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   414
  "rec_scan = CN rec_mod [Id 1 0, constn 2]"
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   415
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   416
definition
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   417
    "rec_newleft =
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   418
       (let cond1 = CN rec_disj [CN rec_eq [Id 3 2, Z], CN rec_eq [Id 3 2, constn 1]] in
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   419
        let cond2 = CN rec_eq [Id 3 2, constn 2] in
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   420
        let cond3 = CN rec_eq [Id 3 2, constn 3] in
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   421
        let case3 = CN rec_add [CN rec_mult [constn 2, Id 3 0], 
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   422
                                CN rec_mod [Id 3 1, constn 2]] in
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   423
        CN rec_if [cond1, Id 3 0, 
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   424
          CN rec_if [cond2, CN rec_quo [Id 3 0, constn 2],
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   425
            CN rec_if [cond3, case3, Id 3 0]]])"
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   426
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   427
definition
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   428
    "rec_newright =
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   429
       (let condn = \<lambda>n. CN rec_eq [Id 3 2, constn n] in
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   430
        let case0 = CN rec_minus [Id 3 1, CN rec_scan [Id 3 1]] in
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   431
        let case1 = CN rec_minus [CN rec_add [Id 3 1, constn 1], CN rec_scan [Id 3 1]] in
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   432
        let case2 = CN rec_add [CN rec_mult [constn 2, Id 3 1],                     
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   433
                                CN rec_mod [Id 3 0, constn 2]] in
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   434
        let case3 = CN rec_quo [Id 2 1, constn 2] in
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   435
        CN rec_if [condn 0, case0, 
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   436
          CN rec_if [condn 1, case1,
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   437
            CN rec_if [condn 2, case2,
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   438
              CN rec_if [condn 3, case3, Id 3 1]]]])"
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   439
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   440
definition 
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   441
  "rec_actn = (let add1 = CN rec_mult [constn 4, CN rec_pred [Id 3 1]] in
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   442
               let add2 = CN rec_mult [constn 2, CN rec_scan [Id 3 2]] in
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   443
               let entry = CN rec_entry [Id 3 0, CN rec_add [add1, add2]]
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   444
               in CN rec_if [Id 3 1, entry, constn 4])"
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   445
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   446
definition rec_newstat :: "recf"
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   447
  where
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   448
  "rec_newstat = (let add1 = CN rec_mult [constn 4, CN rec_pred [Id 3 1]] in
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   449
                  let add2 = CN S [CN rec_mult [constn 2, CN rec_scan [Id 3 2]]] in
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   450
                  let entry = CN rec_entry [Id 3 0, CN rec_add [add1, add2]]
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   451
                  in CN rec_if [Id 3 1, entry, Z])"
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   452
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   453
definition 
256
04700724250f completed coding functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 250
diff changeset
   454
  "rec_trpl = CN rec_penc [CN rec_penc [Id 3 0, Id 3 1], Id 3 2]"
250
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   455
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   456
definition
256
04700724250f completed coding functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 250
diff changeset
   457
  "rec_left = rec_pdec1"
250
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   458
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   459
definition 
256
04700724250f completed coding functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 250
diff changeset
   460
  "rec_right = CN rec_pdec2 [rec_pdec1]"
250
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   461
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   462
definition 
256
04700724250f completed coding functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 250
diff changeset
   463
  "rec_stat = CN rec_pdec2 [rec_pdec2]"
250
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   464
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   465
definition 
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   466
  "rec_newconf = (let act = CN rec_actn [Id 2 0, CN rec_stat [Id 2 1], CN rec_right [Id 2 1]] in
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   467
                  let left = CN rec_left [Id 2 1] in
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   468
                  let right = CN rec_right [Id 2 1] in
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   469
                  let stat = CN rec_stat [Id 2 1] in
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   470
                  let one = CN rec_newleft [left, right, act] in
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   471
                  let two = CN rec_newstat [Id 2 0, stat, right] in
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   472
                  let three = CN rec_newright [left, right, act]
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   473
                  in CN rec_trpl [one, two, three])" 
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   474
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   475
definition 
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   476
  "rec_conf = PR (CN rec_trpl [constn 0, constn 1, Id 2 1])
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   477
                 (CN rec_newconf [Id 4 2 , Id 4 1])"
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   478
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   479
definition 
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   480
  "rec_nstd = (let disj1 = CN rec_noteq [rec_stat, constn 0] in
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   481
               let disj2 = CN rec_noteq [rec_left, constn 0] in
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   482
               let rhs = CN rec_pred [CN rec_power [constn 2, CN rec_lg [CN S [rec_right], constn 2]]] in
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   483
               let disj3 = CN rec_noteq [rec_right, rhs] in
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   484
               let disj4 = CN rec_eq [rec_right, constn 0] in
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   485
               CN rec_disj [CN rec_disj [CN rec_disj [disj1, disj2], disj3], disj4])"
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   486
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   487
definition 
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   488
  "rec_nostop = CN rec_nstd [rec_conf]"
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   489
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   490
definition 
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   491
  "rec_value = CN rec_pred [CN rec_lg [S, constn 2]]"
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   492
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   493
definition 
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   494
  "rec_halt = MN rec_nostop" 
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   495
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   496
definition 
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   497
  "rec_uf = CN rec_value [CN rec_right [CN rec_conf [rec_halt, Id 2 0, Id 2 1]]]"
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   498
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   499
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   500
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   501
section {* Correctness Proofs for Recursive Functions *}
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   502
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   503
lemma entry_lemma [simp]:
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   504
  "rec_eval rec_entry [sr, i] = Entry sr i"
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   505
by(simp add: rec_entry_def)
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   506
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   507
lemma listsum2_lemma [simp]: 
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   508
  "length xs = vl \<Longrightarrow> rec_eval (rec_listsum2 vl n) xs = Listsum2 xs n"
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   509
by (induct n) (simp_all)
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   510
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   511
lemma strt'_lemma [simp]:
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   512
  "length xs = vl \<Longrightarrow> rec_eval (rec_strt' vl n) xs = Strt' xs n"
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   513
by (induct n) (simp_all add: Let_def)
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   514
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   515
lemma map_suc:
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   516
  "map (\<lambda>x. Suc (xs ! x)) [0..<length xs] = map Suc xs"
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   517
proof -
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   518
  have "Suc \<circ> (\<lambda>x. xs ! x) = (\<lambda>x. Suc (xs ! x))" by (simp add: comp_def)
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   519
  then have "map (\<lambda>x. Suc (xs ! x)) [0..<length xs] = map (Suc \<circ> (\<lambda>x. xs ! x)) [0..<length xs]" by simp
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   520
  also have "... = map Suc (map (\<lambda>x. xs ! x) [0..<length xs])" by simp
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   521
  also have "... = map Suc xs" by (simp add: map_nth)
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   522
  finally show "map (\<lambda>x. Suc (xs ! x)) [0..<length xs] = map Suc xs" .
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   523
qed
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   524
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   525
lemma strt_lemma [simp]: 
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   526
  "length xs = vl \<Longrightarrow> rec_eval (rec_strt vl) xs = Strt xs"
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   527
by (simp add: comp_def map_suc[symmetric])
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   528
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   529
lemma scan_lemma [simp]: 
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   530
  "rec_eval rec_scan [r] = r mod 2"
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   531
by(simp add: rec_scan_def)
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   532
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   533
lemma newleft_lemma [simp]:
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   534
  "rec_eval rec_newleft [p, r, a] = Newleft p r a"
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   535
by (simp add: rec_newleft_def Let_def)
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   536
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   537
lemma newright_lemma [simp]:
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   538
  "rec_eval rec_newright [p, r, a] = Newright p r a"
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   539
by (simp add: rec_newright_def Let_def)
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   540
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   541
lemma actn_lemma [simp]:
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   542
  "rec_eval rec_actn [m, q, r] = Actn m q r"
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   543
by (simp add: rec_actn_def)
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   544
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   545
lemma newstat_lemma [simp]: 
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   546
  "rec_eval rec_newstat [m, q, r] = Newstat m q r"
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   547
by (simp add: rec_newstat_def)
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   548
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   549
lemma trpl_lemma [simp]: 
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   550
  "rec_eval rec_trpl [p, q, r] = Trpl p q r"
256
04700724250f completed coding functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 250
diff changeset
   551
apply(simp)
04700724250f completed coding functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 250
diff changeset
   552
apply (simp add: rec_trpl_def)
250
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   553
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   554
lemma left_lemma [simp]:
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   555
  "rec_eval rec_left [c] = Left c" 
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   556
by(simp add: rec_left_def)
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   557
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   558
lemma right_lemma [simp]:
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   559
  "rec_eval rec_right [c] = Right c" 
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   560
by(simp add: rec_right_def)
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   561
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   562
lemma stat_lemma [simp]:
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   563
  "rec_eval rec_stat [c] = Stat c" 
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   564
by(simp add: rec_stat_def)
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   565
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   566
lemma newconf_lemma [simp]: 
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   567
  "rec_eval rec_newconf [m, c] = Newconf m c"
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   568
by (simp add: rec_newconf_def Let_def)
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   569
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   570
lemma conf_lemma [simp]: 
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   571
  "rec_eval rec_conf [k, m, r] = Conf k m r"
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   572
by(induct k) (simp_all add: rec_conf_def)
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   573
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   574
lemma nstd_lemma [simp]:
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   575
  "rec_eval rec_nstd [c] = (if Nstd c then 1 else 0)"
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   576
by(simp add: rec_nstd_def)
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   577
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   578
lemma nostop_lemma [simp]:
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   579
  "rec_eval rec_nostop [t, m, r] = (if Nostop t m r then 1 else 0)" 
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   580
by (simp add: rec_nostop_def)
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   581
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   582
lemma value_lemma [simp]:
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   583
  "rec_eval rec_value [x] = Value x"
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   584
by (simp add: rec_value_def)
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   585
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   586
lemma halt_lemma [simp]:
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   587
  "rec_eval rec_halt [m, r] = Halt m r"
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   588
by (simp add: rec_halt_def)
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   589
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   590
lemma uf_lemma [simp]:
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   591
  "rec_eval rec_uf [m, r] = UF m r"
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   592
by (simp add: rec_uf_def)
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   593
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   594
248
aea02b5a58d2 repaired old files
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 246
diff changeset
   595
subsection {* Relating interperter functions to the execution of TMs *}
246
e113420a2fce separated recursive functions and UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   596
250
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   597
lemma rec_step: 
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   598
  assumes "(\<lambda> (s, l, r). s \<le> length tp div 2) c"
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   599
  shows "Trpl_code (step0 c tp) = Newconf (Code tp) (Trpl_code c)"
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   600
apply(cases c)
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   601
apply(simp only: Trpl_code.simps)
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   602
apply(simp only: Let_def step.simps)
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   603
apply(case_tac "fetch tp (a - 0) (read ca)")
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   604
apply(simp only: prod.cases)
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   605
apply(case_tac "update aa (b, ca)")
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   606
apply(simp only: prod.cases)
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   607
apply(simp only: Trpl_code.simps)
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   608
apply(simp only: Newconf.simps)
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   609
apply(simp only: Left.simps)
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   610
oops
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   611
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   612
lemma rec_steps:
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   613
  assumes "tm_wf0 tp"
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   614
  shows "Trpl_code (steps0 (1, Bk \<up> l, <lm>) tp stp) = Conf stp (Code tp) (bl2wc (<lm>))"
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   615
apply(induct stp)
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   616
apply(simp)
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   617
apply(simp)
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   618
oops
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   619
246
e113420a2fce separated recursive functions and UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   620
248
aea02b5a58d2 repaired old files
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 246
diff changeset
   621
lemma F_correct: 
250
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   622
  assumes tm: "steps0 (1, Bk \<up> l, <lm>) tp stp = (0, Bk \<up> m, Oc \<up> rs @ Bk \<up> n)"
248
aea02b5a58d2 repaired old files
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 246
diff changeset
   623
  and     wf:  "tm_wf0 tp" "0 < rs"
aea02b5a58d2 repaired old files
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 246
diff changeset
   624
  shows "rec_eval rec_uf [Code tp, bl2wc (<lm>)] = (rs - Suc 0)"
250
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   625
proof -
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   626
  from least_steps[OF tm] 
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   627
  obtain stp_least where
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   628
    before: "\<forall>stp' < stp_least. \<not> is_final (steps0 (1, Bk \<up> l, <lm>) tp stp')" and
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   629
    after:  "\<forall>stp' \<ge> stp_least. is_final (steps0 (1, Bk \<up> l, <lm>) tp stp')" by blast
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   630
  have "Halt (Code tp) (bl2wc (<lm>)) = stp_least" sorry
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   631
  show ?thesis
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   632
    apply(simp only: uf_lemma)
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   633
    apply(simp only: UF.simps)
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   634
    apply(simp only: Halt.simps)
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   635
    oops
246
e113420a2fce separated recursive functions and UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   636
e113420a2fce separated recursive functions and UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   637
248
aea02b5a58d2 repaired old files
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 246
diff changeset
   638
end
246
e113420a2fce separated recursive functions and UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   639