thys2/UF_Rec.thy
author Christian Urban <christian dot urban at kcl dot ac dot uk>
Fri, 24 May 2013 20:35:28 +0100
changeset 261 ca1fe315cb0a
parent 260 1e45b5b6482a
child 262 5704925ad138
permissions -rwxr-xr-x
completed the UF-simulation lemmas
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
261
ca1fe315cb0a completed the UF-simulation lemmas
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 260
diff changeset
    33
lemma code_tp_append [simp]:
ca1fe315cb0a completed the UF-simulation lemmas
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 260
diff changeset
    34
  "code_tp (tp1 @ tp2) = code_tp tp1 @ code_tp tp2"
ca1fe315cb0a completed the UF-simulation lemmas
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 260
diff changeset
    35
by(induct tp1) (simp_all)
ca1fe315cb0a completed the UF-simulation lemmas
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 260
diff changeset
    36
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
    37
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
    38
  "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
    39
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
    40
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
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
    42
  "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
    43
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
    44
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
    45
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
    46
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
    47
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
    48
261
ca1fe315cb0a completed the UF-simulation lemmas
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 260
diff changeset
    49
lemma code_tp_replicate [simp]:
ca1fe315cb0a completed the UF-simulation lemmas
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 260
diff changeset
    50
  "code_tp (c \<up> n) = (cell_num c) \<up> n"
ca1fe315cb0a completed the UF-simulation lemmas
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 260
diff changeset
    51
by(induct n) (simp_all)
ca1fe315cb0a completed the UF-simulation lemmas
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 260
diff changeset
    52
ca1fe315cb0a completed the UF-simulation lemmas
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 260
diff changeset
    53
258
32c5e8d1f6ff added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
    54
fun Code_conf where
32c5e8d1f6ff added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
    55
  "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
    56
32c5e8d1f6ff added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
    57
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
    58
  "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
    59
  
32c5e8d1f6ff added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
    60
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
    61
  "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
    62
32c5e8d1f6ff added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
    63
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
    64
  where
32c5e8d1f6ff added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
    65
  "code_tprog [] =  []"
32c5e8d1f6ff added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
    66
| "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
    67
32c5e8d1f6ff added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
    68
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
    69
  "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
    70
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
    71
32c5e8d1f6ff added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
    72
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
    73
  "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
    74
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
    75
32c5e8d1f6ff added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
    76
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
    77
  where 
32c5e8d1f6ff added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
    78
  "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
    79
250
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
    80
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
    81
258
32c5e8d1f6ff added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
    82
259
4524c5edcafb moved new theries into a separate directory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 258
diff changeset
    83
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
    84
259
4524c5edcafb moved new theries into a separate directory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 258
diff changeset
    85
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
    86
  "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
    87
258
32c5e8d1f6ff added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
    88
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
    89
  "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
    90
258
32c5e8d1f6ff added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
    91
text {* 
32c5e8d1f6ff added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
    92
  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
    93
  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
    94
  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
    95
*}
246
e113420a2fce separated recursive functions and UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    96
e113420a2fce separated recursive functions and UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    97
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
    98
  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
    99
  "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
   100
                    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
   101
                    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
   102
                    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
   103
                    else l)"
246
e113420a2fce separated recursive functions and UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   104
e113420a2fce separated recursive functions and UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   105
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
   106
  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
   107
  "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
   108
                      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
   109
                      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
   110
                      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
   111
                      else r)"
e113420a2fce separated recursive functions and UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   112
e113420a2fce separated recursive functions and UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   113
text {*
e113420a2fce separated recursive functions and UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   114
  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
   115
  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
   116
  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
   117
  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
   118
*}
32c5e8d1f6ff added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
   119
32c5e8d1f6ff added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
   120
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
   121
  "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
   122
| "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
   123
246
e113420a2fce separated recursive functions and UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   124
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
   125
  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
   126
  "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
   127
259
4524c5edcafb moved new theries into a separate directory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 258
diff changeset
   128
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
   129
  "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
   130
| "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
   131
259
4524c5edcafb moved new theries into a separate directory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 258
diff changeset
   132
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
   133
  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
   134
  "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
   135
258
32c5e8d1f6ff added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
   136
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
   137
  where
261
ca1fe315cb0a completed the UF-simulation lemmas
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 260
diff changeset
   138
  "Conf (q, l, r) = lenc [q, l, r]"
258
32c5e8d1f6ff added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
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 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
   141
  "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
   142
e113420a2fce separated recursive functions and UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   143
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
   144
  "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
   145
e113420a2fce separated recursive functions and UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   146
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
   147
  "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
   148
259
4524c5edcafb moved new theries into a separate directory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 258
diff changeset
   149
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
   150
  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
   151
  "Step cf m = Conf (Newstate m (State cf) (Read (Right cf)), 
261
ca1fe315cb0a completed the UF-simulation lemmas
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 260
diff changeset
   152
                     Newleft (Left cf) (Right cf) (Actn m (State cf) (Read (Right cf))),
ca1fe315cb0a completed the UF-simulation lemmas
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 260
diff changeset
   153
                     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
   154
e113420a2fce separated recursive functions and UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   155
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
   156
  @{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
   157
  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
   158
*}
250
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   159
258
32c5e8d1f6ff added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
   160
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
   161
  where
258
32c5e8d1f6ff added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
   162
  "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
   163
| "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
   164
e113420a2fce separated recursive functions and UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   165
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
   166
  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
   167
*}
4524c5edcafb moved new theries into a separate directory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 258
diff changeset
   168
4524c5edcafb moved new theries into a separate directory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 258
diff changeset
   169
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
   170
  where
261
ca1fe315cb0a completed the UF-simulation lemmas
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 260
diff changeset
   171
  "Stknum z \<equiv> (\<Sum>i < enclen z. ldec z i)"
259
4524c5edcafb moved new theries into a separate directory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 258
diff changeset
   172
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
   173
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
   174
definition
261
ca1fe315cb0a completed the UF-simulation lemmas
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 260
diff changeset
   175
  "right_std z \<equiv> (\<exists>i \<le> enclen z. 1 \<le> i \<and> (\<forall>j < i. ldec z j = 1) \<and> (\<forall>j < enclen z - i. ldec z (i + j) = 0))"
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
   176
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
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
   178
  "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
   179
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
   180
lemma ww:
261
ca1fe315cb0a completed the UF-simulation lemmas
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 260
diff changeset
   181
 "(\<exists>k l. 1 \<le> k \<and> tp = Oc \<up> k @ Bk \<up> l) \<longleftrightarrow> 
ca1fe315cb0a completed the UF-simulation lemmas
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 260
diff changeset
   182
  (\<exists>i\<le>length tp. 1 \<le> i \<and> (\<forall>j < i. tp ! j = Oc) \<and> (\<forall>j < length tp - i. tp ! (i + j) = Bk))"
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
   183
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
   184
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
   185
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
   186
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
   187
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
   188
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
   189
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
   190
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
   191
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
   192
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
   193
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
   194
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
   195
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
   196
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
   197
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
   198
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
   199
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
   200
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
lemma right_std:
261
ca1fe315cb0a completed the UF-simulation lemmas
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 260
diff changeset
   202
  "(\<exists>k l. 1 \<le> k \<and> tp = Oc \<up> k @ Bk \<up> l) \<longleftrightarrow> right_std (Code_tp tp)"
ca1fe315cb0a completed the UF-simulation lemmas
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 260
diff changeset
   203
apply(simp only: ww)
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
   204
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
   205
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
   206
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
   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
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
   209
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
   210
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
   211
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
   212
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
   213
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
   214
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
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
   216
  "(\<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
   217
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
   218
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
   219
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
   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(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
   222
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
   223
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
   224
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
   225
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
   226
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
   227
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
   228
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
   229
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
   230
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
   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
261
ca1fe315cb0a completed the UF-simulation lemmas
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 260
diff changeset
   233
lemma Stknum_append:
ca1fe315cb0a completed the UF-simulation lemmas
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 260
diff changeset
   234
  "Stknum (Code_tp (tp1 @ tp2)) = Stknum (Code_tp tp1) + Stknum (Code_tp tp2)"
ca1fe315cb0a completed the UF-simulation lemmas
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 260
diff changeset
   235
apply(simp only: Code_tp.simps)
ca1fe315cb0a completed the UF-simulation lemmas
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 260
diff changeset
   236
apply(simp only: code_tp_append)
ca1fe315cb0a completed the UF-simulation lemmas
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 260
diff changeset
   237
apply(simp only: Stknum_def)
ca1fe315cb0a completed the UF-simulation lemmas
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 260
diff changeset
   238
apply(simp only: enclen_length length_append code_tp_length)
ca1fe315cb0a completed the UF-simulation lemmas
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 260
diff changeset
   239
apply(simp only: list_encode_inverse)
ca1fe315cb0a completed the UF-simulation lemmas
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 260
diff changeset
   240
apply(simp only: enclen_length length_append code_tp_length)
ca1fe315cb0a completed the UF-simulation lemmas
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 260
diff changeset
   241
apply(simp)
ca1fe315cb0a completed the UF-simulation lemmas
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 260
diff changeset
   242
apply(subgoal_tac "{..<length tp1 + length tp2} = {..<length tp1} \<union> {length tp1 ..<length tp1 + length tp2}")
ca1fe315cb0a completed the UF-simulation lemmas
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 260
diff changeset
   243
prefer 2
ca1fe315cb0a completed the UF-simulation lemmas
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 260
diff changeset
   244
apply(auto)[1]
ca1fe315cb0a completed the UF-simulation lemmas
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 260
diff changeset
   245
apply(simp only:)
ca1fe315cb0a completed the UF-simulation lemmas
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 260
diff changeset
   246
apply(subst setsum_Un_disjoint)
ca1fe315cb0a completed the UF-simulation lemmas
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 260
diff changeset
   247
apply(auto)[2]
ca1fe315cb0a completed the UF-simulation lemmas
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 260
diff changeset
   248
apply (metis ivl_disj_int_one(2))
ca1fe315cb0a completed the UF-simulation lemmas
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 260
diff changeset
   249
apply(simp add: nth_append)
ca1fe315cb0a completed the UF-simulation lemmas
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 260
diff changeset
   250
apply(subgoal_tac "{length tp1..<length tp1 + length tp2} = (\<lambda>x. x + length tp1) ` {0..<length tp2}")
ca1fe315cb0a completed the UF-simulation lemmas
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 260
diff changeset
   251
prefer 2
ca1fe315cb0a completed the UF-simulation lemmas
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 260
diff changeset
   252
apply(simp only: image_add_atLeastLessThan)
ca1fe315cb0a completed the UF-simulation lemmas
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 260
diff changeset
   253
apply (metis comm_monoid_add_class.add.left_neutral nat_add_commute)
ca1fe315cb0a completed the UF-simulation lemmas
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 260
diff changeset
   254
apply(simp only:)
ca1fe315cb0a completed the UF-simulation lemmas
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 260
diff changeset
   255
apply(subst setsum_reindex)
ca1fe315cb0a completed the UF-simulation lemmas
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 260
diff changeset
   256
prefer 2
ca1fe315cb0a completed the UF-simulation lemmas
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 260
diff changeset
   257
apply(simp add: comp_def)
ca1fe315cb0a completed the UF-simulation lemmas
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 260
diff changeset
   258
apply (metis atLeast0LessThan)
ca1fe315cb0a completed the UF-simulation lemmas
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 260
diff changeset
   259
apply(simp add: inj_on_def)
ca1fe315cb0a completed the UF-simulation lemmas
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 260
diff changeset
   260
done
ca1fe315cb0a completed the UF-simulation lemmas
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 260
diff changeset
   261
ca1fe315cb0a completed the UF-simulation lemmas
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 260
diff changeset
   262
lemma Stknum_up:
ca1fe315cb0a completed the UF-simulation lemmas
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 260
diff changeset
   263
  "Stknum (lenc (a \<up> n)) = n * a"
ca1fe315cb0a completed the UF-simulation lemmas
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 260
diff changeset
   264
apply(induct n)
ca1fe315cb0a completed the UF-simulation lemmas
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 260
diff changeset
   265
apply(simp_all add: Stknum_def list_encode_inverse del: replicate.simps)
ca1fe315cb0a completed the UF-simulation lemmas
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 260
diff changeset
   266
done
ca1fe315cb0a completed the UF-simulation lemmas
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 260
diff changeset
   267
ca1fe315cb0a completed the UF-simulation lemmas
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 260
diff changeset
   268
lemma result:
ca1fe315cb0a completed the UF-simulation lemmas
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 260
diff changeset
   269
  "Stknum (Code_tp (<n> @ Bk \<up> l)) - 1 = n"
ca1fe315cb0a completed the UF-simulation lemmas
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 260
diff changeset
   270
apply(simp only: Stknum_append)
ca1fe315cb0a completed the UF-simulation lemmas
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 260
diff changeset
   271
apply(simp only: tape_of_nat.simps)
ca1fe315cb0a completed the UF-simulation lemmas
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 260
diff changeset
   272
apply(simp only: Code_tp.simps)
ca1fe315cb0a completed the UF-simulation lemmas
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 260
diff changeset
   273
apply(simp only: code_tp_replicate)
ca1fe315cb0a completed the UF-simulation lemmas
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 260
diff changeset
   274
apply(simp only: cell_num.simps)
ca1fe315cb0a completed the UF-simulation lemmas
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 260
diff changeset
   275
apply(simp only: Stknum_up)
ca1fe315cb0a completed the UF-simulation lemmas
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 260
diff changeset
   276
apply(simp)
ca1fe315cb0a completed the UF-simulation lemmas
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 260
diff changeset
   277
done
ca1fe315cb0a completed the UF-simulation lemmas
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 260
diff changeset
   278
259
4524c5edcafb moved new theries into a separate directory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 258
diff changeset
   279
text {*
4524c5edcafb moved new theries into a separate directory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 258
diff changeset
   280
  @{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
   281
  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
   282
*}
4524c5edcafb moved new theries into a separate directory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 258
diff changeset
   283
4524c5edcafb moved new theries into a separate directory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 258
diff changeset
   284
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
   285
  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
   286
  "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
   287
e113420a2fce separated recursive functions and UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   288
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
   289
  @{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
   290
  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
   291
  @{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
   292
4524c5edcafb moved new theries into a separate directory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 258
diff changeset
   293
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
   294
  where
4524c5edcafb moved new theries into a separate directory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 258
diff changeset
   295
    "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
   296
261
ca1fe315cb0a completed the UF-simulation lemmas
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 260
diff changeset
   297
fun Stop :: "nat \<Rightarrow> nat \<Rightarrow> nat \<Rightarrow> bool"
246
e113420a2fce separated recursive functions and UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   298
  where
261
ca1fe315cb0a completed the UF-simulation lemmas
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 260
diff changeset
   299
  "Stop m cf k = (Final (Steps cf m k) \<and> 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
   300
e113420a2fce separated recursive functions and UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   301
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
   302
  @{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
   303
  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
   304
  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
   305
  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
   306
  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
   307
*}
246
e113420a2fce separated recursive functions and UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   308
250
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   309
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
   310
  where
261
ca1fe315cb0a completed the UF-simulation lemmas
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 260
diff changeset
   311
  "Halt m cf = (LEAST k. Stop 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
   312
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   313
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
   314
  where
261
ca1fe315cb0a completed the UF-simulation lemmas
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 260
diff changeset
   315
  "UF m cf = Stknum (Right (Steps cf m (Halt m cf))) - 1"
258
32c5e8d1f6ff added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
   316
32c5e8d1f6ff added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
   317
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
   318
32c5e8d1f6ff added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
   319
lemma Update_left_simulate:
32c5e8d1f6ff added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
   320
  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
   321
apply(induct a)
32c5e8d1f6ff added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
   322
apply(simp_all)
32c5e8d1f6ff added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
   323
apply(case_tac l)
32c5e8d1f6ff added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
   324
apply(simp_all)
32c5e8d1f6ff added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
   325
apply(case_tac r)
32c5e8d1f6ff added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
   326
apply(simp_all)
32c5e8d1f6ff added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
   327
done
32c5e8d1f6ff added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
   328
32c5e8d1f6ff added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
   329
lemma Update_right_simulate:
32c5e8d1f6ff added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
   330
  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
   331
apply(induct a)
32c5e8d1f6ff added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
   332
apply(simp_all)
32c5e8d1f6ff added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
   333
apply(case_tac r)
32c5e8d1f6ff added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
   334
apply(simp_all)
32c5e8d1f6ff added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
   335
apply(case_tac r)
32c5e8d1f6ff added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
   336
apply(simp_all)
32c5e8d1f6ff added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
   337
apply(case_tac l)
32c5e8d1f6ff added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
   338
apply(simp_all)
32c5e8d1f6ff added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
   339
apply(case_tac r)
32c5e8d1f6ff added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
   340
apply(simp_all)
32c5e8d1f6ff added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
   341
done
32c5e8d1f6ff added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
   342
32c5e8d1f6ff added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
   343
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
   344
  "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
   345
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
   346
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
   347
done
32c5e8d1f6ff added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
   348
32c5e8d1f6ff added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
   349
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
   350
  "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
   351
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
   352
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
   353
done
32c5e8d1f6ff added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
   354
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
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
   356
  "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
   357
apply(case_tac tp)
32c5e8d1f6ff added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
   358
apply(simp_all)
32c5e8d1f6ff added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
   359
done
32c5e8d1f6ff added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
   360
32c5e8d1f6ff added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
   361
lemma misc:
32c5e8d1f6ff added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
   362
  "2 < (3::nat)"
32c5e8d1f6ff added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
   363
  "1 < (3::nat)"
32c5e8d1f6ff added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
   364
  "0 < (3::nat)" 
32c5e8d1f6ff added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
   365
  "length [x] = 1"
32c5e8d1f6ff added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
   366
  "length [x, y] = 2"
32c5e8d1f6ff added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
   367
  "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
   368
  "[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
   369
  "[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
   370
  "[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
   371
apply(simp_all)
32c5e8d1f6ff added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
   372
done
32c5e8d1f6ff added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
   373
259
4524c5edcafb moved new theries into a separate directory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 258
diff changeset
   374
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
   375
  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
   376
  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
   377
apply(subst step.simps) 
32c5e8d1f6ff added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
   378
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
   379
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
   380
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
   381
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
   382
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
   383
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
   384
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
   385
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
   386
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
   387
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
   388
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
   389
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
   390
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
   391
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
   392
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
   393
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
   394
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
   395
apply(simp)
32c5e8d1f6ff added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
   396
done
32c5e8d1f6ff added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
   397
259
4524c5edcafb moved new theries into a separate directory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 258
diff changeset
   398
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
   399
  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
   400
  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
   401
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
   402
apply(simp)
32c5e8d1f6ff added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
   403
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
   404
apply(case_tac cf)
32c5e8d1f6ff added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
   405
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
   406
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
   407
apply(rule assms)
32c5e8d1f6ff added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
   408
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
   409
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
   410
done
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   411
259
4524c5edcafb moved new theries into a separate directory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 258
diff changeset
   412
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
   413
  "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
   414
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
   415
259
4524c5edcafb moved new theries into a separate directory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 258
diff changeset
   416
lemma Std_simulate:
261
ca1fe315cb0a completed the UF-simulation lemmas
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 260
diff changeset
   417
  "Std (Conf (Code_conf cf)) = std_tape 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
   418
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
   419
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
   420
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
   421
apply(simp only: Conf.simps)
261
ca1fe315cb0a completed the UF-simulation lemmas
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 260
diff changeset
   422
apply(simp only: Std.simps)
ca1fe315cb0a completed the UF-simulation lemmas
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 260
diff changeset
   423
apply(simp only: Left.simps Right.simps)
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
   424
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
   425
apply(simp only: misc if_True)
261
ca1fe315cb0a completed the UF-simulation lemmas
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 260
diff changeset
   426
apply(simp only: left_std[symmetric] right_std[symmetric])
ca1fe315cb0a completed the UF-simulation lemmas
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 260
diff changeset
   427
apply(simp)
ca1fe315cb0a completed the UF-simulation lemmas
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 260
diff changeset
   428
apply(auto)
ca1fe315cb0a completed the UF-simulation lemmas
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 260
diff changeset
   429
apply(rule_tac x="ka - 1" in exI)
ca1fe315cb0a completed the UF-simulation lemmas
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 260
diff changeset
   430
apply(rule_tac x="l" in exI)
ca1fe315cb0a completed the UF-simulation lemmas
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 260
diff changeset
   431
apply(simp)
ca1fe315cb0a completed the UF-simulation lemmas
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 260
diff changeset
   432
apply (metis Suc_diff_le diff_Suc_Suc diff_zero replicate_Suc)
ca1fe315cb0a completed the UF-simulation lemmas
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 260
diff changeset
   433
apply(rule_tac x="n + 1" in exI)
ca1fe315cb0a completed the UF-simulation lemmas
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 260
diff changeset
   434
apply(simp)
ca1fe315cb0a completed the UF-simulation lemmas
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 260
diff changeset
   435
done
246
e113420a2fce separated recursive functions and UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   436
261
ca1fe315cb0a completed the UF-simulation lemmas
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 260
diff changeset
   437
lemma UF_simulate:
ca1fe315cb0a completed the UF-simulation lemmas
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 260
diff changeset
   438
  assumes "tm_wf tm"
ca1fe315cb0a completed the UF-simulation lemmas
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 260
diff changeset
   439
  shows "UF (Code_tprog tm) (Conf (Code_conf cf)) = 
ca1fe315cb0a completed the UF-simulation lemmas
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 260
diff changeset
   440
  Stknum (Right (Conf 
ca1fe315cb0a completed the UF-simulation lemmas
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 260
diff changeset
   441
  (Code_conf (steps cf tm (LEAST n. is_final (steps cf tm n) \<and> std_tape (steps cf tm n)))))) - 1" 
ca1fe315cb0a completed the UF-simulation lemmas
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 260
diff changeset
   442
apply(simp only: UF.simps)
ca1fe315cb0a completed the UF-simulation lemmas
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 260
diff changeset
   443
apply(subst Steps_simulate[symmetric, OF assms])
ca1fe315cb0a completed the UF-simulation lemmas
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 260
diff changeset
   444
apply(subst Final_simulate[symmetric])
ca1fe315cb0a completed the UF-simulation lemmas
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 260
diff changeset
   445
apply(subst Std_simulate[symmetric])
ca1fe315cb0a completed the UF-simulation lemmas
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 260
diff changeset
   446
apply(simp only: Halt.simps)
ca1fe315cb0a completed the UF-simulation lemmas
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 260
diff changeset
   447
apply(simp only: Steps_simulate[symmetric, OF assms])
ca1fe315cb0a completed the UF-simulation lemmas
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 260
diff changeset
   448
apply(simp only: Stop.simps[symmetric])
ca1fe315cb0a completed the UF-simulation lemmas
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 260
diff changeset
   449
done
246
e113420a2fce separated recursive functions and UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   450
261
ca1fe315cb0a completed the UF-simulation lemmas
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 260
diff changeset
   451
text {* UNTIL HERE *}
250
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
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
   454
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   455
definition 
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   456
  "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
   457
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   458
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
   459
  where
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   460
  "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
   461
| "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
   462
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   463
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
   464
  where
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   465
  "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
   466
| "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
   467
      (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
   468
       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
   469
       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
   470
       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
   471
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   472
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
   473
  where
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   474
  "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
   475
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   476
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
   477
  where
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   478
  "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
   479
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   480
definition 
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   481
  "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
   482
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   483
definition
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   484
    "rec_newleft =
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   485
       (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
   486
        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
   487
        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
   488
        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
   489
                                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
   490
        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
   491
          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
   492
            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
   493
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   494
definition
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   495
    "rec_newright =
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   496
       (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
   497
        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
   498
        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
   499
        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
   500
                                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
   501
        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
   502
        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
   503
          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
   504
            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
   505
              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
   506
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   507
definition 
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   508
  "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
   509
               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
   510
               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
   511
               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
   512
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   513
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
   514
  where
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   515
  "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
   516
                  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
   517
                  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
   518
                  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
   519
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   520
definition 
256
04700724250f completed coding functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 250
diff changeset
   521
  "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
   522
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   523
definition
256
04700724250f completed coding functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 250
diff changeset
   524
  "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
   525
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   526
definition 
256
04700724250f completed coding functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 250
diff changeset
   527
  "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
   528
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   529
definition 
256
04700724250f completed coding functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 250
diff changeset
   530
  "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
   531
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   532
definition 
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   533
  "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
   534
                  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
   535
                  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
   536
                  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
   537
                  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
   538
                  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
   539
                  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
   540
                  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
   541
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   542
definition 
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   543
  "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
   544
                 (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
   545
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   546
definition 
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   547
  "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
   548
               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
   549
               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
   550
               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
   551
               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
   552
               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
   553
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   554
definition 
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   555
  "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
   556
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   557
definition 
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   558
  "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
   559
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   560
definition 
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   561
  "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
   562
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   563
definition 
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   564
  "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
   565
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   566
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   567
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   568
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
   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 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
   571
  "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
   572
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
   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 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
   575
  "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
   576
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
   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 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
   579
  "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
   580
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
   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 map_suc:
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   583
  "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
   584
proof -
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   585
  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
   586
  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
   587
  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
   588
  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
   589
  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
   590
qed
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   591
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   592
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
   593
  "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
   594
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
   595
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   596
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
   597
  "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
   598
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
   599
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   600
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
   601
  "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
   602
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
   603
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   604
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
   605
  "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
   606
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
   607
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   608
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
   609
  "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
   610
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
   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 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
   613
  "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
   614
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
   615
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   616
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
   617
  "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
   618
apply(simp)
04700724250f completed coding functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 250
diff changeset
   619
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
   620
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   621
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
   622
  "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
   623
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
   624
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   625
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
   626
  "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
   627
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
   628
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   629
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
   630
  "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
   631
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
   632
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   633
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
   634
  "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
   635
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
   636
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   637
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
   638
  "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
   639
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
   640
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   641
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
   642
  "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
   643
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
   644
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   645
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
   646
  "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
   647
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
   648
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   649
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
   650
  "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
   651
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
   652
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   653
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
   654
  "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
   655
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
   656
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   657
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
   658
  "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
   659
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
   660
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   661
248
aea02b5a58d2 repaired old files
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 246
diff changeset
   662
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
   663
250
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   664
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
   665
  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
   666
  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
   667
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
   668
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
   669
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
   670
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
   671
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
   672
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
   673
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
   674
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
   675
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
   676
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
   677
oops
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   678
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   679
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
   680
  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
   681
  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
   682
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
   683
apply(simp)
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   684
apply(simp)
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   685
oops
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   686
246
e113420a2fce separated recursive functions and UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   687
248
aea02b5a58d2 repaired old files
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 246
diff changeset
   688
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
   689
  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
   690
  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
   691
  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
   692
proof -
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   693
  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
   694
  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
   695
    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
   696
    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
   697
  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
   698
  show ?thesis
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   699
    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
   700
    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
   701
    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
   702
    oops
246
e113420a2fce separated recursive functions and UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   703
e113420a2fce separated recursive functions and UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   704
248
aea02b5a58d2 repaired old files
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 246
diff changeset
   705
end
246
e113420a2fce separated recursive functions and UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   706