thys2/UF_Rec.thy
author Christian Urban <christian dot urban at kcl dot ac dot uk>
Wed, 22 May 2013 13:50:20 +0100
changeset 259 4524c5edcafb
parent 258 thys/UF_Rec.thy@32c5e8d1f6ff
child 260 1e45b5b6482a
permissions -rwxr-xr-x
moved new theries into a separate directory
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
32c5e8d1f6ff added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
    33
fun Code_conf where
32c5e8d1f6ff added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
    34
  "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
    35
32c5e8d1f6ff added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
    36
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
    37
  "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
    38
  
32c5e8d1f6ff added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
    39
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
    40
  "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
    41
32c5e8d1f6ff added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
    42
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
    43
  where
32c5e8d1f6ff added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
    44
  "code_tprog [] =  []"
32c5e8d1f6ff added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
    45
| "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
    46
32c5e8d1f6ff added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
    47
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
    48
  "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
    49
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
    50
32c5e8d1f6ff added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
    51
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
    52
  "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
    53
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
    54
32c5e8d1f6ff added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
    55
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
    56
  where 
32c5e8d1f6ff added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
    57
  "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
    58
250
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
    59
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
    60
258
32c5e8d1f6ff added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
    61
259
4524c5edcafb moved new theries into a separate directory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 258
diff changeset
    62
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
    63
259
4524c5edcafb moved new theries into a separate directory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 258
diff changeset
    64
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
    65
  "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
    66
258
32c5e8d1f6ff added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
    67
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
    68
  "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
    69
258
32c5e8d1f6ff added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
    70
text {* 
32c5e8d1f6ff added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
    71
  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
    72
  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
    73
  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
    74
*}
246
e113420a2fce separated recursive functions and UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    75
e113420a2fce separated recursive functions and UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    76
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
    77
  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
    78
  "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
    79
                    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
    80
                    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
    81
                    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
    82
                    else l)"
246
e113420a2fce separated recursive functions and UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    83
e113420a2fce separated recursive functions and UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    84
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
    85
  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
    86
  "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
    87
                      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
    88
                      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
    89
                      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
    90
                      else r)"
e113420a2fce separated recursive functions and UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    91
e113420a2fce separated recursive functions and UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    92
text {*
e113420a2fce separated recursive functions and UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    93
  The @{text "Actn"} function given on page 92 of B book, which is used to 
e113420a2fce separated recursive functions and UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    94
  fetch Turing Machine intructions. In @{text "Actn m q r"}, @{text "m"} is 
258
32c5e8d1f6ff added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
    95
  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
    96
  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
    97
*}
32c5e8d1f6ff added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
    98
32c5e8d1f6ff added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
    99
fun actn :: "nat \<Rightarrow> nat \<Rightarrow> nat" where
32c5e8d1f6ff added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
   100
  "actn n 0 = pdec1 (pdec1 n)"
32c5e8d1f6ff added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
   101
| "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
   102
246
e113420a2fce separated recursive functions and UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   103
fun Actn :: "nat \<Rightarrow> nat \<Rightarrow> nat \<Rightarrow> nat"
e113420a2fce separated recursive functions and UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   104
  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
   105
  "Actn m q r = (if q \<noteq> 0 \<and> within m (q - 1) then (actn (ldec m (q - 1)) r) else 4)"
258
32c5e8d1f6ff added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
   106
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
fun newstate :: "nat \<Rightarrow> nat \<Rightarrow> nat" where
4524c5edcafb moved new theries into a separate directory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 258
diff changeset
   108
  "newstate n 0 = pdec2 (pdec1 n)"
4524c5edcafb moved new theries into a separate directory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 258
diff changeset
   109
| "newstate n _ = pdec2 (pdec2 n)"
246
e113420a2fce separated recursive functions and UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   110
259
4524c5edcafb moved new theries into a separate directory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 258
diff changeset
   111
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
   112
  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
   113
  "Newstate m q r = (if q \<noteq> 0 then (newstate (ldec m (q - 1)) r) else 0)"
246
e113420a2fce separated recursive functions and UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   114
258
32c5e8d1f6ff added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
   115
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
   116
  where
258
32c5e8d1f6ff added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
   117
  "Conf (q, (l, r)) = lenc [q, l, r]"
32c5e8d1f6ff added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
   118
259
4524c5edcafb moved new theries into a separate directory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 258
diff changeset
   119
fun 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
   120
  "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
   121
e113420a2fce separated recursive functions and UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   122
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
   123
  "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
   124
e113420a2fce separated recursive functions and UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   125
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
   126
  "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
   127
259
4524c5edcafb moved new theries into a separate directory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 258
diff changeset
   128
fun 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
   129
  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
   130
  "Step cf m = Conf (Newstate m (State cf) (Read (Right cf)), 
4524c5edcafb moved new theries into a separate directory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 258
diff changeset
   131
                    (Newleft (Left cf) (Right cf) (Actn m (State cf) (Read (Right cf))),
4524c5edcafb moved new theries into a separate directory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 258
diff changeset
   132
                     Newright (Left cf) (Right cf) (Actn m (State cf) (Read (Right cf)))))"
246
e113420a2fce separated recursive functions and UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   133
e113420a2fce separated recursive functions and UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   134
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
   135
  @{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
   136
  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
   137
*}
250
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   138
258
32c5e8d1f6ff added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
   139
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
   140
  where
258
32c5e8d1f6ff added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
   141
  "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
   142
| "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
   143
e113420a2fce separated recursive functions and UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   144
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
   145
  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
   146
*}
4524c5edcafb moved new theries into a separate directory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 258
diff changeset
   147
4524c5edcafb moved new theries into a separate directory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 258
diff changeset
   148
definition Binnum :: "nat \<Rightarrow> nat"
4524c5edcafb moved new theries into a separate directory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 258
diff changeset
   149
  where
4524c5edcafb moved new theries into a separate directory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 258
diff changeset
   150
  "Binnum z \<equiv> (\<Sum>i < enclen z. ldec z i * 2 ^ i)"
4524c5edcafb moved new theries into a separate directory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 258
diff changeset
   151
4524c5edcafb moved new theries into a separate directory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 258
diff changeset
   152
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
   153
  where
4524c5edcafb moved new theries into a separate directory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 258
diff changeset
   154
  "Stknum z \<equiv> (\<Sum>i < enclen z. ldec z i) - 1"
4524c5edcafb moved new theries into a separate directory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 258
diff changeset
   155
4524c5edcafb moved new theries into a separate directory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 258
diff changeset
   156
lemma Binnum_simulate1:
4524c5edcafb moved new theries into a separate directory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 258
diff changeset
   157
  "(Binnum z = 0) \<longleftrightarrow> (\<forall>i \<in> {..<enclen z}. ldec z i = 0)"
4524c5edcafb moved new theries into a separate directory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 258
diff changeset
   158
by(auto simp add: Binnum_def)
250
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   159
259
4524c5edcafb moved new theries into a separate directory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 258
diff changeset
   160
lemma Binnum_simulate2:
4524c5edcafb moved new theries into a separate directory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 258
diff changeset
   161
  "(\<forall>i \<in> {..<enclen (Code_tp tp)}. ldec (Code_tp tp) i = 0) \<longleftrightarrow> (\<exists>k. tp = Bk \<up> k)"
4524c5edcafb moved new theries into a separate directory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 258
diff changeset
   162
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
   163
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
   164
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
   165
apply(simp add: lessThan_Suc)
4524c5edcafb moved new theries into a separate directory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 258
diff changeset
   166
apply(case_tac a)
4524c5edcafb moved new theries into a separate directory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 258
diff changeset
   167
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
   168
defer
4524c5edcafb moved new theries into a separate directory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 258
diff changeset
   169
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
   170
oops
4524c5edcafb moved new theries into a separate directory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 258
diff changeset
   171
4524c5edcafb moved new theries into a separate directory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 258
diff changeset
   172
apply(simp add: Binnum_def)
4524c5edcafb moved new theries into a separate directory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 258
diff changeset
   173
4524c5edcafb moved new theries into a separate directory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 258
diff changeset
   174
text {*
4524c5edcafb moved new theries into a separate directory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 258
diff changeset
   175
  @{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
   176
  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
   177
*}
4524c5edcafb moved new theries into a separate directory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 258
diff changeset
   178
4524c5edcafb moved new theries into a separate directory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 258
diff changeset
   179
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
   180
  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
   181
  "Std cf = (Binnum (Left cf) = 0 \<and> 
4524c5edcafb moved new theries into a separate directory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 258
diff changeset
   182
            (\<exists>x\<le>(enclen (Right cf)). Binnum (Right cf) = 2 ^ x))"
246
e113420a2fce separated recursive functions and UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   183
e113420a2fce separated recursive functions and UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   184
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
   185
  @{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
   186
  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
   187
  @{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
   188
4524c5edcafb moved new theries into a separate directory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 258
diff changeset
   189
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
   190
  where
4524c5edcafb moved new theries into a separate directory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 258
diff changeset
   191
    "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
   192
246
e113420a2fce separated recursive functions and UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   193
fun Nostop :: "nat \<Rightarrow> nat \<Rightarrow> nat \<Rightarrow> bool"
e113420a2fce separated recursive functions and UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   194
  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
   195
  "Nostop m cf k = (Final (Steps cf m k) \<and> \<not> Std (Steps cf m k))"
246
e113420a2fce separated recursive functions and UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   196
e113420a2fce separated recursive functions and UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   197
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
   198
  @{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
   199
  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
   200
  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
   201
  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
   202
  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
   203
*}
246
e113420a2fce separated recursive functions and UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   204
250
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   205
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
   206
  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
   207
  "Halt m cf = (LEAST k. \<not> Nostop m cf k)"
250
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   208
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   209
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
   210
  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
   211
  "UF m cf = Stknum (Right (Steps m cf (Halt m cf)))"
258
32c5e8d1f6ff added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
   212
32c5e8d1f6ff added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
   213
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
   214
32c5e8d1f6ff added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
   215
lemma Update_left_simulate:
32c5e8d1f6ff added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
   216
  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
   217
apply(induct a)
32c5e8d1f6ff added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
   218
apply(simp_all)
32c5e8d1f6ff added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
   219
apply(case_tac l)
32c5e8d1f6ff added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
   220
apply(simp_all)
32c5e8d1f6ff added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
   221
apply(case_tac r)
32c5e8d1f6ff added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
   222
apply(simp_all)
32c5e8d1f6ff added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
   223
done
32c5e8d1f6ff added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
   224
32c5e8d1f6ff added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
   225
lemma Update_right_simulate:
32c5e8d1f6ff added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
   226
  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
   227
apply(induct a)
32c5e8d1f6ff added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
   228
apply(simp_all)
32c5e8d1f6ff added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
   229
apply(case_tac r)
32c5e8d1f6ff added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
   230
apply(simp_all)
32c5e8d1f6ff added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
   231
apply(case_tac r)
32c5e8d1f6ff added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
   232
apply(simp_all)
32c5e8d1f6ff added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
   233
apply(case_tac l)
32c5e8d1f6ff added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
   234
apply(simp_all)
32c5e8d1f6ff added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
   235
apply(case_tac r)
32c5e8d1f6ff added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
   236
apply(simp_all)
32c5e8d1f6ff added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
   237
done
32c5e8d1f6ff added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
   238
32c5e8d1f6ff added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
   239
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
   240
  "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
   241
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
   242
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
   243
done
32c5e8d1f6ff added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
   244
32c5e8d1f6ff added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
   245
lemma Fetch_action_simulate:
259
4524c5edcafb moved new theries into a separate directory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 258
diff changeset
   246
  "tm_wf tp \<Longrightarrow> Actn (Code_tprog tp) st (cell_num c) = action_num (fst (fetch tp st c))"
258
32c5e8d1f6ff added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
   247
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
   248
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
   249
done
32c5e8d1f6ff added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
   250
259
4524c5edcafb moved new theries into a separate directory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 258
diff changeset
   251
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
   252
  "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
   253
apply(case_tac tp)
32c5e8d1f6ff added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
   254
apply(simp_all)
32c5e8d1f6ff added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
   255
done
32c5e8d1f6ff added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
   256
32c5e8d1f6ff added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
   257
lemma misc:
32c5e8d1f6ff added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
   258
  "2 < (3::nat)"
32c5e8d1f6ff added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
   259
  "1 < (3::nat)"
32c5e8d1f6ff added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
   260
  "0 < (3::nat)" 
32c5e8d1f6ff added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
   261
  "length [x] = 1"
32c5e8d1f6ff added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
   262
  "length [x, y] = 2"
32c5e8d1f6ff added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
   263
  "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
   264
  "[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
   265
  "[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
   266
  "[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
   267
apply(simp_all)
32c5e8d1f6ff added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
   268
done
32c5e8d1f6ff added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
   269
259
4524c5edcafb moved new theries into a separate directory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 258
diff changeset
   270
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
   271
  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
   272
  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
   273
apply(subst step.simps) 
32c5e8d1f6ff added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
   274
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
   275
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
   276
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
   277
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
   278
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
   279
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
   280
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
   281
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
   282
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
   283
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
   284
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
   285
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
   286
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
   287
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
   288
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
   289
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
   290
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
   291
apply(simp)
32c5e8d1f6ff added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
   292
done
32c5e8d1f6ff added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
   293
259
4524c5edcafb moved new theries into a separate directory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 258
diff changeset
   294
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
   295
  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
   296
  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
   297
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
   298
apply(simp)
32c5e8d1f6ff added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
   299
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
   300
apply(case_tac cf)
32c5e8d1f6ff added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
   301
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
   302
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
   303
apply(rule assms)
32c5e8d1f6ff added more about UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
   304
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
   305
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
   306
done
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   307
259
4524c5edcafb moved new theries into a separate directory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 258
diff changeset
   308
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
   309
  "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
   310
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
   311
259
4524c5edcafb moved new theries into a separate directory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 258
diff changeset
   312
lemma Std_simulate:
4524c5edcafb moved new theries into a separate directory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 258
diff changeset
   313
  "Std (Conf (Code_conf cf)) = std_tape (snd cf)" 
4524c5edcafb moved new theries into a separate directory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 258
diff changeset
   314
apply(case_tac cf)
4524c5edcafb moved new theries into a separate directory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 258
diff changeset
   315
apply(simp add: std_tape_def del: Std.simps)
4524c5edcafb moved new theries into a separate directory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 258
diff changeset
   316
apply(subst Std.simps)
246
e113420a2fce separated recursive functions and UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   317
259
4524c5edcafb moved new theries into a separate directory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 258
diff changeset
   318
(* UNTIL HERE *)
246
e113420a2fce separated recursive functions and UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   319
250
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   320
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   321
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
   322
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   323
definition 
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   324
  "rec_entry = CN rec_lo [Id 2 0, CN rec_pi [CN S [Id 2 1]]]"
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   325
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   326
fun rec_listsum2 :: "nat \<Rightarrow> nat \<Rightarrow> recf"
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   327
  where
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   328
  "rec_listsum2 vl 0 = CN Z [Id vl 0]"
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   329
| "rec_listsum2 vl (Suc n) = CN rec_add [rec_listsum2 vl n, Id vl n]"
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   330
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   331
fun rec_strt' :: "nat \<Rightarrow> nat \<Rightarrow> recf"
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   332
  where
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   333
  "rec_strt' xs 0 = Z"
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   334
| "rec_strt' xs (Suc n) = 
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   335
      (let dbound = CN rec_add [rec_listsum2 xs n, constn n] in
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   336
       let t1 = CN rec_power [constn 2, dbound] in
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   337
       let t2 = CN rec_power [constn 2, CN rec_add [Id xs n, dbound]] in
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   338
       CN rec_add [rec_strt' xs n, CN rec_minus [t2, t1]])"
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   339
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   340
fun rec_map :: "recf \<Rightarrow> nat \<Rightarrow> recf list"
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   341
  where
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   342
  "rec_map rf vl = map (\<lambda>i. CN rf [Id vl i]) [0..<vl]"
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   343
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   344
fun rec_strt :: "nat \<Rightarrow> recf"
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   345
  where
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   346
  "rec_strt xs = CN (rec_strt' xs xs) (rec_map S xs)"
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   347
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   348
definition 
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   349
  "rec_scan = CN rec_mod [Id 1 0, constn 2]"
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   350
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   351
definition
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   352
    "rec_newleft =
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   353
       (let cond1 = CN rec_disj [CN rec_eq [Id 3 2, Z], CN rec_eq [Id 3 2, constn 1]] in
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   354
        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
   355
        let cond3 = CN rec_eq [Id 3 2, constn 3] in
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   356
        let case3 = CN rec_add [CN rec_mult [constn 2, Id 3 0], 
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   357
                                CN rec_mod [Id 3 1, constn 2]] in
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   358
        CN rec_if [cond1, Id 3 0, 
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   359
          CN rec_if [cond2, CN rec_quo [Id 3 0, constn 2],
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   360
            CN rec_if [cond3, case3, Id 3 0]]])"
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   361
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   362
definition
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   363
    "rec_newright =
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   364
       (let condn = \<lambda>n. CN rec_eq [Id 3 2, constn n] in
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   365
        let case0 = CN rec_minus [Id 3 1, CN rec_scan [Id 3 1]] in
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   366
        let case1 = CN rec_minus [CN rec_add [Id 3 1, constn 1], CN rec_scan [Id 3 1]] in
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   367
        let case2 = CN rec_add [CN rec_mult [constn 2, Id 3 1],                     
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   368
                                CN rec_mod [Id 3 0, constn 2]] in
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   369
        let case3 = CN rec_quo [Id 2 1, constn 2] in
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   370
        CN rec_if [condn 0, case0, 
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   371
          CN rec_if [condn 1, case1,
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   372
            CN rec_if [condn 2, case2,
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   373
              CN rec_if [condn 3, case3, Id 3 1]]]])"
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   374
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   375
definition 
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   376
  "rec_actn = (let add1 = CN rec_mult [constn 4, CN rec_pred [Id 3 1]] in
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   377
               let add2 = CN rec_mult [constn 2, CN rec_scan [Id 3 2]] in
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   378
               let entry = CN rec_entry [Id 3 0, CN rec_add [add1, add2]]
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   379
               in CN rec_if [Id 3 1, entry, constn 4])"
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   380
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   381
definition rec_newstat :: "recf"
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   382
  where
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   383
  "rec_newstat = (let add1 = CN rec_mult [constn 4, CN rec_pred [Id 3 1]] in
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   384
                  let add2 = CN S [CN rec_mult [constn 2, CN rec_scan [Id 3 2]]] in
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   385
                  let entry = CN rec_entry [Id 3 0, CN rec_add [add1, add2]]
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   386
                  in CN rec_if [Id 3 1, entry, Z])"
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   387
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   388
definition 
256
04700724250f completed coding functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 250
diff changeset
   389
  "rec_trpl = CN rec_penc [CN rec_penc [Id 3 0, Id 3 1], Id 3 2]"
250
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   390
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   391
definition
256
04700724250f completed coding functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 250
diff changeset
   392
  "rec_left = rec_pdec1"
250
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   393
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   394
definition 
256
04700724250f completed coding functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 250
diff changeset
   395
  "rec_right = CN rec_pdec2 [rec_pdec1]"
250
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   396
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   397
definition 
256
04700724250f completed coding functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 250
diff changeset
   398
  "rec_stat = CN rec_pdec2 [rec_pdec2]"
250
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   399
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   400
definition 
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   401
  "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
   402
                  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
   403
                  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
   404
                  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
   405
                  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
   406
                  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
   407
                  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
   408
                  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
   409
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   410
definition 
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   411
  "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
   412
                 (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
   413
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   414
definition 
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   415
  "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
   416
               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
   417
               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
   418
               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
   419
               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
   420
               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
   421
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   422
definition 
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   423
  "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
   424
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   425
definition 
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   426
  "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
   427
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   428
definition 
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   429
  "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
   430
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   431
definition 
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   432
  "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
   433
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   434
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   435
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   436
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
   437
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   438
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
   439
  "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
   440
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
   441
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   442
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
   443
  "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
   444
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
   445
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   446
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
   447
  "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
   448
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
   449
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   450
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
   451
  "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
   452
proof -
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   453
  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
   454
  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
   455
  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
   456
  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
   457
  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
   458
qed
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   459
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   460
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
   461
  "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
   462
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
   463
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   464
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
   465
  "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
   466
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
   467
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   468
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
   469
  "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
   470
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
   471
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   472
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
   473
  "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
   474
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
   475
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   476
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
   477
  "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
   478
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
   479
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   480
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
   481
  "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
   482
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
   483
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   484
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
   485
  "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
   486
apply(simp)
04700724250f completed coding functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 250
diff changeset
   487
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
   488
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   489
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
   490
  "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
   491
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
   492
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   493
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
   494
  "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
   495
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
   496
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   497
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
   498
  "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
   499
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
   500
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   501
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
   502
  "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
   503
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
   504
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   505
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
   506
  "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
   507
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
   508
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   509
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
   510
  "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
   511
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
   512
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   513
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
   514
  "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
   515
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
   516
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   517
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
   518
  "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
   519
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
   520
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   521
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
   522
  "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
   523
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
   524
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   525
lemma 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
   526
  "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
   527
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
   528
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   529
248
aea02b5a58d2 repaired old files
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 246
diff changeset
   530
subsection {* Relating interperter functions to the execution of TMs *}
246
e113420a2fce separated recursive functions and UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   531
250
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   532
lemma rec_step: 
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   533
  assumes "(\<lambda> (s, l, r). s \<le> length tp div 2) c"
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   534
  shows "Trpl_code (step0 c tp) = Newconf (Code tp) (Trpl_code c)"
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   535
apply(cases c)
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   536
apply(simp only: Trpl_code.simps)
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   537
apply(simp only: Let_def step.simps)
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   538
apply(case_tac "fetch tp (a - 0) (read ca)")
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   539
apply(simp only: prod.cases)
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   540
apply(case_tac "update aa (b, ca)")
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   541
apply(simp only: prod.cases)
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   542
apply(simp only: Trpl_code.simps)
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   543
apply(simp only: Newconf.simps)
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   544
apply(simp only: Left.simps)
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   545
oops
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   546
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   547
lemma rec_steps:
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   548
  assumes "tm_wf0 tp"
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   549
  shows "Trpl_code (steps0 (1, Bk \<up> l, <lm>) tp stp) = Conf stp (Code tp) (bl2wc (<lm>))"
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   550
apply(induct stp)
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   551
apply(simp)
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   552
apply(simp)
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   553
oops
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   554
246
e113420a2fce separated recursive functions and UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   555
248
aea02b5a58d2 repaired old files
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 246
diff changeset
   556
lemma F_correct: 
250
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   557
  assumes tm: "steps0 (1, Bk \<up> l, <lm>) tp stp = (0, Bk \<up> m, Oc \<up> rs @ Bk \<up> n)"
248
aea02b5a58d2 repaired old files
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 246
diff changeset
   558
  and     wf:  "tm_wf0 tp" "0 < rs"
aea02b5a58d2 repaired old files
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 246
diff changeset
   559
  shows "rec_eval rec_uf [Code tp, bl2wc (<lm>)] = (rs - Suc 0)"
250
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   560
proof -
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   561
  from least_steps[OF tm] 
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   562
  obtain stp_least where
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   563
    before: "\<forall>stp' < stp_least. \<not> is_final (steps0 (1, Bk \<up> l, <lm>) tp stp')" and
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   564
    after:  "\<forall>stp' \<ge> stp_least. is_final (steps0 (1, Bk \<up> l, <lm>) tp stp')" by blast
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   565
  have "Halt (Code tp) (bl2wc (<lm>)) = stp_least" sorry
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   566
  show ?thesis
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   567
    apply(simp only: uf_lemma)
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   568
    apply(simp only: UF.simps)
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   569
    apply(simp only: Halt.simps)
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   570
    oops
246
e113420a2fce separated recursive functions and UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   571
e113420a2fce separated recursive functions and UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   572
248
aea02b5a58d2 repaired old files
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 246
diff changeset
   573
end
246
e113420a2fce separated recursive functions and UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   574