thys/UF_Rec.thy
author Christian Urban <christian dot urban at kcl dot ac dot uk>
Thu, 03 Apr 2014 12:55:43 +0100
changeset 15 e3ecf558aef2
child 19 087d82632852
permissions -rwxr-xr-x
recursive function theories / UF_rec still need coding of tapes and programs
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
15
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
     1
theory UF_Rec
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
     2
imports Recs Hoare_tm
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
     3
begin
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
     4
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
     5
section {* Coding of Turing Machines and Tapes*}
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
     6
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
     7
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
     8
fun actnum :: "taction \<Rightarrow> nat"
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
     9
  where
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    10
  "actnum W0 = 0"
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    11
| "actnum W1 = 1"
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    12
| "actnum L  = 2"
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    13
| "actnum R  = 3"
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    14
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    15
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    16
fun cellnum :: "Block \<Rightarrow> nat" where
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    17
  "cellnum Bk = 0"
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    18
| "cellnum Oc = 1"
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    19
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    20
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    21
(* NEED TO CODE TAPES *)
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    22
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    23
text {* Coding tapes *}
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    24
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    25
fun code_tp :: "cell list \<Rightarrow> nat list"
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    26
  where
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    27
  "code_tp [] = []"
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    28
| "code_tp (c # tp) = (cellnum c) # code_tp tp"
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    29
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    30
fun Code_tp where
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    31
  "Code_tp tp = lenc (code_tp tp)"
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    32
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    33
lemma code_tp_append [simp]:
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    34
  "code_tp (tp1 @ tp2) = code_tp tp1 @ code_tp tp2"
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    35
by(induct tp1) (simp_all)
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    36
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    37
lemma code_tp_length [simp]:
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    38
  "length (code_tp tp) = length tp"
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    39
by (induct tp) (simp_all)
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    40
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    41
lemma code_tp_nth [simp]:
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    42
  "n < length tp \<Longrightarrow> (code_tp tp) ! n = cellnum (tp ! n)"
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    43
apply(induct n arbitrary: tp) 
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    44
apply(simp_all)
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    45
apply(case_tac [!] tp)
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    46
apply(simp_all)
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    47
done
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    48
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    49
lemma code_tp_replicate [simp]:
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    50
  "code_tp (c \<up> n) = (cellnum c) \<up> n"
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    51
by(induct n) (simp_all)
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    52
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    53
text {* Coding Configurations and TMs *}
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    54
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    55
fun Code_conf where
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    56
  "Code_conf (s, l, r) = (s, Code_tp l, Code_tp r)"
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    57
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    58
fun code_instr :: "instr \<Rightarrow> nat" where
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    59
  "code_instr i = penc (actnum (fst i)) (snd i)"
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    60
  
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    61
fun Code_instr :: "instr \<times> instr \<Rightarrow> nat" where
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    62
  "Code_instr i = penc (code_instr (fst i)) (code_instr (snd i))"
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    63
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    64
fun code_tprog :: "tprog \<Rightarrow> nat list"
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    65
  where
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    66
  "code_tprog [] =  []"
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    67
| "code_tprog (i # tm) = Code_instr i # code_tprog tm"
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    68
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    69
lemma code_tprog_length [simp]:
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    70
  "length (code_tprog tp) = length tp"
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    71
by (induct tp) (simp_all)
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    72
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    73
lemma code_tprog_nth [simp]:
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    74
  "n < length tp \<Longrightarrow> (code_tprog tp) ! n = Code_instr (tp ! n)"
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    75
by (induct tp arbitrary: n) (simp_all add: nth_Cons')
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    76
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    77
fun Code_tprog :: "tprog \<Rightarrow> nat"
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    78
  where 
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    79
  "Code_tprog tm = lenc (code_tprog tm)"
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    80
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    81
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    82
section {* An Universal Function in HOL *}
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    83
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    84
text {* Reading and writing the encoded tape *}
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    85
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    86
fun Read where
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    87
  "Read tp = ldec tp 0"
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    88
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    89
fun Write where
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    90
  "Write n tp = penc (Suc n) (pdec2 tp)"
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    91
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    92
text {* 
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    93
  The @{text Newleft} and @{text Newright} functions on page 91 of B book. 
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    94
  They calculate the new left and right tape (@{text p} and @{text r}) 
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    95
  according to an action @{text a}. Adapted to our encoding functions.
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    96
*}
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    97
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    98
fun Newleft :: "nat \<Rightarrow> nat \<Rightarrow> nat \<Rightarrow> nat"
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    99
  where
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   100
  "Newleft l r a = (if a = 0 then l else 
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   101
                    if a = 1 then l else 
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   102
                    if a = 2 then pdec2 l else 
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   103
                    if a = 3 then penc (Suc (Read r)) l
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   104
                    else l)"
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   105
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   106
fun Newright :: "nat \<Rightarrow> nat \<Rightarrow> nat \<Rightarrow> nat"
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   107
  where
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   108
  "Newright l r a  = (if a = 0 then Write 0 r
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   109
                      else if a = 1 then Write 1 r
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   110
                      else if a = 2 then penc (Suc (Read l)) r
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   111
                      else if a = 3 then pdec2 r
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   112
                      else r)"
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   113
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   114
text {*
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   115
  The @{text "Action"} function given on page 92 of B book, which is used to 
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   116
  fetch Turing Machine intructions. In @{text "Action m q r"}, @{text "m"} is 
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   117
  the code of the Turing Machine, @{text "q"} is the current state of 
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   118
  Turing Machine, and @{text "r"} is the scanned cell of is the right tape. 
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   119
*}
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   120
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   121
fun Actn :: "nat \<Rightarrow> nat \<Rightarrow> nat" where
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   122
  "Actn n 0 = pdec1 (pdec1 n)"
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   123
| "Actn n _ = pdec1 (pdec2 n)"
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   124
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   125
fun Action :: "nat \<Rightarrow> nat \<Rightarrow> nat \<Rightarrow> nat"
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   126
  where
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   127
  "Action m q c = (if q \<noteq> 0 \<and> within m (q - 1) then Actn (ldec m (q - 1)) c else 4)"
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   128
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   129
fun Newstat :: "nat \<Rightarrow> nat \<Rightarrow> nat" where
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   130
  "Newstat n 0 = pdec2 (pdec1 n)"
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   131
| "Newstat n _ = pdec2 (pdec2 n)"
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   132
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   133
fun Newstate :: "nat \<Rightarrow> nat \<Rightarrow> nat \<Rightarrow> nat"
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   134
  where
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   135
  "Newstate m q r = (if q \<noteq> 0 then Newstat (ldec m (q - 1)) r else 0)"
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   136
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   137
fun Conf :: "nat \<times> (nat \<times> nat) \<Rightarrow> nat"
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   138
  where
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   139
  "Conf (q, l, r) = lenc [q, l, r]"
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   140
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   141
fun State where
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   142
  "State cf = ldec cf 0"
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   143
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   144
fun Left where
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   145
  "Left cf = ldec cf 1"
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   146
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   147
fun Right where
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   148
  "Right cf = ldec cf 2"
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   149
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   150
text {*
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   151
  @{text "Steps cf m k"} computes the TM configuration after @{text "k"} steps of 
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   152
  execution of TM coded as @{text "m"}. @{text Step} is a single step of the TM.
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   153
*}
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   154
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   155
fun Step :: "nat \<Rightarrow> nat \<Rightarrow> nat"
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   156
  where
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   157
  "Step cf m = Conf (Newstate m (State cf) (Read (Right cf)), 
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   158
                     Newleft (Left cf) (Right cf) (Action m (State cf) (Read (Right cf))),
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   159
                     Newright (Left cf) (Right cf) (Action m (State cf) (Read (Right cf))))"
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   160
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   161
fun Steps :: "nat \<Rightarrow> nat \<Rightarrow> nat \<Rightarrow> nat"
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   162
  where
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   163
  "Steps cf p 0  = cf"
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   164
| "Steps cf p (Suc n) = Steps (Step cf p) p n"
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   165
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   166
lemma Step_Steps_comm:
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   167
  "Step (Steps cf p n) p = Steps (Step cf p) p n"
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   168
by (induct n arbitrary: cf) (simp_all only: Steps.simps)
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   169
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   170
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   171
text {* Decoding tapes back into numbers. *}
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   172
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   173
definition Stknum :: "nat \<Rightarrow> nat"
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   174
  where
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   175
  "Stknum z \<equiv> (\<Sum>i < enclen z. ldec z i)"
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   176
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   177
lemma Stknum_append:
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   178
  "Stknum (Code_tp (tp1 @ tp2)) = Stknum (Code_tp tp1) + Stknum (Code_tp tp2)"
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   179
apply(simp only: Code_tp.simps)
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   180
apply(simp only: code_tp_append)
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   181
apply(simp only: Stknum_def)
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   182
apply(simp only: enclen_length length_append code_tp_length)
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   183
apply(simp only: list_encode_inverse)
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   184
apply(simp only: enclen_length length_append code_tp_length)
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   185
apply(simp)
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   186
apply(subgoal_tac "{..<length tp1 + length tp2} = {..<length tp1} \<union> {length tp1 ..<length tp1 + length tp2}")
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   187
prefer 2
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   188
apply(auto)[1]
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   189
apply(simp only:)
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   190
apply(subst setsum_Un_disjoint)
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   191
apply(auto)[2]
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   192
apply (metis ivl_disj_int_one(2))
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   193
apply(simp add: nth_append)
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   194
apply(subgoal_tac "{length tp1..<length tp1 + length tp2} = (\<lambda>x. x + length tp1) ` {0..<length tp2}")
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   195
prefer 2
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   196
apply(simp only: image_add_atLeastLessThan)
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   197
apply (metis comm_monoid_add_class.add.left_neutral nat_add_commute)
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   198
apply(simp only:)
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   199
apply(subst setsum_reindex)
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   200
prefer 2
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   201
apply(simp add: comp_def)
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   202
apply (metis atLeast0LessThan)
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   203
apply(simp add: inj_on_def)
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   204
done
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   205
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   206
lemma Stknum_up:
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   207
  "Stknum (lenc (a \<up> n)) = n * a"
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   208
apply(induct n)
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   209
apply(simp_all add: Stknum_def list_encode_inverse del: replicate.simps)
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   210
done
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   211
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   212
lemma result:
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   213
  "Stknum (Code_tp (<n> @ Bk \<up> l)) - 1 = n"
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   214
apply(simp only: Stknum_append)
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   215
apply(simp only: tape_of_nat.simps)
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   216
apply(simp only: Code_tp.simps)
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   217
apply(simp only: code_tp_replicate)
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   218
apply(simp only: cellnum.simps)
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   219
apply(simp only: Stknum_up)
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   220
apply(simp)
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   221
done
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   222
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   223
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   224
section  {* Standard Tapes *}
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   225
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   226
definition
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   227
  "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))"
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   228
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   229
definition
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   230
  "left_std z \<equiv> (\<forall>j < enclen z. ldec z j = 0)"
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   231
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   232
lemma ww:
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   233
 "(\<exists>k l. 1 \<le> k \<and> tp = Oc \<up> k @ Bk \<up> l) \<longleftrightarrow> 
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   234
  (\<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))"
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   235
apply(rule iffI)
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   236
apply(erule exE)+
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   237
apply(simp)
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   238
apply(rule_tac x="k" in exI)
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   239
apply(auto)[1]
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   240
apply(simp add: nth_append)
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   241
apply(simp add: nth_append)
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   242
apply(erule exE)
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   243
apply(rule_tac x="i" in exI)
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   244
apply(rule_tac x="length tp - i" in exI)
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   245
apply(auto)
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   246
apply(rule sym)
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   247
apply(subst append_eq_conv_conj)
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   248
apply(simp)
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   249
apply(rule conjI)
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   250
apply (smt length_replicate length_take nth_equalityI nth_replicate nth_take)
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   251
by (smt length_drop length_replicate nth_drop nth_equalityI nth_replicate)
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   252
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   253
lemma right_std:
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   254
  "(\<exists>k l. 1 \<le> k \<and> tp = Oc \<up> k @ Bk \<up> l) \<longleftrightarrow> right_std (Code_tp tp)"
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   255
apply(simp only: ww)
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   256
apply(simp add: right_std_def)
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   257
apply(simp only: list_encode_inverse)
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   258
apply(simp)
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   259
apply(auto)
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   260
apply(rule_tac x="i" in exI)
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   261
apply(simp)
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   262
apply(rule conjI)
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   263
apply (metis Suc_eq_plus1 Suc_neq_Zero cellnum.cases cellnum.simps(1) leD less_trans linorder_neqE_nat)
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   264
apply(auto)
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   265
by (metis One_nat_def cellnum.cases cellnum.simps(2) less_diff_conv n_not_Suc_n nat_add_commute)
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   266
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   267
lemma left_std:
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   268
  "(\<exists>k. tp = Bk \<up> k) \<longleftrightarrow> left_std (Code_tp tp)"
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   269
apply(simp add: left_std_def)
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   270
apply(simp only: list_encode_inverse)
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   271
apply(simp)
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   272
apply(auto)
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   273
apply(rule_tac x="length tp" in exI)
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   274
apply(induct tp)
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   275
apply(simp)
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   276
apply(simp)
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   277
apply(auto)
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   278
apply(case_tac a)
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   279
apply(auto)
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   280
apply(case_tac a)
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   281
apply(auto)
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   282
by (metis Suc_less_eq nth_Cons_Suc)
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   283
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   284
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   285
section {* Standard- and Final Configurations, the Universal Function *}
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   286
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   287
text {*
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   288
  @{text "Std cf"} returns true, if the  configuration  @{text "cf"} 
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   289
  is a stardard tape. 
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   290
*}
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   291
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   292
fun Std :: "nat \<Rightarrow> bool"
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   293
  where
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   294
  "Std cf = (left_std (Left cf) \<and> right_std (Right cf))"
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   295
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   296
text{* 
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   297
  @{text "Stop m cf k"} means that afer @{text k} steps of 
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   298
  execution the TM coded by @{text m} and started in configuration
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   299
  @{text cf} is in a stardard final configuration. *}
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   300
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   301
fun Final :: "nat \<Rightarrow> bool"
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   302
  where
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   303
    "Final cf = (State cf = 0)"
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   304
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   305
fun Stop :: "nat \<Rightarrow> nat \<Rightarrow> nat \<Rightarrow> bool"
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   306
  where
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   307
  "Stop m cf k = (Final (Steps cf m k) \<and> Std (Steps cf m k))"
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   308
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   309
text{*
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   310
  @{text "Halt"} is the function calculating the steps a TM needs to 
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   311
  execute before reaching a stardard final configuration. This recursive 
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   312
  function is the only one that uses unbounded minimization. So it is the 
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   313
  only non-primitive recursive function needs to be used in the construction 
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   314
  of the universal function @{text "UF"}. 
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   315
*}
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   316
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   317
fun Halt :: "nat \<Rightarrow> nat \<Rightarrow> nat"
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   318
  where
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   319
  "Halt m cf = (LEAST k. Stop m cf k)"
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   320
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   321
fun UF :: "nat \<Rightarrow> nat \<Rightarrow> nat"
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   322
  where
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   323
  "UF m cf = Stknum (Right (Steps cf m (Halt m cf))) - 1"
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   324
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   325
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   326
section {* The UF simulates Turing machines *}
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   327
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   328
lemma Update_left_simulate:
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   329
  shows "Newleft (Code_tp l) (Code_tp r) (actnum a) = Code_tp (fst (update a (l, r)))"
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   330
apply(induct a)
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   331
apply(simp_all)
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   332
apply(case_tac l)
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   333
apply(simp_all)
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   334
apply(case_tac r)
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   335
apply(simp_all)
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   336
done
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   337
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   338
lemma Update_right_simulate:
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   339
  shows "Newright (Code_tp l) (Code_tp r) (actnum a) = Code_tp (snd (update a (l, r)))"
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   340
apply(induct a)
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   341
apply(simp_all)
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   342
apply(case_tac r)
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   343
apply(simp_all)
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   344
apply(case_tac r)
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   345
apply(simp_all)
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   346
apply(case_tac l)
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   347
apply(simp_all)
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   348
apply(case_tac r)
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   349
apply(simp_all)
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   350
done
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   351
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   352
lemma Fetch_state_simulate:
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   353
  "tm_wf tp \<Longrightarrow> Newstate (Code_tprog tp) st (cellnum c) = snd (fetch tp st c)"
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   354
apply(induct tp st c rule: fetch.induct)
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   355
apply(simp_all add: list_encode_inverse split: cell.split)
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   356
done
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   357
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   358
lemma Fetch_action_simulate:
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   359
  "tm_wf tp \<Longrightarrow> Action (Code_tprog tp) st (cellnum c) = actnum (fst (fetch tp st c))"
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   360
apply(induct tp st c rule: fetch.induct)
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   361
apply(simp_all add: list_encode_inverse split: cell.split)
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   362
done
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   363
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   364
lemma Read_simulate:
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   365
  "Read (Code_tp tp) = cellnum (read tp)"
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   366
apply(case_tac tp)
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   367
apply(simp_all)
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   368
done
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   369
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   370
lemma misc:
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   371
  "2 < (3::nat)"
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   372
  "1 < (3::nat)"
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   373
  "0 < (3::nat)" 
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   374
  "length [x] = 1"
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   375
  "length [x, y] = 2"
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   376
  "length [x, y , z] = 3"
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   377
  "[x, y, z] ! 0 = x"
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   378
  "[x, y, z] ! 1 = y"
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   379
  "[x, y, z] ! 2 = z"
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   380
apply(simp_all)
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   381
done
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   382
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   383
lemma Step_simulate:
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   384
  assumes "tm_wf tp"
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   385
  shows "Step (Conf (Code_conf (st, l, r))) (Code_tprog tp) = Conf (Code_conf (step (st, l, r) tp))"
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   386
apply(subst step.simps) 
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   387
apply(simp only: Let_def)
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   388
apply(subst Step.simps)
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   389
apply(simp only: Conf.simps Code_conf.simps Right.simps Left.simps)
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   390
apply(simp only: list_encode_inverse)
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   391
apply(simp only: misc if_True Code_tp.simps)
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   392
apply(simp only: prod_case_beta) 
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   393
apply(subst Fetch_state_simulate[OF assms, symmetric])
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   394
apply(simp only: State.simps)
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   395
apply(simp only: list_encode_inverse)
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   396
apply(simp only: misc if_True)
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   397
apply(simp only: Read_simulate[simplified Code_tp.simps])
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   398
apply(simp only: Fetch_action_simulate[OF assms])
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   399
apply(simp only: Update_left_simulate[simplified Code_tp.simps])
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   400
apply(simp only: Update_right_simulate[simplified Code_tp.simps])
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   401
apply(case_tac "update (fst (fetch tp st (read r))) (l, r)")
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   402
apply(simp only: Code_conf.simps)
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   403
apply(simp only: Conf.simps)
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   404
apply(simp)
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   405
done
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   406
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   407
lemma Steps_simulate:
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   408
  assumes "tm_wf tp" 
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   409
  shows "Steps (Conf (Code_conf cf)) (Code_tprog tp) n = Conf (Code_conf (steps cf tp n))"
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   410
apply(induct n arbitrary: cf) 
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   411
apply(simp)
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   412
apply(simp only: Steps.simps steps.simps)
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   413
apply(case_tac cf)
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   414
apply(simp only: )
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   415
apply(subst Step_simulate)
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   416
apply(rule assms)
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   417
apply(drule_tac x="step (a, b, c) tp" in meta_spec)
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   418
apply(simp)
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   419
done
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   420
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   421
lemma Final_simulate:
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   422
  "Final (Conf (Code_conf cf)) = is_final cf"
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   423
by (case_tac cf) (simp)
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   424
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   425
lemma Std_simulate:
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   426
  "Std (Conf (Code_conf cf)) = std_tape cf" 
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   427
apply(case_tac cf)
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   428
apply(simp only: std_tape_def)
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   429
apply(simp only: Code_conf.simps)
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   430
apply(simp only: Conf.simps)
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   431
apply(simp only: Std.simps)
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   432
apply(simp only: Left.simps Right.simps)
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   433
apply(simp only: list_encode_inverse)
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   434
apply(simp only: misc if_True)
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   435
apply(simp only: left_std[symmetric] right_std[symmetric])
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   436
apply(simp)
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   437
by (metis Suc_le_D Suc_neq_Zero append_Cons nat.exhaust not_less_eq_eq replicate_Suc)
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   438
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   439
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   440
lemma UF_simulate:
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   441
  assumes "tm_wf tm"
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   442
  shows "UF (Code_tprog tm) (Conf (Code_conf cf)) = 
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   443
  Stknum (Right (Conf 
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   444
  (Code_conf (steps cf tm (LEAST n. is_final (steps cf tm n) \<and> std_tape (steps cf tm n)))))) - 1" 
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   445
apply(simp only: UF.simps)
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   446
apply(subst Steps_simulate[symmetric, OF assms])
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   447
apply(subst Final_simulate[symmetric])
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   448
apply(subst Std_simulate[symmetric])
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   449
apply(simp only: Halt.simps)
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   450
apply(simp only: Steps_simulate[symmetric, OF assms])
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   451
apply(simp only: Stop.simps[symmetric])
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   452
done
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   453
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   454
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   455
section {* Universal Function as Recursive Functions *}
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   456
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   457
definition 
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   458
  "rec_read = CN rec_ldec [Id 1 0, constn 0]"
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   459
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   460
definition 
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   461
  "rec_write = CN rec_penc [CN S [Id 2 0], CN rec_pdec2 [Id 2 1]]"
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   462
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   463
definition
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   464
    "rec_newleft =
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   465
       (let cond0 = CN rec_eq [Id 3 2, constn 0] in 
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   466
        let cond1 = CN rec_eq [Id 3 2, constn 1] in
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   467
        let cond2 = CN rec_eq [Id 3 2, constn 2] in
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   468
        let cond3 = CN rec_eq [Id 3 2, constn 3] in
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   469
        let case3 = CN rec_penc [CN S [CN rec_read [Id 3 1]], Id 3 0] in
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   470
        CN rec_if [cond0, Id 3 0,
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   471
          CN rec_if [cond1, Id 3 0,  
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   472
            CN rec_if [cond2, CN rec_pdec2 [Id 3 0],
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   473
              CN rec_if [cond3, case3, Id 3 0]]]])"
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   474
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   475
definition
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   476
    "rec_newright =
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   477
       (let cond0 = CN rec_eq [Id 3 2, constn 0] in
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   478
        let cond1 = CN rec_eq [Id 3 2, constn 1] in
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   479
        let cond2 = CN rec_eq [Id 3 2, constn 2] in
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   480
        let cond3 = CN rec_eq [Id 3 2, constn 3] in
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   481
        let case2 = CN rec_penc [CN S [CN rec_read [Id 3 0]], Id 3 1] in
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   482
        CN rec_if [cond0, CN rec_write [constn 0, Id 3 1], 
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   483
          CN rec_if [cond1, CN rec_write [constn 1, Id 3 1],
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   484
            CN rec_if [cond2, case2,
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   485
              CN rec_if [cond3, CN rec_pdec2 [Id 3 1], Id 3 1]]]])"
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   486
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   487
definition
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   488
  "rec_actn = rec_swap (PR (CN rec_pdec1 [CN rec_pdec1 [Id 1 0]])
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   489
                           (CN rec_pdec1 [CN rec_pdec2 [Id 3 2]]))"
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   490
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   491
definition 
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   492
  "rec_action = (let cond1 = CN rec_noteq [Id 3 1, Z] in 
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   493
                 let cond2 = CN rec_within [Id 3 0, CN rec_pred [Id 3 1]] in
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   494
                 let if_branch = CN rec_actn [CN rec_ldec [Id 3 0, CN rec_pred [Id 3 1]], Id 3 2]
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   495
                 in CN rec_if [CN rec_conj [cond1, cond2], if_branch, constn 4])"
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   496
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   497
definition
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   498
  "rec_newstat = rec_swap (PR (CN rec_pdec2 [CN rec_pdec1 [Id 1 0]])
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   499
                              (CN rec_pdec2 [CN rec_pdec2 [Id 3 2]]))"
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   500
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   501
definition
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   502
  "rec_newstate = (let cond = CN rec_noteq [Id 3 1, Z] in
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   503
                   let if_branch = CN rec_newstat [CN rec_ldec [Id 3 0, CN rec_pred [Id 3 1]], Id 3 2]
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   504
                   in CN rec_if [cond, if_branch, Z])"
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   505
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   506
definition
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   507
  "rec_conf = rec_lenc [Id 3 0, Id 3 1, Id 3 2]"
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   508
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   509
definition 
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   510
  "rec_state = CN rec_ldec [Id 1 0, Z]"
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   511
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   512
definition
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   513
  "rec_left = CN rec_ldec [Id 1 0, constn 1]"
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   514
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   515
definition 
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   516
  "rec_right = CN rec_ldec [Id 1 0, constn 2]"
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   517
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   518
definition 
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   519
  "rec_step = (let left = CN rec_left [Id 2 0] in
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   520
               let right = CN rec_right [Id 2 0] in
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   521
               let state = CN rec_state [Id 2 0] in
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   522
               let read = CN rec_read [right] in
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   523
               let action = CN rec_action [Id 2 1, state, read] in
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   524
               let newstate = CN rec_newstate [Id 2 1, state, read] in
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   525
               let newleft = CN rec_newleft [left, right, action] in
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   526
               let newright = CN rec_newright [left, right, action] 
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   527
               in CN rec_conf [newstate, newleft, newright])" 
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   528
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   529
definition 
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   530
  "rec_steps = PR (Id 2 0) (CN rec_step [Id 4 1, Id 4 3])"
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   531
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   532
definition
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   533
  "rec_stknum = CN rec_minus 
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   534
                  [CN (rec_sigma1 (CN rec_ldec [Id 2 1, Id 2 0])) [CN rec_enclen [Id 1 0], Id 1 0],
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   535
                   CN rec_ldec [Id 1 0, CN rec_enclen [Id 1 0]]]"
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   536
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   537
definition
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   538
  "rec_right_std = (let bound = CN rec_enclen [Id 1 0] in
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   539
                    let cond1 = CN rec_le [CN (constn 1) [Id 2 0], Id 2 0] in
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   540
                    let cond2 = rec_all1_less (CN rec_eq [CN rec_ldec [Id 2 1, Id 2 0], constn 1]) in
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   541
                    let bound2 = CN rec_minus [CN rec_enclen [Id 2 1], Id 2 0] in
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   542
                    let cond3 = CN (rec_all2_less 
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   543
                                     (CN rec_eq [CN rec_ldec [Id 3 2, CN rec_add [Id 3 1, Id 3 0]], Z])) 
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   544
                                [bound2, Id 2 0, Id 2 1] in
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   545
                    CN (rec_ex1 (CN rec_conj [CN rec_conj [cond1, cond2], cond3])) [bound, Id 1 0])"
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   546
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   547
definition
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   548
  "rec_left_std = (let cond = CN rec_eq [CN rec_ldec [Id 2 1, Id 2 0], Z]
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   549
                   in CN (rec_all1_less cond) [CN rec_enclen [Id 1 0], Id 1 0])"
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   550
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   551
definition
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   552
  "rec_std = CN rec_conj [CN rec_left_std [CN rec_left [Id 1 0]],
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   553
                          CN rec_right_std [CN rec_right [Id 1 0]]]"
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   554
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   555
definition 
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   556
  "rec_final = CN rec_eq [CN rec_state [Id 1 0], Z]"
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   557
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   558
definition 
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   559
  "rec_stop = (let steps = CN rec_steps [Id 3 2, Id 3 1, Id 3 0] in
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   560
               CN rec_conj [CN rec_final [steps], CN rec_std [steps]])"
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   561
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   562
definition
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   563
  "rec_halt = MN (CN rec_not [CN rec_stop [Id 3 1, Id 3 2, Id 3 0]])"
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   564
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   565
definition 
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   566
  "rec_uf = CN rec_pred 
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   567
              [CN rec_stknum 
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   568
                  [CN rec_right 
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   569
                     [CN rec_steps [CN rec_halt [Id 2 0, Id 2 1], Id 2 1, Id 2 0]]]]"
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   570
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   571
lemma read_lemma [simp]:
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   572
  "rec_eval rec_read [x] = Read x"
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   573
by (simp add: rec_read_def)
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   574
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   575
lemma write_lemma [simp]:
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   576
  "rec_eval rec_write [x, y] = Write x y"
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   577
by (simp add: rec_write_def)
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   578
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   579
lemma newleft_lemma [simp]:
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   580
  "rec_eval rec_newleft [p, r, a] = Newleft p r a"
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   581
by (simp add: rec_newleft_def Let_def)
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   582
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   583
lemma newright_lemma [simp]:
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   584
  "rec_eval rec_newright [p, r, a] = Newright p r a"
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   585
by (simp add: rec_newright_def Let_def)
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   586
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   587
lemma act_lemma [simp]:
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   588
  "rec_eval rec_actn [n, c] = Actn n c"
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   589
apply(simp add: rec_actn_def)
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   590
apply(case_tac c)
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   591
apply(simp_all)
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   592
done
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   593
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   594
lemma action_lemma [simp]:
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   595
  "rec_eval rec_action [m, q, c] = Action m q c"
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   596
by (simp add: rec_action_def)
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   597
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   598
lemma newstat_lemma [simp]:
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   599
  "rec_eval rec_newstat [n, c] = Newstat n c"
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   600
apply(simp add: rec_newstat_def)
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   601
apply(case_tac c)
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   602
apply(simp_all)
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   603
done
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   604
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   605
lemma newstate_lemma [simp]:
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   606
  "rec_eval rec_newstate [m, q, r] = Newstate m q r"
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   607
by (simp add: rec_newstate_def)
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   608
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   609
lemma conf_lemma [simp]:
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   610
  "rec_eval rec_conf [q, l, r] = Conf (q, l, r)"
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   611
by(simp add: rec_conf_def)
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   612
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   613
lemma state_lemma [simp]:
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   614
  "rec_eval rec_state [cf] = State cf"
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   615
by (simp add: rec_state_def)
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   616
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   617
lemma left_lemma [simp]:
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   618
  "rec_eval rec_left [cf] = Left cf"
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   619
by (simp add: rec_left_def)
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   620
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   621
lemma right_lemma [simp]:
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   622
  "rec_eval rec_right [cf] = Right cf"
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   623
by (simp add: rec_right_def)
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   624
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   625
lemma step_lemma [simp]:
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   626
  "rec_eval rec_step [cf, m] = Step cf m"
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   627
by (simp add: Let_def rec_step_def)
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   628
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   629
lemma steps_lemma [simp]:
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   630
  "rec_eval rec_steps [n, cf, p] = Steps cf p n"
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   631
by (induct n) (simp_all add: rec_steps_def Step_Steps_comm del: Step.simps)
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   632
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   633
lemma stknum_lemma [simp]:
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   634
  "rec_eval rec_stknum [z] = Stknum z"
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   635
by (simp add: rec_stknum_def Stknum_def lessThan_Suc_atMost[symmetric])
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   636
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   637
lemma left_std_lemma [simp]:
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   638
  "rec_eval rec_left_std [z] = (if left_std z then 1 else 0)"
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   639
by (simp add: Let_def rec_left_std_def left_std_def)
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   640
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   641
lemma right_std_lemma [simp]:
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   642
  "rec_eval rec_right_std [z] = (if right_std z then 1 else 0)"
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   643
by (simp add: Let_def rec_right_std_def right_std_def)
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   644
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   645
lemma std_lemma [simp]:
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   646
  "rec_eval rec_std [cf] = (if Std cf then 1 else 0)"
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   647
by (simp add: rec_std_def)
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   648
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   649
lemma final_lemma [simp]:
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   650
  "rec_eval rec_final [cf] = (if Final cf then 1 else 0)"
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   651
by (simp add: rec_final_def)
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   652
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   653
lemma stop_lemma [simp]:
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   654
  "rec_eval rec_stop [m, cf, k] = (if Stop m cf k then 1 else 0)"
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   655
by (simp add: Let_def rec_stop_def)
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   656
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   657
lemma halt_lemma [simp]:
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   658
  "rec_eval rec_halt [m, cf] = Halt m cf"
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   659
by (simp add: rec_halt_def del: Stop.simps)
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   660
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   661
lemma uf_lemma [simp]:
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   662
  "rec_eval rec_uf [m, cf] = UF m cf"
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   663
by (simp add: rec_uf_def)
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   664
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   665
(* value "size rec_uf" *)
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   666
end
e3ecf558aef2 recursive function theories / UF_rec still need coding of tapes and programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   667