thys3/src/Blexer.thy
author Chengsong
Fri, 23 Sep 2022 00:44:22 +0100
changeset 602 46db6ae66448
parent 569 5af61c89f51e
permissions -rw-r--r--
chap1
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
495
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
     1
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
     2
theory Blexer
563
c92a41d9c4da updated paper and theories to include n-times
Christian Urban <christian.urban@kcl.ac.uk>
parents: 496
diff changeset
     3
  imports "Lexer"
495
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
     4
begin
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
     5
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
     6
section \<open>Bit-Encodings\<close>
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
     7
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
     8
datatype bit = Z | S
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
     9
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    10
fun code :: "val \<Rightarrow> bit list"
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    11
where
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    12
  "code Void = []"
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    13
| "code (Char c) = []"
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    14
| "code (Left v) = Z # (code v)"
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    15
| "code (Right v) = S # (code v)"
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    16
| "code (Seq v1 v2) = (code v1) @ (code v2)"
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    17
| "code (Stars []) = [S]"
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    18
| "code (Stars (v # vs)) =  (Z # code v) @ code (Stars vs)"
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    19
563
c92a41d9c4da updated paper and theories to include n-times
Christian Urban <christian.urban@kcl.ac.uk>
parents: 496
diff changeset
    20
fun sz where
c92a41d9c4da updated paper and theories to include n-times
Christian Urban <christian.urban@kcl.ac.uk>
parents: 496
diff changeset
    21
  "sz ZERO = 0"
c92a41d9c4da updated paper and theories to include n-times
Christian Urban <christian.urban@kcl.ac.uk>
parents: 496
diff changeset
    22
| "sz ONE = 0"
c92a41d9c4da updated paper and theories to include n-times
Christian Urban <christian.urban@kcl.ac.uk>
parents: 496
diff changeset
    23
| "sz (CH _) = 0"
c92a41d9c4da updated paper and theories to include n-times
Christian Urban <christian.urban@kcl.ac.uk>
parents: 496
diff changeset
    24
| "sz (SEQ r1 r2) = 1 + sz r1 + sz r2"
c92a41d9c4da updated paper and theories to include n-times
Christian Urban <christian.urban@kcl.ac.uk>
parents: 496
diff changeset
    25
| "sz (ALT r1 r2) = 1 + sz r1 + sz r2"
c92a41d9c4da updated paper and theories to include n-times
Christian Urban <christian.urban@kcl.ac.uk>
parents: 496
diff changeset
    26
| "sz (STAR r) = 1 + sz r"
c92a41d9c4da updated paper and theories to include n-times
Christian Urban <christian.urban@kcl.ac.uk>
parents: 496
diff changeset
    27
| "sz (NTIMES r n) = 1 + n + sz r"
c92a41d9c4da updated paper and theories to include n-times
Christian Urban <christian.urban@kcl.ac.uk>
parents: 496
diff changeset
    28
495
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    29
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    30
fun 
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    31
  Stars_add :: "val \<Rightarrow> val \<Rightarrow> val"
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    32
where
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    33
  "Stars_add v (Stars vs) = Stars (v # vs)"
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    34
563
c92a41d9c4da updated paper and theories to include n-times
Christian Urban <christian.urban@kcl.ac.uk>
parents: 496
diff changeset
    35
function (sequential)
495
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    36
  decode' :: "bit list \<Rightarrow> rexp \<Rightarrow> (val * bit list)"
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    37
where
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    38
  "decode' bs ZERO = (undefined, bs)"
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    39
| "decode' bs ONE = (Void, bs)"
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    40
| "decode' bs (CH d) = (Char d, bs)"
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    41
| "decode' [] (ALT r1 r2) = (Void, [])"
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    42
| "decode' (Z # bs) (ALT r1 r2) = (let (v, bs') = decode' bs r1 in (Left v, bs'))"
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    43
| "decode' (S # bs) (ALT r1 r2) = (let (v, bs') = decode' bs r2 in (Right v, bs'))"
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    44
| "decode' bs (SEQ r1 r2) = (let (v1, bs') = decode' bs r1 in
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    45
                             let (v2, bs'') = decode' bs' r2 in (Seq v1 v2, bs''))"
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    46
| "decode' [] (STAR r) = (Void, [])"
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    47
| "decode' (S # bs) (STAR r) = (Stars [], bs)"
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    48
| "decode' (Z # bs) (STAR r) = (let (v, bs') = decode' bs r in
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    49
                                    let (vs, bs'') = decode' bs' (STAR r) 
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    50
                                    in (Stars_add v vs, bs''))"
563
c92a41d9c4da updated paper and theories to include n-times
Christian Urban <christian.urban@kcl.ac.uk>
parents: 496
diff changeset
    51
| "decode' [] (NTIMES r n) = (Void, [])"
c92a41d9c4da updated paper and theories to include n-times
Christian Urban <christian.urban@kcl.ac.uk>
parents: 496
diff changeset
    52
| "decode' (S # bs) (NTIMES r n) = (Stars [], bs)"
c92a41d9c4da updated paper and theories to include n-times
Christian Urban <christian.urban@kcl.ac.uk>
parents: 496
diff changeset
    53
| "decode' (Z # bs) (NTIMES r n) = (let (v, bs') = decode' bs r in
c92a41d9c4da updated paper and theories to include n-times
Christian Urban <christian.urban@kcl.ac.uk>
parents: 496
diff changeset
    54
                                    let (vs, bs'') = decode' bs' (NTIMES r (n - 1)) 
c92a41d9c4da updated paper and theories to include n-times
Christian Urban <christian.urban@kcl.ac.uk>
parents: 496
diff changeset
    55
                                    in (Stars_add v vs, bs''))"
495
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    56
by pat_completeness auto
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    57
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    58
lemma decode'_smaller:
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    59
  assumes "decode'_dom (bs, r)"
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    60
  shows "length (snd (decode' bs r)) \<le> length bs"
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    61
using assms
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    62
apply(induct bs r)
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    63
apply(auto simp add: decode'.psimps split: prod.split)
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    64
using dual_order.trans apply blast
563
c92a41d9c4da updated paper and theories to include n-times
Christian Urban <christian.urban@kcl.ac.uk>
parents: 496
diff changeset
    65
apply (meson dual_order.trans le_SucI)
c92a41d9c4da updated paper and theories to include n-times
Christian Urban <christian.urban@kcl.ac.uk>
parents: 496
diff changeset
    66
  apply (meson le_SucI le_trans)
c92a41d9c4da updated paper and theories to include n-times
Christian Urban <christian.urban@kcl.ac.uk>
parents: 496
diff changeset
    67
  done
495
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    68
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    69
termination "decode'"  
563
c92a41d9c4da updated paper and theories to include n-times
Christian Urban <christian.urban@kcl.ac.uk>
parents: 496
diff changeset
    70
apply(relation "inv_image (measure(%cs. sz cs) <*lex*> measure(%s. size s)) (%(ds,r). (r,ds))") 
495
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    71
apply(auto dest!: decode'_smaller)
563
c92a41d9c4da updated paper and theories to include n-times
Christian Urban <christian.urban@kcl.ac.uk>
parents: 496
diff changeset
    72
   apply (metis less_Suc_eq_le snd_conv)
c92a41d9c4da updated paper and theories to include n-times
Christian Urban <christian.urban@kcl.ac.uk>
parents: 496
diff changeset
    73
  by (metis less_Suc_eq_le snd_conv)
495
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    74
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    75
definition
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    76
  decode :: "bit list \<Rightarrow> rexp \<Rightarrow> val option"
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    77
where
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    78
  "decode ds r \<equiv> (let (v, ds') = decode' ds r 
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    79
                  in (if ds' = [] then Some v else None))"
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    80
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    81
lemma decode'_code_Stars:
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    82
  assumes "\<forall>v\<in>set vs. \<Turnstile> v : r \<and> (\<forall>x. decode' (code v @ x) r = (v, x)) \<and> flat v \<noteq> []" 
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    83
  shows "decode' (code (Stars vs) @ ds) (STAR r) = (Stars vs, ds)"
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    84
  using assms
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    85
  apply(induct vs)
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    86
  apply(auto)
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    87
  done
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    88
563
c92a41d9c4da updated paper and theories to include n-times
Christian Urban <christian.urban@kcl.ac.uk>
parents: 496
diff changeset
    89
lemma decode'_code_NTIMES:
c92a41d9c4da updated paper and theories to include n-times
Christian Urban <christian.urban@kcl.ac.uk>
parents: 496
diff changeset
    90
  assumes "\<forall>v\<in>set vs. \<Turnstile> v : r \<and> (\<forall>x. decode' (code v @ x) r = (v, x))" 
c92a41d9c4da updated paper and theories to include n-times
Christian Urban <christian.urban@kcl.ac.uk>
parents: 496
diff changeset
    91
  shows "decode' (code (Stars vs) @ ds) (NTIMES r n) = (Stars vs, ds)"
c92a41d9c4da updated paper and theories to include n-times
Christian Urban <christian.urban@kcl.ac.uk>
parents: 496
diff changeset
    92
  using assms
c92a41d9c4da updated paper and theories to include n-times
Christian Urban <christian.urban@kcl.ac.uk>
parents: 496
diff changeset
    93
  apply(induct vs arbitrary: n r ds)
c92a41d9c4da updated paper and theories to include n-times
Christian Urban <christian.urban@kcl.ac.uk>
parents: 496
diff changeset
    94
   apply(auto)
c92a41d9c4da updated paper and theories to include n-times
Christian Urban <christian.urban@kcl.ac.uk>
parents: 496
diff changeset
    95
  done
c92a41d9c4da updated paper and theories to include n-times
Christian Urban <christian.urban@kcl.ac.uk>
parents: 496
diff changeset
    96
c92a41d9c4da updated paper and theories to include n-times
Christian Urban <christian.urban@kcl.ac.uk>
parents: 496
diff changeset
    97
495
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    98
lemma decode'_code:
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    99
  assumes "\<Turnstile> v : r"
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   100
  shows "decode' ((code v) @ ds) r = (v, ds)"
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   101
using assms
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   102
  apply(induct v r arbitrary: ds) 
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   103
  apply(auto)
563
c92a41d9c4da updated paper and theories to include n-times
Christian Urban <christian.urban@kcl.ac.uk>
parents: 496
diff changeset
   104
  using decode'_code_Stars apply blast
c92a41d9c4da updated paper and theories to include n-times
Christian Urban <christian.urban@kcl.ac.uk>
parents: 496
diff changeset
   105
   by (metis Un_iff decode'_code_NTIMES set_append)  
495
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   106
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   107
lemma decode_code:
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   108
  assumes "\<Turnstile> v : r"
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   109
  shows "decode (code v) r = Some v"
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   110
  using assms unfolding decode_def
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   111
  by (smt append_Nil2 decode'_code old.prod.case)
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   112
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   113
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   114
section {* Annotated Regular Expressions *}
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   115
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   116
datatype arexp = 
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   117
  AZERO
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   118
| AONE "bit list"
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   119
| ACHAR "bit list" char
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   120
| ASEQ "bit list" arexp arexp
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   121
| AALTs "bit list" "arexp list"
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   122
| ASTAR "bit list" arexp
563
c92a41d9c4da updated paper and theories to include n-times
Christian Urban <christian.urban@kcl.ac.uk>
parents: 496
diff changeset
   123
| ANTIMES "bit list" arexp nat
495
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   124
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   125
abbreviation
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   126
  "AALT bs r1 r2 \<equiv> AALTs bs [r1, r2]"
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   127
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   128
fun asize :: "arexp \<Rightarrow> nat" where
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   129
  "asize AZERO = 1"
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   130
| "asize (AONE cs) = 1" 
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   131
| "asize (ACHAR cs c) = 1"
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   132
| "asize (AALTs cs rs) = Suc (sum_list (map asize rs))"
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   133
| "asize (ASEQ cs r1 r2) = Suc (asize r1 + asize r2)"
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   134
| "asize (ASTAR cs r) = Suc (asize r)"
563
c92a41d9c4da updated paper and theories to include n-times
Christian Urban <christian.urban@kcl.ac.uk>
parents: 496
diff changeset
   135
| "asize (ANTIMES cs r n) = Suc (asize r) + n"
495
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   136
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   137
fun 
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   138
  erase :: "arexp \<Rightarrow> rexp"
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   139
where
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   140
  "erase AZERO = ZERO"
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   141
| "erase (AONE _) = ONE"
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   142
| "erase (ACHAR _ c) = CH c"
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   143
| "erase (AALTs _ []) = ZERO"
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   144
| "erase (AALTs _ [r]) = (erase r)"
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   145
| "erase (AALTs bs (r#rs)) = ALT (erase r) (erase (AALTs bs rs))"
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   146
| "erase (ASEQ _ r1 r2) = SEQ (erase r1) (erase r2)"
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   147
| "erase (ASTAR _ r) = STAR (erase r)"
563
c92a41d9c4da updated paper and theories to include n-times
Christian Urban <christian.urban@kcl.ac.uk>
parents: 496
diff changeset
   148
| "erase (ANTIMES _ r n) = NTIMES (erase r) n"
495
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   149
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   150
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   151
fun fuse :: "bit list \<Rightarrow> arexp \<Rightarrow> arexp" where
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   152
  "fuse bs AZERO = AZERO"
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   153
| "fuse bs (AONE cs) = AONE (bs @ cs)" 
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   154
| "fuse bs (ACHAR cs c) = ACHAR (bs @ cs) c"
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   155
| "fuse bs (AALTs cs rs) = AALTs (bs @ cs) rs"
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   156
| "fuse bs (ASEQ cs r1 r2) = ASEQ (bs @ cs) r1 r2"
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   157
| "fuse bs (ASTAR cs r) = ASTAR (bs @ cs) r"
563
c92a41d9c4da updated paper and theories to include n-times
Christian Urban <christian.urban@kcl.ac.uk>
parents: 496
diff changeset
   158
| "fuse bs (ANTIMES cs r n) = ANTIMES (bs @ cs) r n"
495
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   159
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   160
lemma fuse_append:
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   161
  shows "fuse (bs1 @ bs2) r = fuse bs1 (fuse bs2 r)"
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   162
  apply(induct r)
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   163
  apply(auto)
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   164
  done
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   165
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   166
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   167
fun intern :: "rexp \<Rightarrow> arexp" where
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   168
  "intern ZERO = AZERO"
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   169
| "intern ONE = AONE []"
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   170
| "intern (CH c) = ACHAR [] c"
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   171
| "intern (ALT r1 r2) = AALT [] (fuse [Z] (intern r1)) 
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   172
                                (fuse [S]  (intern r2))"
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   173
| "intern (SEQ r1 r2) = ASEQ [] (intern r1) (intern r2)"
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   174
| "intern (STAR r) = ASTAR [] (intern r)"
563
c92a41d9c4da updated paper and theories to include n-times
Christian Urban <christian.urban@kcl.ac.uk>
parents: 496
diff changeset
   175
| "intern (NTIMES r n) = ANTIMES [] (intern r) n"
495
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   176
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   177
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   178
fun retrieve :: "arexp \<Rightarrow> val \<Rightarrow> bit list" where
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   179
  "retrieve (AONE bs) Void = bs"
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   180
| "retrieve (ACHAR bs c) (Char d) = bs"
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   181
| "retrieve (AALTs bs [r]) v = bs @ retrieve r v"
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   182
| "retrieve (AALTs bs (r#rs)) (Left v) = bs @ retrieve r v"
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   183
| "retrieve (AALTs bs (r#rs)) (Right v) = bs @ retrieve (AALTs [] rs) v"
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   184
| "retrieve (ASEQ bs r1 r2) (Seq v1 v2) = bs @ retrieve r1 v1 @ retrieve r2 v2"
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   185
| "retrieve (ASTAR bs r) (Stars []) = bs @ [S]"
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   186
| "retrieve (ASTAR bs r) (Stars (v#vs)) = 
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   187
     bs @ [Z] @ retrieve r v @ retrieve (ASTAR [] r) (Stars vs)"
563
c92a41d9c4da updated paper and theories to include n-times
Christian Urban <christian.urban@kcl.ac.uk>
parents: 496
diff changeset
   188
| "retrieve (ANTIMES bs r 0) (Stars []) = bs @ [S]"
c92a41d9c4da updated paper and theories to include n-times
Christian Urban <christian.urban@kcl.ac.uk>
parents: 496
diff changeset
   189
| "retrieve (ANTIMES bs r (Suc n)) (Stars (v#vs)) = 
c92a41d9c4da updated paper and theories to include n-times
Christian Urban <christian.urban@kcl.ac.uk>
parents: 496
diff changeset
   190
     bs @ [Z] @ retrieve r v @ retrieve (ANTIMES [] r n) (Stars vs)"
495
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   191
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   192
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   193
fun
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   194
 bnullable :: "arexp \<Rightarrow> bool"
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   195
where
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   196
  "bnullable (AZERO) = False"
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   197
| "bnullable (AONE bs) = True"
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   198
| "bnullable (ACHAR bs c) = False"
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   199
| "bnullable (AALTs bs rs) = (\<exists>r \<in> set rs. bnullable r)"
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   200
| "bnullable (ASEQ bs r1 r2) = (bnullable r1 \<and> bnullable r2)"
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   201
| "bnullable (ASTAR bs r) = True"
563
c92a41d9c4da updated paper and theories to include n-times
Christian Urban <christian.urban@kcl.ac.uk>
parents: 496
diff changeset
   202
| "bnullable (ANTIMES bs r n) = (if n  = 0 then True else bnullable r)"
495
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   203
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   204
abbreviation
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   205
  bnullables :: "arexp list \<Rightarrow> bool"
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   206
where
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   207
  "bnullables rs \<equiv> (\<exists>r \<in> set rs. bnullable r)"
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   208
563
c92a41d9c4da updated paper and theories to include n-times
Christian Urban <christian.urban@kcl.ac.uk>
parents: 496
diff changeset
   209
function (sequential)
c92a41d9c4da updated paper and theories to include n-times
Christian Urban <christian.urban@kcl.ac.uk>
parents: 496
diff changeset
   210
  bmkeps :: "arexp \<Rightarrow> bit list" 
495
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   211
where
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   212
  "bmkeps(AONE bs) = bs"
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   213
| "bmkeps(ASEQ bs r1 r2) = bs @ (bmkeps r1) @ (bmkeps r2)"
563
c92a41d9c4da updated paper and theories to include n-times
Christian Urban <christian.urban@kcl.ac.uk>
parents: 496
diff changeset
   214
| "bmkeps(AALTs bs (r#rs)) = 
c92a41d9c4da updated paper and theories to include n-times
Christian Urban <christian.urban@kcl.ac.uk>
parents: 496
diff changeset
   215
    (if bnullable(r) then (bs @ bmkeps r) else (bmkeps (AALTs bs rs)))"
495
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   216
| "bmkeps(ASTAR bs r) = bs @ [S]"
569
5af61c89f51e updated paper and corresponding theories
Christian Urban <christian.urban@kcl.ac.uk>
parents: 563
diff changeset
   217
| "bmkeps(ANTIMES bs r n) = 
5af61c89f51e updated paper and corresponding theories
Christian Urban <christian.urban@kcl.ac.uk>
parents: 563
diff changeset
   218
    (if n = 0 then bs @ [S] else bs @ [Z] @ (bmkeps r) @ bmkeps(ANTIMES [] r (n - 1)))"
563
c92a41d9c4da updated paper and theories to include n-times
Christian Urban <christian.urban@kcl.ac.uk>
parents: 496
diff changeset
   219
apply(pat_completeness)
c92a41d9c4da updated paper and theories to include n-times
Christian Urban <christian.urban@kcl.ac.uk>
parents: 496
diff changeset
   220
apply(auto)
c92a41d9c4da updated paper and theories to include n-times
Christian Urban <christian.urban@kcl.ac.uk>
parents: 496
diff changeset
   221
done
c92a41d9c4da updated paper and theories to include n-times
Christian Urban <christian.urban@kcl.ac.uk>
parents: 496
diff changeset
   222
c92a41d9c4da updated paper and theories to include n-times
Christian Urban <christian.urban@kcl.ac.uk>
parents: 496
diff changeset
   223
termination "bmkeps"  
c92a41d9c4da updated paper and theories to include n-times
Christian Urban <christian.urban@kcl.ac.uk>
parents: 496
diff changeset
   224
apply(relation "measure asize") 
c92a41d9c4da updated paper and theories to include n-times
Christian Urban <christian.urban@kcl.ac.uk>
parents: 496
diff changeset
   225
        apply(auto)
c92a41d9c4da updated paper and theories to include n-times
Christian Urban <christian.urban@kcl.ac.uk>
parents: 496
diff changeset
   226
  using asize.elims by force
c92a41d9c4da updated paper and theories to include n-times
Christian Urban <christian.urban@kcl.ac.uk>
parents: 496
diff changeset
   227
c92a41d9c4da updated paper and theories to include n-times
Christian Urban <christian.urban@kcl.ac.uk>
parents: 496
diff changeset
   228
fun
c92a41d9c4da updated paper and theories to include n-times
Christian Urban <christian.urban@kcl.ac.uk>
parents: 496
diff changeset
   229
   bmkepss :: "arexp list \<Rightarrow> bit list"
c92a41d9c4da updated paper and theories to include n-times
Christian Urban <christian.urban@kcl.ac.uk>
parents: 496
diff changeset
   230
where
c92a41d9c4da updated paper and theories to include n-times
Christian Urban <christian.urban@kcl.ac.uk>
parents: 496
diff changeset
   231
  "bmkepss (r # rs) = (if bnullable(r) then (bmkeps r) else (bmkepss rs))"
c92a41d9c4da updated paper and theories to include n-times
Christian Urban <christian.urban@kcl.ac.uk>
parents: 496
diff changeset
   232
495
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   233
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   234
lemma bmkepss1:
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   235
  assumes "\<not> bnullables rs1"
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   236
  shows "bmkepss (rs1 @ rs2) = bmkepss rs2"
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   237
  using assms
563
c92a41d9c4da updated paper and theories to include n-times
Christian Urban <christian.urban@kcl.ac.uk>
parents: 496
diff changeset
   238
  by(induct rs1) (auto)
c92a41d9c4da updated paper and theories to include n-times
Christian Urban <christian.urban@kcl.ac.uk>
parents: 496
diff changeset
   239
  
495
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   240
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   241
lemma bmkepss2:
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   242
  assumes "bnullables rs1"
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   243
  shows "bmkepss (rs1 @ rs2) = bmkepss rs1"
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   244
  using assms
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   245
  by (induct rs1) (auto)
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   246
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   247
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   248
fun
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   249
 bder :: "char \<Rightarrow> arexp \<Rightarrow> arexp"
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   250
where
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   251
  "bder c (AZERO) = AZERO"
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   252
| "bder c (AONE bs) = AZERO"
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   253
| "bder c (ACHAR bs d) = (if c = d then AONE bs else AZERO)"
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   254
| "bder c (AALTs bs rs) = AALTs bs (map (bder c) rs)"
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   255
| "bder c (ASEQ bs r1 r2) = 
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   256
     (if bnullable r1
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   257
      then AALT bs (ASEQ [] (bder c r1) r2) (fuse (bmkeps r1) (bder c r2))
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   258
      else ASEQ bs (bder c r1) r2)"
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   259
| "bder c (ASTAR bs r) = ASEQ (bs @ [Z]) (bder c r) (ASTAR [] r)"
563
c92a41d9c4da updated paper and theories to include n-times
Christian Urban <christian.urban@kcl.ac.uk>
parents: 496
diff changeset
   260
| "bder c (ANTIMES bs r n) = (if n = 0 then AZERO else ASEQ (bs @ [Z]) (bder c r) (ANTIMES [] r (n - 1)))"
495
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   261
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   262
fun 
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   263
  bders :: "arexp \<Rightarrow> string \<Rightarrow> arexp"
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   264
where
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   265
  "bders r [] = r"
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   266
| "bders r (c#s) = bders (bder c r) s"
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   267
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   268
lemma bders_append:
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   269
  "bders c (s1 @ s2) = bders (bders c s1) s2"
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   270
  apply(induct s1 arbitrary: c s2)
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   271
  apply(simp_all)
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   272
  done
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   273
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   274
lemma bnullable_correctness:
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   275
  shows "nullable (erase r) = bnullable r"
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   276
  apply(induct r rule: erase.induct)
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   277
  apply(simp_all)
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   278
  done
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   279
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   280
lemma erase_fuse:
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   281
  shows "erase (fuse bs r) = erase r"
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   282
  apply(induct r rule: erase.induct)
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   283
  apply(simp_all)
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   284
  done
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   285
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   286
lemma erase_intern [simp]:
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   287
  shows "erase (intern r) = r"
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   288
  apply(induct r)
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   289
  apply(simp_all add: erase_fuse)
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   290
  done
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   291
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   292
lemma erase_bder [simp]:
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   293
  shows "erase (bder a r) = der a (erase r)"
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   294
  apply(induct r rule: erase.induct)
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   295
  apply(simp_all add: erase_fuse bnullable_correctness)
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   296
  done
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   297
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   298
lemma erase_bders [simp]:
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   299
  shows "erase (bders r s) = ders s (erase r)"
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   300
  apply(induct s arbitrary: r )
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   301
  apply(simp_all)
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   302
  done
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   303
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   304
lemma bnullable_fuse:
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   305
  shows "bnullable (fuse bs r) = bnullable r"
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   306
  apply(induct r arbitrary: bs)
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   307
  apply(auto)
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   308
  done
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   309
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   310
lemma retrieve_encode_STARS:
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   311
  assumes "\<forall>v\<in>set vs. \<Turnstile> v : r \<and> code v = retrieve (intern r) v"
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   312
  shows "code (Stars vs) = retrieve (ASTAR [] (intern r)) (Stars vs)"
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   313
  using assms
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   314
  apply(induct vs)
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   315
  apply(simp_all)
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   316
  done
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   317
563
c92a41d9c4da updated paper and theories to include n-times
Christian Urban <christian.urban@kcl.ac.uk>
parents: 496
diff changeset
   318
lemma retrieve_encode_NTIMES:
c92a41d9c4da updated paper and theories to include n-times
Christian Urban <christian.urban@kcl.ac.uk>
parents: 496
diff changeset
   319
  assumes "\<forall>v\<in>set vs. \<Turnstile> v : r \<and> code v = retrieve (intern r) v" "length vs = n"
c92a41d9c4da updated paper and theories to include n-times
Christian Urban <christian.urban@kcl.ac.uk>
parents: 496
diff changeset
   320
  shows "code (Stars vs) = retrieve (ANTIMES [] (intern r) n) (Stars vs)"
c92a41d9c4da updated paper and theories to include n-times
Christian Urban <christian.urban@kcl.ac.uk>
parents: 496
diff changeset
   321
  using assms
c92a41d9c4da updated paper and theories to include n-times
Christian Urban <christian.urban@kcl.ac.uk>
parents: 496
diff changeset
   322
  apply(induct vs arbitrary: n)
c92a41d9c4da updated paper and theories to include n-times
Christian Urban <christian.urban@kcl.ac.uk>
parents: 496
diff changeset
   323
   apply(simp_all)
c92a41d9c4da updated paper and theories to include n-times
Christian Urban <christian.urban@kcl.ac.uk>
parents: 496
diff changeset
   324
  by force
c92a41d9c4da updated paper and theories to include n-times
Christian Urban <christian.urban@kcl.ac.uk>
parents: 496
diff changeset
   325
c92a41d9c4da updated paper and theories to include n-times
Christian Urban <christian.urban@kcl.ac.uk>
parents: 496
diff changeset
   326
495
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   327
lemma retrieve_fuse2:
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   328
  assumes "\<Turnstile> v : (erase r)"
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   329
  shows "retrieve (fuse bs r) v = bs @ retrieve r v"
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   330
  using assms
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   331
  apply(induct r arbitrary: v bs)
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   332
  apply(auto elim: Prf_elims)[4]
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   333
  apply(case_tac x2a)
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   334
  apply(simp)
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   335
  using Prf_elims(1) apply blast
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   336
  apply(case_tac x2a)
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   337
  apply(simp)
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   338
  apply(simp)
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   339
  apply(case_tac list)
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   340
  apply(simp)
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   341
  apply(simp)
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   342
  apply (smt (verit, best) Prf_elims(3) append_assoc retrieve.simps(4) retrieve.simps(5))
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   343
  apply(simp)
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   344
  using retrieve_encode_STARS
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   345
  apply(auto elim!: Prf_elims)[1]
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   346
  apply(case_tac vs)
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   347
  apply(simp)
563
c92a41d9c4da updated paper and theories to include n-times
Christian Urban <christian.urban@kcl.ac.uk>
parents: 496
diff changeset
   348
   apply(simp)
c92a41d9c4da updated paper and theories to include n-times
Christian Urban <christian.urban@kcl.ac.uk>
parents: 496
diff changeset
   349
  (* NTIMES *)
c92a41d9c4da updated paper and theories to include n-times
Christian Urban <christian.urban@kcl.ac.uk>
parents: 496
diff changeset
   350
  apply(auto elim!: Prf_elims)[1]
c92a41d9c4da updated paper and theories to include n-times
Christian Urban <christian.urban@kcl.ac.uk>
parents: 496
diff changeset
   351
  apply(case_tac vs1)
c92a41d9c4da updated paper and theories to include n-times
Christian Urban <christian.urban@kcl.ac.uk>
parents: 496
diff changeset
   352
   apply(simp_all)
c92a41d9c4da updated paper and theories to include n-times
Christian Urban <christian.urban@kcl.ac.uk>
parents: 496
diff changeset
   353
  apply(case_tac vs2)
c92a41d9c4da updated paper and theories to include n-times
Christian Urban <christian.urban@kcl.ac.uk>
parents: 496
diff changeset
   354
   apply(simp_all)
495
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   355
  done
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   356
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   357
lemma retrieve_fuse:
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   358
  assumes "\<Turnstile> v : r"
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   359
  shows "retrieve (fuse bs (intern r)) v = bs @ retrieve (intern r) v"
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   360
  using assms 
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   361
  by (simp_all add: retrieve_fuse2)
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   362
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   363
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   364
lemma retrieve_code:
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   365
  assumes "\<Turnstile> v : r"
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   366
  shows "code v = retrieve (intern r) v"
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   367
  using assms
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   368
  apply(induct v r )
563
c92a41d9c4da updated paper and theories to include n-times
Christian Urban <christian.urban@kcl.ac.uk>
parents: 496
diff changeset
   369
        apply(simp_all add: retrieve_fuse retrieve_encode_STARS)
c92a41d9c4da updated paper and theories to include n-times
Christian Urban <christian.urban@kcl.ac.uk>
parents: 496
diff changeset
   370
  apply(subst retrieve_encode_NTIMES)
c92a41d9c4da updated paper and theories to include n-times
Christian Urban <christian.urban@kcl.ac.uk>
parents: 496
diff changeset
   371
    apply(auto)
c92a41d9c4da updated paper and theories to include n-times
Christian Urban <christian.urban@kcl.ac.uk>
parents: 496
diff changeset
   372
  done 
c92a41d9c4da updated paper and theories to include n-times
Christian Urban <christian.urban@kcl.ac.uk>
parents: 496
diff changeset
   373
 
495
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   374
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   375
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   376
lemma retrieve_AALTs_bnullable1:
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   377
  assumes "bnullable r"
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   378
  shows "retrieve (AALTs bs (r # rs)) (mkeps (erase (AALTs bs (r # rs))))
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   379
         = bs @ retrieve r (mkeps (erase r))"
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   380
  using assms
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   381
  apply(case_tac rs)
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   382
  apply(auto simp add: bnullable_correctness)
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   383
  done
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   384
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   385
lemma retrieve_AALTs_bnullable2:
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   386
  assumes "\<not>bnullable r" "bnullables rs"
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   387
  shows "retrieve (AALTs bs (r # rs)) (mkeps (erase (AALTs bs (r # rs))))
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   388
         = retrieve (AALTs bs rs) (mkeps (erase (AALTs bs rs)))"
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   389
  using assms
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   390
  apply(induct rs arbitrary: r bs)
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   391
  apply(auto)
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   392
  using bnullable_correctness apply blast
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   393
  apply(case_tac rs)
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   394
  apply(auto)
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   395
  using bnullable_correctness apply blast
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   396
  apply(case_tac rs)
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   397
  apply(auto)
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   398
  done
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   399
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   400
lemma bmkeps_retrieve_AALTs: 
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   401
  assumes "\<forall>r \<in> set rs. bnullable r \<longrightarrow> bmkeps r = retrieve r (mkeps (erase r))" 
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   402
          "bnullables rs"
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   403
  shows "bs @ bmkepss rs = retrieve (AALTs bs rs) (mkeps (erase (AALTs bs rs)))"
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   404
 using assms
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   405
  apply(induct rs arbitrary: bs)
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   406
  apply(auto)
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   407
  using retrieve_AALTs_bnullable1 apply presburger
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   408
  apply (metis retrieve_AALTs_bnullable2)
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   409
  apply (simp add: retrieve_AALTs_bnullable1)
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   410
  by (metis retrieve_AALTs_bnullable2)
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   411
563
c92a41d9c4da updated paper and theories to include n-times
Christian Urban <christian.urban@kcl.ac.uk>
parents: 496
diff changeset
   412
lemma bmkeps_retrieve_ANTIMES: 
c92a41d9c4da updated paper and theories to include n-times
Christian Urban <christian.urban@kcl.ac.uk>
parents: 496
diff changeset
   413
  assumes "if n = 0 then True else bmkeps r = retrieve r (mkeps (erase r))" 
c92a41d9c4da updated paper and theories to include n-times
Christian Urban <christian.urban@kcl.ac.uk>
parents: 496
diff changeset
   414
  and     "bnullable (ANTIMES bs r n)"
c92a41d9c4da updated paper and theories to include n-times
Christian Urban <christian.urban@kcl.ac.uk>
parents: 496
diff changeset
   415
  shows "bmkeps (ANTIMES bs r n) = retrieve (ANTIMES bs r n) (Stars (replicate n (mkeps (erase r))))"
c92a41d9c4da updated paper and theories to include n-times
Christian Urban <christian.urban@kcl.ac.uk>
parents: 496
diff changeset
   416
 using assms
c92a41d9c4da updated paper and theories to include n-times
Christian Urban <christian.urban@kcl.ac.uk>
parents: 496
diff changeset
   417
  apply(induct n arbitrary: r bs)
c92a41d9c4da updated paper and theories to include n-times
Christian Urban <christian.urban@kcl.ac.uk>
parents: 496
diff changeset
   418
  apply(auto)[1]
c92a41d9c4da updated paper and theories to include n-times
Christian Urban <christian.urban@kcl.ac.uk>
parents: 496
diff changeset
   419
  apply(simp)
c92a41d9c4da updated paper and theories to include n-times
Christian Urban <christian.urban@kcl.ac.uk>
parents: 496
diff changeset
   420
  done
c92a41d9c4da updated paper and theories to include n-times
Christian Urban <christian.urban@kcl.ac.uk>
parents: 496
diff changeset
   421
495
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   422
lemma bmkeps_retrieve:
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   423
  assumes "bnullable r"
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   424
  shows "bmkeps r = retrieve r (mkeps (erase r))"
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   425
  using assms
563
c92a41d9c4da updated paper and theories to include n-times
Christian Urban <christian.urban@kcl.ac.uk>
parents: 496
diff changeset
   426
  apply(induct r rule: bmkeps.induct)
c92a41d9c4da updated paper and theories to include n-times
Christian Urban <christian.urban@kcl.ac.uk>
parents: 496
diff changeset
   427
        apply(auto)
c92a41d9c4da updated paper and theories to include n-times
Christian Urban <christian.urban@kcl.ac.uk>
parents: 496
diff changeset
   428
  apply (simp add: retrieve_AALTs_bnullable1)
c92a41d9c4da updated paper and theories to include n-times
Christian Urban <christian.urban@kcl.ac.uk>
parents: 496
diff changeset
   429
  using retrieve_AALTs_bnullable1 apply force
569
5af61c89f51e updated paper and corresponding theories
Christian Urban <christian.urban@kcl.ac.uk>
parents: 563
diff changeset
   430
  apply(metis retrieve_AALTs_bnullable2)
5af61c89f51e updated paper and corresponding theories
Christian Urban <christian.urban@kcl.ac.uk>
parents: 563
diff changeset
   431
  by (metis Cons_eq_appendI One_nat_def Suc_diff_1 eq_Nil_appendI replicate_Suc retrieve.simps(10))  
563
c92a41d9c4da updated paper and theories to include n-times
Christian Urban <christian.urban@kcl.ac.uk>
parents: 496
diff changeset
   432
  
495
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   433
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   434
lemma bder_retrieve:
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   435
  assumes "\<Turnstile> v : der c (erase r)"
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   436
  shows "retrieve (bder c r) v = retrieve r (injval (erase r) c v)"
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   437
  using assms  
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   438
  apply(induct r arbitrary: v rule: erase.induct)
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   439
  using Prf_elims(1) apply auto[1]
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   440
  using Prf_elims(1) apply auto[1]
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   441
  apply(auto)[1]
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   442
  apply (metis Prf_elims(4) injval.simps(1) retrieve.simps(1) retrieve.simps(2))
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   443
  using Prf_elims(1) apply blast
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   444
  (* AALTs case *)
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   445
  apply(simp)
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   446
  apply(erule Prf_elims)
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   447
  apply(simp)
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   448
  apply(simp)
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   449
  apply(rename_tac "r\<^sub>1" "r\<^sub>2" rs v)
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   450
  apply(erule Prf_elims)
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   451
  apply(simp)
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   452
  apply(simp)
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   453
  apply(case_tac rs)
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   454
  apply(simp)
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   455
  apply(simp)
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   456
  using Prf_elims(3) apply fastforce
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   457
  (* ASEQ case *) 
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   458
  apply(simp)
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   459
  apply(case_tac "nullable (erase r1)")
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   460
  apply(simp)
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   461
  apply(erule Prf_elims)
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   462
  using Prf_elims(2) bnullable_correctness apply force
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   463
  apply (simp add: bmkeps_retrieve bnullable_correctness retrieve_fuse2)
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   464
  apply (simp add: bmkeps_retrieve bnullable_correctness retrieve_fuse2)
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   465
  using Prf_elims(2) apply force
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   466
  (* ASTAR case *)  
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   467
  apply(rename_tac bs r v)
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   468
  apply(simp)  
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   469
  apply(erule Prf_elims)
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   470
  apply(clarify)
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   471
  apply(erule Prf_elims)
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   472
  apply(clarify)
563
c92a41d9c4da updated paper and theories to include n-times
Christian Urban <christian.urban@kcl.ac.uk>
parents: 496
diff changeset
   473
   apply (simp add: retrieve_fuse2)
c92a41d9c4da updated paper and theories to include n-times
Christian Urban <christian.urban@kcl.ac.uk>
parents: 496
diff changeset
   474
  (* ANTIMES case *)
c92a41d9c4da updated paper and theories to include n-times
Christian Urban <christian.urban@kcl.ac.uk>
parents: 496
diff changeset
   475
  apply(auto)  
c92a41d9c4da updated paper and theories to include n-times
Christian Urban <christian.urban@kcl.ac.uk>
parents: 496
diff changeset
   476
  apply(erule Prf_elims)
c92a41d9c4da updated paper and theories to include n-times
Christian Urban <christian.urban@kcl.ac.uk>
parents: 496
diff changeset
   477
  apply(erule Prf_elims)
c92a41d9c4da updated paper and theories to include n-times
Christian Urban <christian.urban@kcl.ac.uk>
parents: 496
diff changeset
   478
  apply(clarify)
c92a41d9c4da updated paper and theories to include n-times
Christian Urban <christian.urban@kcl.ac.uk>
parents: 496
diff changeset
   479
  apply(erule Prf_elims)
c92a41d9c4da updated paper and theories to include n-times
Christian Urban <christian.urban@kcl.ac.uk>
parents: 496
diff changeset
   480
  apply(clarify)
c92a41d9c4da updated paper and theories to include n-times
Christian Urban <christian.urban@kcl.ac.uk>
parents: 496
diff changeset
   481
  by (metis (full_types) Suc_pred append_assoc injval.simps(8) retrieve.simps(10) retrieve.simps(6))
495
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   482
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   483
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   484
lemma MAIN_decode:
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   485
  assumes "\<Turnstile> v : ders s r"
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   486
  shows "Some (flex r id s v) = decode (retrieve (bders (intern r) s) v) r"
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   487
  using assms
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   488
proof (induct s arbitrary: v rule: rev_induct)
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   489
  case Nil
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   490
  have "\<Turnstile> v : ders [] r" by fact
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   491
  then have "\<Turnstile> v : r" by simp
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   492
  then have "Some v = decode (retrieve (intern r) v) r"
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   493
    using decode_code retrieve_code by auto
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   494
  then show "Some (flex r id [] v) = decode (retrieve (bders (intern r) []) v) r"
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   495
    by simp
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   496
next
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   497
  case (snoc c s v)
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   498
  have IH: "\<And>v. \<Turnstile> v : ders s r \<Longrightarrow> 
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   499
     Some (flex r id s v) = decode (retrieve (bders (intern r) s) v) r" by fact
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   500
  have asm: "\<Turnstile> v : ders (s @ [c]) r" by fact
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   501
  then have asm2: "\<Turnstile> injval (ders s r) c v : ders s r" 
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   502
    by (simp add: Prf_injval ders_append)
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   503
  have "Some (flex r id (s @ [c]) v) = Some (flex r id s (injval (ders s r) c v))"
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   504
    by (simp add: flex_append)
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   505
  also have "... = decode (retrieve (bders (intern r) s) (injval (ders s r) c v)) r"
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   506
    using asm2 IH by simp
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   507
  also have "... = decode (retrieve (bder c (bders (intern r) s)) v) r"
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   508
    using asm by (simp_all add: bder_retrieve ders_append)
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   509
  finally show "Some (flex r id (s @ [c]) v) = 
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   510
                 decode (retrieve (bders (intern r) (s @ [c])) v) r" by (simp add: bders_append)
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   511
qed
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   512
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   513
definition blexer where
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   514
 "blexer r s \<equiv> if bnullable (bders (intern r) s) then 
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   515
                decode (bmkeps (bders (intern r) s)) r else None"
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   516
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   517
lemma blexer_correctness:
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   518
  shows "blexer r s = lexer r s"
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   519
proof -
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   520
  { define bds where "bds \<equiv> bders (intern r) s"
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   521
    define ds  where "ds \<equiv> ders s r"
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   522
    assume asm: "nullable ds"
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   523
    have era: "erase bds = ds" 
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   524
      unfolding ds_def bds_def by simp
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   525
    have mke: "\<Turnstile> mkeps ds : ds"
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   526
      using asm by (simp add: mkeps_nullable)
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   527
    have "decode (bmkeps bds) r = decode (retrieve bds (mkeps ds)) r"
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   528
      using bmkeps_retrieve
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   529
      using asm era
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   530
      using bnullable_correctness by force 
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   531
    also have "... =  Some (flex r id s (mkeps ds))"
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   532
      using mke by (simp_all add: MAIN_decode ds_def bds_def)
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   533
    finally have "decode (bmkeps bds) r = Some (flex r id s (mkeps ds))" 
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   534
      unfolding bds_def ds_def .
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   535
  }
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   536
  then show "blexer r s = lexer r s"
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   537
    unfolding blexer_def lexer_flex
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   538
    by (auto simp add: bnullable_correctness[symmetric])
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   539
qed
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   540
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   541
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   542
unused_thms
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   543
f9cdc295ccf7 a fresh directory with cleaned up code
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   544
end