thys/UF_Rec.thy
author Christian Urban <christian dot urban at kcl dot ac dot uk>
Fri, 30 May 2014 12:04:49 +0100
changeset 20 e04123f4bacc
parent 19 087d82632852
permissions -rwxr-xr-x
soem more work
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
20
e04123f4bacc soem more work
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 19
diff changeset
     2
imports Recs Hoare_tm3
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
     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
20
e04123f4bacc soem more work
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 19
diff changeset
     8
fun actenc :: "action \<Rightarrow> nat"
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
     9
  where
20
e04123f4bacc soem more work
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 19
diff changeset
    10
  "actenc W0 = 0"
e04123f4bacc soem more work
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 19
diff changeset
    11
| "actenc W1 = 1"
e04123f4bacc soem more work
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 19
diff changeset
    12
| "actenc L  = 2"
e04123f4bacc soem more work
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 19
diff changeset
    13
| "actenc R  = 3"
19
087d82632852 added FMap theory and adapted tm-theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 15
diff changeset
    14
20
e04123f4bacc soem more work
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 19
diff changeset
    15
fun cellenc :: "Block \<Rightarrow> nat" where
e04123f4bacc soem more work
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 19
diff changeset
    16
  "cellenc Bk = 0"
e04123f4bacc soem more work
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 19
diff changeset
    17
| "cellenc Oc = 1"
19
087d82632852 added FMap theory and adapted tm-theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 15
diff changeset
    18
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
    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
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
    21
20
e04123f4bacc soem more work
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 19
diff changeset
    22
definition 
e04123f4bacc soem more work
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 19
diff changeset
    23
  "intenc i \<equiv> (if (0 \<le> i) then penc 0 (nat i) else penc 1 (nat (-i)))" 
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
    24
20
e04123f4bacc soem more work
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 19
diff changeset
    25
definition
e04123f4bacc soem more work
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 19
diff changeset
    26
  "intdec n \<equiv> (if (0 = pdec1 n) then (int (pdec2 n)) else -(int (pdec2 n)))"
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
    27
20
e04123f4bacc soem more work
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 19
diff changeset
    28
definition 
e04123f4bacc soem more work
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 19
diff changeset
    29
  tapeenc :: "(int f\<rightharpoonup> Block) \<Rightarrow> nat"
e04123f4bacc soem more work
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 19
diff changeset
    30
where
e04123f4bacc soem more work
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 19
diff changeset
    31
  "tapeenc tp = lenc (map (\<lambda>(x, y). penc (intenc x) (cellenc y)) (fmap_to_alist tp))"
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
    32
20
e04123f4bacc soem more work
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 19
diff changeset
    33
fun 
e04123f4bacc soem more work
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 19
diff changeset
    34
  instenc :: "tm_inst \<Rightarrow> nat"
e04123f4bacc soem more work
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 19
diff changeset
    35
where
e04123f4bacc soem more work
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 19
diff changeset
    36
  "instenc ((a1, s1), (a2, s2)) = lenc [actenc a1, s1, actenc a2, s2]"
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
    37
20
e04123f4bacc soem more work
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 19
diff changeset
    38
definition 
e04123f4bacc soem more work
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 19
diff changeset
    39
  progenc :: "(nat f\<rightharpoonup> tm_inst) \<Rightarrow> nat"
e04123f4bacc soem more work
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 19
diff changeset
    40
where
e04123f4bacc soem more work
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 19
diff changeset
    41
  "progenc p = lenc (map (\<lambda>(x, y). penc x (instenc y)) (fmap_to_alist p))"
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
    42
20
e04123f4bacc soem more work
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 19
diff changeset
    43
text {* Coding Configurations of TMs *}
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
    44
20
e04123f4bacc soem more work
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 19
diff changeset
    45
fun confenc where
e04123f4bacc soem more work
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 19
diff changeset
    46
  "confenc (faults, prog, s, pos, tp) = lenc [faults, progenc prog, s, intenc pos, tapeenc tp]"
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
    47
20
e04123f4bacc soem more work
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 19
diff changeset
    48
section {* A Universal Function in HOL *}
e04123f4bacc soem more work
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 19
diff changeset
    49
e04123f4bacc soem more work
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 19
diff changeset
    50
fun Step :: "nat \<Rightarrow> nat"
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
    51
  where
20
e04123f4bacc soem more work
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 19
diff changeset
    52
  "Step cf = Conf (Newstate m (State cf) (Read (Right cf)), 
e04123f4bacc soem more work
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 19
diff changeset
    53
                     Newleft (Left cf) (Right cf) (Action m (State cf) (Read (Right cf))),
e04123f4bacc soem more work
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 19
diff changeset
    54
                     Newright (Left cf) (Right cf) (Action m (State cf) (Read (Right cf))))"
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
    55
e3ecf558aef2 recursive function 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
20
e04123f4bacc soem more work
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 19
diff changeset
    57
text {* Reading and Writing the Encoded Tape *}
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
    58
e3ecf558aef2 recursive function 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
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
    60
  "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
    61
e3ecf558aef2 recursive function 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
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
    63
  "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
    64
e3ecf558aef2 recursive function 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
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
    66
  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
    67
  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
    68
  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
    69
*}
e3ecf558aef2 recursive function 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
e3ecf558aef2 recursive function 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
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
    72
  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
    73
  "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
    74
                    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
    75
                    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
    76
                    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
    77
                    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
    78
e3ecf558aef2 recursive function 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
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
    80
  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
    81
  "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
    82
                      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
    83
                      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
    84
                      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
    85
                      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
    86
e3ecf558aef2 recursive function 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
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
    88
  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
    89
  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
    90
  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
    91
  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
    92
*}
e3ecf558aef2 recursive function 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
e3ecf558aef2 recursive function 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
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
    95
  "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
    96
| "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
    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 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
    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
  "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
   101
e3ecf558aef2 recursive function 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
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
   103
  "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
   104
| "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
   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 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
   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
  "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
   109
e3ecf558aef2 recursive function 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
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
   111
  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
   112
  "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
   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
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
   115
  "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
   116
e3ecf558aef2 recursive function 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
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
   118
  "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
   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
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
   121
  "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
   122
e3ecf558aef2 recursive function 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
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
   124
  @{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
   125
  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
   126
*}
e3ecf558aef2 recursive function 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
e3ecf558aef2 recursive function 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
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
   129
  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
  "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
   131
                     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
   132
                     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
   133
e3ecf558aef2 recursive function 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
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
   135
  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
   136
  "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
   137
| "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
   138
e3ecf558aef2 recursive function 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
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
   140
  "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
   141
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
   142
e3ecf558aef2 recursive function 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
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
   145
e3ecf558aef2 recursive function 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
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
   147
  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
  "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
   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
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
   151
  "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
   152
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
   153
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
   154
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
   155
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
   156
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
   157
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
   158
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
   159
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
   160
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
   161
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
   162
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
   163
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
   164
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
   165
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
   166
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
   167
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
   168
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
   169
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
   170
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
   171
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
   172
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
   173
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
   174
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
   175
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
   176
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
   177
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
   178
e3ecf558aef2 recursive function 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
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
   180
  "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
   181
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
   182
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
   183
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
   184
e3ecf558aef2 recursive function 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
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
   186
  "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
   187
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
   188
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
   189
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
   190
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
   191
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
   192
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
   193
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
   194
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
   195
e3ecf558aef2 recursive function 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
e3ecf558aef2 recursive function 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
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
   198
e3ecf558aef2 recursive function 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
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
   200
  "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
   201
e3ecf558aef2 recursive function 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
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
   203
  "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
   204
e3ecf558aef2 recursive function 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
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
   206
 "(\<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
   207
  (\<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
   208
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
   209
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
   210
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
   211
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
   212
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
   213
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
   214
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
   215
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
   216
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
   217
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
   218
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
   219
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
   220
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
   221
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
   222
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
   223
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
   224
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
   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
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
   227
  "(\<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
   228
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
   229
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
   230
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
   231
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
   232
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
   233
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
   234
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
   235
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
   236
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
   237
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
   238
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
   239
e3ecf558aef2 recursive function 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
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
   241
  "(\<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
   242
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
   243
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
   244
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
   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_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
   247
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
   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(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
   250
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
   251
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
   252
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
   253
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
   254
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
   255
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
   256
e3ecf558aef2 recursive function 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
e3ecf558aef2 recursive function 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
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
   259
e3ecf558aef2 recursive function 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
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
   261
  @{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
   262
  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
   263
*}
e3ecf558aef2 recursive function 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
e3ecf558aef2 recursive function 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
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
   266
  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
   267
  "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
   268
e3ecf558aef2 recursive function 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
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
   270
  @{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
   271
  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
   272
  @{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
   273
e3ecf558aef2 recursive function 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
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
   275
  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
   276
    "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
   277
e3ecf558aef2 recursive function 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
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
   279
  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
   280
  "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
   281
e3ecf558aef2 recursive function 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
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
   283
  @{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
   284
  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
   285
  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
   286
  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
   287
  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
   288
*}
e3ecf558aef2 recursive function 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
e3ecf558aef2 recursive function 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
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
   291
  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
   292
  "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
   293
e3ecf558aef2 recursive function 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
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
   295
  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
   296
  "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
   297
e3ecf558aef2 recursive function 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
e3ecf558aef2 recursive function 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
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
   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
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
   302
  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
   303
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
   304
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
   305
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
   306
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
   307
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
   308
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
   309
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
   310
e3ecf558aef2 recursive function 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
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
   312
  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
   313
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
   314
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
   315
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
   316
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
   317
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
   318
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
   319
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
   320
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
   321
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
   322
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
   323
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
   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
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
   326
  "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
   327
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
   328
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
   329
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
   330
e3ecf558aef2 recursive function 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
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
   332
  "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
   333
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
   334
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
   335
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
   336
e3ecf558aef2 recursive function 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
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
   338
  "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
   339
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
   340
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
   341
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
   342
e3ecf558aef2 recursive function 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
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
   344
  "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
   345
  "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
   346
  "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
   347
  "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
   348
  "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
   349
  "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
   350
  "[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
   351
  "[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
   352
  "[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
   353
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
   354
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
   355
e3ecf558aef2 recursive function 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
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
   357
  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
   358
  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
   359
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
   360
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
   361
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
   362
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
   363
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
   364
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
   365
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
   366
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
   367
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
   368
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
   369
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
   370
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
   371
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
   372
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
   373
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
   374
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
   375
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
   376
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
   377
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
   378
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
   379
e3ecf558aef2 recursive function 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
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
   381
  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
   382
  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
   383
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
   384
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
   385
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
   386
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
   387
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
   388
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
   389
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
   390
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
   391
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
   392
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
   393
e3ecf558aef2 recursive function 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
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
   395
  "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
   396
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
   397
e3ecf558aef2 recursive function 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
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
   399
  "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
   400
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
   401
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
   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 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
   405
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
   406
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
   407
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
   408
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
   409
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
   410
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
   411
e3ecf558aef2 recursive function 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
e3ecf558aef2 recursive function 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
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
   414
  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
   415
  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
   416
  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
   417
  (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
   418
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
   419
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
   420
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
   421
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
   422
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
   423
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
   424
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
   425
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
   426
e3ecf558aef2 recursive function 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
e3ecf558aef2 recursive function 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
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
   429
e3ecf558aef2 recursive function 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
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
   431
  "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
   432
e3ecf558aef2 recursive function 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
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
   434
  "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
   435
e3ecf558aef2 recursive function 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
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
   437
    "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
   438
       (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
   439
        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
   440
        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
   441
        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
   442
        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
   443
        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
   444
          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
   445
            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
   446
              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
   447
e3ecf558aef2 recursive function 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
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
   449
    "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
   450
       (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
   451
        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
   452
        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
   453
        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
   454
        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
   455
        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
   456
          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
   457
            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
   458
              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
   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_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
   462
                           (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
   463
e3ecf558aef2 recursive function 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
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
   465
  "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
   466
                 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
   467
                 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
   468
                 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
   469
e3ecf558aef2 recursive function 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
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
   471
  "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
   472
                              (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
   473
e3ecf558aef2 recursive function 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
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
   475
  "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
   476
                   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
   477
                   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
   478
e3ecf558aef2 recursive function 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
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
   480
  "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
   481
e3ecf558aef2 recursive function 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
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
   483
  "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
   484
e3ecf558aef2 recursive function 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
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
   486
  "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
   487
e3ecf558aef2 recursive function 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
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
   489
  "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
   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_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
   493
               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
   494
               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
   495
               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
   496
               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
   497
               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
   498
               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
   499
               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
   500
               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
   501
e3ecf558aef2 recursive function 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
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
   503
  "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
   504
e3ecf558aef2 recursive function 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
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
   506
  "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
   507
                  [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
   508
                   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
   509
e3ecf558aef2 recursive function 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
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
   511
  "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
   512
                    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
   513
                    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
   514
                    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
   515
                    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
   516
                                     (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
   517
                                [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
   518
                    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
   519
e3ecf558aef2 recursive function 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
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
   521
  "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
   522
                   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
   523
e3ecf558aef2 recursive function 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
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
   525
  "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
   526
                          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
   527
e3ecf558aef2 recursive function 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
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
   529
  "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
   530
e3ecf558aef2 recursive function 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
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
   532
  "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
   533
               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
   534
e3ecf558aef2 recursive function 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
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
   536
  "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
   537
e3ecf558aef2 recursive function 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
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
   539
  "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
   540
              [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
   541
                  [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
   542
                     [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
   543
e3ecf558aef2 recursive function 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
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
   545
  "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
   546
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
   547
e3ecf558aef2 recursive function 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
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
   549
  "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
   550
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
   551
e3ecf558aef2 recursive function 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
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
   553
  "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
   554
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
   555
e3ecf558aef2 recursive function 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
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
   557
  "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
   558
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
   559
e3ecf558aef2 recursive function 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
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
   561
  "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
   562
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
   563
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
   564
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
   565
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
   566
e3ecf558aef2 recursive function 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
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
   568
  "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
   569
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
   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 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
   572
  "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
   573
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
   574
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
   575
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
   576
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
   577
e3ecf558aef2 recursive function 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
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
   579
  "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
   580
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
   581
e3ecf558aef2 recursive function 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
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
   583
  "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
   584
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
   585
e3ecf558aef2 recursive function 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
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
   587
  "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
   588
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
   589
e3ecf558aef2 recursive function 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
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
   591
  "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
   592
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
   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 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
   595
  "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
   596
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
   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 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
   599
  "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
   600
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
   601
e3ecf558aef2 recursive function 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
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
   603
  "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
   604
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
   605
e3ecf558aef2 recursive function 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
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
   607
  "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
   608
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
   609
e3ecf558aef2 recursive function 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
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
   611
  "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
   612
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
   613
e3ecf558aef2 recursive function 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
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
   615
  "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
   616
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
   617
e3ecf558aef2 recursive function 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
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
   619
  "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
   620
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
   621
e3ecf558aef2 recursive function 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
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
   623
  "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
   624
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
   625
e3ecf558aef2 recursive function 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
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
   627
  "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
   628
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
   629
e3ecf558aef2 recursive function 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
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
   631
  "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
   632
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
   633
e3ecf558aef2 recursive function 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
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
   635
  "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
   636
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
   637
e3ecf558aef2 recursive function 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
(* 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
   639
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
   640