thys2/SizeBoundStrong.thy
author Chengsong
Wed, 23 Aug 2023 03:02:31 +0100
changeset 668 3831621d7b14
parent 494 c730d018ebfa
permissions -rw-r--r--
added technical Overview section, almost done introduction
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
432
994403dbbed5 strong!
Chengsong
parents:
diff changeset
     1
994403dbbed5 strong!
Chengsong
parents:
diff changeset
     2
theory SizeBoundStrong
994403dbbed5 strong!
Chengsong
parents:
diff changeset
     3
  imports "Lexer" 
994403dbbed5 strong!
Chengsong
parents:
diff changeset
     4
begin
994403dbbed5 strong!
Chengsong
parents:
diff changeset
     5
994403dbbed5 strong!
Chengsong
parents:
diff changeset
     6
section \<open>Bit-Encodings\<close>
994403dbbed5 strong!
Chengsong
parents:
diff changeset
     7
994403dbbed5 strong!
Chengsong
parents:
diff changeset
     8
datatype bit = Z | S
994403dbbed5 strong!
Chengsong
parents:
diff changeset
     9
994403dbbed5 strong!
Chengsong
parents:
diff changeset
    10
fun code :: "val \<Rightarrow> bit list"
994403dbbed5 strong!
Chengsong
parents:
diff changeset
    11
where
994403dbbed5 strong!
Chengsong
parents:
diff changeset
    12
  "code Void = []"
994403dbbed5 strong!
Chengsong
parents:
diff changeset
    13
| "code (Char c) = []"
994403dbbed5 strong!
Chengsong
parents:
diff changeset
    14
| "code (Left v) = Z # (code v)"
994403dbbed5 strong!
Chengsong
parents:
diff changeset
    15
| "code (Right v) = S # (code v)"
994403dbbed5 strong!
Chengsong
parents:
diff changeset
    16
| "code (Seq v1 v2) = (code v1) @ (code v2)"
994403dbbed5 strong!
Chengsong
parents:
diff changeset
    17
| "code (Stars []) = [S]"
994403dbbed5 strong!
Chengsong
parents:
diff changeset
    18
| "code (Stars (v # vs)) =  (Z # code v) @ code (Stars vs)"
994403dbbed5 strong!
Chengsong
parents:
diff changeset
    19
994403dbbed5 strong!
Chengsong
parents:
diff changeset
    20
994403dbbed5 strong!
Chengsong
parents:
diff changeset
    21
fun 
994403dbbed5 strong!
Chengsong
parents:
diff changeset
    22
  Stars_add :: "val \<Rightarrow> val \<Rightarrow> val"
994403dbbed5 strong!
Chengsong
parents:
diff changeset
    23
where
994403dbbed5 strong!
Chengsong
parents:
diff changeset
    24
  "Stars_add v (Stars vs) = Stars (v # vs)"
994403dbbed5 strong!
Chengsong
parents:
diff changeset
    25
994403dbbed5 strong!
Chengsong
parents:
diff changeset
    26
function
994403dbbed5 strong!
Chengsong
parents:
diff changeset
    27
  decode' :: "bit list \<Rightarrow> rexp \<Rightarrow> (val * bit list)"
994403dbbed5 strong!
Chengsong
parents:
diff changeset
    28
where
994403dbbed5 strong!
Chengsong
parents:
diff changeset
    29
  "decode' ds ZERO = (Void, [])"
994403dbbed5 strong!
Chengsong
parents:
diff changeset
    30
| "decode' ds ONE = (Void, ds)"
994403dbbed5 strong!
Chengsong
parents:
diff changeset
    31
| "decode' ds (CH d) = (Char d, ds)"
994403dbbed5 strong!
Chengsong
parents:
diff changeset
    32
| "decode' [] (ALT r1 r2) = (Void, [])"
994403dbbed5 strong!
Chengsong
parents:
diff changeset
    33
| "decode' (Z # ds) (ALT r1 r2) = (let (v, ds') = decode' ds r1 in (Left v, ds'))"
994403dbbed5 strong!
Chengsong
parents:
diff changeset
    34
| "decode' (S # ds) (ALT r1 r2) = (let (v, ds') = decode' ds r2 in (Right v, ds'))"
994403dbbed5 strong!
Chengsong
parents:
diff changeset
    35
| "decode' ds (SEQ r1 r2) = (let (v1, ds') = decode' ds r1 in
994403dbbed5 strong!
Chengsong
parents:
diff changeset
    36
                             let (v2, ds'') = decode' ds' r2 in (Seq v1 v2, ds''))"
994403dbbed5 strong!
Chengsong
parents:
diff changeset
    37
| "decode' [] (STAR r) = (Void, [])"
994403dbbed5 strong!
Chengsong
parents:
diff changeset
    38
| "decode' (S # ds) (STAR r) = (Stars [], ds)"
994403dbbed5 strong!
Chengsong
parents:
diff changeset
    39
| "decode' (Z # ds) (STAR r) = (let (v, ds') = decode' ds r in
994403dbbed5 strong!
Chengsong
parents:
diff changeset
    40
                                    let (vs, ds'') = decode' ds' (STAR r) 
994403dbbed5 strong!
Chengsong
parents:
diff changeset
    41
                                    in (Stars_add v vs, ds''))"
994403dbbed5 strong!
Chengsong
parents:
diff changeset
    42
by pat_completeness auto
994403dbbed5 strong!
Chengsong
parents:
diff changeset
    43
994403dbbed5 strong!
Chengsong
parents:
diff changeset
    44
lemma decode'_smaller:
994403dbbed5 strong!
Chengsong
parents:
diff changeset
    45
  assumes "decode'_dom (ds, r)"
994403dbbed5 strong!
Chengsong
parents:
diff changeset
    46
  shows "length (snd (decode' ds r)) \<le> length ds"
994403dbbed5 strong!
Chengsong
parents:
diff changeset
    47
using assms
994403dbbed5 strong!
Chengsong
parents:
diff changeset
    48
apply(induct ds r)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
    49
apply(auto simp add: decode'.psimps split: prod.split)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
    50
using dual_order.trans apply blast
994403dbbed5 strong!
Chengsong
parents:
diff changeset
    51
by (meson dual_order.trans le_SucI)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
    52
994403dbbed5 strong!
Chengsong
parents:
diff changeset
    53
termination "decode'"  
994403dbbed5 strong!
Chengsong
parents:
diff changeset
    54
apply(relation "inv_image (measure(%cs. size cs) <*lex*> measure(%s. size s)) (%(ds,r). (r,ds))") 
994403dbbed5 strong!
Chengsong
parents:
diff changeset
    55
apply(auto dest!: decode'_smaller)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
    56
by (metis less_Suc_eq_le snd_conv)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
    57
994403dbbed5 strong!
Chengsong
parents:
diff changeset
    58
definition
994403dbbed5 strong!
Chengsong
parents:
diff changeset
    59
  decode :: "bit list \<Rightarrow> rexp \<Rightarrow> val option"
994403dbbed5 strong!
Chengsong
parents:
diff changeset
    60
where
994403dbbed5 strong!
Chengsong
parents:
diff changeset
    61
  "decode ds r \<equiv> (let (v, ds') = decode' ds r 
994403dbbed5 strong!
Chengsong
parents:
diff changeset
    62
                  in (if ds' = [] then Some v else None))"
994403dbbed5 strong!
Chengsong
parents:
diff changeset
    63
994403dbbed5 strong!
Chengsong
parents:
diff changeset
    64
lemma decode'_code_Stars:
994403dbbed5 strong!
Chengsong
parents:
diff changeset
    65
  assumes "\<forall>v\<in>set vs. \<Turnstile> v : r \<and> (\<forall>x. decode' (code v @ x) r = (v, x)) \<and> flat v \<noteq> []" 
994403dbbed5 strong!
Chengsong
parents:
diff changeset
    66
  shows "decode' (code (Stars vs) @ ds) (STAR r) = (Stars vs, ds)"
994403dbbed5 strong!
Chengsong
parents:
diff changeset
    67
  using assms
994403dbbed5 strong!
Chengsong
parents:
diff changeset
    68
  apply(induct vs)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
    69
  apply(auto)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
    70
  done
994403dbbed5 strong!
Chengsong
parents:
diff changeset
    71
994403dbbed5 strong!
Chengsong
parents:
diff changeset
    72
lemma decode'_code:
994403dbbed5 strong!
Chengsong
parents:
diff changeset
    73
  assumes "\<Turnstile> v : r"
994403dbbed5 strong!
Chengsong
parents:
diff changeset
    74
  shows "decode' ((code v) @ ds) r = (v, ds)"
994403dbbed5 strong!
Chengsong
parents:
diff changeset
    75
using assms
994403dbbed5 strong!
Chengsong
parents:
diff changeset
    76
  apply(induct v r arbitrary: ds) 
994403dbbed5 strong!
Chengsong
parents:
diff changeset
    77
  apply(auto)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
    78
  using decode'_code_Stars by blast
994403dbbed5 strong!
Chengsong
parents:
diff changeset
    79
994403dbbed5 strong!
Chengsong
parents:
diff changeset
    80
lemma decode_code:
994403dbbed5 strong!
Chengsong
parents:
diff changeset
    81
  assumes "\<Turnstile> v : r"
994403dbbed5 strong!
Chengsong
parents:
diff changeset
    82
  shows "decode (code v) r = Some v"
994403dbbed5 strong!
Chengsong
parents:
diff changeset
    83
  using assms unfolding decode_def
994403dbbed5 strong!
Chengsong
parents:
diff changeset
    84
  by (smt append_Nil2 decode'_code old.prod.case)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
    85
994403dbbed5 strong!
Chengsong
parents:
diff changeset
    86
994403dbbed5 strong!
Chengsong
parents:
diff changeset
    87
section {* Annotated Regular Expressions *}
994403dbbed5 strong!
Chengsong
parents:
diff changeset
    88
994403dbbed5 strong!
Chengsong
parents:
diff changeset
    89
datatype arexp = 
994403dbbed5 strong!
Chengsong
parents:
diff changeset
    90
  AZERO
994403dbbed5 strong!
Chengsong
parents:
diff changeset
    91
| AONE "bit list"
994403dbbed5 strong!
Chengsong
parents:
diff changeset
    92
| ACHAR "bit list" char
994403dbbed5 strong!
Chengsong
parents:
diff changeset
    93
| ASEQ "bit list" arexp arexp
994403dbbed5 strong!
Chengsong
parents:
diff changeset
    94
| AALTs "bit list" "arexp list"
994403dbbed5 strong!
Chengsong
parents:
diff changeset
    95
| ASTAR "bit list" arexp
994403dbbed5 strong!
Chengsong
parents:
diff changeset
    96
994403dbbed5 strong!
Chengsong
parents:
diff changeset
    97
abbreviation
994403dbbed5 strong!
Chengsong
parents:
diff changeset
    98
  "AALT bs r1 r2 \<equiv> AALTs bs [r1, r2]"
994403dbbed5 strong!
Chengsong
parents:
diff changeset
    99
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   100
fun asize :: "arexp \<Rightarrow> nat" where
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   101
  "asize AZERO = 1"
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   102
| "asize (AONE cs) = 1" 
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   103
| "asize (ACHAR cs c) = 1"
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   104
| "asize (AALTs cs rs) = Suc (sum_list (map asize rs))"
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   105
| "asize (ASEQ cs r1 r2) = Suc (asize r1 + asize r2)"
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   106
| "asize (ASTAR cs r) = Suc (asize r)"
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   107
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   108
fun 
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   109
  erase :: "arexp \<Rightarrow> rexp"
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   110
where
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   111
  "erase AZERO = ZERO"
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   112
| "erase (AONE _) = ONE"
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   113
| "erase (ACHAR _ c) = CH c"
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   114
| "erase (AALTs _ []) = ZERO"
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   115
| "erase (AALTs _ [r]) = (erase r)"
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   116
| "erase (AALTs bs (r#rs)) = ALT (erase r) (erase (AALTs bs rs))"
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   117
| "erase (ASEQ _ r1 r2) = SEQ (erase r1) (erase r2)"
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   118
| "erase (ASTAR _ r) = STAR (erase r)"
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   119
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   120
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   121
fun nonalt :: "arexp \<Rightarrow> bool"
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   122
  where
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   123
  "nonalt (AALTs bs2 rs) = False"
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   124
| "nonalt r = True"
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   125
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   126
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   127
fun fuse :: "bit list \<Rightarrow> arexp \<Rightarrow> arexp" where
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   128
  "fuse bs AZERO = AZERO"
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   129
| "fuse bs (AONE cs) = AONE (bs @ cs)" 
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   130
| "fuse bs (ACHAR cs c) = ACHAR (bs @ cs) c"
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   131
| "fuse bs (AALTs cs rs) = AALTs (bs @ cs) rs"
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   132
| "fuse bs (ASEQ cs r1 r2) = ASEQ (bs @ cs) r1 r2"
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   133
| "fuse bs (ASTAR cs r) = ASTAR (bs @ cs) r"
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   134
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   135
lemma fuse_append:
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   136
  shows "fuse (bs1 @ bs2) r = fuse bs1 (fuse bs2 r)"
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   137
  apply(induct r)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   138
  apply(auto)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   139
  done
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   140
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   141
lemma fuse_Nil:
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   142
  shows "fuse [] r = r"
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   143
  by (induct r)(simp_all)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   144
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   145
lemma map_fuse_Nil:
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   146
  shows "map (fuse []) rs = rs"
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   147
  by (induct rs)(simp_all add: fuse_Nil)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   148
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   149
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   150
fun intern :: "rexp \<Rightarrow> arexp" where
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   151
  "intern ZERO = AZERO"
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   152
| "intern ONE = AONE []"
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   153
| "intern (CH c) = ACHAR [] c"
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   154
| "intern (ALT r1 r2) = AALT [] (fuse [Z] (intern r1)) 
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   155
                                (fuse [S]  (intern r2))"
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   156
| "intern (SEQ r1 r2) = ASEQ [] (intern r1) (intern r2)"
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   157
| "intern (STAR r) = ASTAR [] (intern r)"
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   158
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   159
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   160
fun retrieve :: "arexp \<Rightarrow> val \<Rightarrow> bit list" where
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   161
  "retrieve (AONE bs) Void = bs"
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   162
| "retrieve (ACHAR bs c) (Char d) = bs"
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   163
| "retrieve (AALTs bs [r]) v = bs @ retrieve r v" 
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   164
| "retrieve (AALTs bs (r#rs)) (Left v) = bs @ retrieve r v"
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   165
| "retrieve (AALTs bs (r#rs)) (Right v) = bs @ retrieve (AALTs [] rs) v"
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   166
| "retrieve (ASEQ bs r1 r2) (Seq v1 v2) = bs @ retrieve r1 v1 @ retrieve r2 v2"
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   167
| "retrieve (ASTAR bs r) (Stars []) = bs @ [S]"
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   168
| "retrieve (ASTAR bs r) (Stars (v#vs)) = 
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   169
     bs @ [Z] @ retrieve r v @ retrieve (ASTAR [] r) (Stars vs)"
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   170
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   171
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   172
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   173
fun
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   174
 bnullable :: "arexp \<Rightarrow> bool"
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   175
where
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   176
  "bnullable (AZERO) = False"
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   177
| "bnullable (AONE bs) = True"
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   178
| "bnullable (ACHAR bs c) = False"
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   179
| "bnullable (AALTs bs rs) = (\<exists>r \<in> set rs. bnullable r)"
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   180
| "bnullable (ASEQ bs r1 r2) = (bnullable r1 \<and> bnullable r2)"
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   181
| "bnullable (ASTAR bs r) = True"
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   182
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   183
fun 
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   184
  bmkeps :: "arexp \<Rightarrow> bit list"
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   185
where
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   186
  "bmkeps(AONE bs) = bs"
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   187
| "bmkeps(ASEQ bs r1 r2) = bs @ (bmkeps r1) @ (bmkeps r2)"
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   188
| "bmkeps(AALTs bs [r]) = bs @ (bmkeps r)"
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   189
| "bmkeps(AALTs bs (r#rs)) = (if bnullable(r) then bs @ (bmkeps r) else (bmkeps (AALTs bs rs)))"
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   190
| "bmkeps(ASTAR bs r) = bs @ [S]"
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   191
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   192
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   193
fun
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   194
 bder :: "char \<Rightarrow> arexp \<Rightarrow> arexp"
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   195
where
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   196
  "bder c (AZERO) = AZERO"
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   197
| "bder c (AONE bs) = AZERO"
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   198
| "bder c (ACHAR bs d) = (if c = d then AONE bs else AZERO)"
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   199
| "bder c (AALTs bs rs) = AALTs bs (map (bder c) rs)"
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   200
| "bder c (ASEQ bs r1 r2) = 
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   201
     (if bnullable r1
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   202
      then AALT bs (ASEQ [] (bder c r1) r2) (fuse (bmkeps r1) (bder c r2))
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   203
      else ASEQ bs (bder c r1) r2)"
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   204
| "bder c (ASTAR bs r) = ASEQ bs (fuse [Z] (bder c r)) (ASTAR [] r)"
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   205
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   206
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   207
fun 
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   208
  bders :: "arexp \<Rightarrow> string \<Rightarrow> arexp"
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   209
where
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   210
  "bders r [] = r"
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   211
| "bders r (c#s) = bders (bder c r) s"
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   212
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   213
lemma bders_append:
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   214
  "bders r (s1 @ s2) = bders (bders r s1) s2"
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   215
  apply(induct s1 arbitrary: r s2)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   216
  apply(simp_all)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   217
  done
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   218
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   219
lemma bnullable_correctness:
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   220
  shows "nullable (erase r) = bnullable r"
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   221
  apply(induct r rule: erase.induct)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   222
  apply(simp_all)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   223
  done
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   224
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   225
lemma erase_fuse:
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   226
  shows "erase (fuse bs r) = erase r"
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   227
  apply(induct r rule: erase.induct)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   228
  apply(simp_all)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   229
  done
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   230
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   231
lemma erase_intern [simp]:
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   232
  shows "erase (intern r) = r"
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   233
  apply(induct r)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   234
  apply(simp_all add: erase_fuse)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   235
  done
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   236
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   237
lemma erase_bder [simp]:
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   238
  shows "erase (bder a r) = der a (erase r)"
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   239
  apply(induct r rule: erase.induct)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   240
  apply(simp_all add: erase_fuse bnullable_correctness)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   241
  done
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   242
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   243
lemma erase_bders [simp]:
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   244
  shows "erase (bders r s) = ders s (erase r)"
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   245
  apply(induct s arbitrary: r )
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   246
  apply(simp_all)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   247
  done
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   248
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   249
lemma bnullable_fuse:
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   250
  shows "bnullable (fuse bs r) = bnullable r"
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   251
  apply(induct r arbitrary: bs)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   252
  apply(auto)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   253
  done
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   254
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   255
lemma retrieve_encode_STARS:
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   256
  assumes "\<forall>v\<in>set vs. \<Turnstile> v : r \<and> code v = retrieve (intern r) v"
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   257
  shows "code (Stars vs) = retrieve (ASTAR [] (intern r)) (Stars vs)"
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   258
  using assms
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   259
  apply(induct vs)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   260
  apply(simp_all)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   261
  done
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   262
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   263
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   264
lemma retrieve_fuse2:
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   265
  assumes "\<Turnstile> v : (erase r)"
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   266
  shows "retrieve (fuse bs r) v = bs @ retrieve r v"
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   267
  using assms
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   268
  apply(induct r arbitrary: v bs)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   269
         apply(auto elim: Prf_elims)[4]
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   270
   defer
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   271
  using retrieve_encode_STARS
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   272
   apply(auto elim!: Prf_elims)[1]
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   273
   apply(case_tac vs)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   274
    apply(simp)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   275
   apply(simp)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   276
  (* AALTs  case *)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   277
  apply(simp)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   278
  apply(case_tac x2a)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   279
   apply(simp)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   280
   apply(auto elim!: Prf_elims)[1]
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   281
  apply(simp)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   282
   apply(case_tac list)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   283
   apply(simp)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   284
  apply(auto)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   285
  apply(auto elim!: Prf_elims)[1]
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   286
  done
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   287
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   288
lemma retrieve_fuse:
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   289
  assumes "\<Turnstile> v : r"
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   290
  shows "retrieve (fuse bs (intern r)) v = bs @ retrieve (intern r) v"
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   291
  using assms 
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   292
  by (simp_all add: retrieve_fuse2)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   293
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   294
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   295
lemma retrieve_code:
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   296
  assumes "\<Turnstile> v : r"
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   297
  shows "code v = retrieve (intern r) v"
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   298
  using assms
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   299
  apply(induct v r )
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   300
  apply(simp_all add: retrieve_fuse retrieve_encode_STARS)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   301
  done
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   302
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   303
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   304
lemma bnullable_Hdbmkeps_Hd:
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   305
  assumes "bnullable a" 
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   306
  shows  "bmkeps (AALTs bs (a # rs)) = bs @ (bmkeps a)"
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   307
  using assms
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   308
  by (metis bmkeps.simps(3) bmkeps.simps(4) list.exhaust)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   309
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   310
lemma r1:
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   311
  assumes "\<not> bnullable a" "bnullable (AALTs bs rs)"
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   312
  shows  "bmkeps (AALTs bs (a # rs)) = bmkeps (AALTs bs rs)"
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   313
  using assms
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   314
  apply(induct rs)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   315
   apply(auto)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   316
  done
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   317
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   318
lemma r2:
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   319
  assumes "x \<in> set rs" "bnullable x"
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   320
  shows "bnullable (AALTs bs rs)"
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   321
  using assms
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   322
  apply(induct rs)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   323
   apply(auto)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   324
  done
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   325
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   326
lemma  r3:
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   327
  assumes "\<not> bnullable r" 
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   328
          " \<exists> x \<in> set rs. bnullable x"
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   329
  shows "retrieve (AALTs bs rs) (mkeps (erase (AALTs bs rs))) =
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   330
         retrieve (AALTs bs (r # rs)) (mkeps (erase (AALTs bs (r # rs))))"
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   331
  using assms
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   332
  apply(induct rs arbitrary: r bs)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   333
   apply(auto)[1]
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   334
  apply(auto)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   335
  using bnullable_correctness apply blast
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   336
    apply(auto simp add: bnullable_correctness mkeps_nullable retrieve_fuse2)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   337
   apply(subst retrieve_fuse2[symmetric])
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   338
  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)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   339
   apply(simp)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   340
  apply(case_tac "bnullable a")
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   341
  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)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   342
  apply(drule_tac x="a" in meta_spec)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   343
  apply(drule_tac x="bs" in meta_spec)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   344
  apply(drule meta_mp)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   345
   apply(simp)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   346
  apply(drule meta_mp)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   347
   apply(auto)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   348
  apply(subst retrieve_fuse2[symmetric])
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   349
  apply(case_tac rs)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   350
    apply(simp)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   351
   apply(auto)[1]
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   352
      apply (simp add: bnullable_correctness)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   353
  apply (metis append_Nil2 bnullable_correctness erase_fuse fuse.simps(4) list.set_intros(1) mkeps.simps(3) mkeps_nullable nullable.simps(4) r2)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   354
    apply (simp add: bnullable_correctness)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   355
  apply (metis append_Nil2 bnullable_correctness erase.simps(6) erase_fuse fuse.simps(4) list.set_intros(2) mkeps.simps(3) mkeps_nullable r2)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   356
  apply(simp)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   357
  done
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   358
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   359
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   360
lemma t: 
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   361
  assumes "\<forall>r \<in> set rs. nullable (erase r) \<longrightarrow> bmkeps r = retrieve r (mkeps (erase r))" 
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   362
          "nullable (erase (AALTs bs rs))"
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   363
  shows " bmkeps (AALTs bs rs) = retrieve (AALTs bs rs) (mkeps (erase (AALTs bs rs)))"
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   364
  using assms
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   365
  apply(induct rs arbitrary: bs)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   366
   apply(simp)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   367
  apply(auto simp add: bnullable_correctness)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   368
   apply(case_tac rs)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   369
     apply(auto simp add: bnullable_correctness)[2]
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   370
   apply(subst r1)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   371
     apply(simp)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   372
    apply(rule r2)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   373
     apply(assumption)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   374
    apply(simp)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   375
   apply(drule_tac x="bs" in meta_spec)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   376
   apply(drule meta_mp)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   377
    apply(auto)[1]
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   378
   prefer 2
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   379
  apply(case_tac "bnullable a")
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   380
    apply(subst bnullable_Hdbmkeps_Hd)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   381
     apply blast
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   382
    apply(subgoal_tac "nullable (erase a)")
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   383
  prefer 2
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   384
  using bnullable_correctness apply blast
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   385
  apply (metis (no_types, lifting) erase.simps(5) erase.simps(6) list.exhaust mkeps.simps(3) retrieve.simps(3) retrieve.simps(4))
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   386
  apply(subst r1)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   387
     apply(simp)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   388
  using r2 apply blast
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   389
  apply(drule_tac x="bs" in meta_spec)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   390
   apply(drule meta_mp)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   391
    apply(auto)[1]
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   392
   apply(simp)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   393
  using r3 apply blast
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   394
  apply(auto)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   395
  using r3 by blast
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   396
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   397
lemma bmkeps_retrieve:
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   398
  assumes "nullable (erase r)"
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   399
  shows "bmkeps r = retrieve r (mkeps (erase r))"
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   400
  using assms
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   401
  apply(induct r)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   402
         apply(simp)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   403
        apply(simp)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   404
       apply(simp)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   405
    apply(simp)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   406
   defer
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   407
   apply(simp)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   408
  apply(rule t)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   409
   apply(auto)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   410
  done
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   411
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   412
lemma bder_retrieve:
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   413
  assumes "\<Turnstile> v : der c (erase r)"
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   414
  shows "retrieve (bder c r) v = retrieve r (injval (erase r) c v)"
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   415
  using assms
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   416
  apply(induct r arbitrary: v rule: erase.induct)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   417
         apply(simp)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   418
         apply(erule Prf_elims)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   419
        apply(simp)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   420
        apply(erule Prf_elims) 
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   421
        apply(simp)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   422
      apply(case_tac "c = ca")
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   423
       apply(simp)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   424
       apply(erule Prf_elims)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   425
       apply(simp)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   426
      apply(simp)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   427
       apply(erule Prf_elims)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   428
  apply(simp)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   429
      apply(erule Prf_elims)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   430
     apply(simp)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   431
    apply(simp)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   432
  apply(rename_tac "r\<^sub>1" "r\<^sub>2" rs v)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   433
    apply(erule Prf_elims)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   434
     apply(simp)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   435
    apply(simp)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   436
    apply(case_tac rs)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   437
     apply(simp)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   438
    apply(simp)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   439
  apply (smt Prf_elims(3) injval.simps(2) injval.simps(3) retrieve.simps(4) retrieve.simps(5) same_append_eq)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   440
   apply(simp)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   441
   apply(case_tac "nullable (erase r1)")
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   442
    apply(simp)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   443
  apply(erule Prf_elims)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   444
     apply(subgoal_tac "bnullable r1")
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   445
  prefer 2
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   446
  using bnullable_correctness apply blast
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   447
    apply(simp)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   448
     apply(erule Prf_elims)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   449
     apply(simp)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   450
   apply(subgoal_tac "bnullable r1")
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   451
  prefer 2
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   452
  using bnullable_correctness apply blast
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   453
    apply(simp)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   454
    apply(simp add: retrieve_fuse2)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   455
    apply(simp add: bmkeps_retrieve)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   456
   apply(simp)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   457
   apply(erule Prf_elims)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   458
   apply(simp)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   459
  using bnullable_correctness apply blast
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   460
  apply(rename_tac bs r v)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   461
  apply(simp)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   462
  apply(erule Prf_elims)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   463
     apply(clarify)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   464
  apply(erule Prf_elims)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   465
  apply(clarify)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   466
  apply(subst injval.simps)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   467
  apply(simp del: retrieve.simps)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   468
  apply(subst retrieve.simps)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   469
  apply(subst retrieve.simps)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   470
  apply(simp)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   471
  apply(simp add: retrieve_fuse2)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   472
  done
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   473
  
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   474
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   475
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   476
lemma MAIN_decode:
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   477
  assumes "\<Turnstile> v : ders s r"
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   478
  shows "Some (flex r id s v) = decode (retrieve (bders (intern r) s) v) r"
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   479
  using assms
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   480
proof (induct s arbitrary: v rule: rev_induct)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   481
  case Nil
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   482
  have "\<Turnstile> v : ders [] r" by fact
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   483
  then have "\<Turnstile> v : r" by simp
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   484
  then have "Some v = decode (retrieve (intern r) v) r"
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   485
    using decode_code retrieve_code by auto
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   486
  then show "Some (flex r id [] v) = decode (retrieve (bders (intern r) []) v) r"
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   487
    by simp
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   488
next
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   489
  case (snoc c s v)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   490
  have IH: "\<And>v. \<Turnstile> v : ders s r \<Longrightarrow> 
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   491
     Some (flex r id s v) = decode (retrieve (bders (intern r) s) v) r" by fact
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   492
  have asm: "\<Turnstile> v : ders (s @ [c]) r" by fact
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   493
  then have asm2: "\<Turnstile> injval (ders s r) c v : ders s r" 
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   494
    by (simp add: Prf_injval ders_append)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   495
  have "Some (flex r id (s @ [c]) v) = Some (flex r id s (injval (ders s r) c v))"
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   496
    by (simp add: flex_append)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   497
  also have "... = decode (retrieve (bders (intern r) s) (injval (ders s r) c v)) r"
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   498
    using asm2 IH by simp
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   499
  also have "... = decode (retrieve (bder c (bders (intern r) s)) v) r"
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   500
    using asm by (simp_all add: bder_retrieve ders_append)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   501
  finally show "Some (flex r id (s @ [c]) v) = 
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   502
                 decode (retrieve (bders (intern r) (s @ [c])) v) r" by (simp add: bders_append)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   503
qed
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   504
492
61eff2abb0b6 problem with erase
Chengsong
parents: 444
diff changeset
   505
corollary main_decode1_horribly_wrong:
61eff2abb0b6 problem with erase
Chengsong
parents: 444
diff changeset
   506
  assumes "\<Turnstile> v : ders s r"
61eff2abb0b6 problem with erase
Chengsong
parents: 444
diff changeset
   507
  shows "Some(v) = decode (retrieve (bders (intern r) s) v) r"
61eff2abb0b6 problem with erase
Chengsong
parents: 444
diff changeset
   508
  using assms
61eff2abb0b6 problem with erase
Chengsong
parents: 444
diff changeset
   509
proof (induct s arbitrary: v rule: rev_induct)
61eff2abb0b6 problem with erase
Chengsong
parents: 444
diff changeset
   510
  case Nil
61eff2abb0b6 problem with erase
Chengsong
parents: 444
diff changeset
   511
  have "\<Turnstile> v : ders [] r" by fact
61eff2abb0b6 problem with erase
Chengsong
parents: 444
diff changeset
   512
  then have "\<Turnstile> v: r" by simp
61eff2abb0b6 problem with erase
Chengsong
parents: 444
diff changeset
   513
  then have "Some v = decode (retrieve (intern r) v) r"
61eff2abb0b6 problem with erase
Chengsong
parents: 444
diff changeset
   514
    using decode_code retrieve_code by force
61eff2abb0b6 problem with erase
Chengsong
parents: 444
diff changeset
   515
  then show "Some (v) = decode (retrieve (bders (intern r) []) v) r"
61eff2abb0b6 problem with erase
Chengsong
parents: 444
diff changeset
   516
    by simp
61eff2abb0b6 problem with erase
Chengsong
parents: 444
diff changeset
   517
next
61eff2abb0b6 problem with erase
Chengsong
parents: 444
diff changeset
   518
  case (snoc c s v)
61eff2abb0b6 problem with erase
Chengsong
parents: 444
diff changeset
   519
  have IH: "\<And>v. \<Turnstile> v : ders s r \<Longrightarrow> 
61eff2abb0b6 problem with erase
Chengsong
parents: 444
diff changeset
   520
    Some ( v) = decode (retrieve (bders (intern r) s) v ) r" by fact
61eff2abb0b6 problem with erase
Chengsong
parents: 444
diff changeset
   521
  have asm: "\<Turnstile> v: ders (s @ [c]) r" by fact
61eff2abb0b6 problem with erase
Chengsong
parents: 444
diff changeset
   522
  then have asm2: "\<Turnstile> injval (ders s r) c v : ders s r"
61eff2abb0b6 problem with erase
Chengsong
parents: 444
diff changeset
   523
    using Prf_injval ders_snoc by force
61eff2abb0b6 problem with erase
Chengsong
parents: 444
diff changeset
   524
  then have injv: "Some (injval (ders s r) c v) = 
61eff2abb0b6 problem with erase
Chengsong
parents: 444
diff changeset
   525
decode (retrieve (bders (intern r) s) (injval (ders s r) c v)) r"
61eff2abb0b6 problem with erase
Chengsong
parents: 444
diff changeset
   526
    by (simp add: IH asm2)
61eff2abb0b6 problem with erase
Chengsong
parents: 444
diff changeset
   527
  oops
61eff2abb0b6 problem with erase
Chengsong
parents: 444
diff changeset
   528
61eff2abb0b6 problem with erase
Chengsong
parents: 444
diff changeset
   529
432
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   530
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   531
definition blex where
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   532
 "blex a s \<equiv> if bnullable (bders a s) then Some (bmkeps (bders a s)) else None"
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   533
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   534
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   535
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   536
definition blexer where
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   537
 "blexer r s \<equiv> if bnullable (bders (intern r) s) then 
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   538
                decode (bmkeps (bders (intern r) s)) r else None"
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   539
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   540
lemma blexer_correctness:
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   541
  shows "blexer r s = lexer r s"
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   542
proof -
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   543
  { define bds where "bds \<equiv> bders (intern r) s"
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   544
    define ds  where "ds \<equiv> ders s r"
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   545
    assume asm: "nullable ds"
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   546
    have era: "erase bds = ds" 
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   547
      unfolding ds_def bds_def by simp
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   548
    have mke: "\<Turnstile> mkeps ds : ds"
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   549
      using asm by (simp add: mkeps_nullable)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   550
    have "decode (bmkeps bds) r = decode (retrieve bds (mkeps ds)) r"
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   551
      using bmkeps_retrieve
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   552
      using asm era by (simp add: bmkeps_retrieve)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   553
    also have "... =  Some (flex r id s (mkeps ds))"
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   554
      using mke by (simp_all add: MAIN_decode ds_def bds_def)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   555
    finally have "decode (bmkeps bds) r = Some (flex r id s (mkeps ds))" 
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   556
      unfolding bds_def ds_def .
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   557
  }
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   558
  then show "blexer r s = lexer r s"
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   559
    unfolding blexer_def lexer_flex
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   560
    apply(subst bnullable_correctness[symmetric])
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   561
    apply(simp)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   562
    done
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   563
qed
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   564
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   565
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   566
fun distinctBy :: "'a list \<Rightarrow> ('a \<Rightarrow> 'b) \<Rightarrow> 'b set \<Rightarrow> 'a list"
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   567
  where
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   568
  "distinctBy [] f acc = []"
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   569
| "distinctBy (x#xs) f acc = 
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   570
     (if (f x) \<in> acc then distinctBy xs f acc 
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   571
      else x # (distinctBy xs f ({f x} \<union> acc)))"
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   572
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   573
(*filter  (\<lambda>rt. case rt of 
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   574
                                      SEQ r1p r2p \<Rightarrow> r2p = (erase r2)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   575
                                      r           \<Rightarrow> False ) allowableTerms*)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   576
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   577
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   578
lemma dB_single_step: 
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   579
  shows "distinctBy (a#rs) f {} = a # distinctBy rs f {f a}"
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   580
  by simp 
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   581
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   582
fun flts :: "arexp list \<Rightarrow> arexp list"
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   583
  where 
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   584
  "flts [] = []"
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   585
| "flts (AZERO # rs) = flts rs"
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   586
| "flts ((AALTs bs  rs1) # rs) = (map (fuse bs) rs1) @ flts rs"
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   587
| "flts (r1 # rs) = r1 # flts rs"
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   588
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   589
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   590
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   591
fun bsimp_ASEQ :: "bit list \<Rightarrow> arexp \<Rightarrow> arexp \<Rightarrow> arexp"
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   592
  where
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   593
  "bsimp_ASEQ _ AZERO _ = AZERO"
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   594
| "bsimp_ASEQ _ _ AZERO = AZERO"
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   595
| "bsimp_ASEQ bs1 (AONE bs2) r2 = fuse (bs1 @ bs2) r2"
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   596
| "bsimp_ASEQ bs1 r1 r2 = ASEQ  bs1 r1 r2"
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   597
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   598
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   599
fun bsimp_AALTs :: "bit list \<Rightarrow> arexp list \<Rightarrow> arexp"
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   600
  where
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   601
  "bsimp_AALTs _ [] = AZERO"
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   602
| "bsimp_AALTs bs1 [r] = fuse bs1 r"
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   603
| "bsimp_AALTs bs1 rs = AALTs bs1 rs"
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   604
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   605
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   606
fun bsimp_ASEQ1 :: "bit list \<Rightarrow> arexp \<Rightarrow> arexp \<Rightarrow> arexp"
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   607
  where
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   608
  "bsimp_ASEQ1 _ AZERO _ = AZERO"
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   609
| "bsimp_ASEQ1 bs (AONE bs1) r2 = fuse (bs @ bs1) r2"
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   610
| "bsimp_ASEQ1 bs r1 r2 = ASEQ  bs r1 r2"
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   611
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   612
436
222333d2bdc2 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 432
diff changeset
   613
fun collect :: "rexp \<Rightarrow> rexp list \<Rightarrow> rexp list" where
432
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   614
  \<open>collect _ [] = []\<close>
436
222333d2bdc2 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 432
diff changeset
   615
|  \<open>collect erasedR2  ((SEQ r1 r2) # rs) = 
222333d2bdc2 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 432
diff changeset
   616
       (if r2 = erasedR2 then r1 # (collect erasedR2 rs) else collect erasedR2 rs)\<close>
432
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   617
| \<open>collect erasedR2 (r # rs) = collect erasedR2 rs\<close>
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   618
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   619
492
61eff2abb0b6 problem with erase
Chengsong
parents: 444
diff changeset
   620
fun pruneRexp :: "arexp \<Rightarrow> rexp list \<Rightarrow> arexp"
61eff2abb0b6 problem with erase
Chengsong
parents: 444
diff changeset
   621
  where
436
222333d2bdc2 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 432
diff changeset
   622
  "pruneRexp (ASEQ bs r1 r2) allowableTerms = 
222333d2bdc2 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 432
diff changeset
   623
          (let termsTruncated = (collect (erase r2) allowableTerms) in 
222333d2bdc2 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 432
diff changeset
   624
             (let pruned = pruneRexp r1 termsTruncated in 
492
61eff2abb0b6 problem with erase
Chengsong
parents: 444
diff changeset
   625
                (bsimp_ASEQ bs pruned r2)))"
436
222333d2bdc2 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 432
diff changeset
   626
| \<open>pruneRexp (AALTs bs rs) allowableTerms = 
222333d2bdc2 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 432
diff changeset
   627
     (let rsp = (filter (\<lambda>r. r \<noteq> AZERO)  (map (\<lambda>r. pruneRexp r allowableTerms) rs) ) in bsimp_AALTs bs rsp )
432
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   628
\<close>
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   629
| \<open>pruneRexp r allowableTerms = (if (erase r) \<in> (set allowableTerms) then r else AZERO)\<close>
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   630
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   631
fun oneSimp :: \<open>rexp \<Rightarrow> rexp\<close> where
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   632
  \<open> oneSimp (SEQ ONE r) = r \<close>
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   633
| \<open> oneSimp (SEQ r1 r2) = SEQ (oneSimp r1) r2 \<close>
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   634
| \<open> oneSimp r = r \<close>
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   635
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   636
fun breakIntoTerms where
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   637
  \<open>breakIntoTerms (SEQ r1 r2) = map (\<lambda>r1p. SEQ r1p r2) (breakIntoTerms r1)\<close>
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   638
| \<open>breakIntoTerms (ALT r1 r2) = (breakIntoTerms r1) @ (breakIntoTerms r2)\<close>
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   639
| \<open>breakIntoTerms r = r # [] \<close>
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   640
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   641
fun addToAcc :: "arexp \<Rightarrow> rexp list \<Rightarrow> rexp list"
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   642
  where
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   643
\<open>addToAcc r acc = filter (\<lambda>r1. oneSimp r1 \<notin> set acc) (breakIntoTerms (erase r)) \<close>
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   644
492
61eff2abb0b6 problem with erase
Chengsong
parents: 444
diff changeset
   645
61eff2abb0b6 problem with erase
Chengsong
parents: 444
diff changeset
   646
(*newSubRexps: terms that are new--have not existed in acc before*)
432
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   647
fun dBStrong :: "arexp list \<Rightarrow> rexp list \<Rightarrow> arexp list"
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   648
  where
492
61eff2abb0b6 problem with erase
Chengsong
parents: 444
diff changeset
   649
  "dBStrong [] acc = []"
432
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   650
| "dBStrong (r # rs) acc = (if (erase r) \<in> (set acc) then dBStrong rs acc
442
09a57446696a some changes
Chengsong
parents: 436
diff changeset
   651
                            else let newSubRexps = (addToAcc r acc) in 
09a57446696a some changes
Chengsong
parents: 436
diff changeset
   652
                                 (case (pruneRexp r newSubRexps) of  
492
61eff2abb0b6 problem with erase
Chengsong
parents: 444
diff changeset
   653
                                    AZERO \<Rightarrow> dBStrong rs (map oneSimp newSubRexps @ acc) |
61eff2abb0b6 problem with erase
Chengsong
parents: 444
diff changeset
   654
                                    r1    \<Rightarrow> r1 # (dBStrong rs (map oneSimp newSubRexps @ acc))
432
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   655
                                 )
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   656
                           )
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   657
                    "
442
09a57446696a some changes
Chengsong
parents: 436
diff changeset
   658
09a57446696a some changes
Chengsong
parents: 436
diff changeset
   659
432
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   660
fun bsimpStrong :: "arexp \<Rightarrow> arexp "
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   661
  where
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   662
  "bsimpStrong (ASEQ bs1 r1 r2) = bsimp_ASEQ bs1 (bsimpStrong r1) (bsimpStrong r2)"
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   663
| "bsimpStrong (AALTs bs1 rs) = bsimp_AALTs bs1 (dBStrong (flts (map bsimpStrong rs)) []) "
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   664
| "bsimpStrong r = r"
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   665
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   666
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   667
fun bdersStrong :: "arexp \<Rightarrow> string \<Rightarrow> arexp"
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   668
where
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   669
  "bdersStrong r [] = r"
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   670
| "bdersStrong r (c # s) = bdersStrong (bsimpStrong (bder c r)) s"
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   671
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   672
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   673
definition blexerStrong where
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   674
 "blexerStrong r s \<equiv> if bnullable (bdersStrong (intern r) s) then 
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   675
                    decode (bmkeps (bdersStrong (intern r) s)) r else None"
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   676
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   677
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   678
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   679
fun bsimp :: "arexp \<Rightarrow> arexp" 
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   680
  where
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   681
  "bsimp (ASEQ bs1 r1 r2) = bsimp_ASEQ bs1 (bsimp r1) (bsimp r2)"
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   682
| "bsimp (AALTs bs1 rs) = bsimp_AALTs bs1 (distinctBy (flts (map bsimp rs)) erase {}) "
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   683
| "bsimp r = r"
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   684
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   685
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   686
fun 
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   687
  bders_simp :: "arexp \<Rightarrow> string \<Rightarrow> arexp"
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   688
where
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   689
  "bders_simp r [] = r"
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   690
| "bders_simp r (c # s) = bders_simp (bsimp (bder c r)) s"
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   691
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   692
definition blexer_simp where
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   693
 "blexer_simp r s \<equiv> if bnullable (bders_simp (intern r) s) then 
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   694
                    decode (bmkeps (bders_simp (intern r) s)) r else None"
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   695
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   696
export_code bders_simp in Scala module_name Example
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   697
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   698
lemma bders_simp_append:
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   699
  shows "bders_simp r (s1 @ s2) = bders_simp (bders_simp r s1) s2"
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   700
  apply(induct s1 arbitrary: r s2)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   701
  apply(simp_all)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   702
  done
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   703
494
c730d018ebfa blexer2
Chengsong
parents: 492
diff changeset
   704
lemma bdersStrong_append:
c730d018ebfa blexer2
Chengsong
parents: 492
diff changeset
   705
  shows "bdersStrong r (s1 @ s2) = bdersStrong (bdersStrong r s1) s2"
c730d018ebfa blexer2
Chengsong
parents: 492
diff changeset
   706
  apply(induct s1 arbitrary: r)
c730d018ebfa blexer2
Chengsong
parents: 492
diff changeset
   707
   apply simp+
c730d018ebfa blexer2
Chengsong
parents: 492
diff changeset
   708
  done
c730d018ebfa blexer2
Chengsong
parents: 492
diff changeset
   709
c730d018ebfa blexer2
Chengsong
parents: 492
diff changeset
   710
432
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   711
lemma L_bsimp_ASEQ:
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   712
  "L (SEQ (erase r1) (erase r2)) = L (erase (bsimp_ASEQ bs r1 r2))"
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   713
  apply(induct bs r1 r2 rule: bsimp_ASEQ.induct)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   714
  apply(simp_all)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   715
  by (metis erase_fuse fuse.simps(4))
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   716
494
c730d018ebfa blexer2
Chengsong
parents: 492
diff changeset
   717
c730d018ebfa blexer2
Chengsong
parents: 492
diff changeset
   718
432
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   719
lemma L_bsimp_AALTs:
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   720
  "L (erase (AALTs bs rs)) = L (erase (bsimp_AALTs bs rs))"
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   721
  apply(induct bs rs rule: bsimp_AALTs.induct)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   722
  apply(simp_all add: erase_fuse)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   723
  done
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   724
494
c730d018ebfa blexer2
Chengsong
parents: 492
diff changeset
   725
432
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   726
lemma L_erase_AALTs:
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   727
  shows "L (erase (AALTs bs rs)) = \<Union> (L ` erase ` (set rs))"
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   728
  apply(induct rs)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   729
   apply(simp)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   730
  apply(simp)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   731
  apply(case_tac rs)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   732
   apply(simp)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   733
  apply(simp)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   734
  done
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   735
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   736
lemma L_erase_flts:
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   737
  shows "\<Union> (L ` erase ` (set (flts rs))) = \<Union> (L ` erase ` (set rs))"
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   738
  apply(induct rs rule: flts.induct)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   739
        apply(simp_all)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   740
  apply(auto)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   741
  using L_erase_AALTs erase_fuse apply auto[1]
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   742
  by (simp add: L_erase_AALTs erase_fuse)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   743
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   744
lemma L_erase_dB_acc:
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   745
  shows "( \<Union>(L ` acc) \<union> ( \<Union> (L ` erase ` (set (distinctBy rs erase acc) ) ) )) = \<Union>(L ` acc) \<union>  \<Union> (L ` erase ` (set rs))"
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   746
  apply(induction rs arbitrary: acc)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   747
   apply simp
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   748
  apply simp
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   749
  by (smt (z3) SUP_absorb UN_insert sup_assoc sup_commute)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   750
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   751
lemma L_erase_dB:
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   752
  shows " ( \<Union> (L ` erase ` (set (distinctBy rs erase {}) ) ) ) = \<Union> (L ` erase ` (set rs))"
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   753
  by (metis L_erase_dB_acc Un_commute Union_image_empty)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   754
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   755
lemma L_bsimp_erase:
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   756
  shows "L (erase r) = L (erase (bsimp r))"
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   757
  apply(induct r)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   758
  apply(simp)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   759
  apply(simp)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   760
  apply(simp)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   761
  apply(auto simp add: Sequ_def)[1]
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   762
  apply(subst L_bsimp_ASEQ[symmetric])
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   763
  apply(auto simp add: Sequ_def)[1]
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   764
  apply(subst (asm)  L_bsimp_ASEQ[symmetric])
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   765
  apply(auto simp add: Sequ_def)[1]
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   766
  apply(simp)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   767
  apply(subst L_bsimp_AALTs[symmetric])
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   768
  defer
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   769
  apply(simp)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   770
  apply(subst (2)L_erase_AALTs)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   771
  apply(subst L_erase_dB)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   772
  apply(subst L_erase_flts)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   773
  apply(auto)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   774
  apply (simp add: L_erase_AALTs)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   775
  using L_erase_AALTs by blast
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   776
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   777
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   778
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   779
lemma bsimp_ASEQ0:
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   780
  shows "bsimp_ASEQ bs r1 AZERO = AZERO"
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   781
  apply(induct r1)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   782
  apply(auto)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   783
  done
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   784
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   785
lemma bsimp_ASEQ1:
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   786
  assumes "r1 \<noteq> AZERO" "r2 \<noteq> AZERO" "\<forall>bs. r1 \<noteq> AONE bs"
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   787
  shows "bsimp_ASEQ bs r1 r2 = ASEQ bs r1 r2"
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   788
  using assms
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   789
  apply(induct bs r1 r2 rule: bsimp_ASEQ.induct)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   790
  apply(auto)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   791
  done
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   792
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   793
lemma bsimp_ASEQ2:
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   794
  shows "bsimp_ASEQ bs (AONE bs1) r2 = fuse (bs @ bs1) r2"
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   795
  apply(induct r2)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   796
  apply(auto)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   797
  done
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   798
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   799
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   800
lemma L_bders_simp:
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   801
  shows "L (erase (bders_simp r s)) = L (erase (bders r s))"
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   802
  apply(induct s arbitrary: r rule: rev_induct)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   803
  apply(simp)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   804
  apply(simp)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   805
  apply(simp add: ders_append)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   806
  apply(simp add: bders_simp_append)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   807
  apply(simp add: L_bsimp_erase[symmetric])
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   808
  by (simp add: der_correctness)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   809
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   810
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   811
lemma b2:
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   812
  assumes "bnullable r"
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   813
  shows "bmkeps (fuse bs r) = bs @ bmkeps r"
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   814
  by (simp add: assms bmkeps_retrieve bnullable_correctness erase_fuse mkeps_nullable retrieve_fuse2)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   815
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   816
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   817
lemma b4:
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   818
  shows "bnullable (bders_simp r s) = bnullable (bders r s)"
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   819
  by (metis L_bders_simp bnullable_correctness lexer.simps(1) lexer_correct_None option.distinct(1))
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   820
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   821
lemma qq1:
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   822
  assumes "\<exists>r \<in> set rs. bnullable r"
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   823
  shows "bmkeps (AALTs bs (rs @ rs1)) = bmkeps (AALTs bs rs)"
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   824
  using assms
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   825
  apply(induct rs arbitrary: rs1 bs)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   826
  apply(simp)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   827
  apply(simp)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   828
  by (metis Nil_is_append_conv bmkeps.simps(4) neq_Nil_conv bnullable_Hdbmkeps_Hd split_list_last)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   829
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   830
lemma qq2:
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   831
  assumes "\<forall>r \<in> set rs. \<not> bnullable r" "\<exists>r \<in> set rs1. bnullable r"
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   832
  shows "bmkeps (AALTs bs (rs @ rs1)) = bmkeps (AALTs bs rs1)"
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   833
  using assms
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   834
  apply(induct rs arbitrary: rs1 bs)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   835
  apply(simp)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   836
  apply(simp)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   837
  by (metis append_assoc in_set_conv_decomp r1 r2)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   838
  
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   839
lemma qq3:
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   840
  assumes "bnullable (AALTs bs (rs @ rs1))"
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   841
          "bnullable (AALTs bs (rs @ rs2))"
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   842
          "\<lbrakk>bnullable (AALTs bs rs1); bnullable (AALTs bs rs2); \<forall>r\<in>set rs. \<not>bnullable r\<rbrakk> \<Longrightarrow> 
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   843
               bmkeps (AALTs bs rs1) = bmkeps (AALTs bs rs2)"
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   844
  shows "bmkeps (AALTs bs (rs @ rs1)) = bmkeps (AALTs bs (rs @ rs2))"
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   845
  using assms
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   846
  apply(case_tac "\<exists>r \<in> set rs. bnullable r")
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   847
  using qq1 apply auto[1]
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   848
  by (metis UnE bnullable.simps(4) qq2 set_append)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   849
  
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   850
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   851
lemma flts_append:
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   852
  shows "flts (xs1 @ xs2) = flts xs1 @ flts xs2"
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   853
by (induct xs1  arbitrary: xs2  rule: flts.induct)(auto)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   854
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   855
lemma  k0a:
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   856
  shows "flts [AALTs bs rs] = map (fuse bs)  rs"
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   857
  apply(simp)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   858
  done
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   859
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   860
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   861
lemma bbbbs1:
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   862
  shows "nonalt r \<or> (\<exists>bs rs. r  = AALTs bs rs)"
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   863
  using nonalt.elims(3) by auto
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   864
  
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   865
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   866
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   867
fun nonazero :: "arexp \<Rightarrow> bool"
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   868
  where
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   869
  "nonazero AZERO = False"
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   870
| "nonazero r = True"
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   871
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   872
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   873
lemma flts_single1:
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   874
  assumes "nonalt r" "nonazero r"
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   875
  shows "flts [r] = [r]"
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   876
  using assms
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   877
  apply(induct r)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   878
  apply(auto)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   879
  done
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   880
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   881
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   882
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   883
lemma q3a:
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   884
  assumes "\<exists>r \<in> set rs. bnullable r"
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   885
  shows "bmkeps (AALTs bs (map (fuse bs1) rs)) = bmkeps (AALTs (bs@bs1) rs)"
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   886
  using assms
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   887
  apply(induct rs arbitrary: bs bs1)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   888
   apply(simp)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   889
  apply(simp)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   890
  apply(auto)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   891
   apply (metis append_assoc b2 bnullable_correctness erase_fuse bnullable_Hdbmkeps_Hd)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   892
  apply(case_tac "bnullable a")
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   893
   apply (metis append.assoc b2 bnullable_correctness erase_fuse bnullable_Hdbmkeps_Hd)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   894
  apply(case_tac rs)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   895
  apply(simp)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   896
  apply(simp)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   897
  apply(auto)[1]
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   898
   apply (metis bnullable_correctness erase_fuse)+
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   899
  done
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   900
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   901
lemma qq4:
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   902
  assumes "\<exists>x\<in>set list. bnullable x"
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   903
  shows "\<exists>x\<in>set (flts list). bnullable x"
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   904
  using assms
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   905
  apply(induct list rule: flts.induct)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   906
        apply(auto)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   907
  by (metis UnCI bnullable_correctness erase_fuse imageI)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   908
  
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   909
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   910
lemma qs3:
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   911
  assumes "\<exists>r \<in> set rs. bnullable r"
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   912
  shows "bmkeps (AALTs bs rs) = bmkeps (AALTs bs (flts rs))"
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   913
  using assms
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   914
  apply(induct rs arbitrary: bs taking: size rule: measure_induct)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   915
  apply(case_tac x)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   916
  apply(simp)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   917
  apply(simp)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   918
  apply(case_tac a)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   919
       apply(simp)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   920
       apply (simp add: r1)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   921
      apply(simp)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   922
      apply (simp add: bnullable_Hdbmkeps_Hd)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   923
     apply(simp)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   924
     apply(case_tac "flts list")
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   925
      apply(simp)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   926
  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)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   927
     apply(simp)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   928
     apply (simp add: r1)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   929
    prefer 3
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   930
    apply(simp)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   931
    apply (simp add: bnullable_Hdbmkeps_Hd)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   932
   prefer 2
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   933
   apply(simp)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   934
  apply(case_tac "\<exists>x\<in>set x52. bnullable x")
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   935
  apply(case_tac "list")
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   936
    apply(simp)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   937
    apply (metis b2 fuse.simps(4) q3a r2)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   938
   apply(erule disjE)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   939
    apply(subst qq1)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   940
     apply(auto)[1]
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   941
     apply (metis bnullable_correctness erase_fuse)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   942
    apply(simp)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   943
     apply (metis b2 fuse.simps(4) q3a r2)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   944
    apply(simp)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   945
    apply(auto)[1]
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   946
     apply(subst qq1)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   947
      apply (metis bnullable_correctness erase_fuse image_eqI set_map)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   948
     apply (metis b2 fuse.simps(4) q3a r2)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   949
  apply(subst qq1)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   950
      apply (metis bnullable_correctness erase_fuse image_eqI set_map)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   951
    apply (metis b2 fuse.simps(4) q3a r2)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   952
   apply(simp)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   953
   apply(subst qq2)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   954
     apply (metis bnullable_correctness erase_fuse imageE set_map)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   955
  prefer 2
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   956
  apply(case_tac "list")
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   957
     apply(simp)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   958
    apply(simp)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   959
   apply (simp add: qq4)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   960
  apply(simp)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   961
  apply(auto)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   962
   apply(case_tac list)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   963
    apply(simp)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   964
   apply(simp)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   965
   apply (simp add: bnullable_Hdbmkeps_Hd)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   966
  apply(case_tac "bnullable (ASEQ x41 x42 x43)")
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   967
   apply(case_tac list)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   968
    apply(simp)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   969
   apply(simp)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   970
   apply (simp add: bnullable_Hdbmkeps_Hd)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   971
  apply(simp)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   972
  using qq4 r1 r2 by auto
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   973
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   974
lemma bder_fuse:
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   975
  shows "bder c (fuse bs a) = fuse bs  (bder c a)"
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   976
  apply(induct a arbitrary: bs c)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   977
       apply(simp_all)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   978
  done
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   979
442
09a57446696a some changes
Chengsong
parents: 436
diff changeset
   980
fun pAKC_aux :: "arexp list \<Rightarrow> arexp \<Rightarrow> rexp \<Rightarrow> arexp"
09a57446696a some changes
Chengsong
parents: 436
diff changeset
   981
  where
444
a7e98deebb5c restructured sizebound proof
Chengsong
parents: 442
diff changeset
   982
"pAKC_aux rsa r ctx = (if (L (SEQ (erase r) ( ctx) )) \<subseteq> (L (erase (AALTs [] rsa))) then AZERO else
a7e98deebb5c restructured sizebound proof
Chengsong
parents: 442
diff changeset
   983
                          case r of (ASEQ bs r1 r2) \<Rightarrow> 
494
c730d018ebfa blexer2
Chengsong
parents: 492
diff changeset
   984
                            bsimp_ASEQ bs (pAKC_aux rsa r1 (SEQ  (erase r2) ( ctx) )) r2   |
444
a7e98deebb5c restructured sizebound proof
Chengsong
parents: 442
diff changeset
   985
                                    (AALTs bs rs) \<Rightarrow> 
494
c730d018ebfa blexer2
Chengsong
parents: 492
diff changeset
   986
                            bsimp_AALTs bs (filter (\<lambda>r. r \<noteq> AZERO) (map (\<lambda>r. pAKC_aux rsa r ( ctx) ) rs) )    |
442
09a57446696a some changes
Chengsong
parents: 436
diff changeset
   987
                                    r             \<Rightarrow> r
09a57446696a some changes
Chengsong
parents: 436
diff changeset
   988
)"
09a57446696a some changes
Chengsong
parents: 436
diff changeset
   989
432
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   990
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   991
inductive 
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   992
  rrewrite:: "arexp \<Rightarrow> arexp \<Rightarrow> bool" ("_ \<leadsto> _" [99, 99] 99)
494
c730d018ebfa blexer2
Chengsong
parents: 492
diff changeset
   993
  where
c730d018ebfa blexer2
Chengsong
parents: 492
diff changeset
   994
 "pAKC_aux rsa a2 ONE = a2' \<Longrightarrow> AALTs bs (rsa @ [a2] @ rsb) \<leadsto> AALTs bs (rsa @ [a2'] @ rsb)"
c730d018ebfa blexer2
Chengsong
parents: 492
diff changeset
   995
c730d018ebfa blexer2
Chengsong
parents: 492
diff changeset
   996
| "ASEQ bs AZERO r2 \<leadsto> AZERO"
432
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   997
| "ASEQ bs r1 AZERO \<leadsto> AZERO"
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   998
| "ASEQ bs1 (AONE bs2) r \<leadsto> fuse (bs1@bs2) r"
994403dbbed5 strong!
Chengsong
parents:
diff changeset
   999
| "r1 \<leadsto> r2 \<Longrightarrow> ASEQ bs r1 r3 \<leadsto> ASEQ bs r2 r3"
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1000
| "r3 \<leadsto> r4 \<Longrightarrow> ASEQ bs r1 r3 \<leadsto> ASEQ bs r1 r4"
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1001
| "r \<leadsto> r' \<Longrightarrow> (AALTs bs (rs1 @ [r] @ rs2)) \<leadsto> (AALTs bs (rs1 @ [r'] @ rs2))"
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1002
(*context rule for eliminating 0, alts--corresponds to the recursive call flts r::rs = r::(flts rs)*)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1003
| "AALTs bs (rsa@ [AZERO] @ rsb) \<leadsto> AALTs bs (rsa @ rsb)"
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1004
| "AALTs bs (rsa@ [AALTs bs1 rs1] @ rsb) \<leadsto> AALTs bs (rsa@(map (fuse bs1) rs1)@rsb)"
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1005
| "AALTs bs [] \<leadsto> AZERO"
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1006
| "AALTs bs [r] \<leadsto> fuse bs r"
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1007
| "erase a1 = erase a2 \<Longrightarrow> AALTs bs (rsa@[a1]@rsb@[a2]@rsc) \<leadsto> AALTs bs (rsa@[a1]@rsb@rsc)"
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1008
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1009
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1010
inductive 
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1011
  rrewrites:: "arexp \<Rightarrow> arexp \<Rightarrow> bool" ("_ \<leadsto>* _" [100, 100] 100)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1012
where 
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1013
  rs1[intro, simp]:"r \<leadsto>* r"
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1014
| rs2[intro]: "\<lbrakk>r1 \<leadsto>* r2; r2 \<leadsto> r3\<rbrakk> \<Longrightarrow> r1 \<leadsto>* r3"
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1015
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1016
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1017
inductive 
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1018
  srewrites:: "arexp list \<Rightarrow> arexp list \<Rightarrow> bool" (" _ s\<leadsto>* _" [100, 100] 100)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1019
where
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1020
  ss1: "[] s\<leadsto>* []"
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1021
| ss2: "\<lbrakk>r \<leadsto>* r'; rs s\<leadsto>* rs'\<rbrakk> \<Longrightarrow> (r#rs) s\<leadsto>* (r'#rs')"
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1022
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1023
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1024
(* rewrites for lists *)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1025
inductive 
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1026
  frewrites:: "arexp list \<Rightarrow> arexp list \<Rightarrow> bool" (" _ f\<leadsto>* _" [100, 100] 100)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1027
where
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1028
  fs1: "[] f\<leadsto>* []"
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1029
| fs2: "\<lbrakk>rs f\<leadsto>* rs'\<rbrakk> \<Longrightarrow> (AZERO#rs) f\<leadsto>* rs'"
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1030
| fs3: "\<lbrakk>rs f\<leadsto>* rs'\<rbrakk> \<Longrightarrow> ((AALTs bs rs1) # rs) f\<leadsto>* ((map (fuse bs) rs1) @ rs')"
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1031
| fs4: "\<lbrakk>rs f\<leadsto>* rs'; nonalt r; nonazero r\<rbrakk> \<Longrightarrow> (r#rs) f\<leadsto>* (r#rs')"
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1032
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1033
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1034
lemma r_in_rstar : "r1 \<leadsto> r2 \<Longrightarrow> r1 \<leadsto>* r2"
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1035
  using rrewrites.intros(1) rrewrites.intros(2) by blast
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1036
 
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1037
lemma real_trans[trans]: 
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1038
  assumes a1: "r1 \<leadsto>* r2"  and a2: "r2 \<leadsto>* r3"
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1039
  shows "r1 \<leadsto>* r3"
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1040
  using a2 a1
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1041
  apply(induct r2 r3 arbitrary: r1 rule: rrewrites.induct) 
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1042
  apply(auto)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1043
  done
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1044
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1045
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1046
lemma  many_steps_later: "\<lbrakk>r1 \<leadsto> r2; r2 \<leadsto>* r3 \<rbrakk> \<Longrightarrow> r1 \<leadsto>* r3"
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1047
  by (meson r_in_rstar real_trans)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1048
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1049
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1050
lemma contextrewrites1: "r \<leadsto>* r' \<Longrightarrow> (AALTs bs (r#rs)) \<leadsto>* (AALTs bs (r'#rs))"
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1051
  apply(induct r r' rule: rrewrites.induct)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1052
   apply simp
494
c730d018ebfa blexer2
Chengsong
parents: 492
diff changeset
  1053
c730d018ebfa blexer2
Chengsong
parents: 492
diff changeset
  1054
  oops
432
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1055
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1056
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1057
lemma contextrewrites2: "r \<leadsto>* r' \<Longrightarrow> (AALTs bs (rs1@[r]@rs)) \<leadsto>* (AALTs bs (rs1@[r']@rs))"
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1058
  apply(induct r r' rule: rrewrites.induct)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1059
   apply simp
494
c730d018ebfa blexer2
Chengsong
parents: 492
diff changeset
  1060
  using rrewrite.intros(6) 
c730d018ebfa blexer2
Chengsong
parents: 492
diff changeset
  1061
  oops
432
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1062
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1063
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1064
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1065
lemma srewrites_alt: "rs1 s\<leadsto>* rs2 \<Longrightarrow> (AALTs bs (rs@rs1)) \<leadsto>* (AALTs bs (rs@rs2))"
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1066
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1067
  apply(induct rs1 rs2 arbitrary: bs rs rule: srewrites.induct)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1068
   apply(rule rs1)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1069
  apply(drule_tac x = "bs" in meta_spec)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1070
  apply(drule_tac x = "rsa@[r']" in meta_spec)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1071
  apply simp
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1072
  apply(rule real_trans)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1073
   prefer 2
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1074
   apply(assumption)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1075
  apply(drule contextrewrites2)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1076
  apply auto
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1077
  done
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1078
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1079
corollary srewrites_alt1: 
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1080
  assumes "rs1 s\<leadsto>* rs2"
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1081
  shows "AALTs bs rs1 \<leadsto>* AALTs bs rs2"
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1082
using assms
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1083
  by (metis append.left_neutral srewrites_alt)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1084
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1085
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1086
lemma star_seq:  
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1087
  assumes "r1 \<leadsto>* r2"
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1088
  shows "ASEQ bs r1 r3 \<leadsto>* ASEQ bs r2 r3"
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1089
using assms
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1090
apply(induct r1 r2 arbitrary: r3 rule: rrewrites.induct)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1091
apply(auto intro: rrewrite.intros)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1092
done
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1093
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1094
lemma star_seq2:  
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1095
  assumes "r3 \<leadsto>* r4"
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1096
  shows "ASEQ bs r1 r3 \<leadsto>* ASEQ bs r1 r4"
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1097
using assms
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1098
apply(induct r3 r4 arbitrary: r1 rule: rrewrites.induct)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1099
apply(auto intro: rrewrite.intros)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1100
done
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1101
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1102
lemma continuous_rewrite: 
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1103
  assumes "r1 \<leadsto>* AZERO"
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1104
  shows "ASEQ bs1 r1 r2 \<leadsto>* AZERO"
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1105
using assms
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1106
  apply(induction ra\<equiv>"r1" rb\<equiv>"AZERO" arbitrary: bs1 r1 r2 rule: rrewrites.induct)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1107
  apply(auto intro: rrewrite.intros r_in_rstar star_seq)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1108
  by (meson rrewrite.intros(1) rs2 star_seq)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1109
  
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1110
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1111
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1112
lemma bsimp_aalts_simpcases: 
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1113
  shows "AONE bs \<leadsto>* bsimp (AONE bs)"  
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1114
  and   "AZERO \<leadsto>* bsimp AZERO" 
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1115
  and   "ACHAR bs c \<leadsto>* bsimp (ACHAR bs c)"
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1116
  by (simp_all)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1117
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1118
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1119
lemma trivialbsimp_srewrites: 
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1120
  "\<lbrakk>\<And>x. x \<in> set rs \<Longrightarrow> x \<leadsto>* f x \<rbrakk> \<Longrightarrow> rs s\<leadsto>* (map f rs)"
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1121
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1122
  apply(induction rs)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1123
   apply simp
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1124
   apply(rule ss1)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1125
  by (metis insert_iff list.simps(15) list.simps(9) srewrites.simps)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1126
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1127
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1128
lemma bsimp_AALTs_rewrites: 
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1129
  "AALTs bs1 rs \<leadsto>* bsimp_AALTs bs1 rs"
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1130
  apply(induction rs)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1131
  apply simp
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1132
   apply(rule r_in_rstar)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1133
  using rrewrite.intros(9) apply blast
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1134
  by (metis bsimp_AALTs.elims list.discI rrewrite.intros(10) rrewrites.simps)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1135
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1136
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1137
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1138
lemma flts_prepend: "\<lbrakk>nonalt a; nonazero a\<rbrakk> \<Longrightarrow> flts (a#rs) = a # (flts rs)"
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1139
  by (metis append_Cons append_Nil flts_single1 flts_append)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1140
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1141
lemma fltsfrewrites: "rs f\<leadsto>* (flts rs)"
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1142
  apply(induction rs)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1143
  apply simp
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1144
   apply(rule fs1)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1145
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1146
  apply(case_tac "a = AZERO")
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1147
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1148
   
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1149
  using fs2 apply auto[1]
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1150
  apply(case_tac "\<exists>bs rs. a = AALTs bs rs")
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1151
   apply(erule exE)+
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1152
   
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1153
   apply (simp add: fs3)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1154
  apply(subst flts_prepend)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1155
    apply(rule nonalt.elims(2))
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1156
  prefer 2
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1157
  thm nonalt.elims
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1158
   
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1159
         apply blast
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1160
   
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1161
  using bbbbs1 apply blast
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1162
       apply(simp)+
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1163
   
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1164
   apply (meson nonazero.elims(3))
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1165
   
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1166
  by (meson fs4 nonalt.elims(3) nonazero.elims(3))
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1167
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1168
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1169
lemma rrewrite0away: "AALTs bs (AZERO # rsb) \<leadsto> AALTs bs rsb"
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1170
  by (metis append_Cons append_Nil rrewrite.intros(7))
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1171
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1172
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1173
lemma frewritesaalts:"rs f\<leadsto>* rs' \<Longrightarrow> (AALTs bs (rs1@rs)) \<leadsto>* (AALTs bs (rs1@rs'))"
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1174
  apply(induct rs rs' arbitrary: bs rs1 rule:frewrites.induct)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1175
    apply(rule rs1)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1176
    apply(drule_tac x = "bs" in meta_spec)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1177
  apply(drule_tac x = "rs1 @ [AZERO]" in meta_spec)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1178
    apply(rule real_trans)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1179
     apply simp
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1180
  using rrewrite.intros(7) apply auto[1]
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1181
    apply(drule_tac x = "bsa" in meta_spec)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1182
  apply(drule_tac x = "rs1a @ [AALTs bs rs1]" in meta_spec)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1183
   apply(rule real_trans)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1184
    apply simp
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1185
  using r_in_rstar rrewrite.intros(8) apply auto[1]
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1186
    apply(drule_tac x = "bs" in meta_spec)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1187
  apply(drule_tac x = "rs1@[r]" in meta_spec)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1188
    apply(rule real_trans)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1189
   apply simp
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1190
  apply auto
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1191
  done
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1192
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1193
lemma flts_rewrites: "  AALTs bs1 rs \<leadsto>* AALTs bs1 (flts rs)"
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1194
  apply(induction rs)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1195
   apply simp
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1196
  apply(case_tac "a = AZERO")
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1197
  apply (metis flts.simps(2) many_steps_later rrewrite0away)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1198
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1199
  apply(case_tac "\<exists>bs2 rs2. a = AALTs bs2 rs2")
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1200
   apply(erule exE)+
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1201
   apply(simp)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1202
   prefer 2
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1203
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1204
  apply(subst flts_prepend)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1205
   
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1206
     apply (meson nonalt.elims(3))
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1207
   
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1208
    apply (meson nonazero.elims(3))
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1209
   apply(subgoal_tac "(a#rs) f\<leadsto>* (a#flts rs)")
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1210
  apply (metis append_Nil frewritesaalts)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1211
  apply (meson fltsfrewrites fs4 nonalt.elims(3) nonazero.elims(3))
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1212
  by (metis append_Cons append_Nil fltsfrewrites frewritesaalts flts_append k0a)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1213
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1214
(* TEST *)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1215
lemma r: 
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1216
  assumes "AALTs bs rs1 \<leadsto> AALTs bs rs2"
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1217
  shows "AALTs bs (x # rs1) \<leadsto>* AALTs bs (x # rs2)"
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1218
  using assms
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1219
  apply(erule_tac rrewrite.cases)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1220
            apply(auto)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1221
  apply (metis append_Cons append_Nil rrewrite.intros(6) r_in_rstar)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1222
  apply (metis append_Cons append_self_conv2 rrewrite.intros(7) r_in_rstar)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1223
  apply (metis Cons_eq_appendI append_eq_append_conv2 rrewrite.intros(8) self_append_conv r_in_rstar)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1224
   apply(case_tac rs2)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1225
    apply(auto)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1226
  apply(case_tac r)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1227
         apply(auto)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1228
  apply (metis append_Nil2 append_butlast_last_id butlast.simps(2) last.simps list.distinct(1) list.map_disc_iff r_in_rstar rrewrite.intros(8))
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1229
     apply(case_tac r)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1230
        apply(auto)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1231
   defer
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1232
   apply(rule r_in_rstar)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1233
  apply (metis append_Cons append_Nil rrewrite.intros(11))
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1234
  apply(rule real_trans)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1235
   apply(rule r_in_rstar)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1236
  using rrewrite.intros(8)[where ?rsb = "[]", of "bs" "[x]" "[]" , simplified]
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1237
   apply(rule_tac rrewrite.intros(8)[where ?rsb = "[]", of "bs" "[x]" "[]" , simplified])
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1238
  apply(simp add: map_fuse_Nil fuse_Nil)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1239
  done 
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1240
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1241
lemma alts_simpalts: 
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1242
  "(\<And>x. x \<in> set rs \<Longrightarrow> x \<leadsto>* bsimp x) \<Longrightarrow> 
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1243
  AALTs bs1 rs \<leadsto>* AALTs bs1 (map bsimp rs)"
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1244
  apply(induct rs)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1245
   apply(auto)[1]
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1246
  using trivialbsimp_srewrites apply auto[1]
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1247
  by (simp add: srewrites_alt1 ss2)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1248
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1249
lemma threelistsappend: "rsa@a#rsb = (rsa@[a])@rsb"
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1250
  apply auto
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1251
  done
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1252
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1253
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1254
lemma somewhereInside: "r \<in> set rs \<Longrightarrow> \<exists>rs1 rs2. rs = rs1@[r]@rs2"
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1255
  using split_list by fastforce
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1256
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1257
lemma somewhereMapInside: "f r \<in> f ` set rs \<Longrightarrow> \<exists>rs1 rs2 a. rs = rs1@[a]@rs2 \<and> f a = f r"
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1258
  apply auto
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1259
  by (metis split_list)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1260
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1261
lemma alts_dBrewrites_withFront: 
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1262
  "AALTs bs (rsa @ rs) \<leadsto>* AALTs bs (rsa @ distinctBy rs erase (erase ` set rsa))"
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1263
  apply(induction rs arbitrary: rsa)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1264
   apply simp
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1265
  apply(drule_tac x = "rsa@[a]" in meta_spec)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1266
  apply(subst threelistsappend)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1267
  apply(rule real_trans)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1268
  apply simp
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1269
  apply(case_tac "a \<in> set rsa")
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1270
   apply simp
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1271
   apply(drule somewhereInside)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1272
   apply(erule exE)+
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1273
   apply simp
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1274
  apply(subgoal_tac " AALTs bs
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1275
            (rs1 @
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1276
             a #
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1277
             rs2 @
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1278
             a #
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1279
             distinctBy rs erase
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1280
              (insert (erase a)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1281
                (erase `
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1282
                 (set rs1 \<union> set rs2)))) \<leadsto> AALTs bs (rs1@ a # rs2 @  distinctBy rs erase
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1283
              (insert (erase a)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1284
                (erase `
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1285
                 (set rs1 \<union> set rs2)))) ")
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1286
  prefer 2
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1287
  using rrewrite.intros(11) apply force
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1288
  using r_in_rstar apply force
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1289
  apply(subgoal_tac "erase ` set (rsa @ [a]) = insert (erase a) (erase ` set rsa)")
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1290
  prefer 2
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1291
    
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1292
   apply auto[1]
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1293
  apply(case_tac "erase a \<in> erase `set rsa")
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1294
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1295
   apply simp
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1296
  apply(subgoal_tac "AALTs bs (rsa @ a # distinctBy rs erase (insert (erase a) (erase ` set rsa))) \<leadsto>
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1297
                     AALTs bs (rsa @ distinctBy rs erase (insert (erase a) (erase ` set rsa)))")
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1298
  apply force
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1299
  apply (smt (verit, ccfv_threshold) append_Cons append_assoc append_self_conv2 r_in_rstar rrewrite.intros(11) same_append_eq somewhereMapInside)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1300
  by force
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1301
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1302
 
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1303
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1304
lemma alts_dBrewrites: "AALTs bs rs \<leadsto>* AALTs bs (distinctBy rs erase {})"
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1305
  apply(induction rs)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1306
   apply simp
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1307
  apply simp
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1308
  using alts_dBrewrites_withFront
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1309
  by (metis append_Nil dB_single_step empty_set image_empty)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1310
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1311
lemma bsimp_rewrite: 
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1312
  shows "r \<leadsto>* bsimp r"
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1313
proof (induction r rule: bsimp.induct)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1314
  case (1 bs1 r1 r2)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1315
  then show "ASEQ bs1 r1 r2 \<leadsto>* bsimp (ASEQ bs1 r1 r2)"
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1316
    apply(simp)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1317
    apply(case_tac "bsimp r1 = AZERO")
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1318
        apply simp
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1319
  using continuous_rewrite apply blast
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1320
       apply(case_tac "\<exists>bs. bsimp r1 = AONE bs")
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1321
        apply(erule exE)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1322
        apply simp
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1323
        apply(subst bsimp_ASEQ2)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1324
        apply (meson real_trans rrewrite.intros(3) rrewrites.intros(2) star_seq star_seq2)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1325
       apply (smt (verit, best) bsimp_ASEQ0 bsimp_ASEQ1 real_trans rrewrite.intros(2) rs2 star_seq star_seq2)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1326
  done
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1327
next
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1328
  case (2 bs1 rs)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1329
  then show "AALTs bs1 rs \<leadsto>* bsimp (AALTs bs1 rs)"
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1330
    by (metis alts_dBrewrites alts_simpalts bsimp.simps(2) bsimp_AALTs_rewrites flts_rewrites real_trans)  
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1331
next
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1332
  case "3_1"
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1333
  then show "AZERO \<leadsto>* bsimp AZERO"
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1334
    by simp
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1335
next
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1336
  case ("3_2" v)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1337
  then show "AONE v \<leadsto>* bsimp (AONE v)" 
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1338
    by simp
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1339
next
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1340
  case ("3_3" v va)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1341
  then show "ACHAR v va \<leadsto>* bsimp (ACHAR v va)" 
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1342
    by simp
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1343
next
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1344
  case ("3_4" v va)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1345
  then show "ASTAR v va \<leadsto>* bsimp (ASTAR v va)" 
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1346
    by simp
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1347
qed
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1348
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1349
lemma rewrite_non_nullable_strong: 
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1350
  assumes "r1 \<leadsto> r2"
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1351
  shows "bnullable r1 = bnullable r2"
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1352
using assms
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1353
apply(induction r1 r2 rule: rrewrite.induct)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1354
apply(auto)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1355
apply(metis bnullable_correctness erase_fuse)+
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1356
apply(metis UnCI bnullable_correctness erase_fuse imageI)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1357
apply(metis bnullable_correctness erase_fuse)+
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1358
done
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1359
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1360
lemma rewrite_nullable: 
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1361
  assumes "r1 \<leadsto> r2" "bnullable r1"
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1362
  shows "bnullable r2"
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1363
using assms rewrite_non_nullable_strong
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1364
by auto
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1365
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1366
lemma rewritesnullable: 
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1367
  assumes "r1 \<leadsto>* r2" "bnullable r1"
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1368
  shows "bnullable r2"
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1369
using assms
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1370
  apply(induction r1 r2 rule: rrewrites.induct)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1371
  apply simp
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1372
  using rewrite_non_nullable_strong by blast
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1373
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1374
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1375
lemma bnullable_segment: 
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1376
  "bnullable (AALTs bs (rs1@[r]@rs2)) \<Longrightarrow> bnullable (AALTs bs rs1) \<or> bnullable (AALTs bs rs2) \<or> bnullable r"
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1377
  by auto
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1378
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1379
lemma bnullablewhichbmkeps: "\<lbrakk>bnullable  (AALTs bs (rs1@[r]@rs2)); \<not> bnullable (AALTs bs rs1); bnullable r \<rbrakk>
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1380
 \<Longrightarrow> bmkeps (AALTs bs (rs1@[r]@rs2)) = bs @ (bmkeps r)"
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1381
  
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1382
  using qq2 bnullable_Hdbmkeps_Hd by force
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1383
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1384
lemma spillbmkepslistr: "bnullable (AALTs bs1 rs1)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1385
    \<Longrightarrow> bmkeps (AALTs bs (AALTs bs1 rs1 # rsb)) = bmkeps (AALTs bs ( map (fuse bs1) rs1 @ rsb))"
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1386
  apply(subst bnullable_Hdbmkeps_Hd)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1387
  
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1388
   apply simp
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1389
  by (metis bmkeps.simps(3) k0a list.set_intros(1) qq1 qq4 qs3)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1390
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1391
lemma third_segment_bnullable: 
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1392
  "\<lbrakk>bnullable (AALTs bs (rs1@rs2@rs3)); \<not>bnullable (AALTs bs rs1); \<not>bnullable (AALTs bs rs2)\<rbrakk> \<Longrightarrow> 
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1393
   bnullable (AALTs bs rs3)"
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1394
  apply(auto)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1395
  done
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1396
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1397
lemma third_segment_bmkeps:  
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1398
  "\<lbrakk>bnullable (AALTs bs (rs1@rs2@rs3)); \<not>bnullable (AALTs bs rs1); \<not>bnullable (AALTs bs rs2)\<rbrakk> \<Longrightarrow> 
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1399
   bmkeps (AALTs bs (rs1@rs2@rs3) ) = bmkeps (AALTs bs rs3)"
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1400
  by (metis bnullable.simps(1) bnullable.simps(4) bsimp_AALTs.simps(1) bsimp_AALTs_rewrites qq2 rewritesnullable self_append_conv third_segment_bnullable)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1401
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1402
lemma rewrite_bmkepsalt: 
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1403
  "\<lbrakk>bnullable (AALTs bs (rsa @ AALTs bs1 rs1 # rsb)); bnullable (AALTs bs (rsa @ map (fuse bs1) rs1 @ rsb))\<rbrakk>
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1404
       \<Longrightarrow> bmkeps (AALTs bs (rsa @ AALTs bs1 rs1 # rsb)) = bmkeps (AALTs bs (rsa @ map (fuse bs1) rs1 @ rsb))"
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1405
  apply(rule qq3)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1406
  apply(simp)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1407
  apply(simp)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1408
  apply(case_tac "bnullable (AALTs bs1 rs1)")
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1409
  using spillbmkepslistr apply blast
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1410
  apply(subst qq2)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1411
    apply(auto simp add: bnullable_fuse r1)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1412
  done
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1413
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1414
lemma rewrite_bmkeps_aux: 
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1415
  assumes "r1 \<leadsto> r2" "bnullable r1" "bnullable r2"
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1416
  shows "bmkeps r1 = bmkeps r2"
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1417
  using assms 
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1418
proof (induction r1 r2 rule: rrewrite.induct)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1419
  case (1 bs r2)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1420
  then show ?case by simp 
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1421
next
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1422
  case (2 bs r1)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1423
  then show ?case by simp
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1424
next
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1425
  case (3 bs bs1 r)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1426
  then show ?case by (simp add: b2) 
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1427
next
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1428
  case (4 r1 r2 bs r3)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1429
  then show ?case by simp
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1430
next
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1431
  case (5 r3 r4 bs r1)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1432
  then show ?case by simp
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1433
next
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1434
  case (6 r r' bs rs1 rs2)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1435
  then show ?case
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1436
    by (metis append_Cons append_Nil bnullable.simps(4) bnullable_segment bnullablewhichbmkeps qq3 r1 rewrite_non_nullable_strong)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1437
next
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1438
  case (7 bs rsa rsb)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1439
  then show ?case
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1440
    by (metis bnullable.simps(1) bnullable.simps(4) bnullable_segment qq1 qq2 rewrite_nullable rrewrite.intros(9) rrewrite0away third_segment_bmkeps) 
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1441
next
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1442
  case (8 bs rsa bs1 rs1 rsb)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1443
  then show ?case
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1444
    by (simp add: rewrite_bmkepsalt) 
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1445
next
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1446
  case (9 bs)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1447
  then show ?case
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1448
    by fastforce 
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1449
next
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1450
  case (10 bs r)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1451
  then show ?case
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1452
    by (simp add: b2) 
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1453
next
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1454
  case (11 a1 a2 bs rsa rsb rsc)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1455
  then show ?case
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1456
    by (smt (verit, ccfv_threshold) append_Cons append_eq_appendI append_self_conv2 bnullable_correctness list.set_intros(1) qq3 r1)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1457
qed
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1458
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1459
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1460
lemma rewrite_bmkeps: 
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1461
  assumes "r1 \<leadsto> r2" "bnullable r1"
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1462
  shows "bmkeps r1 = bmkeps r2"
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1463
  using assms(1) assms(2) rewrite_bmkeps_aux rewrite_nullable by blast
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1464
  
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1465
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1466
lemma rewrites_bmkeps: 
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1467
  assumes "r1 \<leadsto>* r2" "bnullable r1" 
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1468
  shows "bmkeps r1 = bmkeps r2"
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1469
  using assms
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1470
proof(induction r1 r2 rule: rrewrites.induct)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1471
  case (rs1 r)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1472
  then show "bmkeps r = bmkeps r" by simp
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1473
next
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1474
  case (rs2 r1 r2 r3)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1475
  then have IH: "bmkeps r1 = bmkeps r2" by simp
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1476
  have a1: "bnullable r1" by fact
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1477
  have a2: "r1 \<leadsto>* r2" by fact
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1478
  have a3: "r2 \<leadsto> r3" by fact
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1479
  have a4: "bnullable r2" using a1 a2 by (simp add: rewritesnullable) 
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1480
  then have "bmkeps r2 = bmkeps r3" using rewrite_bmkeps a3 a4 by simp
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1481
  then show "bmkeps r1 = bmkeps r3" using IH by simp
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1482
qed
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1483
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1484
lemma alts_rewrite_front: "r \<leadsto> r' \<Longrightarrow> AALTs bs (r # rs) \<leadsto> AALTs bs (r' # rs)"
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1485
  by (metis append_Cons append_Nil rrewrite.intros(6))
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1486
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1487
lemma to_zero_in_alt: " AALT bs (ASEQ [] AZERO r) r2 \<leadsto>  AALT bs AZERO r2"
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1488
  by (simp add: alts_rewrite_front rrewrite.intros(1))
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1489
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1490
lemma rewrite_fuse: 
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1491
  assumes "r2 \<leadsto> r3"
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1492
  shows "fuse bs r2 \<leadsto>* fuse bs r3"
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1493
  using assms
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1494
proof(induction r2 r3 arbitrary: bs rule: rrewrite.induct)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1495
  case (1 bs r2)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1496
  then show ?case
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1497
    by (simp add: continuous_rewrite) 
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1498
next
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1499
  case (2 bs r1)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1500
  then show ?case
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1501
    using rrewrite.intros(2) by force 
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1502
next
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1503
  case (3 bs bs1 r)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1504
  then show ?case
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1505
    by (metis fuse.simps(5) fuse_append r_in_rstar rrewrite.intros(3)) 
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1506
next
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1507
  case (4 r1 r2 bs r3)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1508
  then show ?case
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1509
    by (simp add: r_in_rstar star_seq) 
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1510
next
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1511
  case (5 r3 r4 bs r1)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1512
  then show ?case
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1513
    using fuse.simps(5) r_in_rstar star_seq2 by auto  
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1514
next
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1515
  case (6 r r' bs rs1 rs2)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1516
  then show ?case
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1517
    using contextrewrites2 r_in_rstar by force 
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1518
next
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1519
  case (7 bs rsa rsb)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1520
  then show ?case
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1521
    using rrewrite.intros(7) by force  
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1522
next
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1523
  case (8 bs rsa bs1 rs1 rsb)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1524
  then show ?case
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1525
    using rrewrite.intros(8) by force 
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1526
next
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1527
  case (9 bs)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1528
  then show ?case
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1529
    by (simp add: r_in_rstar rrewrite.intros(9))
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1530
next
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1531
  case (10 bs r)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1532
  then show ?case
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1533
    by (metis fuse.simps(4) fuse_append r_in_rstar rrewrite.intros(10)) 
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1534
next
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1535
  case (11 a1 a2 bs rsa rsb rsc)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1536
  then show ?case
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1537
    using fuse.simps(4) r_in_rstar rrewrite.intros(11) by auto 
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1538
qed
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1539
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1540
lemma rewrites_fuse:  
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1541
  assumes "r1 \<leadsto>* r2"
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1542
  shows "fuse bs r1 \<leadsto>* fuse bs r2"
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1543
using assms
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1544
apply(induction r1 r2 arbitrary: bs rule: rrewrites.induct)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1545
apply(auto intro: rewrite_fuse real_trans)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1546
done
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1547
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1548
lemma  bder_fuse_list: 
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1549
  shows "map (bder c \<circ> fuse bs1) rs1 = map (fuse bs1 \<circ> bder c) rs1"
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1550
apply(induction rs1)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1551
apply(simp_all add: bder_fuse)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1552
done
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1553
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1554
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1555
lemma rewrite_der_altmiddle: 
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1556
  "bder c (AALTs bs (rsa @ AALTs bs1 rs1 # rsb)) \<leadsto>* bder c (AALTs bs (rsa @ map (fuse bs1) rs1 @ rsb))"
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1557
   apply simp
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1558
   apply(simp add: bder_fuse_list del: append.simps)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1559
  by (metis append.assoc map_map r_in_rstar rrewrite.intros(8) threelistsappend)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1560
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1561
lemma lock_step_der_removal: 
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1562
  shows " erase a1 = erase a2 \<Longrightarrow> 
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1563
                                  bder c (AALTs bs (rsa @ [a1] @ rsb @ [a2] @ rsc)) \<leadsto>* 
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1564
                                  bder c (AALTs bs (rsa @ [a1] @ rsb @ rsc))"
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1565
  apply(simp)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1566
  
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1567
  using rrewrite.intros(11) by auto
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1568
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1569
lemma rewrite_after_der: 
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1570
  assumes "r1 \<leadsto> r2"
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1571
  shows "(bder c r1) \<leadsto>* (bder c r2)"
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1572
  using assms
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1573
proof(induction r1 r2 rule: rrewrite.induct)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1574
  case (1 bs r2)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1575
  then show "bder c (ASEQ bs AZERO r2) \<leadsto>* bder c AZERO"
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1576
    by (simp add: continuous_rewrite) 
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1577
next
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1578
  case (2 bs r1)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1579
  then show "bder c (ASEQ bs r1 AZERO) \<leadsto>* bder c AZERO"
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1580
    apply(simp)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1581
    by (meson contextrewrites1 r_in_rstar real_trans rrewrite.intros(9) rrewrite.intros(2) rrewrite0away)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1582
next
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1583
  case (3 bs bs1 r)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1584
  then show "bder c (ASEQ bs (AONE bs1) r) \<leadsto>* bder c (fuse (bs @ bs1) r)" 
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1585
    apply(simp)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1586
    by (metis bder_fuse fuse_append rrewrite.intros(10) rrewrite0away rrewrites.simps to_zero_in_alt)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1587
next
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1588
  case (4 r1 r2 bs r3)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1589
  have as: "r1 \<leadsto> r2" by fact
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1590
  have IH: "bder c r1 \<leadsto>* bder c r2" by fact
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1591
  from as IH show "bder c (ASEQ bs r1 r3) \<leadsto>* bder c (ASEQ bs r2 r3)"
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1592
    by (simp add: contextrewrites1 rewrite_bmkeps rewrite_non_nullable_strong star_seq) 
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1593
next
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1594
  case (5 r3 r4 bs r1)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1595
  have as: "r3 \<leadsto> r4" by fact 
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1596
  have IH: "bder c r3 \<leadsto>* bder c r4" by fact 
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1597
  from as IH show "bder c (ASEQ bs r1 r3) \<leadsto>* bder c (ASEQ bs r1 r4)"
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1598
    using bder.simps(5) r_in_rstar rewrites_fuse srewrites_alt1 ss1 ss2 star_seq2 by presburger
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1599
next
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1600
  case (6 r r' bs rs1 rs2)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1601
  have as: "r \<leadsto> r'" by fact
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1602
  have IH: "bder c r \<leadsto>* bder c r'" by fact
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1603
  from as IH show "bder c (AALTs bs (rs1 @ [r] @ rs2)) \<leadsto>* bder c (AALTs bs (rs1 @ [r'] @ rs2))" 
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1604
    apply(simp)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1605
    using contextrewrites2 by force
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1606
next
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1607
  case (7 bs rsa rsb)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1608
  then show "bder c (AALTs bs (rsa @ [AZERO] @ rsb)) \<leadsto>* bder c (AALTs bs (rsa @ rsb))" 
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1609
    apply(simp)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1610
    using rrewrite.intros(7) by auto
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1611
next
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1612
  case (8 bs rsa bs1 rs1 rsb)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1613
  then show 
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1614
    "bder c (AALTs bs (rsa @ [AALTs bs1 rs1] @ rsb)) \<leadsto>* bder c (AALTs bs (rsa @ map (fuse bs1) rs1 @ rsb))"
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1615
    using rewrite_der_altmiddle by auto 
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1616
next
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1617
  case (9 bs)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1618
  then show "bder c (AALTs bs []) \<leadsto>* bder c AZERO"
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1619
    by (simp add: r_in_rstar rrewrite.intros(9))
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1620
next
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1621
  case (10 bs r)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1622
  then show "bder c (AALTs bs [r]) \<leadsto>* bder c (fuse bs r)"
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1623
    by (simp add: bder_fuse r_in_rstar rrewrite.intros(10)) 
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1624
next
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1625
  case (11 a1 a2 bs rsa rsb rsc)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1626
  have as: "erase a1 = erase a2" by fact
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1627
  then show "bder c (AALTs bs (rsa @ [a1] @ rsb @ [a2] @ rsc)) \<leadsto>* bder c (AALTs bs (rsa @ [a1] @ rsb @ rsc))"
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1628
    using lock_step_der_removal by force 
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1629
qed
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1630
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1631
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1632
lemma rewrites_after_der: 
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1633
  assumes "r1 \<leadsto>* r2"
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1634
  shows "bder c r1 \<leadsto>* bder c r2"
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1635
using assms  
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1636
apply(induction r1 r2 rule: rrewrites.induct)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1637
apply(simp_all add: rewrite_after_der real_trans)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1638
done
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1639
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1640
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1641
lemma central:  
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1642
  shows "bders r s \<leadsto>* bders_simp r s"
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1643
proof(induct s arbitrary: r rule: rev_induct)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1644
  case Nil
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1645
  then show "bders r [] \<leadsto>* bders_simp r []" by simp
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1646
next
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1647
  case (snoc x xs)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1648
  have IH: "\<And>r. bders r xs \<leadsto>* bders_simp r xs" by fact
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1649
  have "bders r (xs @ [x]) = bders (bders r xs) [x]" by (simp add: bders_append)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1650
  also have "... \<leadsto>* bders (bders_simp r xs) [x]" using IH
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1651
    by (simp add: rewrites_after_der)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1652
  also have "... \<leadsto>* bders_simp (bders_simp r xs) [x]" using IH
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1653
    by (simp add: bsimp_rewrite)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1654
  finally show "bders r (xs @ [x]) \<leadsto>* bders_simp r (xs @ [x])" 
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1655
    by (simp add: bders_simp_append)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1656
qed
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1657
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1658
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1659
  
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1660
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1661
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1662
lemma quasi_main: 
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1663
  assumes "bnullable (bders r s)"
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1664
  shows "bmkeps (bders r s) = bmkeps (bders_simp r s)"
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1665
proof -
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1666
  have "bders r s \<leadsto>* bders_simp r s" by (rule central)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1667
  then 
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1668
  show "bmkeps (bders r s) = bmkeps (bders_simp r s)" using assms
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1669
    by (rule rewrites_bmkeps)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1670
qed  
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1671
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1672
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1673
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1674
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1675
theorem main_main: 
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1676
  shows "blexer r s = blexer_simp r s"
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1677
  unfolding blexer_def blexer_simp_def
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1678
  using b4 quasi_main by simp
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1679
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1680
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1681
theorem blexersimp_correctness: 
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1682
  shows "lexer r s = blexer_simp r s"
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1683
  using blexer_correctness main_main by simp
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1684
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1685
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1686
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1687
export_code blexer_simp blexer lexer bders bders_simp in Scala module_name VerifiedLexers
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1688
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1689
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1690
unused_thms
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1691
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1692
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1693
inductive aggressive:: "arexp \<Rightarrow> arexp \<Rightarrow> bool" ("_ \<leadsto>? _" [99, 99] 99)
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1694
  where
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1695
 "ASEQ bs (AALTs bs1 rs) r \<leadsto>? AALTs (bs@bs1) (map (\<lambda>r'. ASEQ [] r' r) rs) "
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1696
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1697
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1698
994403dbbed5 strong!
Chengsong
parents:
diff changeset
  1699
end