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