thys/BitCoded.thy
author Christian Urban <urbanc@in.tum.de>
Wed, 13 Mar 2019 10:36:29 +0000
changeset 314 20a57552d722
parent 313 3b8e3a156200
child 316 0eaa1851a5b6
permissions -rw-r--r--
updated
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
148
702ed601349b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
     1
   
311
8b8db9558ecf updated
Christian Urban <urbanc@in.tum.de>
parents: 307
diff changeset
     2
theory BitCoded
286
804fbb227568 added proof for bitcoded algorithm
Christian Urban <urbanc@in.tum.de>
parents: 256
diff changeset
     3
  imports "Lexer" 
148
702ed601349b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
     4
begin
702ed601349b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
     5
154
2de3cf684ba0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 148
diff changeset
     6
section {* Bit-Encodings *}
2de3cf684ba0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 148
diff changeset
     7
289
807acaf7f599 updated
Christian Urban <urbanc@in.tum.de>
parents: 288
diff changeset
     8
datatype bit = Z | S
807acaf7f599 updated
Christian Urban <urbanc@in.tum.de>
parents: 288
diff changeset
     9
154
2de3cf684ba0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 148
diff changeset
    10
fun 
289
807acaf7f599 updated
Christian Urban <urbanc@in.tum.de>
parents: 288
diff changeset
    11
  code :: "val \<Rightarrow> bit list"
154
2de3cf684ba0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 148
diff changeset
    12
where
286
804fbb227568 added proof for bitcoded algorithm
Christian Urban <urbanc@in.tum.de>
parents: 256
diff changeset
    13
  "code Void = []"
804fbb227568 added proof for bitcoded algorithm
Christian Urban <urbanc@in.tum.de>
parents: 256
diff changeset
    14
| "code (Char c) = []"
289
807acaf7f599 updated
Christian Urban <urbanc@in.tum.de>
parents: 288
diff changeset
    15
| "code (Left v) = Z # (code v)"
807acaf7f599 updated
Christian Urban <urbanc@in.tum.de>
parents: 288
diff changeset
    16
| "code (Right v) = S # (code v)"
286
804fbb227568 added proof for bitcoded algorithm
Christian Urban <urbanc@in.tum.de>
parents: 256
diff changeset
    17
| "code (Seq v1 v2) = (code v1) @ (code v2)"
289
807acaf7f599 updated
Christian Urban <urbanc@in.tum.de>
parents: 288
diff changeset
    18
| "code (Stars []) = [S]"
807acaf7f599 updated
Christian Urban <urbanc@in.tum.de>
parents: 288
diff changeset
    19
| "code (Stars (v # vs)) =  (Z # code v) @ code (Stars vs)"
286
804fbb227568 added proof for bitcoded algorithm
Christian Urban <urbanc@in.tum.de>
parents: 256
diff changeset
    20
154
2de3cf684ba0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 148
diff changeset
    21
2de3cf684ba0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 148
diff changeset
    22
fun 
2de3cf684ba0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 148
diff changeset
    23
  Stars_add :: "val \<Rightarrow> val \<Rightarrow> val"
2de3cf684ba0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 148
diff changeset
    24
where
2de3cf684ba0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 148
diff changeset
    25
  "Stars_add v (Stars vs) = Stars (v # vs)"
2de3cf684ba0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 148
diff changeset
    26
2de3cf684ba0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 148
diff changeset
    27
function
289
807acaf7f599 updated
Christian Urban <urbanc@in.tum.de>
parents: 288
diff changeset
    28
  decode' :: "bit list \<Rightarrow> rexp \<Rightarrow> (val * bit list)"
154
2de3cf684ba0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 148
diff changeset
    29
where
2de3cf684ba0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 148
diff changeset
    30
  "decode' ds ZERO = (Void, [])"
2de3cf684ba0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 148
diff changeset
    31
| "decode' ds ONE = (Void, ds)"
2de3cf684ba0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 148
diff changeset
    32
| "decode' ds (CHAR d) = (Char d, ds)"
2de3cf684ba0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 148
diff changeset
    33
| "decode' [] (ALT r1 r2) = (Void, [])"
289
807acaf7f599 updated
Christian Urban <urbanc@in.tum.de>
parents: 288
diff changeset
    34
| "decode' (Z # ds) (ALT r1 r2) = (let (v, ds') = decode' ds r1 in (Left v, ds'))"
807acaf7f599 updated
Christian Urban <urbanc@in.tum.de>
parents: 288
diff changeset
    35
| "decode' (S # ds) (ALT r1 r2) = (let (v, ds') = decode' ds r2 in (Right v, ds'))"
154
2de3cf684ba0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 148
diff changeset
    36
| "decode' ds (SEQ r1 r2) = (let (v1, ds') = decode' ds r1 in
2de3cf684ba0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 148
diff changeset
    37
                             let (v2, ds'') = decode' ds' r2 in (Seq v1 v2, ds''))"
2de3cf684ba0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 148
diff changeset
    38
| "decode' [] (STAR r) = (Void, [])"
289
807acaf7f599 updated
Christian Urban <urbanc@in.tum.de>
parents: 288
diff changeset
    39
| "decode' (S # ds) (STAR r) = (Stars [], ds)"
807acaf7f599 updated
Christian Urban <urbanc@in.tum.de>
parents: 288
diff changeset
    40
| "decode' (Z # ds) (STAR r) = (let (v, ds') = decode' ds r in
154
2de3cf684ba0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 148
diff changeset
    41
                                    let (vs, ds'') = decode' ds' (STAR r) 
2de3cf684ba0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 148
diff changeset
    42
                                    in (Stars_add v vs, ds''))"
2de3cf684ba0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 148
diff changeset
    43
by pat_completeness auto
2de3cf684ba0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 148
diff changeset
    44
2de3cf684ba0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 148
diff changeset
    45
lemma decode'_smaller:
2de3cf684ba0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 148
diff changeset
    46
  assumes "decode'_dom (ds, r)"
2de3cf684ba0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 148
diff changeset
    47
  shows "length (snd (decode' ds r)) \<le> length ds"
2de3cf684ba0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 148
diff changeset
    48
using assms
2de3cf684ba0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 148
diff changeset
    49
apply(induct ds r)
2de3cf684ba0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 148
diff changeset
    50
apply(auto simp add: decode'.psimps split: prod.split)
2de3cf684ba0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 148
diff changeset
    51
using dual_order.trans apply blast
2de3cf684ba0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 148
diff changeset
    52
by (meson dual_order.trans le_SucI)
2de3cf684ba0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 148
diff changeset
    53
2de3cf684ba0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 148
diff changeset
    54
termination "decode'"  
2de3cf684ba0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 148
diff changeset
    55
apply(relation "inv_image (measure(%cs. size cs) <*lex*> measure(%s. size s)) (%(ds,r). (r,ds))") 
2de3cf684ba0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 148
diff changeset
    56
apply(auto dest!: decode'_smaller)
2de3cf684ba0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 148
diff changeset
    57
by (metis less_Suc_eq_le snd_conv)
2de3cf684ba0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 148
diff changeset
    58
286
804fbb227568 added proof for bitcoded algorithm
Christian Urban <urbanc@in.tum.de>
parents: 256
diff changeset
    59
definition
289
807acaf7f599 updated
Christian Urban <urbanc@in.tum.de>
parents: 288
diff changeset
    60
  decode :: "bit list \<Rightarrow> rexp \<Rightarrow> val option"
154
2de3cf684ba0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 148
diff changeset
    61
where
286
804fbb227568 added proof for bitcoded algorithm
Christian Urban <urbanc@in.tum.de>
parents: 256
diff changeset
    62
  "decode ds r \<equiv> (let (v, ds') = decode' ds r 
154
2de3cf684ba0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 148
diff changeset
    63
                  in (if ds' = [] then Some v else None))"
2de3cf684ba0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 148
diff changeset
    64
286
804fbb227568 added proof for bitcoded algorithm
Christian Urban <urbanc@in.tum.de>
parents: 256
diff changeset
    65
lemma decode'_code_Stars:
804fbb227568 added proof for bitcoded algorithm
Christian Urban <urbanc@in.tum.de>
parents: 256
diff changeset
    66
  assumes "\<forall>v\<in>set vs. \<Turnstile> v : r \<and> (\<forall>x. decode' (code v @ x) r = (v, x)) \<and> flat v \<noteq> []" 
804fbb227568 added proof for bitcoded algorithm
Christian Urban <urbanc@in.tum.de>
parents: 256
diff changeset
    67
  shows "decode' (code (Stars vs) @ ds) (STAR r) = (Stars vs, ds)"
804fbb227568 added proof for bitcoded algorithm
Christian Urban <urbanc@in.tum.de>
parents: 256
diff changeset
    68
  using assms
804fbb227568 added proof for bitcoded algorithm
Christian Urban <urbanc@in.tum.de>
parents: 256
diff changeset
    69
  apply(induct vs)
804fbb227568 added proof for bitcoded algorithm
Christian Urban <urbanc@in.tum.de>
parents: 256
diff changeset
    70
  apply(auto)
804fbb227568 added proof for bitcoded algorithm
Christian Urban <urbanc@in.tum.de>
parents: 256
diff changeset
    71
  done
804fbb227568 added proof for bitcoded algorithm
Christian Urban <urbanc@in.tum.de>
parents: 256
diff changeset
    72
154
2de3cf684ba0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 148
diff changeset
    73
lemma decode'_code:
286
804fbb227568 added proof for bitcoded algorithm
Christian Urban <urbanc@in.tum.de>
parents: 256
diff changeset
    74
  assumes "\<Turnstile> v : r"
804fbb227568 added proof for bitcoded algorithm
Christian Urban <urbanc@in.tum.de>
parents: 256
diff changeset
    75
  shows "decode' ((code v) @ ds) r = (v, ds)"
154
2de3cf684ba0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 148
diff changeset
    76
using assms
286
804fbb227568 added proof for bitcoded algorithm
Christian Urban <urbanc@in.tum.de>
parents: 256
diff changeset
    77
  apply(induct v r arbitrary: ds) 
804fbb227568 added proof for bitcoded algorithm
Christian Urban <urbanc@in.tum.de>
parents: 256
diff changeset
    78
  apply(auto)
804fbb227568 added proof for bitcoded algorithm
Christian Urban <urbanc@in.tum.de>
parents: 256
diff changeset
    79
  using decode'_code_Stars by blast
154
2de3cf684ba0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 148
diff changeset
    80
2de3cf684ba0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 148
diff changeset
    81
lemma decode_code:
286
804fbb227568 added proof for bitcoded algorithm
Christian Urban <urbanc@in.tum.de>
parents: 256
diff changeset
    82
  assumes "\<Turnstile> v : r"
804fbb227568 added proof for bitcoded algorithm
Christian Urban <urbanc@in.tum.de>
parents: 256
diff changeset
    83
  shows "decode (code v) r = Some v"
804fbb227568 added proof for bitcoded algorithm
Christian Urban <urbanc@in.tum.de>
parents: 256
diff changeset
    84
  using assms unfolding decode_def
804fbb227568 added proof for bitcoded algorithm
Christian Urban <urbanc@in.tum.de>
parents: 256
diff changeset
    85
  by (smt append_Nil2 decode'_code old.prod.case)
804fbb227568 added proof for bitcoded algorithm
Christian Urban <urbanc@in.tum.de>
parents: 256
diff changeset
    86
154
2de3cf684ba0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 148
diff changeset
    87
311
8b8db9558ecf updated
Christian Urban <urbanc@in.tum.de>
parents: 307
diff changeset
    88
section {* Annotated Regular Expressions *}
8b8db9558ecf updated
Christian Urban <urbanc@in.tum.de>
parents: 307
diff changeset
    89
314
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
    90
datatype arexp = 
159
940530087f30 updated programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 154
diff changeset
    91
  AZERO
289
807acaf7f599 updated
Christian Urban <urbanc@in.tum.de>
parents: 288
diff changeset
    92
| AONE "bit list"
807acaf7f599 updated
Christian Urban <urbanc@in.tum.de>
parents: 288
diff changeset
    93
| ACHAR "bit list" char
807acaf7f599 updated
Christian Urban <urbanc@in.tum.de>
parents: 288
diff changeset
    94
| ASEQ "bit list" arexp arexp
311
8b8db9558ecf updated
Christian Urban <urbanc@in.tum.de>
parents: 307
diff changeset
    95
| AALTs "bit list" "arexp list"
289
807acaf7f599 updated
Christian Urban <urbanc@in.tum.de>
parents: 288
diff changeset
    96
| ASTAR "bit list" arexp
159
940530087f30 updated programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 154
diff changeset
    97
311
8b8db9558ecf updated
Christian Urban <urbanc@in.tum.de>
parents: 307
diff changeset
    98
abbreviation
8b8db9558ecf updated
Christian Urban <urbanc@in.tum.de>
parents: 307
diff changeset
    99
  "AALT bs r1 r2 \<equiv> AALTs bs [r1, r2]"
8b8db9558ecf updated
Christian Urban <urbanc@in.tum.de>
parents: 307
diff changeset
   100
8b8db9558ecf updated
Christian Urban <urbanc@in.tum.de>
parents: 307
diff changeset
   101
289
807acaf7f599 updated
Christian Urban <urbanc@in.tum.de>
parents: 288
diff changeset
   102
fun fuse :: "bit list \<Rightarrow> arexp \<Rightarrow> arexp" where
159
940530087f30 updated programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 154
diff changeset
   103
  "fuse bs AZERO = AZERO"
940530087f30 updated programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 154
diff changeset
   104
| "fuse bs (AONE cs) = AONE (bs @ cs)" 
940530087f30 updated programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 154
diff changeset
   105
| "fuse bs (ACHAR cs c) = ACHAR (bs @ cs) c"
311
8b8db9558ecf updated
Christian Urban <urbanc@in.tum.de>
parents: 307
diff changeset
   106
| "fuse bs (AALTs cs rs) = AALTs (bs @ cs) rs"
159
940530087f30 updated programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 154
diff changeset
   107
| "fuse bs (ASEQ cs r1 r2) = ASEQ (bs @ cs) r1 r2"
940530087f30 updated programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 154
diff changeset
   108
| "fuse bs (ASTAR cs r) = ASTAR (bs @ cs) r"
940530087f30 updated programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 154
diff changeset
   109
314
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   110
lemma fuse_append:
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   111
  shows "fuse (bs1 @ bs2) r = fuse bs1 (fuse bs2 r)"
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   112
  apply(induct r)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   113
  apply(auto)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   114
  done
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   115
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   116
289
807acaf7f599 updated
Christian Urban <urbanc@in.tum.de>
parents: 288
diff changeset
   117
fun intern :: "rexp \<Rightarrow> arexp" where
807acaf7f599 updated
Christian Urban <urbanc@in.tum.de>
parents: 288
diff changeset
   118
  "intern ZERO = AZERO"
807acaf7f599 updated
Christian Urban <urbanc@in.tum.de>
parents: 288
diff changeset
   119
| "intern ONE = AONE []"
807acaf7f599 updated
Christian Urban <urbanc@in.tum.de>
parents: 288
diff changeset
   120
| "intern (CHAR c) = ACHAR [] c"
807acaf7f599 updated
Christian Urban <urbanc@in.tum.de>
parents: 288
diff changeset
   121
| "intern (ALT r1 r2) = AALT [] (fuse [Z] (intern r1)) 
295
c6ec5f369037 updated
Christian Urban <urbanc@in.tum.de>
parents: 293
diff changeset
   122
                                (fuse [S]  (intern r2))"
289
807acaf7f599 updated
Christian Urban <urbanc@in.tum.de>
parents: 288
diff changeset
   123
| "intern (SEQ r1 r2) = ASEQ [] (intern r1) (intern r2)"
807acaf7f599 updated
Christian Urban <urbanc@in.tum.de>
parents: 288
diff changeset
   124
| "intern (STAR r) = ASTAR [] (intern r)"
159
940530087f30 updated programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 154
diff changeset
   125
286
804fbb227568 added proof for bitcoded algorithm
Christian Urban <urbanc@in.tum.de>
parents: 256
diff changeset
   126
289
807acaf7f599 updated
Christian Urban <urbanc@in.tum.de>
parents: 288
diff changeset
   127
fun retrieve :: "arexp \<Rightarrow> val \<Rightarrow> bit list" where
159
940530087f30 updated programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 154
diff changeset
   128
  "retrieve (AONE bs) Void = bs"
940530087f30 updated programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 154
diff changeset
   129
| "retrieve (ACHAR bs c) (Char d) = bs"
313
3b8e3a156200 adapted the Bitcoded correctness proof to using AALTs
Christian Urban <urbanc@in.tum.de>
parents: 311
diff changeset
   130
| "retrieve (AALTs bs [r]) v = bs @ retrieve r v" 
311
8b8db9558ecf updated
Christian Urban <urbanc@in.tum.de>
parents: 307
diff changeset
   131
| "retrieve (AALTs bs (r#rs)) (Left v) = bs @ retrieve r v"
8b8db9558ecf updated
Christian Urban <urbanc@in.tum.de>
parents: 307
diff changeset
   132
| "retrieve (AALTs bs (r#rs)) (Right v) = bs @ retrieve (AALTs [] rs) v"
159
940530087f30 updated programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 154
diff changeset
   133
| "retrieve (ASEQ bs r1 r2) (Seq v1 v2) = bs @ retrieve r1 v1 @ retrieve r2 v2"
289
807acaf7f599 updated
Christian Urban <urbanc@in.tum.de>
parents: 288
diff changeset
   134
| "retrieve (ASTAR bs r) (Stars []) = bs @ [S]"
159
940530087f30 updated programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 154
diff changeset
   135
| "retrieve (ASTAR bs r) (Stars (v#vs)) = 
289
807acaf7f599 updated
Christian Urban <urbanc@in.tum.de>
parents: 288
diff changeset
   136
     bs @ [Z] @ retrieve r v @ retrieve (ASTAR [] r) (Stars vs)"
286
804fbb227568 added proof for bitcoded algorithm
Christian Urban <urbanc@in.tum.de>
parents: 256
diff changeset
   137
804fbb227568 added proof for bitcoded algorithm
Christian Urban <urbanc@in.tum.de>
parents: 256
diff changeset
   138
fun 
289
807acaf7f599 updated
Christian Urban <urbanc@in.tum.de>
parents: 288
diff changeset
   139
  erase :: "arexp \<Rightarrow> rexp"
807acaf7f599 updated
Christian Urban <urbanc@in.tum.de>
parents: 288
diff changeset
   140
where
807acaf7f599 updated
Christian Urban <urbanc@in.tum.de>
parents: 288
diff changeset
   141
  "erase AZERO = ZERO"
807acaf7f599 updated
Christian Urban <urbanc@in.tum.de>
parents: 288
diff changeset
   142
| "erase (AONE _) = ONE"
807acaf7f599 updated
Christian Urban <urbanc@in.tum.de>
parents: 288
diff changeset
   143
| "erase (ACHAR _ c) = CHAR c"
311
8b8db9558ecf updated
Christian Urban <urbanc@in.tum.de>
parents: 307
diff changeset
   144
| "erase (AALTs _ []) = ZERO"
8b8db9558ecf updated
Christian Urban <urbanc@in.tum.de>
parents: 307
diff changeset
   145
| "erase (AALTs _ [r]) = (erase r)"
313
3b8e3a156200 adapted the Bitcoded correctness proof to using AALTs
Christian Urban <urbanc@in.tum.de>
parents: 311
diff changeset
   146
| "erase (AALTs bs (r#rs)) = ALT (erase r) (erase (AALTs bs rs))"
289
807acaf7f599 updated
Christian Urban <urbanc@in.tum.de>
parents: 288
diff changeset
   147
| "erase (ASEQ _ r1 r2) = SEQ (erase r1) (erase r2)"
807acaf7f599 updated
Christian Urban <urbanc@in.tum.de>
parents: 288
diff changeset
   148
| "erase (ASTAR _ r) = STAR (erase r)"
807acaf7f599 updated
Christian Urban <urbanc@in.tum.de>
parents: 288
diff changeset
   149
807acaf7f599 updated
Christian Urban <urbanc@in.tum.de>
parents: 288
diff changeset
   150
fun
807acaf7f599 updated
Christian Urban <urbanc@in.tum.de>
parents: 288
diff changeset
   151
 bnullable :: "arexp \<Rightarrow> bool"
286
804fbb227568 added proof for bitcoded algorithm
Christian Urban <urbanc@in.tum.de>
parents: 256
diff changeset
   152
where
289
807acaf7f599 updated
Christian Urban <urbanc@in.tum.de>
parents: 288
diff changeset
   153
  "bnullable (AZERO) = False"
807acaf7f599 updated
Christian Urban <urbanc@in.tum.de>
parents: 288
diff changeset
   154
| "bnullable (AONE bs) = True"
807acaf7f599 updated
Christian Urban <urbanc@in.tum.de>
parents: 288
diff changeset
   155
| "bnullable (ACHAR bs c) = False"
311
8b8db9558ecf updated
Christian Urban <urbanc@in.tum.de>
parents: 307
diff changeset
   156
| "bnullable (AALTs bs rs) = (\<exists>r \<in> set rs. bnullable r)"
289
807acaf7f599 updated
Christian Urban <urbanc@in.tum.de>
parents: 288
diff changeset
   157
| "bnullable (ASEQ bs r1 r2) = (bnullable r1 \<and> bnullable r2)"
807acaf7f599 updated
Christian Urban <urbanc@in.tum.de>
parents: 288
diff changeset
   158
| "bnullable (ASTAR bs r) = True"
286
804fbb227568 added proof for bitcoded algorithm
Christian Urban <urbanc@in.tum.de>
parents: 256
diff changeset
   159
289
807acaf7f599 updated
Christian Urban <urbanc@in.tum.de>
parents: 288
diff changeset
   160
fun 
807acaf7f599 updated
Christian Urban <urbanc@in.tum.de>
parents: 288
diff changeset
   161
  bmkeps :: "arexp \<Rightarrow> bit list"
807acaf7f599 updated
Christian Urban <urbanc@in.tum.de>
parents: 288
diff changeset
   162
where
807acaf7f599 updated
Christian Urban <urbanc@in.tum.de>
parents: 288
diff changeset
   163
  "bmkeps(AONE bs) = bs"
807acaf7f599 updated
Christian Urban <urbanc@in.tum.de>
parents: 288
diff changeset
   164
| "bmkeps(ASEQ bs r1 r2) = bs @ (bmkeps r1) @ (bmkeps r2)"
313
3b8e3a156200 adapted the Bitcoded correctness proof to using AALTs
Christian Urban <urbanc@in.tum.de>
parents: 311
diff changeset
   165
| "bmkeps(AALTs bs [r]) = bs @ (bmkeps r)"
311
8b8db9558ecf updated
Christian Urban <urbanc@in.tum.de>
parents: 307
diff changeset
   166
| "bmkeps(AALTs bs (r#rs)) = (if bnullable(r) then bs @ (bmkeps r) else (bmkeps (AALTs bs rs)))"
289
807acaf7f599 updated
Christian Urban <urbanc@in.tum.de>
parents: 288
diff changeset
   167
| "bmkeps(ASTAR bs r) = bs @ [S]"
286
804fbb227568 added proof for bitcoded algorithm
Christian Urban <urbanc@in.tum.de>
parents: 256
diff changeset
   168
804fbb227568 added proof for bitcoded algorithm
Christian Urban <urbanc@in.tum.de>
parents: 256
diff changeset
   169
159
940530087f30 updated programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 154
diff changeset
   170
fun
289
807acaf7f599 updated
Christian Urban <urbanc@in.tum.de>
parents: 288
diff changeset
   171
 bder :: "char \<Rightarrow> arexp \<Rightarrow> arexp"
159
940530087f30 updated programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 154
diff changeset
   172
where
289
807acaf7f599 updated
Christian Urban <urbanc@in.tum.de>
parents: 288
diff changeset
   173
  "bder c (AZERO) = AZERO"
807acaf7f599 updated
Christian Urban <urbanc@in.tum.de>
parents: 288
diff changeset
   174
| "bder c (AONE bs) = AZERO"
807acaf7f599 updated
Christian Urban <urbanc@in.tum.de>
parents: 288
diff changeset
   175
| "bder c (ACHAR bs d) = (if c = d then AONE bs else AZERO)"
311
8b8db9558ecf updated
Christian Urban <urbanc@in.tum.de>
parents: 307
diff changeset
   176
| "bder c (AALTs bs rs) = AALTs bs (map (bder c) rs)"
289
807acaf7f599 updated
Christian Urban <urbanc@in.tum.de>
parents: 288
diff changeset
   177
| "bder c (ASEQ bs r1 r2) = 
807acaf7f599 updated
Christian Urban <urbanc@in.tum.de>
parents: 288
diff changeset
   178
     (if bnullable r1
807acaf7f599 updated
Christian Urban <urbanc@in.tum.de>
parents: 288
diff changeset
   179
      then AALT bs (ASEQ [] (bder c r1) r2) (fuse (bmkeps r1) (bder c r2))
807acaf7f599 updated
Christian Urban <urbanc@in.tum.de>
parents: 288
diff changeset
   180
      else ASEQ bs (bder c r1) r2)"
807acaf7f599 updated
Christian Urban <urbanc@in.tum.de>
parents: 288
diff changeset
   181
| "bder c (ASTAR bs r) = ASEQ bs (fuse [Z] (bder c r)) (ASTAR [] r)"
159
940530087f30 updated programs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 154
diff changeset
   182
286
804fbb227568 added proof for bitcoded algorithm
Christian Urban <urbanc@in.tum.de>
parents: 256
diff changeset
   183
804fbb227568 added proof for bitcoded algorithm
Christian Urban <urbanc@in.tum.de>
parents: 256
diff changeset
   184
fun 
289
807acaf7f599 updated
Christian Urban <urbanc@in.tum.de>
parents: 288
diff changeset
   185
  bders :: "arexp \<Rightarrow> string \<Rightarrow> arexp"
286
804fbb227568 added proof for bitcoded algorithm
Christian Urban <urbanc@in.tum.de>
parents: 256
diff changeset
   186
where
289
807acaf7f599 updated
Christian Urban <urbanc@in.tum.de>
parents: 288
diff changeset
   187
  "bders r [] = r"
807acaf7f599 updated
Christian Urban <urbanc@in.tum.de>
parents: 288
diff changeset
   188
| "bders r (c#s) = bders (bder c r) s"
286
804fbb227568 added proof for bitcoded algorithm
Christian Urban <urbanc@in.tum.de>
parents: 256
diff changeset
   189
289
807acaf7f599 updated
Christian Urban <urbanc@in.tum.de>
parents: 288
diff changeset
   190
lemma bders_append:
807acaf7f599 updated
Christian Urban <urbanc@in.tum.de>
parents: 288
diff changeset
   191
  "bders r (s1 @ s2) = bders (bders r s1) s2"
287
95b3880d428f updated
Christian Urban <urbanc@in.tum.de>
parents: 286
diff changeset
   192
  apply(induct s1 arbitrary: r s2)
95b3880d428f updated
Christian Urban <urbanc@in.tum.de>
parents: 286
diff changeset
   193
  apply(simp_all)
95b3880d428f updated
Christian Urban <urbanc@in.tum.de>
parents: 286
diff changeset
   194
  done
286
804fbb227568 added proof for bitcoded algorithm
Christian Urban <urbanc@in.tum.de>
parents: 256
diff changeset
   195
289
807acaf7f599 updated
Christian Urban <urbanc@in.tum.de>
parents: 288
diff changeset
   196
lemma bnullable_correctness:
807acaf7f599 updated
Christian Urban <urbanc@in.tum.de>
parents: 288
diff changeset
   197
  shows "nullable (erase r) = bnullable r"
311
8b8db9558ecf updated
Christian Urban <urbanc@in.tum.de>
parents: 307
diff changeset
   198
  apply(induct r rule: erase.induct)
286
804fbb227568 added proof for bitcoded algorithm
Christian Urban <urbanc@in.tum.de>
parents: 256
diff changeset
   199
  apply(simp_all)
804fbb227568 added proof for bitcoded algorithm
Christian Urban <urbanc@in.tum.de>
parents: 256
diff changeset
   200
  done
804fbb227568 added proof for bitcoded algorithm
Christian Urban <urbanc@in.tum.de>
parents: 256
diff changeset
   201
289
807acaf7f599 updated
Christian Urban <urbanc@in.tum.de>
parents: 288
diff changeset
   202
lemma erase_fuse:
807acaf7f599 updated
Christian Urban <urbanc@in.tum.de>
parents: 288
diff changeset
   203
  shows "erase (fuse bs r) = erase r"
311
8b8db9558ecf updated
Christian Urban <urbanc@in.tum.de>
parents: 307
diff changeset
   204
  apply(induct r rule: erase.induct)
286
804fbb227568 added proof for bitcoded algorithm
Christian Urban <urbanc@in.tum.de>
parents: 256
diff changeset
   205
  apply(simp_all)
804fbb227568 added proof for bitcoded algorithm
Christian Urban <urbanc@in.tum.de>
parents: 256
diff changeset
   206
  done
804fbb227568 added proof for bitcoded algorithm
Christian Urban <urbanc@in.tum.de>
parents: 256
diff changeset
   207
311
8b8db9558ecf updated
Christian Urban <urbanc@in.tum.de>
parents: 307
diff changeset
   208
lemma erase_intern [simp]:
289
807acaf7f599 updated
Christian Urban <urbanc@in.tum.de>
parents: 288
diff changeset
   209
  shows "erase (intern r) = r"
287
95b3880d428f updated
Christian Urban <urbanc@in.tum.de>
parents: 286
diff changeset
   210
  apply(induct r)
289
807acaf7f599 updated
Christian Urban <urbanc@in.tum.de>
parents: 288
diff changeset
   211
  apply(simp_all add: erase_fuse)
287
95b3880d428f updated
Christian Urban <urbanc@in.tum.de>
parents: 286
diff changeset
   212
  done
286
804fbb227568 added proof for bitcoded algorithm
Christian Urban <urbanc@in.tum.de>
parents: 256
diff changeset
   213
311
8b8db9558ecf updated
Christian Urban <urbanc@in.tum.de>
parents: 307
diff changeset
   214
lemma erase_bder [simp]:
289
807acaf7f599 updated
Christian Urban <urbanc@in.tum.de>
parents: 288
diff changeset
   215
  shows "erase (bder a r) = der a (erase r)"
311
8b8db9558ecf updated
Christian Urban <urbanc@in.tum.de>
parents: 307
diff changeset
   216
  apply(induct r rule: erase.induct)
289
807acaf7f599 updated
Christian Urban <urbanc@in.tum.de>
parents: 288
diff changeset
   217
  apply(simp_all add: erase_fuse bnullable_correctness)
286
804fbb227568 added proof for bitcoded algorithm
Christian Urban <urbanc@in.tum.de>
parents: 256
diff changeset
   218
  done
804fbb227568 added proof for bitcoded algorithm
Christian Urban <urbanc@in.tum.de>
parents: 256
diff changeset
   219
311
8b8db9558ecf updated
Christian Urban <urbanc@in.tum.de>
parents: 307
diff changeset
   220
lemma erase_bders [simp]:
289
807acaf7f599 updated
Christian Urban <urbanc@in.tum.de>
parents: 288
diff changeset
   221
  shows "erase (bders r s) = ders s (erase r)"
286
804fbb227568 added proof for bitcoded algorithm
Christian Urban <urbanc@in.tum.de>
parents: 256
diff changeset
   222
  apply(induct s arbitrary: r )
289
807acaf7f599 updated
Christian Urban <urbanc@in.tum.de>
parents: 288
diff changeset
   223
  apply(simp_all)
286
804fbb227568 added proof for bitcoded algorithm
Christian Urban <urbanc@in.tum.de>
parents: 256
diff changeset
   224
  done
804fbb227568 added proof for bitcoded algorithm
Christian Urban <urbanc@in.tum.de>
parents: 256
diff changeset
   225
804fbb227568 added proof for bitcoded algorithm
Christian Urban <urbanc@in.tum.de>
parents: 256
diff changeset
   226
lemma retrieve_encode_STARS:
289
807acaf7f599 updated
Christian Urban <urbanc@in.tum.de>
parents: 288
diff changeset
   227
  assumes "\<forall>v\<in>set vs. \<Turnstile> v : r \<and> code v = retrieve (intern r) v"
807acaf7f599 updated
Christian Urban <urbanc@in.tum.de>
parents: 288
diff changeset
   228
  shows "code (Stars vs) = retrieve (ASTAR [] (intern r)) (Stars vs)"
286
804fbb227568 added proof for bitcoded algorithm
Christian Urban <urbanc@in.tum.de>
parents: 256
diff changeset
   229
  using assms
804fbb227568 added proof for bitcoded algorithm
Christian Urban <urbanc@in.tum.de>
parents: 256
diff changeset
   230
  apply(induct vs)
289
807acaf7f599 updated
Christian Urban <urbanc@in.tum.de>
parents: 288
diff changeset
   231
  apply(simp_all)
807acaf7f599 updated
Christian Urban <urbanc@in.tum.de>
parents: 288
diff changeset
   232
  done
807acaf7f599 updated
Christian Urban <urbanc@in.tum.de>
parents: 288
diff changeset
   233
807acaf7f599 updated
Christian Urban <urbanc@in.tum.de>
parents: 288
diff changeset
   234
lemma retrieve_fuse2:
807acaf7f599 updated
Christian Urban <urbanc@in.tum.de>
parents: 288
diff changeset
   235
  assumes "\<Turnstile> v : (erase r)"
807acaf7f599 updated
Christian Urban <urbanc@in.tum.de>
parents: 288
diff changeset
   236
  shows "retrieve (fuse bs r) v = bs @ retrieve r v"
807acaf7f599 updated
Christian Urban <urbanc@in.tum.de>
parents: 288
diff changeset
   237
  using assms
313
3b8e3a156200 adapted the Bitcoded correctness proof to using AALTs
Christian Urban <urbanc@in.tum.de>
parents: 311
diff changeset
   238
  apply(induct r arbitrary: v bs)
3b8e3a156200 adapted the Bitcoded correctness proof to using AALTs
Christian Urban <urbanc@in.tum.de>
parents: 311
diff changeset
   239
         apply(auto elim: Prf_elims)[4]
3b8e3a156200 adapted the Bitcoded correctness proof to using AALTs
Christian Urban <urbanc@in.tum.de>
parents: 311
diff changeset
   240
   defer
3b8e3a156200 adapted the Bitcoded correctness proof to using AALTs
Christian Urban <urbanc@in.tum.de>
parents: 311
diff changeset
   241
  using retrieve_encode_STARS
3b8e3a156200 adapted the Bitcoded correctness proof to using AALTs
Christian Urban <urbanc@in.tum.de>
parents: 311
diff changeset
   242
   apply(auto elim!: Prf_elims)[1]
3b8e3a156200 adapted the Bitcoded correctness proof to using AALTs
Christian Urban <urbanc@in.tum.de>
parents: 311
diff changeset
   243
   apply(case_tac vs)
3b8e3a156200 adapted the Bitcoded correctness proof to using AALTs
Christian Urban <urbanc@in.tum.de>
parents: 311
diff changeset
   244
    apply(simp)
3b8e3a156200 adapted the Bitcoded correctness proof to using AALTs
Christian Urban <urbanc@in.tum.de>
parents: 311
diff changeset
   245
   apply(simp)
3b8e3a156200 adapted the Bitcoded correctness proof to using AALTs
Christian Urban <urbanc@in.tum.de>
parents: 311
diff changeset
   246
  (* AALTs  case *)
3b8e3a156200 adapted the Bitcoded correctness proof to using AALTs
Christian Urban <urbanc@in.tum.de>
parents: 311
diff changeset
   247
  apply(simp)
3b8e3a156200 adapted the Bitcoded correctness proof to using AALTs
Christian Urban <urbanc@in.tum.de>
parents: 311
diff changeset
   248
  apply(case_tac x2a)
3b8e3a156200 adapted the Bitcoded correctness proof to using AALTs
Christian Urban <urbanc@in.tum.de>
parents: 311
diff changeset
   249
   apply(simp)
3b8e3a156200 adapted the Bitcoded correctness proof to using AALTs
Christian Urban <urbanc@in.tum.de>
parents: 311
diff changeset
   250
   apply(auto elim!: Prf_elims)[1]
3b8e3a156200 adapted the Bitcoded correctness proof to using AALTs
Christian Urban <urbanc@in.tum.de>
parents: 311
diff changeset
   251
  apply(simp)
3b8e3a156200 adapted the Bitcoded correctness proof to using AALTs
Christian Urban <urbanc@in.tum.de>
parents: 311
diff changeset
   252
   apply(case_tac list)
3b8e3a156200 adapted the Bitcoded correctness proof to using AALTs
Christian Urban <urbanc@in.tum.de>
parents: 311
diff changeset
   253
   apply(simp)
3b8e3a156200 adapted the Bitcoded correctness proof to using AALTs
Christian Urban <urbanc@in.tum.de>
parents: 311
diff changeset
   254
  apply(auto)
3b8e3a156200 adapted the Bitcoded correctness proof to using AALTs
Christian Urban <urbanc@in.tum.de>
parents: 311
diff changeset
   255
  apply(auto elim!: Prf_elims)[1]
3b8e3a156200 adapted the Bitcoded correctness proof to using AALTs
Christian Urban <urbanc@in.tum.de>
parents: 311
diff changeset
   256
  done
286
804fbb227568 added proof for bitcoded algorithm
Christian Urban <urbanc@in.tum.de>
parents: 256
diff changeset
   257
289
807acaf7f599 updated
Christian Urban <urbanc@in.tum.de>
parents: 288
diff changeset
   258
lemma retrieve_fuse:
807acaf7f599 updated
Christian Urban <urbanc@in.tum.de>
parents: 288
diff changeset
   259
  assumes "\<Turnstile> v : r"
807acaf7f599 updated
Christian Urban <urbanc@in.tum.de>
parents: 288
diff changeset
   260
  shows "retrieve (fuse bs (intern r)) v = bs @ retrieve (intern r) v"
807acaf7f599 updated
Christian Urban <urbanc@in.tum.de>
parents: 288
diff changeset
   261
  using assms 
807acaf7f599 updated
Christian Urban <urbanc@in.tum.de>
parents: 288
diff changeset
   262
  by (simp_all add: retrieve_fuse2)
807acaf7f599 updated
Christian Urban <urbanc@in.tum.de>
parents: 288
diff changeset
   263
807acaf7f599 updated
Christian Urban <urbanc@in.tum.de>
parents: 288
diff changeset
   264
807acaf7f599 updated
Christian Urban <urbanc@in.tum.de>
parents: 288
diff changeset
   265
lemma retrieve_code:
807acaf7f599 updated
Christian Urban <urbanc@in.tum.de>
parents: 288
diff changeset
   266
  assumes "\<Turnstile> v : r"
807acaf7f599 updated
Christian Urban <urbanc@in.tum.de>
parents: 288
diff changeset
   267
  shows "code v = retrieve (intern r) v"
286
804fbb227568 added proof for bitcoded algorithm
Christian Urban <urbanc@in.tum.de>
parents: 256
diff changeset
   268
  using assms
311
8b8db9558ecf updated
Christian Urban <urbanc@in.tum.de>
parents: 307
diff changeset
   269
  apply(induct v r )
289
807acaf7f599 updated
Christian Urban <urbanc@in.tum.de>
parents: 288
diff changeset
   270
  apply(simp_all add: retrieve_fuse retrieve_encode_STARS)
313
3b8e3a156200 adapted the Bitcoded correctness proof to using AALTs
Christian Urban <urbanc@in.tum.de>
parents: 311
diff changeset
   271
  done
3b8e3a156200 adapted the Bitcoded correctness proof to using AALTs
Christian Urban <urbanc@in.tum.de>
parents: 311
diff changeset
   272
3b8e3a156200 adapted the Bitcoded correctness proof to using AALTs
Christian Urban <urbanc@in.tum.de>
parents: 311
diff changeset
   273
lemma r:
3b8e3a156200 adapted the Bitcoded correctness proof to using AALTs
Christian Urban <urbanc@in.tum.de>
parents: 311
diff changeset
   274
  assumes "bnullable (AALTs bs (a # rs))"
3b8e3a156200 adapted the Bitcoded correctness proof to using AALTs
Christian Urban <urbanc@in.tum.de>
parents: 311
diff changeset
   275
  shows "bnullable a \<or> (\<not> bnullable a \<and> bnullable (AALTs bs rs))"
3b8e3a156200 adapted the Bitcoded correctness proof to using AALTs
Christian Urban <urbanc@in.tum.de>
parents: 311
diff changeset
   276
  using assms
3b8e3a156200 adapted the Bitcoded correctness proof to using AALTs
Christian Urban <urbanc@in.tum.de>
parents: 311
diff changeset
   277
  apply(induct rs)
3b8e3a156200 adapted the Bitcoded correctness proof to using AALTs
Christian Urban <urbanc@in.tum.de>
parents: 311
diff changeset
   278
   apply(auto)
3b8e3a156200 adapted the Bitcoded correctness proof to using AALTs
Christian Urban <urbanc@in.tum.de>
parents: 311
diff changeset
   279
  done
3b8e3a156200 adapted the Bitcoded correctness proof to using AALTs
Christian Urban <urbanc@in.tum.de>
parents: 311
diff changeset
   280
3b8e3a156200 adapted the Bitcoded correctness proof to using AALTs
Christian Urban <urbanc@in.tum.de>
parents: 311
diff changeset
   281
lemma r0:
3b8e3a156200 adapted the Bitcoded correctness proof to using AALTs
Christian Urban <urbanc@in.tum.de>
parents: 311
diff changeset
   282
  assumes "bnullable a" 
3b8e3a156200 adapted the Bitcoded correctness proof to using AALTs
Christian Urban <urbanc@in.tum.de>
parents: 311
diff changeset
   283
  shows  "bmkeps (AALTs bs (a # rs)) = bs @ (bmkeps a)"
3b8e3a156200 adapted the Bitcoded correctness proof to using AALTs
Christian Urban <urbanc@in.tum.de>
parents: 311
diff changeset
   284
  using assms
3b8e3a156200 adapted the Bitcoded correctness proof to using AALTs
Christian Urban <urbanc@in.tum.de>
parents: 311
diff changeset
   285
  by (metis bmkeps.simps(3) bmkeps.simps(4) list.exhaust)
3b8e3a156200 adapted the Bitcoded correctness proof to using AALTs
Christian Urban <urbanc@in.tum.de>
parents: 311
diff changeset
   286
3b8e3a156200 adapted the Bitcoded correctness proof to using AALTs
Christian Urban <urbanc@in.tum.de>
parents: 311
diff changeset
   287
lemma r1:
3b8e3a156200 adapted the Bitcoded correctness proof to using AALTs
Christian Urban <urbanc@in.tum.de>
parents: 311
diff changeset
   288
  assumes "\<not> bnullable a" "bnullable (AALTs bs rs)"
3b8e3a156200 adapted the Bitcoded correctness proof to using AALTs
Christian Urban <urbanc@in.tum.de>
parents: 311
diff changeset
   289
  shows  "bmkeps (AALTs bs (a # rs)) = bmkeps (AALTs bs rs)"
3b8e3a156200 adapted the Bitcoded correctness proof to using AALTs
Christian Urban <urbanc@in.tum.de>
parents: 311
diff changeset
   290
  using assms
3b8e3a156200 adapted the Bitcoded correctness proof to using AALTs
Christian Urban <urbanc@in.tum.de>
parents: 311
diff changeset
   291
  apply(induct rs)
3b8e3a156200 adapted the Bitcoded correctness proof to using AALTs
Christian Urban <urbanc@in.tum.de>
parents: 311
diff changeset
   292
   apply(auto)
3b8e3a156200 adapted the Bitcoded correctness proof to using AALTs
Christian Urban <urbanc@in.tum.de>
parents: 311
diff changeset
   293
  done
3b8e3a156200 adapted the Bitcoded correctness proof to using AALTs
Christian Urban <urbanc@in.tum.de>
parents: 311
diff changeset
   294
3b8e3a156200 adapted the Bitcoded correctness proof to using AALTs
Christian Urban <urbanc@in.tum.de>
parents: 311
diff changeset
   295
lemma r2:
3b8e3a156200 adapted the Bitcoded correctness proof to using AALTs
Christian Urban <urbanc@in.tum.de>
parents: 311
diff changeset
   296
  assumes "x \<in> set rs" "bnullable x"
3b8e3a156200 adapted the Bitcoded correctness proof to using AALTs
Christian Urban <urbanc@in.tum.de>
parents: 311
diff changeset
   297
  shows "bnullable (AALTs bs rs)"
3b8e3a156200 adapted the Bitcoded correctness proof to using AALTs
Christian Urban <urbanc@in.tum.de>
parents: 311
diff changeset
   298
  using assms
3b8e3a156200 adapted the Bitcoded correctness proof to using AALTs
Christian Urban <urbanc@in.tum.de>
parents: 311
diff changeset
   299
  apply(induct rs)
3b8e3a156200 adapted the Bitcoded correctness proof to using AALTs
Christian Urban <urbanc@in.tum.de>
parents: 311
diff changeset
   300
   apply(auto)
3b8e3a156200 adapted the Bitcoded correctness proof to using AALTs
Christian Urban <urbanc@in.tum.de>
parents: 311
diff changeset
   301
  done
286
804fbb227568 added proof for bitcoded algorithm
Christian Urban <urbanc@in.tum.de>
parents: 256
diff changeset
   302
313
3b8e3a156200 adapted the Bitcoded correctness proof to using AALTs
Christian Urban <urbanc@in.tum.de>
parents: 311
diff changeset
   303
lemma  r3:
3b8e3a156200 adapted the Bitcoded correctness proof to using AALTs
Christian Urban <urbanc@in.tum.de>
parents: 311
diff changeset
   304
  assumes "\<not> bnullable r" 
3b8e3a156200 adapted the Bitcoded correctness proof to using AALTs
Christian Urban <urbanc@in.tum.de>
parents: 311
diff changeset
   305
          " \<exists> x \<in> set rs. bnullable x"
3b8e3a156200 adapted the Bitcoded correctness proof to using AALTs
Christian Urban <urbanc@in.tum.de>
parents: 311
diff changeset
   306
  shows "retrieve (AALTs bs rs) (mkeps (erase (AALTs bs rs))) =
3b8e3a156200 adapted the Bitcoded correctness proof to using AALTs
Christian Urban <urbanc@in.tum.de>
parents: 311
diff changeset
   307
         retrieve (AALTs bs (r # rs)) (mkeps (erase (AALTs bs (r # rs))))"
3b8e3a156200 adapted the Bitcoded correctness proof to using AALTs
Christian Urban <urbanc@in.tum.de>
parents: 311
diff changeset
   308
  using assms
3b8e3a156200 adapted the Bitcoded correctness proof to using AALTs
Christian Urban <urbanc@in.tum.de>
parents: 311
diff changeset
   309
  apply(induct rs arbitrary: r bs)
3b8e3a156200 adapted the Bitcoded correctness proof to using AALTs
Christian Urban <urbanc@in.tum.de>
parents: 311
diff changeset
   310
   apply(auto)[1]
3b8e3a156200 adapted the Bitcoded correctness proof to using AALTs
Christian Urban <urbanc@in.tum.de>
parents: 311
diff changeset
   311
  apply(auto)
3b8e3a156200 adapted the Bitcoded correctness proof to using AALTs
Christian Urban <urbanc@in.tum.de>
parents: 311
diff changeset
   312
  using bnullable_correctness apply blast
3b8e3a156200 adapted the Bitcoded correctness proof to using AALTs
Christian Urban <urbanc@in.tum.de>
parents: 311
diff changeset
   313
    apply(auto simp add: bnullable_correctness mkeps_nullable retrieve_fuse2)
3b8e3a156200 adapted the Bitcoded correctness proof to using AALTs
Christian Urban <urbanc@in.tum.de>
parents: 311
diff changeset
   314
   apply(subst retrieve_fuse2[symmetric])
3b8e3a156200 adapted the Bitcoded correctness proof to using AALTs
Christian Urban <urbanc@in.tum.de>
parents: 311
diff changeset
   315
  apply (smt bnullable.simps(4) bnullable_correctness erase.simps(5) erase.simps(6) insert_iff list.exhaust list.set(2) mkeps.simps(3) mkeps_nullable)
3b8e3a156200 adapted the Bitcoded correctness proof to using AALTs
Christian Urban <urbanc@in.tum.de>
parents: 311
diff changeset
   316
   apply(simp)
3b8e3a156200 adapted the Bitcoded correctness proof to using AALTs
Christian Urban <urbanc@in.tum.de>
parents: 311
diff changeset
   317
  apply(case_tac "bnullable a")
3b8e3a156200 adapted the Bitcoded correctness proof to using AALTs
Christian Urban <urbanc@in.tum.de>
parents: 311
diff changeset
   318
  apply (smt append_Nil2 bnullable.simps(4) bnullable_correctness erase.simps(5) erase.simps(6) fuse.simps(4) insert_iff list.exhaust list.set(2) mkeps.simps(3) mkeps_nullable retrieve_fuse2)
3b8e3a156200 adapted the Bitcoded correctness proof to using AALTs
Christian Urban <urbanc@in.tum.de>
parents: 311
diff changeset
   319
  apply(drule_tac x="a" in meta_spec)
3b8e3a156200 adapted the Bitcoded correctness proof to using AALTs
Christian Urban <urbanc@in.tum.de>
parents: 311
diff changeset
   320
  apply(drule_tac x="bs" in meta_spec)
3b8e3a156200 adapted the Bitcoded correctness proof to using AALTs
Christian Urban <urbanc@in.tum.de>
parents: 311
diff changeset
   321
  apply(drule meta_mp)
3b8e3a156200 adapted the Bitcoded correctness proof to using AALTs
Christian Urban <urbanc@in.tum.de>
parents: 311
diff changeset
   322
   apply(simp)
3b8e3a156200 adapted the Bitcoded correctness proof to using AALTs
Christian Urban <urbanc@in.tum.de>
parents: 311
diff changeset
   323
  apply(drule meta_mp)
3b8e3a156200 adapted the Bitcoded correctness proof to using AALTs
Christian Urban <urbanc@in.tum.de>
parents: 311
diff changeset
   324
   apply(auto)
3b8e3a156200 adapted the Bitcoded correctness proof to using AALTs
Christian Urban <urbanc@in.tum.de>
parents: 311
diff changeset
   325
  apply(subst retrieve_fuse2[symmetric])
3b8e3a156200 adapted the Bitcoded correctness proof to using AALTs
Christian Urban <urbanc@in.tum.de>
parents: 311
diff changeset
   326
  apply(case_tac rs)
3b8e3a156200 adapted the Bitcoded correctness proof to using AALTs
Christian Urban <urbanc@in.tum.de>
parents: 311
diff changeset
   327
    apply(simp)
3b8e3a156200 adapted the Bitcoded correctness proof to using AALTs
Christian Urban <urbanc@in.tum.de>
parents: 311
diff changeset
   328
   apply(auto)[1]
3b8e3a156200 adapted the Bitcoded correctness proof to using AALTs
Christian Urban <urbanc@in.tum.de>
parents: 311
diff changeset
   329
      apply (simp add: bnullable_correctness)
3b8e3a156200 adapted the Bitcoded correctness proof to using AALTs
Christian Urban <urbanc@in.tum.de>
parents: 311
diff changeset
   330
  apply (metis append_Nil2 bnullable_correctness erase_fuse fuse.simps(4) list.set_intros(1) mkeps.simps(3) mkeps_nullable nullable.simps(4) r2)
3b8e3a156200 adapted the Bitcoded correctness proof to using AALTs
Christian Urban <urbanc@in.tum.de>
parents: 311
diff changeset
   331
    apply (simp add: bnullable_correctness)
3b8e3a156200 adapted the Bitcoded correctness proof to using AALTs
Christian Urban <urbanc@in.tum.de>
parents: 311
diff changeset
   332
  apply (metis append_Nil2 bnullable_correctness erase.simps(6) erase_fuse fuse.simps(4) list.set_intros(2) mkeps.simps(3) mkeps_nullable r2)
3b8e3a156200 adapted the Bitcoded correctness proof to using AALTs
Christian Urban <urbanc@in.tum.de>
parents: 311
diff changeset
   333
  apply(simp)
3b8e3a156200 adapted the Bitcoded correctness proof to using AALTs
Christian Urban <urbanc@in.tum.de>
parents: 311
diff changeset
   334
  done
3b8e3a156200 adapted the Bitcoded correctness proof to using AALTs
Christian Urban <urbanc@in.tum.de>
parents: 311
diff changeset
   335
3b8e3a156200 adapted the Bitcoded correctness proof to using AALTs
Christian Urban <urbanc@in.tum.de>
parents: 311
diff changeset
   336
3b8e3a156200 adapted the Bitcoded correctness proof to using AALTs
Christian Urban <urbanc@in.tum.de>
parents: 311
diff changeset
   337
lemma t: 
3b8e3a156200 adapted the Bitcoded correctness proof to using AALTs
Christian Urban <urbanc@in.tum.de>
parents: 311
diff changeset
   338
  assumes "\<forall>r \<in> set rs. nullable (erase r) \<longrightarrow> bmkeps r = retrieve r (mkeps (erase r))" 
3b8e3a156200 adapted the Bitcoded correctness proof to using AALTs
Christian Urban <urbanc@in.tum.de>
parents: 311
diff changeset
   339
          "nullable (erase (AALTs bs rs))"
3b8e3a156200 adapted the Bitcoded correctness proof to using AALTs
Christian Urban <urbanc@in.tum.de>
parents: 311
diff changeset
   340
  shows " bmkeps (AALTs bs rs) = retrieve (AALTs bs rs) (mkeps (erase (AALTs bs rs)))"
3b8e3a156200 adapted the Bitcoded correctness proof to using AALTs
Christian Urban <urbanc@in.tum.de>
parents: 311
diff changeset
   341
  using assms
3b8e3a156200 adapted the Bitcoded correctness proof to using AALTs
Christian Urban <urbanc@in.tum.de>
parents: 311
diff changeset
   342
  apply(induct rs arbitrary: bs)
3b8e3a156200 adapted the Bitcoded correctness proof to using AALTs
Christian Urban <urbanc@in.tum.de>
parents: 311
diff changeset
   343
   apply(simp)
3b8e3a156200 adapted the Bitcoded correctness proof to using AALTs
Christian Urban <urbanc@in.tum.de>
parents: 311
diff changeset
   344
  apply(auto simp add: bnullable_correctness)
3b8e3a156200 adapted the Bitcoded correctness proof to using AALTs
Christian Urban <urbanc@in.tum.de>
parents: 311
diff changeset
   345
   apply(case_tac rs)
3b8e3a156200 adapted the Bitcoded correctness proof to using AALTs
Christian Urban <urbanc@in.tum.de>
parents: 311
diff changeset
   346
     apply(auto simp add: bnullable_correctness)[2]
3b8e3a156200 adapted the Bitcoded correctness proof to using AALTs
Christian Urban <urbanc@in.tum.de>
parents: 311
diff changeset
   347
   apply(subst r1)
3b8e3a156200 adapted the Bitcoded correctness proof to using AALTs
Christian Urban <urbanc@in.tum.de>
parents: 311
diff changeset
   348
     apply(simp)
3b8e3a156200 adapted the Bitcoded correctness proof to using AALTs
Christian Urban <urbanc@in.tum.de>
parents: 311
diff changeset
   349
    apply(rule r2)
3b8e3a156200 adapted the Bitcoded correctness proof to using AALTs
Christian Urban <urbanc@in.tum.de>
parents: 311
diff changeset
   350
     apply(assumption)
3b8e3a156200 adapted the Bitcoded correctness proof to using AALTs
Christian Urban <urbanc@in.tum.de>
parents: 311
diff changeset
   351
    apply(simp)
3b8e3a156200 adapted the Bitcoded correctness proof to using AALTs
Christian Urban <urbanc@in.tum.de>
parents: 311
diff changeset
   352
   apply(drule_tac x="bs" in meta_spec)
3b8e3a156200 adapted the Bitcoded correctness proof to using AALTs
Christian Urban <urbanc@in.tum.de>
parents: 311
diff changeset
   353
   apply(drule meta_mp)
3b8e3a156200 adapted the Bitcoded correctness proof to using AALTs
Christian Urban <urbanc@in.tum.de>
parents: 311
diff changeset
   354
    apply(auto)[1]
3b8e3a156200 adapted the Bitcoded correctness proof to using AALTs
Christian Urban <urbanc@in.tum.de>
parents: 311
diff changeset
   355
   prefer 2
3b8e3a156200 adapted the Bitcoded correctness proof to using AALTs
Christian Urban <urbanc@in.tum.de>
parents: 311
diff changeset
   356
  apply(case_tac "bnullable a")
3b8e3a156200 adapted the Bitcoded correctness proof to using AALTs
Christian Urban <urbanc@in.tum.de>
parents: 311
diff changeset
   357
    apply(subst r0)
3b8e3a156200 adapted the Bitcoded correctness proof to using AALTs
Christian Urban <urbanc@in.tum.de>
parents: 311
diff changeset
   358
     apply blast
3b8e3a156200 adapted the Bitcoded correctness proof to using AALTs
Christian Urban <urbanc@in.tum.de>
parents: 311
diff changeset
   359
    apply(subgoal_tac "nullable (erase a)")
3b8e3a156200 adapted the Bitcoded correctness proof to using AALTs
Christian Urban <urbanc@in.tum.de>
parents: 311
diff changeset
   360
  prefer 2
3b8e3a156200 adapted the Bitcoded correctness proof to using AALTs
Christian Urban <urbanc@in.tum.de>
parents: 311
diff changeset
   361
  using bnullable_correctness apply blast
3b8e3a156200 adapted the Bitcoded correctness proof to using AALTs
Christian Urban <urbanc@in.tum.de>
parents: 311
diff changeset
   362
  apply (metis (no_types, lifting) erase.simps(5) erase.simps(6) list.exhaust mkeps.simps(3) retrieve.simps(3) retrieve.simps(4))
3b8e3a156200 adapted the Bitcoded correctness proof to using AALTs
Christian Urban <urbanc@in.tum.de>
parents: 311
diff changeset
   363
  apply(subst r1)
3b8e3a156200 adapted the Bitcoded correctness proof to using AALTs
Christian Urban <urbanc@in.tum.de>
parents: 311
diff changeset
   364
     apply(simp)
3b8e3a156200 adapted the Bitcoded correctness proof to using AALTs
Christian Urban <urbanc@in.tum.de>
parents: 311
diff changeset
   365
  using r2 apply blast
3b8e3a156200 adapted the Bitcoded correctness proof to using AALTs
Christian Urban <urbanc@in.tum.de>
parents: 311
diff changeset
   366
  apply(drule_tac x="bs" in meta_spec)
3b8e3a156200 adapted the Bitcoded correctness proof to using AALTs
Christian Urban <urbanc@in.tum.de>
parents: 311
diff changeset
   367
   apply(drule meta_mp)
3b8e3a156200 adapted the Bitcoded correctness proof to using AALTs
Christian Urban <urbanc@in.tum.de>
parents: 311
diff changeset
   368
    apply(auto)[1]
3b8e3a156200 adapted the Bitcoded correctness proof to using AALTs
Christian Urban <urbanc@in.tum.de>
parents: 311
diff changeset
   369
   apply(simp)
3b8e3a156200 adapted the Bitcoded correctness proof to using AALTs
Christian Urban <urbanc@in.tum.de>
parents: 311
diff changeset
   370
  using r3 apply blast
3b8e3a156200 adapted the Bitcoded correctness proof to using AALTs
Christian Urban <urbanc@in.tum.de>
parents: 311
diff changeset
   371
  apply(auto)
3b8e3a156200 adapted the Bitcoded correctness proof to using AALTs
Christian Urban <urbanc@in.tum.de>
parents: 311
diff changeset
   372
  using r3 by blast
286
804fbb227568 added proof for bitcoded algorithm
Christian Urban <urbanc@in.tum.de>
parents: 256
diff changeset
   373
289
807acaf7f599 updated
Christian Urban <urbanc@in.tum.de>
parents: 288
diff changeset
   374
lemma bmkeps_retrieve:
807acaf7f599 updated
Christian Urban <urbanc@in.tum.de>
parents: 288
diff changeset
   375
  assumes "nullable (erase r)"
807acaf7f599 updated
Christian Urban <urbanc@in.tum.de>
parents: 288
diff changeset
   376
  shows "bmkeps r = retrieve r (mkeps (erase r))"
286
804fbb227568 added proof for bitcoded algorithm
Christian Urban <urbanc@in.tum.de>
parents: 256
diff changeset
   377
  using assms
804fbb227568 added proof for bitcoded algorithm
Christian Urban <urbanc@in.tum.de>
parents: 256
diff changeset
   378
  apply(induct r)
313
3b8e3a156200 adapted the Bitcoded correctness proof to using AALTs
Christian Urban <urbanc@in.tum.de>
parents: 311
diff changeset
   379
         apply(simp)
3b8e3a156200 adapted the Bitcoded correctness proof to using AALTs
Christian Urban <urbanc@in.tum.de>
parents: 311
diff changeset
   380
        apply(simp)
3b8e3a156200 adapted the Bitcoded correctness proof to using AALTs
Christian Urban <urbanc@in.tum.de>
parents: 311
diff changeset
   381
       apply(simp)
3b8e3a156200 adapted the Bitcoded correctness proof to using AALTs
Christian Urban <urbanc@in.tum.de>
parents: 311
diff changeset
   382
    apply(simp)
3b8e3a156200 adapted the Bitcoded correctness proof to using AALTs
Christian Urban <urbanc@in.tum.de>
parents: 311
diff changeset
   383
   defer
3b8e3a156200 adapted the Bitcoded correctness proof to using AALTs
Christian Urban <urbanc@in.tum.de>
parents: 311
diff changeset
   384
   apply(simp)
3b8e3a156200 adapted the Bitcoded correctness proof to using AALTs
Christian Urban <urbanc@in.tum.de>
parents: 311
diff changeset
   385
  apply(rule t)
3b8e3a156200 adapted the Bitcoded correctness proof to using AALTs
Christian Urban <urbanc@in.tum.de>
parents: 311
diff changeset
   386
   apply(auto)
3b8e3a156200 adapted the Bitcoded correctness proof to using AALTs
Christian Urban <urbanc@in.tum.de>
parents: 311
diff changeset
   387
  done
3b8e3a156200 adapted the Bitcoded correctness proof to using AALTs
Christian Urban <urbanc@in.tum.de>
parents: 311
diff changeset
   388
289
807acaf7f599 updated
Christian Urban <urbanc@in.tum.de>
parents: 288
diff changeset
   389
lemma bder_retrieve:
807acaf7f599 updated
Christian Urban <urbanc@in.tum.de>
parents: 288
diff changeset
   390
  assumes "\<Turnstile> v : der c (erase r)"
807acaf7f599 updated
Christian Urban <urbanc@in.tum.de>
parents: 288
diff changeset
   391
  shows "retrieve (bder c r) v = retrieve r (injval (erase r) c v)"
286
804fbb227568 added proof for bitcoded algorithm
Christian Urban <urbanc@in.tum.de>
parents: 256
diff changeset
   392
  using assms
313
3b8e3a156200 adapted the Bitcoded correctness proof to using AALTs
Christian Urban <urbanc@in.tum.de>
parents: 311
diff changeset
   393
  apply(induct r arbitrary: v rule: erase.induct)
289
807acaf7f599 updated
Christian Urban <urbanc@in.tum.de>
parents: 288
diff changeset
   394
  apply(auto elim!: Prf_elims simp add: retrieve_fuse2 bnullable_correctness bmkeps_retrieve)
313
3b8e3a156200 adapted the Bitcoded correctness proof to using AALTs
Christian Urban <urbanc@in.tum.de>
parents: 311
diff changeset
   395
  apply(case_tac va)
3b8e3a156200 adapted the Bitcoded correctness proof to using AALTs
Christian Urban <urbanc@in.tum.de>
parents: 311
diff changeset
   396
   apply(simp)
3b8e3a156200 adapted the Bitcoded correctness proof to using AALTs
Christian Urban <urbanc@in.tum.de>
parents: 311
diff changeset
   397
  apply(auto)
3b8e3a156200 adapted the Bitcoded correctness proof to using AALTs
Christian Urban <urbanc@in.tum.de>
parents: 311
diff changeset
   398
  by (smt Prf_elims(3) injval.simps(2) injval.simps(3) retrieve.simps(4) retrieve.simps(5) same_append_eq)
3b8e3a156200 adapted the Bitcoded correctness proof to using AALTs
Christian Urban <urbanc@in.tum.de>
parents: 311
diff changeset
   399
  
286
804fbb227568 added proof for bitcoded algorithm
Christian Urban <urbanc@in.tum.de>
parents: 256
diff changeset
   400
289
807acaf7f599 updated
Christian Urban <urbanc@in.tum.de>
parents: 288
diff changeset
   401
lemma MAIN_decode:
807acaf7f599 updated
Christian Urban <urbanc@in.tum.de>
parents: 288
diff changeset
   402
  assumes "\<Turnstile> v : ders s r"
807acaf7f599 updated
Christian Urban <urbanc@in.tum.de>
parents: 288
diff changeset
   403
  shows "Some (flex r id s v) = decode (retrieve (bders (intern r) s) v) r"
807acaf7f599 updated
Christian Urban <urbanc@in.tum.de>
parents: 288
diff changeset
   404
  using assms
807acaf7f599 updated
Christian Urban <urbanc@in.tum.de>
parents: 288
diff changeset
   405
proof (induct s arbitrary: v rule: rev_induct)
807acaf7f599 updated
Christian Urban <urbanc@in.tum.de>
parents: 288
diff changeset
   406
  case Nil
807acaf7f599 updated
Christian Urban <urbanc@in.tum.de>
parents: 288
diff changeset
   407
  have "\<Turnstile> v : ders [] r" by fact
807acaf7f599 updated
Christian Urban <urbanc@in.tum.de>
parents: 288
diff changeset
   408
  then have "\<Turnstile> v : r" by simp
807acaf7f599 updated
Christian Urban <urbanc@in.tum.de>
parents: 288
diff changeset
   409
  then have "Some v = decode (retrieve (intern r) v) r"
807acaf7f599 updated
Christian Urban <urbanc@in.tum.de>
parents: 288
diff changeset
   410
    using decode_code retrieve_code by auto
807acaf7f599 updated
Christian Urban <urbanc@in.tum.de>
parents: 288
diff changeset
   411
  then show "Some (flex r id [] v) = decode (retrieve (bders (intern r) []) v) r"
807acaf7f599 updated
Christian Urban <urbanc@in.tum.de>
parents: 288
diff changeset
   412
    by simp
807acaf7f599 updated
Christian Urban <urbanc@in.tum.de>
parents: 288
diff changeset
   413
next
807acaf7f599 updated
Christian Urban <urbanc@in.tum.de>
parents: 288
diff changeset
   414
  case (snoc c s v)
807acaf7f599 updated
Christian Urban <urbanc@in.tum.de>
parents: 288
diff changeset
   415
  have IH: "\<And>v. \<Turnstile> v : ders s r \<Longrightarrow> 
807acaf7f599 updated
Christian Urban <urbanc@in.tum.de>
parents: 288
diff changeset
   416
     Some (flex r id s v) = decode (retrieve (bders (intern r) s) v) r" by fact
807acaf7f599 updated
Christian Urban <urbanc@in.tum.de>
parents: 288
diff changeset
   417
  have asm: "\<Turnstile> v : ders (s @ [c]) r" by fact
807acaf7f599 updated
Christian Urban <urbanc@in.tum.de>
parents: 288
diff changeset
   418
  then have asm2: "\<Turnstile> injval (ders s r) c v : ders s r" 
807acaf7f599 updated
Christian Urban <urbanc@in.tum.de>
parents: 288
diff changeset
   419
    by(simp add: Prf_injval ders_append)
807acaf7f599 updated
Christian Urban <urbanc@in.tum.de>
parents: 288
diff changeset
   420
  have "Some (flex r id (s @ [c]) v) = Some (flex r id s (injval (ders s r) c v))"
807acaf7f599 updated
Christian Urban <urbanc@in.tum.de>
parents: 288
diff changeset
   421
    by (simp add: flex_append)
807acaf7f599 updated
Christian Urban <urbanc@in.tum.de>
parents: 288
diff changeset
   422
  also have "... = decode (retrieve (bders (intern r) s) (injval (ders s r) c v)) r"
807acaf7f599 updated
Christian Urban <urbanc@in.tum.de>
parents: 288
diff changeset
   423
    using asm2 IH by simp
807acaf7f599 updated
Christian Urban <urbanc@in.tum.de>
parents: 288
diff changeset
   424
  also have "... = decode (retrieve (bder c (bders (intern r) s)) v) r"
807acaf7f599 updated
Christian Urban <urbanc@in.tum.de>
parents: 288
diff changeset
   425
    using asm by(simp_all add: bder_retrieve ders_append)
807acaf7f599 updated
Christian Urban <urbanc@in.tum.de>
parents: 288
diff changeset
   426
  finally show "Some (flex r id (s @ [c]) v) = 
807acaf7f599 updated
Christian Urban <urbanc@in.tum.de>
parents: 288
diff changeset
   427
                 decode (retrieve (bders (intern r) (s @ [c])) v) r" by (simp add: bders_append)
807acaf7f599 updated
Christian Urban <urbanc@in.tum.de>
parents: 288
diff changeset
   428
qed
286
804fbb227568 added proof for bitcoded algorithm
Christian Urban <urbanc@in.tum.de>
parents: 256
diff changeset
   429
804fbb227568 added proof for bitcoded algorithm
Christian Urban <urbanc@in.tum.de>
parents: 256
diff changeset
   430
289
807acaf7f599 updated
Christian Urban <urbanc@in.tum.de>
parents: 288
diff changeset
   431
definition blexer where
807acaf7f599 updated
Christian Urban <urbanc@in.tum.de>
parents: 288
diff changeset
   432
 "blexer r s \<equiv> if bnullable (bders (intern r) s) then 
807acaf7f599 updated
Christian Urban <urbanc@in.tum.de>
parents: 288
diff changeset
   433
                decode (bmkeps (bders (intern r) s)) r else None"
807acaf7f599 updated
Christian Urban <urbanc@in.tum.de>
parents: 288
diff changeset
   434
807acaf7f599 updated
Christian Urban <urbanc@in.tum.de>
parents: 288
diff changeset
   435
lemma blexer_correctness:
807acaf7f599 updated
Christian Urban <urbanc@in.tum.de>
parents: 288
diff changeset
   436
  shows "blexer r s = lexer r s"
807acaf7f599 updated
Christian Urban <urbanc@in.tum.de>
parents: 288
diff changeset
   437
proof -
807acaf7f599 updated
Christian Urban <urbanc@in.tum.de>
parents: 288
diff changeset
   438
  { define bds where "bds \<equiv> bders (intern r) s"
807acaf7f599 updated
Christian Urban <urbanc@in.tum.de>
parents: 288
diff changeset
   439
    define ds  where "ds \<equiv> ders s r"
807acaf7f599 updated
Christian Urban <urbanc@in.tum.de>
parents: 288
diff changeset
   440
    assume asm: "nullable ds"
807acaf7f599 updated
Christian Urban <urbanc@in.tum.de>
parents: 288
diff changeset
   441
    have era: "erase bds = ds" 
807acaf7f599 updated
Christian Urban <urbanc@in.tum.de>
parents: 288
diff changeset
   442
      unfolding ds_def bds_def by simp
807acaf7f599 updated
Christian Urban <urbanc@in.tum.de>
parents: 288
diff changeset
   443
    have mke: "\<Turnstile> mkeps ds : ds"
807acaf7f599 updated
Christian Urban <urbanc@in.tum.de>
parents: 288
diff changeset
   444
      using asm by (simp add: mkeps_nullable)
807acaf7f599 updated
Christian Urban <urbanc@in.tum.de>
parents: 288
diff changeset
   445
    have "decode (bmkeps bds) r = decode (retrieve bds (mkeps ds)) r"
807acaf7f599 updated
Christian Urban <urbanc@in.tum.de>
parents: 288
diff changeset
   446
      using bmkeps_retrieve
807acaf7f599 updated
Christian Urban <urbanc@in.tum.de>
parents: 288
diff changeset
   447
      using asm era by (simp add: bmkeps_retrieve)
807acaf7f599 updated
Christian Urban <urbanc@in.tum.de>
parents: 288
diff changeset
   448
    also have "... =  Some (flex r id s (mkeps ds))"
807acaf7f599 updated
Christian Urban <urbanc@in.tum.de>
parents: 288
diff changeset
   449
      using mke by (simp_all add: MAIN_decode ds_def bds_def)
807acaf7f599 updated
Christian Urban <urbanc@in.tum.de>
parents: 288
diff changeset
   450
    finally have "decode (bmkeps bds) r = Some (flex r id s (mkeps ds))" 
807acaf7f599 updated
Christian Urban <urbanc@in.tum.de>
parents: 288
diff changeset
   451
      unfolding bds_def ds_def .
807acaf7f599 updated
Christian Urban <urbanc@in.tum.de>
parents: 288
diff changeset
   452
  }
807acaf7f599 updated
Christian Urban <urbanc@in.tum.de>
parents: 288
diff changeset
   453
  then show "blexer r s = lexer r s"
807acaf7f599 updated
Christian Urban <urbanc@in.tum.de>
parents: 288
diff changeset
   454
    unfolding blexer_def lexer_flex
293
1a4e5b94293b updated
Christian Urban <urbanc@in.tum.de>
parents: 289
diff changeset
   455
    apply(subst bnullable_correctness[symmetric])
1a4e5b94293b updated
Christian Urban <urbanc@in.tum.de>
parents: 289
diff changeset
   456
    apply(simp)
1a4e5b94293b updated
Christian Urban <urbanc@in.tum.de>
parents: 289
diff changeset
   457
    done
289
807acaf7f599 updated
Christian Urban <urbanc@in.tum.de>
parents: 288
diff changeset
   458
qed
286
804fbb227568 added proof for bitcoded algorithm
Christian Urban <urbanc@in.tum.de>
parents: 256
diff changeset
   459
295
c6ec5f369037 updated
Christian Urban <urbanc@in.tum.de>
parents: 293
diff changeset
   460
314
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   461
fun distinctBy :: "'a list \<Rightarrow> ('a \<Rightarrow> 'b) \<Rightarrow> 'b set \<Rightarrow> 'a list"
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   462
  where
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   463
  "distinctBy [] f acc = []"
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   464
| "distinctBy (x#xs) f acc = 
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   465
     (if (f x) \<in> acc then distinctBy xs f acc 
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   466
      else x # (distinctBy xs f ({f x} \<union> acc)))"
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   467
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   468
fun flts :: "arexp list \<Rightarrow> arexp list"
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   469
  where 
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   470
  "flts [] = []"
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   471
| "flts (AZERO # rs) = flts rs"
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   472
| "flts ((AALTs bs  rs1) # rs) = (map (fuse bs) rs1) @ flts rs"
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   473
| "flts (r1 # rs) = r1 # flts rs"
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   474
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   475
(*
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   476
lemma flts_map:
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   477
  assumes "\<forall>r \<in> set rs. f r = r"
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   478
  shows "map f (flts rs) = flts (map f rs)"
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   479
  using assms
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   480
  apply(induct rs rule: flts.induct)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   481
        apply(simp_all)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   482
       apply(case_tac rs)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   483
  apply(simp)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   484
*)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   485
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   486
fun bsimp_ASEQ :: "bit list \<Rightarrow> arexp \<Rightarrow> arexp \<Rightarrow> arexp"
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   487
  where
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   488
  "bsimp_ASEQ _ AZERO _ = AZERO"
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   489
| "bsimp_ASEQ _ _ AZERO = AZERO"
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   490
| "bsimp_ASEQ bs1 (AONE bs2) r2 = fuse (bs1 @ bs2) r2"
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   491
| "bsimp_ASEQ bs1 r1 r2 = ASEQ  bs1 r1 r2"
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   492
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   493
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   494
fun bsimp_AALTs :: "bit list \<Rightarrow> arexp list \<Rightarrow> arexp"
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   495
  where
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   496
  "bsimp_AALTs _ [] = AZERO"
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   497
| "bsimp_AALTs bs1 [r] = fuse bs1 r"
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   498
| "bsimp_AALTs bs1 rs = AALTs bs1 rs"
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   499
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   500
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   501
fun bsimp :: "arexp \<Rightarrow> arexp" 
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   502
  where
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   503
  "bsimp (ASEQ bs1 r1 r2) = bsimp_ASEQ bs1 (bsimp r1) (bsimp r2)"
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   504
| "bsimp (AALTs bs1 rs) = bsimp_AALTs bs1 (flts (map bsimp rs))"
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   505
| "bsimp r = r"
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   506
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   507
fun 
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   508
  bders_simp :: "arexp \<Rightarrow> string \<Rightarrow> arexp"
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   509
where
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   510
  "bders_simp r [] = r"
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   511
| "bders_simp r (c # s) = bders_simp (bsimp (bder c r)) s"
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   512
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   513
definition blexer_simp where
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   514
 "blexer_simp r s \<equiv> if bnullable (bders_simp (intern r) s) then 
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   515
                decode (bmkeps (bders_simp (intern r) s)) r else None"
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   516
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   517
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   518
lemma bders_simp_append:
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   519
  shows "bders_simp r (s1 @ s2) = bders_simp (bders_simp r s1) s2"
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   520
  apply(induct s1 arbitrary: r s2)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   521
   apply(simp)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   522
  apply(simp)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   523
  done
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   524
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   525
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   526
lemma L_bsimp_ASEQ:
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   527
  "L (SEQ (erase r1) (erase r2)) = L (erase (bsimp_ASEQ bs r1 r2))"
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   528
  apply(induct bs r1 r2 rule: bsimp_ASEQ.induct)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   529
  apply(simp_all)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   530
  by (metis erase_fuse fuse.simps(4))
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   531
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   532
lemma L_bsimp_AALTs:
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   533
  "L (erase (AALTs bs rs)) = L (erase (bsimp_AALTs bs rs))"
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   534
  apply(induct bs rs rule: bsimp_AALTs.induct)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   535
  apply(simp_all add: erase_fuse)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   536
  done
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   537
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   538
lemma L_erase_AALTs:
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   539
  shows "L (erase (AALTs bs rs)) = \<Union> (L ` erase ` (set rs))"
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   540
  apply(induct rs)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   541
   apply(simp)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   542
  apply(simp)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   543
  apply(case_tac rs)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   544
   apply(simp)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   545
  apply(simp)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   546
  done
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   547
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   548
lemma L_erase_flts:
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   549
  shows "\<Union> (L ` erase ` (set (flts rs))) = \<Union> (L ` erase ` (set rs))"
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   550
  apply(induct rs rule: flts.induct)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   551
        apply(simp_all)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   552
  apply(auto)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   553
  using L_erase_AALTs erase_fuse apply auto[1]
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   554
  by (simp add: L_erase_AALTs erase_fuse)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   555
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   556
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   557
lemma L_bsimp_erase:
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   558
  shows "L (erase r) = L (erase (bsimp r))"
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   559
  apply(induct r)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   560
  apply(simp)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   561
  apply(simp)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   562
  apply(simp)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   563
  apply(auto simp add: Sequ_def)[1]
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   564
  apply(subst L_bsimp_ASEQ[symmetric])
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   565
  apply(auto simp add: Sequ_def)[1]
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   566
  apply(subst (asm)  L_bsimp_ASEQ[symmetric])
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   567
  apply(auto simp add: Sequ_def)[1]
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   568
   apply(simp)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   569
   apply(subst L_bsimp_AALTs[symmetric])
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   570
   defer
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   571
   apply(simp)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   572
  apply(subst (2)L_erase_AALTs)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   573
  apply(subst L_erase_flts)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   574
  apply(auto)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   575
   apply (simp add: L_erase_AALTs)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   576
  using L_erase_AALTs by blast
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   577
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   578
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   579
lemma bsimp_ASEQ1:
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   580
  assumes "r1 \<noteq> AZERO" "r2 \<noteq> AZERO" "\<forall>bs. r1 \<noteq> AONE bs"
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   581
  shows "bsimp_ASEQ bs r1 r2 = ASEQ bs r1 r2"
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   582
  using assms
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   583
  apply(induct bs r1 r2 rule: bsimp_ASEQ.induct)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   584
  apply(auto)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   585
  done
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   586
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   587
lemma bsimp_ASEQ2:
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   588
  shows "bsimp_ASEQ bs (AONE bs1) r2 = fuse (bs @ bs1) r2"
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   589
  apply(induct r2)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   590
  apply(auto)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   591
  done
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   592
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   593
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   594
lemma L_bders_simp:
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   595
  shows "L (erase (bders_simp r s)) = L (erase (bders r s))"
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   596
  apply(induct s arbitrary: r rule: rev_induct)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   597
   apply(simp)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   598
  apply(simp)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   599
  apply(simp add: ders_append)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   600
  apply(simp add: bders_simp_append)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   601
  apply(simp add: L_bsimp_erase[symmetric])
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   602
  by (simp add: der_correctness)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   603
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   604
lemma b1:
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   605
  "bsimp_ASEQ bs1 (AONE bs) r =  fuse (bs1 @ bs) r" 
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   606
  apply(induct r)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   607
       apply(auto)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   608
  done
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   609
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   610
lemma b2:
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   611
  assumes "bnullable r"
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   612
  shows "bmkeps (fuse bs r) = bs @ bmkeps r"
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   613
  by (simp add: assms bmkeps_retrieve bnullable_correctness erase_fuse mkeps_nullable retrieve_fuse2)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   614
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   615
lemma b3:
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   616
  shows "bnullable r = bnullable (bsimp r)"
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   617
  using L_bsimp_erase bnullable_correctness nullable_correctness by auto
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   618
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   619
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   620
lemma b4:
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   621
  shows "bnullable (bders_simp r s) = bnullable (bders r s)"
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   622
  by (metis L_bders_simp bnullable_correctness lexer.simps(1) lexer_correct_None option.distinct(1))
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   623
  
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   624
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   625
lemma q1:
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   626
  assumes "\<forall>r \<in> set rs. bmkeps(bsimp r) = bmkeps r"
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   627
  shows "map (\<lambda>r. bmkeps(bsimp r)) rs = map bmkeps rs"
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   628
  using assms
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   629
  apply(induct rs)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   630
  apply(simp)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   631
  apply(simp)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   632
  done
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   633
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   634
lemma q3:
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   635
  assumes "\<exists>r \<in> set rs. bnullable r"
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   636
  shows "bmkeps (AALTs bs rs) = bmkeps (bsimp_AALTs bs rs)"
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   637
  using assms
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   638
  apply(induct bs rs rule: bsimp_AALTs.induct)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   639
    apply(simp)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   640
   apply(simp)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   641
  apply (simp add: b2)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   642
  apply(simp)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   643
  done
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   644
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   645
lemma qq1:
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   646
  assumes "\<exists>r \<in> set rs. bnullable r"
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   647
  shows "bmkeps (AALTs bs (rs @ rs1)) = bmkeps (AALTs bs rs)"
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   648
  using assms
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   649
  apply(induct rs arbitrary: rs1 bs)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   650
  apply(simp)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   651
  apply(simp)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   652
  by (metis Nil_is_append_conv bmkeps.simps(4) neq_Nil_conv r0 split_list_last)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   653
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   654
lemma qq2:
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   655
  assumes "\<forall>r \<in> set rs. \<not> bnullable r" "\<exists>r \<in> set rs1. bnullable r"
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   656
  shows "bmkeps (AALTs bs (rs @ rs1)) = bmkeps (AALTs bs rs1)"
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   657
  using assms
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   658
  apply(induct rs arbitrary: rs1 bs)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   659
  apply(simp)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   660
  apply(simp)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   661
  by (metis append_assoc in_set_conv_decomp r1 r2)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   662
  
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   663
lemma qq3:
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   664
  shows "bnullable (AALTs bs rs) = (\<exists>r \<in> set rs. bnullable r)"
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   665
  apply(induct rs arbitrary: bs)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   666
  apply(simp)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   667
  apply(simp)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   668
  done
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   669
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   670
lemma q3a:
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   671
  assumes "\<exists>r \<in> set rs. bnullable r"
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   672
  shows "bmkeps (AALTs bs (map (fuse bs1) rs)) = bmkeps (AALTs (bs@bs1) rs)"
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   673
  using assms
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   674
  apply(induct rs arbitrary: bs bs1)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   675
   apply(simp)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   676
  apply(simp)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   677
  apply(auto)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   678
   apply (metis append_assoc b2 bnullable_correctness erase_fuse r0)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   679
  apply(case_tac "bnullable a")
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   680
   apply (metis append.assoc b2 bnullable_correctness erase_fuse r0)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   681
  apply(case_tac rs)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   682
  apply(simp)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   683
  apply(simp)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   684
  apply(auto)[1]
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   685
   apply (metis bnullable_correctness erase_fuse)+
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   686
  done
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   687
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   688
lemma qq4:
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   689
  assumes "\<exists>x\<in>set list. bnullable x"
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   690
  shows "\<exists>x\<in>set (flts list). bnullable x"
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   691
  using assms
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   692
  apply(induct list rule: flts.induct)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   693
        apply(auto)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   694
  by (metis UnCI bnullable_correctness erase_fuse imageI)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   695
  
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   696
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   697
lemma qs3:
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   698
  assumes "\<exists>r \<in> set rs. bnullable r"
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   699
  shows "bmkeps (AALTs bs rs) = bmkeps (AALTs bs (flts rs))"
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   700
  using assms
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   701
  apply(induct rs arbitrary: bs taking: size rule: measure_induct)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   702
  apply(case_tac x)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   703
  apply(simp)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   704
  apply(simp)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   705
  apply(case_tac a)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   706
       apply(simp)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   707
       apply (simp add: r1)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   708
      apply(simp)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   709
      apply (simp add: r0)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   710
     apply(simp)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   711
     apply(case_tac "flts list")
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   712
      apply(simp)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   713
  apply (metis L_erase_AALTs L_erase_flts L_flat_Prf1 L_flat_Prf2 Prf_elims(1) bnullable_correctness erase.simps(4) mkeps_nullable r2)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   714
     apply(simp)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   715
     apply (simp add: r1)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   716
    prefer 3
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   717
    apply(simp)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   718
    apply (simp add: r0)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   719
   prefer 2
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   720
   apply(simp)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   721
  apply(case_tac "\<exists>x\<in>set x52. bnullable x")
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   722
  apply(case_tac "list")
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   723
    apply(simp)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   724
    apply (metis b2 fuse.simps(4) q3a r2)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   725
   apply(erule disjE)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   726
    apply(subst qq1)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   727
     apply(auto)[1]
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   728
     apply (metis bnullable_correctness erase_fuse)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   729
    apply(simp)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   730
     apply (metis b2 fuse.simps(4) q3a r2)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   731
    apply(simp)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   732
    apply(auto)[1]
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   733
     apply(subst qq1)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   734
      apply (metis bnullable_correctness erase_fuse image_eqI set_map)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   735
     apply (metis b2 fuse.simps(4) q3a r2)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   736
  apply(subst qq1)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   737
      apply (metis bnullable_correctness erase_fuse image_eqI set_map)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   738
    apply (metis b2 fuse.simps(4) q3a r2)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   739
   apply(simp)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   740
   apply(subst qq2)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   741
     apply (metis bnullable_correctness erase_fuse imageE set_map)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   742
  prefer 2
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   743
  apply(case_tac "list")
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   744
     apply(simp)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   745
    apply(simp)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   746
   apply (simp add: qq4)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   747
  apply(simp)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   748
  apply(auto)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   749
   apply(case_tac list)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   750
    apply(simp)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   751
   apply(simp)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   752
   apply (simp add: r0)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   753
  apply(case_tac "bnullable (ASEQ x41 x42 x43)")
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   754
   apply(case_tac list)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   755
    apply(simp)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   756
   apply(simp)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   757
   apply (simp add: r0)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   758
  apply(simp)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   759
  using qq4 r1 r2 by auto
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   760
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   761
lemma  k0:
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   762
  shows "flts (r # rs1) = flts [r] @ flts rs1"
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   763
  apply(induct r arbitrary: rs1)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   764
   apply(auto)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   765
  done
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   766
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   767
lemma k1:
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   768
  assumes "\<And>x2aa. \<lbrakk>x2aa \<in> set x2a; bnullable x2aa\<rbrakk> \<Longrightarrow> bmkeps x2aa = bmkeps (bsimp x2aa)"
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   769
          "\<exists>x\<in>set x2a. bnullable x"
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   770
        shows "bmkeps (AALTs x1 (flts x2a)) = bmkeps (AALTs x1 (flts (map bsimp x2a)))"
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   771
  using assms
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   772
  apply(induct x2a)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   773
  apply fastforce
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   774
  apply(simp)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   775
  apply(subst k0)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   776
  apply(subst (2) k0)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   777
  apply(auto)[1]
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   778
  apply (metis b3 k0 list.set_intros(1) qs3 r0)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   779
  by (smt b3 imageI insert_iff k0 list.set(2) qq3 qs3 r0 r1 set_map)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   780
  
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   781
  
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   782
  
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   783
lemma bmkeps_simp:
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   784
  assumes "bnullable r"
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   785
  shows "bmkeps r = bmkeps (bsimp r)"
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   786
  using  assms
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   787
  apply(induct r)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   788
       apply(simp)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   789
      apply(simp)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   790
     apply(simp)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   791
    apply(simp)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   792
    prefer 3
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   793
  apply(simp)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   794
   apply(case_tac "bsimp r1 = AZERO")
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   795
    apply(simp)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   796
    apply(auto)[1]
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   797
  apply (metis L_bsimp_erase L_flat_Prf1 L_flat_Prf2 Prf_elims(1) bnullable_correctness erase.simps(1) mkeps_nullable)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   798
 apply(case_tac "bsimp r2 = AZERO")
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   799
    apply(simp)  
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   800
    apply(auto)[1]
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   801
  apply (metis L_bsimp_erase L_flat_Prf1 L_flat_Prf2 Prf_elims(1) bnullable_correctness erase.simps(1) mkeps_nullable)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   802
  apply(case_tac "\<exists>bs. bsimp r1 = AONE bs")
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   803
    apply(auto)[1]
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   804
    apply(subst b1)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   805
    apply(subst b2)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   806
  apply(simp add: b3[symmetric])
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   807
    apply(simp)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   808
   apply(subgoal_tac "bsimp_ASEQ x1 (bsimp r1) (bsimp r2) = ASEQ x1 (bsimp r1) (bsimp r2)")
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   809
    prefer 2
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   810
  apply (smt b3 bnullable.elims(2) bsimp_ASEQ.simps(17) bsimp_ASEQ.simps(19) bsimp_ASEQ.simps(20) bsimp_ASEQ.simps(21) bsimp_ASEQ.simps(22) bsimp_ASEQ.simps(24) bsimp_ASEQ.simps(25) bsimp_ASEQ.simps(26) bsimp_ASEQ.simps(27) bsimp_ASEQ.simps(29) bsimp_ASEQ.simps(30) bsimp_ASEQ.simps(31))
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   811
   apply(simp)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   812
  apply(simp)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   813
  apply(subst q3[symmetric])
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   814
   apply simp
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   815
  using b3 qq4 apply auto[1]
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   816
  apply(subst qs3)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   817
   apply simp
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   818
  using k1 by blast
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   819
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   820
thm bmkeps_retrieve bmkeps_simp bder_retrieve
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   821
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   822
lemma bmkeps_bder_AALTs:
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   823
  assumes "\<exists>r \<in> set rs. bnullable (bder c r)" 
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   824
  shows "bmkeps (bder c (bsimp_AALTs bs rs)) = bmkeps (bsimp_AALTs bs (map (bder c) rs))"
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   825
  using assms
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   826
  apply(induct rs)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   827
   apply(simp)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   828
  apply(simp)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   829
  apply(auto)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   830
  apply(case_tac rs)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   831
    apply(simp)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   832
  apply (metis (full_types) Prf_injval bder_retrieve bmkeps_retrieve bnullable_correctness erase_bder erase_fuse mkeps_nullable retrieve_fuse2)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   833
   apply(simp)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   834
  apply(case_tac  rs)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   835
   apply(simp_all)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   836
  done
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   837
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   838
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   839
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   840
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   841
lemma MAIN_decode:
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   842
  assumes "\<Turnstile> v : ders s r"
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   843
  shows "Some (flex r id s v) = decode (retrieve (bders_simp (intern r) s) v) r"
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   844
  using assms
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   845
proof (induct s arbitrary: v rule: rev_induct)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   846
  case Nil
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   847
  have "\<Turnstile> v : ders [] r" by fact
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   848
  then have "\<Turnstile> v : r" by simp
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   849
  then have "Some v = decode (retrieve (intern r) v) r"
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   850
    using decode_code retrieve_code by auto
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   851
  then show "Some (flex r id [] v) = decode (retrieve (bders_simp (intern r) []) v) r"
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   852
    by simp
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   853
next
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   854
  case (snoc c s v)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   855
  have IH: "\<And>v. \<Turnstile> v : ders s r \<Longrightarrow> 
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   856
     Some (flex r id s v) = decode (retrieve (bders_simp (intern r) s) v) r" by fact
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   857
  have asm: "\<Turnstile> v : ders (s @ [c]) r" by fact
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   858
  then have asm2: "\<Turnstile> injval (ders s r) c v : ders s r" 
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   859
    by(simp add: Prf_injval ders_append)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   860
  have "Some (flex r id (s @ [c]) v) = Some (flex r id s (injval (ders s r) c v))"
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   861
    by (simp add: flex_append)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   862
  also have "... = decode (retrieve (bders_simp (intern r) s) (injval (ders s r) c v)) r"
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   863
    using asm2 IH by simp
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   864
  also have "... = decode (retrieve (bder c (bders_simp (intern r) s)) v) r"
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   865
    using asm bder_retrieve ders_append 
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   866
    apply -
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   867
    apply(drule_tac x="v" in meta_spec)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   868
    apply(drule_tac x="c" in meta_spec)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   869
    apply(drule_tac x="bders_simp (intern r) s" in meta_spec)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   870
    apply(drule_tac  meta_mp)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   871
     apply(simp add: ders_append)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   872
     defer
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   873
    apply(simp)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   874
    oops
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   875
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   876
function (sequential) bretrieve :: "arexp \<Rightarrow> bit list \<Rightarrow> (bit list) * (bit list)" where
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   877
  "bretrieve (AZERO) bs1 = ([], bs1)"
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   878
| "bretrieve (AONE bs) bs1 = (bs, bs1)"
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   879
| "bretrieve (ACHAR bs c) bs1 = (bs, bs1)"
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   880
| "bretrieve (AALTs bs rs) [] = (bs, [])"
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   881
| "bretrieve (AALTs bs [r]) bs1 = 
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   882
     (let (bs2, bs3) = bretrieve r bs1 in (bs @ bs2, bs3))"
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   883
| "bretrieve (AALTs bs (r#rs)) (Z#bs1) = 
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   884
     (let (bs2, bs3) = bretrieve r bs1 in (bs @ [Z] @ bs2, bs3))"
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   885
| "bretrieve (AALTs bs (r#rs)) (S#bs1) = 
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   886
     (let (bs2, bs3) = bretrieve (AALTs [] rs) bs1 in (bs @ [S] @ bs2, bs3))"
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   887
| "bretrieve (ASEQ bs r1 r2) bs1 = 
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   888
     (let (bs2, bs3) = bretrieve r1 bs1 in 
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   889
      let (bs4, bs5) = bretrieve r2 bs3 in (bs @ bs2 @ bs4, bs5))"
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   890
| "bretrieve (ASTAR bs r) [] = (bs, [])"
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   891
| "bretrieve (ASTAR bs r) (S#bs1) = (bs @ [S], bs1)"
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   892
| "bretrieve (ASTAR bs r) (Z#bs1) = 
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   893
     (let (bs2, bs3) = bretrieve r bs1 in 
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   894
      let (bs4, bs5) = bretrieve (ASTAR [] r) bs3 in (bs @ bs2 @ [Z] @ bs4, bs5))"
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   895
  by (pat_completeness) (auto)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   896
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   897
termination
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   898
  sorry
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   899
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   900
thm Prf.intros
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   901
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   902
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   903
lemma retrieve_XXX:
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   904
  assumes "\<Turnstile> v : erase r" 
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   905
  shows "\<exists>v'. \<Turnstile> v' : erase (bsimp r)  \<and> retrieve (bsimp r) v' = retrieve r v"
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   906
  using assms
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   907
  apply(induct r arbitrary: v)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   908
       apply(simp)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   909
  using Prf_elims(1) apply blast
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   910
      apply(simp)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   911
  using Prf_elims(4) apply fastforce
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   912
    apply(simp)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   913
  apply blast
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   914
  apply simp
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   915
   apply(case_tac  "r1 = AZERO")
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   916
     apply(simp)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   917
  apply (meson Prf_elims(1) Prf_elims(2))
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   918
  apply(case_tac  "r2 = AZERO")
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   919
     apply(simp)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   920
     apply (meson Prf_elims(1) Prf_elims(2))
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   921
  apply(erule Prf_elims)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   922
  apply(simp)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   923
   apply(case_tac "\<exists>bs. bsimp r1 = AONE bs")
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   924
     apply(clarify)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   925
     apply(simp)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   926
    apply(subst bsimp_ASEQ2)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   927
     defer
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   928
     apply(subst bsimp_ASEQ1)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   929
  using L_bsimp_erase L_flat_Prf1 L_flat_Prf2 apply fastforce
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   930
  using L_bsimp_erase L_flat_Prf1 L_flat_Prf2 apply fastforce
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   931
      apply(simp)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   932
    apply(simp)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   933
  apply(drule_tac  x="v1" in meta_spec)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   934
  apply(drule_tac  x="v2" in meta_spec)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   935
     apply(simp)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   936
  apply(clarify)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   937
     apply(rule_tac x="Seq v' v'a" in exI)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   938
     apply(simp)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   939
  apply (metis Prf.intros(1) Prf_elims(1) bsimp_ASEQ1 erase.simps(1) retrieve.simps(6))
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   940
    prefer 3
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   941
  apply(drule_tac  x="v1" in meta_spec)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   942
  apply(drule_tac  x="v2" in meta_spec)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   943
     apply(simp)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   944
    apply(clarify)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   945
    apply(rule_tac x="v'a" in exI)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   946
    apply(subst bsimp_ASEQ2)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   947
    apply (metis Prf_elims(4) append_assoc erase_fuse retrieve.simps(1) retrieve_fuse2)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   948
   prefer 2  
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   949
   apply(auto)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   950
  apply(case_tac "x2a")
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   951
   apply(simp)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   952
  using Prf_elims(1) apply blast
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   953
  apply(simp)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   954
  apply(case_tac "list")
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   955
   apply(simp)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   956
  sorry
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   957
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   958
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   959
lemma TEST:
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   960
  assumes "\<Turnstile> v : ders s r"
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   961
  shows "retrieve (bders (intern r) s) v = retrieve (bsimp (bders (intern r) s)) v"
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   962
  using assms
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   963
  apply(induct s arbitrary: r v rule: rev_induct)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   964
   apply(simp)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   965
   defer
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   966
   apply(simp add: ders_append)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   967
   apply(frule Prf_injval)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   968
  apply(drule_tac x="r" in meta_spec)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   969
   apply(drule_tac x="injval (ders xs r) x v" in meta_spec)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   970
   apply(simp)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   971
   apply(simp add: bders_append)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   972
   apply(subst bder_retrieve)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   973
    apply(simp)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   974
   apply(simp)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   975
  thm bder_retrieve
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   976
  thm bmkeps_retrieve
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   977
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   978
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   979
lemma bmkeps_simp2:
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   980
  assumes "bnullable (bder c r)"
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   981
  shows "bmkeps (bder c (bsimp r)) = bmkeps (bder c r)"
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   982
  using  assms
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   983
  apply(induct r)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   984
       apply(simp)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   985
      apply(simp)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   986
     apply(simp)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   987
  prefer 3
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   988
    apply(simp)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   989
   apply(simp)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   990
   apply(auto)[1]
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   991
     prefer 2
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   992
     apply(case_tac "r1 = AZERO")
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   993
      apply(simp)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   994
   apply(case_tac "r2 = AZERO")
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   995
      apply(simp)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   996
     apply(case_tac "\<exists>bs. (bsimp r1) = AONE bs")
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   997
      apply(clarify)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   998
      apply(simp)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
   999
      apply(subst bsimp_ASEQ2)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1000
  
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1001
   apply(simp add: bmkeps_simp)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1002
  apply(simp add: bders_append)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1003
  apply(drule_tac x="bder a r" in meta_spec)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1004
       apply(simp)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1005
      apply(simp)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1006
     apply(simp)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1007
    prefer 3
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1008
    apply(simp)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1009
   prefer 2
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1010
   apply(simp)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1011
   apply(case_tac x2a)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1012
    apply(simp)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1013
  apply(simp add: )
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1014
  apply(subst k0)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1015
   apply(auto)[1]
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1016
    apply(case_tac list)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1017
     apply(simp)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1018
  
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1019
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1020
   apply(case_tac  "r1=AZERO")
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1021
    apply(simp)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1022
   apply(case_tac  "r2=AZERO")
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1023
    apply(simp)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1024
    apply(auto)[1]
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1025
   apply(case_tac  "\<exists>bs. r1=AONE bs")
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1026
  apply(simp)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1027
    apply(auto)[1]
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1028
     apply(subst bsimp_ASEQ2)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1029
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1030
  
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1031
   prefer 2
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1032
   apply(simp)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1033
  apply(subst  bmkeps_bder_AALTs)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1034
   apply(case_tac x2a)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1035
    apply(simp)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1036
   apply(simp)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1037
   apply(auto)[1]
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1038
    apply(subst  bmkeps_bder_AALTs)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1039
  
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1040
   apply(case_tac a)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1041
  apply(simp_all)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1042
   apply(auto)[1]
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1043
    apply(case_tac list)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1044
         apply(simp)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1045
        apply(simp)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1046
  
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1047
     prefer 2
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1048
  apply(simp)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1049
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1050
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1051
lemma bbs0:
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1052
  shows "blexer_simp r [] = blexer r []"
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1053
  apply(simp add: blexer_def blexer_simp_def)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1054
  done
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1055
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1056
lemma bbs1:
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1057
  shows "blexer_simp r [c] = blexer r [c]"
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1058
  apply(simp add: blexer_def blexer_simp_def)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1059
  apply(auto)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1060
    defer
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1061
  using b3 apply auto[1]
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1062
  using b3 apply auto[1]  
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1063
  apply(subst bmkeps_simp[symmetric])
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1064
   apply(simp)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1065
  apply(simp)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1066
  done
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1067
  
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1068
lemma bbs1:
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1069
  shows "blexer_simp r [c1, c2] = blexer r [c1, c2]"
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1070
  apply(simp add: blexer_def blexer_simp_def)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1071
  apply(auto)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1072
    defer
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1073
  apply (metis L_bsimp_erase bnullable_correctness der_correctness erase_bder lexer.simps(1) lexer_correct_None option.distinct(1))
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1074
  apply (metis L_bsimp_erase bnullable_correctness der_correctness erase_bder lexer.simps(1) lexer_correct_None option.distinct(1))
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1075
  apply(subst bmkeps_simp[symmetric])
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1076
  using b3 apply auto[1]
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1077
  apply(subst bmkeps_retrieve)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1078
  using b3 bnullable_correctness apply blast
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1079
  apply(subst bder_retrieve)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1080
  using b3 bnullable_correctness mkeps_nullable apply fastforce
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1081
  apply(subst bmkeps_retrieve)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1082
  using bnullable_correctness apply blast
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1083
  apply(subst bder_retrieve)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1084
  using bnullable_correctness mkeps_nullable apply force
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1085
  
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1086
  using bder_retrieve bmkeps_simp bmkeps_retrieve
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1087
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1088
  
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1089
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1090
lemma bsimp_retrieve_bder:
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1091
  assumes "\<Turnstile> v : der c (erase r)"
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1092
  shows "retrieve (bder c r) v = retrieve (bsimp (bder c r)) v"
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1093
  thm bder_retrieve bmkeps_simp
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1094
  apply(induct  r arbitrary: c v)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1095
       apply(simp)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1096
      apply(simp)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1097
     apply(simp)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1098
    apply(auto)[1]
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1099
     apply(case_tac "bsimp (bder c r1) = AZERO")
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1100
      apply(simp)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1101
  
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1102
    prefer 3
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1103
    apply(simp)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1104
  apply(auto elim!: Prf_elims)[1]
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1105
    apply(case_tac "(bsimp (fuse [Z] (bder c r))) = AZERO")
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1106
     apply(simp)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1107
     apply (metis L_bsimp_erase L_flat_Prf1 L_flat_Prf2 Prf_elims(1) erase.simps(1) erase_bder erase_fuse)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1108
    apply(case_tac "\<exists>bs. bsimp (fuse [Z] (bder c r)) = AONE bs")
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1109
     apply(clarify)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1110
     apply(subgoal_tac "L (der c (erase r)) = {[]}")
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1111
      prefer 2
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1112
      apply (metis L.simps(2) L_bsimp_erase erase.simps(2) erase_bder erase_fuse)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1113
     apply(simp)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1114
  
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1115
  
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1116
  
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1117
    apply(subst bsimp_ASEQ1)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1118
       apply(simp)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1119
      apply(simp)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1120
  apply(auto)[1]
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1121
  
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1122
     prefer 2
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1123
  
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1124
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1125
lemma oo:
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1126
  shows "(case (blexer (der c r) s) of None \<Rightarrow> None | Some v \<Rightarrow> Some (injval r c v)) = blexer r (c # s)"
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1127
  apply(simp add: blexer_correctness)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1128
  done
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1129
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1130
lemma oo2a:
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1131
  assumes "\<forall>r. bmkeps (bders_simp r s) = bmkeps (bders r s)" "c # s \<in> L r"
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1132
          "bnullable (bders_simp (bsimp (bder c (intern r))) s)"
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1133
  shows "(case (blexer_simp (der c r) s) of None \<Rightarrow> None | Some v \<Rightarrow> Some (injval r c v)) = blexer_simp r (c # s)"
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1134
  using assms
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1135
  apply(simp add: blexer_simp_def)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1136
  apply(auto  split: option.split)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1137
    apply (metis blexer_correctness blexer_def lexer.simps(2) lexer_correct_None option.simps(4))
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1138
   prefer 2
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1139
  apply (metis L_bders_simp L_bsimp_erase Posix1(1) Posix_mkeps bnullable_correctness ders_correctness erase_bder erase_bders erase_intern lexer.simps(1) lexer_correct_None)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1140
  apply(subst bmkeps_retrieve)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1141
  using L_bders_simp bnullable_correctness nullable_correctness apply blast
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1142
  
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1143
  thm bder_retrieve
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1144
  
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1145
  
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1146
  apply(subst bder_retrieve[symmetric])
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1147
  
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1148
  
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1149
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1150
  apply(drule_tac x="bsimp (bder c (intern r))" in  spec)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1151
  apply(drule sym)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1152
   apply(simp)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1153
   apply(subst blexer_simp_def)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1154
  apply(case_tac "bnullable (bders_simp (intern (der c r)) s)")
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1155
   apply(simp)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1156
  apply(auto split: option.split)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1157
  apply(subst oo)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1158
  apply(simp)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1159
  done
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1160
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1161
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1162
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1163
lemma oo3:
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1164
  assumes "\<forall>r. bders r s = bders_simp r s"
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1165
  shows "blexer_simp r (s @ [c]) = blexer r (s @ [c])"
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1166
  using assms
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1167
  apply(simp (no_asm) add: blexer_simp_def)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1168
  apply(auto)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1169
   prefer 2
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1170
  apply (metis L_bders_simp blexer_def bnullable_correctness lexer.simps(1) lexer_correct_None option.distinct(1))
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1171
  apply(simp add: bders_simp_append)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1172
  apply(subst bmkeps_simp[symmetric])
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1173
  using b3 apply auto[1]
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1174
  apply(simp add: blexer_def)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1175
  apply(auto)[1]
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1176
   prefer 2
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1177
  apply (metis (mono_tags, lifting) L_bders_simp Posix_mkeps append.right_neutral bders_simp.simps(1) bders_simp.simps(2) bders_simp_append bnullable_correctness lexer.simps(1) lexer_correct_None lexer_correctness(1) option.distinct(1))
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1178
  apply(simp add: bders_append)     
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1179
  done
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1180
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1181
lemma oo4:
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1182
  assumes "\<forall>r. bmkeps (bders r s) = bmkeps (bders_simp r s)" "bnullable (bder c (bders r s))"
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1183
  shows "bmkeps (bders_simp r (s @ [c])) = bmkeps (bders r (s @ [c]))"
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1184
  using assms
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1185
  apply(simp add: bders_simp_append)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1186
  apply(subst bmkeps_simp[symmetric])
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1187
  apply (metis L_bders_simp bnullable_correctness der_correctness erase_bder lexer.simps(1) lexer_correct_None option.distinct(1))
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1188
  apply(simp add: bders_append)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1189
  done
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1190
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1191
lemma oo4:
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1192
  shows "blexer_simp r s = blexer r s"
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1193
  apply(induct s arbitrary: r rule: rev_induct)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1194
   apply(simp only: blexer_simp_def blexer_def)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1195
   apply(simp)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1196
  apply(simp only: blexer_simp_def blexer_def)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1197
  apply(subgoal_tac "bnullable (bders_simp (intern r) (xs @ [x])) = bnullable (bders (intern r) (xs @ [x]))")
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1198
   prefer 2
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1199
   apply (simp add: b4)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1200
  apply(simp)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1201
  apply(rule impI)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1202
  apply(simp add: bders_simp_append)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1203
  apply(subst bmkeps_simp[symmetric])
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1204
  using b3 apply auto[1]
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1205
  apply(subst bmkeps_retrieve)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1206
  using b3 bnullable_correctness apply blast
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1207
  apply(subst bder_retrieve)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1208
  using b3 bnullable_correctness mkeps_nullable apply fastforce
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1209
  apply(simp add: bders_append)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1210
  apply(subst bmkeps_retrieve)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1211
  using bnullable_correctness apply blast
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1212
  apply(subst bder_retrieve)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1213
  using bnullable_correctness mkeps_nullable apply fastforce
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1214
  apply(subst erase_bder)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1215
  apply(case_tac "xs \<in> L")
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1216
  apply(subst (asm) (2) bmkeps_retrieve)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1217
  
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1218
  
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1219
  thm bmkeps_retrieve bmkeps_retrieve
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1220
  apply(subst bmkeps_retrieve[symmetric])
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1221
  
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1222
   apply (simp add: bnullable_correctness)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1223
  apply(simp add: bders_simp_append)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1224
   
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1225
  
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1226
  apply(induct s arbitrary: r rule: rev_induct) 
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1227
   apply(simp add: blexer_def blexer_simp_def)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1228
  apply(rule oo3)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1229
  apply(simp (no_asm) add: blexer_simp_def)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1230
  apply(auto)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1231
   prefer 2
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1232
  apply (metis L_bders_simp blexer_def bnullable_correctness lexer.simps(1) lexer_correct_None option.distinct(1))
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1233
  apply(simp add: bders_simp_append)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1234
  apply(subst bmkeps_simp[symmetric])
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1235
  using b3 apply auto[1]
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1236
  apply(simp add: blexer_def)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1237
  apply(auto)[1]
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1238
   prefer 2
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1239
  apply (m etis (mono_tags, lifting) L_bders_simp Posix_mkeps append.right_neutral bders_simp.simps(1) bders_simp.simps(2) bders_simp_append bnullable_correctness lexer.simps(1) lexer_correct_None lexer_correctness(1) option.distinct(1))
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1240
  apply(simp add: bders_append)     
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1241
  oops
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1242
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1243
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1244
lemma bnullable_simp:
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1245
  assumes "s \<in> L (erase r)"
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1246
  shows "bmkeps (bders r s) = bmkeps (bders_simp r s)"
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1247
  using assms
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1248
  apply(induct s arbitrary: r rule: rev_induct)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1249
   apply(simp)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1250
  apply(simp add: bders_append bders_simp_append)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1251
  apply(subst bmkeps_simp[symmetric])
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1252
  apply (metis L_bders_simp b3 bders_simp.simps(1) bders_simp.simps(2) bders_simp_append blexer_correctness blexer_def bnullable_correctness erase_bders erase_intern lexer.simps(1) lexer_correct_None lexer_correct_Some lexer_correctness(1))
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1253
  apply(subst bmkeps_retrieve)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1254
  apply (metis bders.simps(1) bders.simps(2) bders_append blexer_correctness blexer_def bnullable_correctness erase_bders erase_intern lexer_correct_Some option.distinct(1))
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1255
  apply(subst bmkeps_retrieve)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1256
  apply (metis L_bders_simp L_bsimp_erase Posix_mkeps bders_simp.simps(1) bders_simp.simps(2) bders_simp_append blexer_correctness blexer_def bnullable_correctness erase_bders erase_intern lexer.simps(1) lexer_correct_None lexer_correctness(2))
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1257
  apply(subst bder_retrieve)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1258
  apply (metis bders.simps(1) bders.simps(2) bders_append blexer_correctness blexer_def bnullable_correctness erase_bder erase_bders erase_intern lexer_correct_Some mkeps_nullable option.distinct(1))
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1259
  apply(subst bder_retrieve)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1260
  apply (metis L_bders_simp L_bsimp_erase Posix_mkeps bders_simp.simps(1) bders_simp.simps(2) bders_simp_append blexer_correctness blexer_def bnullable_correctness erase_bder erase_bders erase_intern lexer.simps(1) lexer_correct_None lexer_correctness(2) mkeps_nullable)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1261
    
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1262
  apply(drule_tac x="bder a r" in meta_spec)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1263
  apply(drule_tac  meta_mp)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1264
  apply (me tis erase_bder lexer.simps(2) lexer_correct_None option.simps(4))
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1265
  apply(simp)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1266
  oops
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1267
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1268
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1269
lemma
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1270
  shows "blexer r s = blexer_simp r s"
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1271
  apply(induct s arbitrary: r rule: rev_induct)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1272
   apply(simp add: blexer_def blexer_simp_def)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1273
  apply(case_tac "xs @ [x] \<in> L r")
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1274
   defer
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1275
   apply(subgoal_tac "blexer (ders xs r) [x] = None")
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1276
    prefer 2
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1277
    apply(subst blexer_correctness)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1278
    apply(simp (no_asm) add: lexer_correct_None)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1279
    apply(simp add: nullable_correctness)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1280
    apply(simp add: der_correctness ders_correctness)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1281
  apply(simp add: Der_def Ders_def)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1282
apply(subgoal_tac "blexer r (xs @ [x]) = None")
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1283
    prefer 2
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1284
    apply (simp add: blexer_correctness)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1285
  using lexer_correct_None apply auto[1]
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1286
  apply(simp)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1287
   apply(subgoal_tac "blexer_simp (ders xs r) [x] = None")
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1288
    prefer 2
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1289
  apply (metis L_bders_simp Posix_injval Posix_mkeps bders.simps(2) blexer_correctness blexer_simp_def bnullable_correctness ders.simps(1) erase_bder erase_bders erase_intern lexer_correct_None lexer_correctness(2))
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1290
   apply(subgoal_tac "[] \<notin> L (erase (bders_simp (intern r) (xs @ [x])))")
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1291
  prefer 2
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1292
  apply(metis L_bders_simp Posix_injval bders.simps(2) blexer_correctness ders.simps(1) ders_append erase_bder erase_bders erase_intern lexer_correct_None lexer_correctness(2))
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1293
  using blexer_simp_def bnullable_correctness lexer_correct_None apply auto[1]
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1294
(* case xs @ [x] \<in> L r *)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1295
  apply(subgoal_tac "\<exists>v. blexer (ders xs r) [x] = Some v \<and> [x] \<in> (ders xs r) \<rightarrow> v")
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1296
   prefer 2  
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1297
  using blexer_correctness lexer_correct_Some apply auto[1]
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1298
    apply (simp add: Posix_injval Posix_mkeps)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1299
  apply (metis ders.simps(1) ders.simps(2) ders_append lexer_correct_None lexer_flex)    
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1300
  apply(clarify)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1301
  apply(subgoal_tac "blexer_simp (ders xs r) [x] = Some v")
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1302
   prefer 2
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1303
   apply(simp add: blexer_simp_def)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1304
   apply(auto)[1]
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1305
    apply (metis bders.simps(1) bders.simps(2) blexer_def bmkeps_simp option.simps(3))
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1306
  using b3 blexer_def apply fastforce
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1307
  apply(subgoal_tac "blexer_simp (ders xs r) [x] = blexer_simp r (xs @ [x])")
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1308
   prefer 2
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1309
   apply(simp add: blexer_simp_def)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1310
  
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1311
   apply(simp)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1312
  
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1313
  
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1314
  
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1315
   apply(simp)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1316
  apply(subst blexer_simp_def)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1317
  apply(simp)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1318
  apply(auto)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1319
  apply(drule_tac x="der a r" in meta_spec)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1320
  apply(subst blexer_def)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1321
   apply(subgoal_tac "bnullable (bders (intern r) (a # s))")
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1322
    prefer 2
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1323
    apply (metis Posix_injval blexer_correctness blexer_def lexer_correctness(2))
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1324
  apply(simp)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1325
  
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1326
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1327
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1328
lemma
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1329
  shows "blexer r s = blexer_simp r s"
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1330
  apply(induct s arbitrary: r)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1331
   apply(simp add: blexer_def blexer_simp_def)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1332
  apply(case_tac "s \<in> L (der a r)")
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1333
   defer
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1334
   apply(subgoal_tac "blexer (der a r) s = None")
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1335
    prefer 2
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1336
    apply (simp add: blexer_correctness lexer_correct_None)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1337
apply(subgoal_tac "blexer r (a # s) = None")
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1338
    prefer 2
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1339
    apply (simp add: blexer_correctness)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1340
   apply(simp)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1341
  
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1342
   apply(subst blexer_simp_def)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1343
   apply(simp)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1344
  apply(drule_tac  x="der a r" in  meta_spec)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1345
   apply(subgoal_tac "s \<notin> L(erase (bder a (intern  r)))")
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1346
  prefer 2
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1347
    apply simp
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1348
   
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1349
   apply(simp only:)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1350
   apply(subst blexer_simp_def)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1351
   apply(subgoal_tac "\<not> bnullable (bders_simp (intern r) (a # s))")
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1352
    apply(simp)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1353
   apply(subst bnullable_correctness[symmetric])
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1354
  apply(simp)
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1355
  
20a57552d722 updated
Christian Urban <urbanc@in.tum.de>
parents: 313
diff changeset
  1356
295
c6ec5f369037 updated
Christian Urban <urbanc@in.tum.de>
parents: 293
diff changeset
  1357
148
702ed601349b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1358
end