thys2/SizeBound5CT.thy
author Chengsong
Tue, 14 Jun 2022 18:06:33 +0100
changeset 542 a7344c9afbaf
parent 430 579caa608a15
permissions -rw-r--r--
chapter3 finished
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
409
Chengsong
parents:
diff changeset
     1
Chengsong
parents:
diff changeset
     2
theory SizeBound5CT
428
Chengsong
parents: 427
diff changeset
     3
  imports "Lexer" "PDerivs" 
409
Chengsong
parents:
diff changeset
     4
begin
Chengsong
parents:
diff changeset
     5
Chengsong
parents:
diff changeset
     6
section \<open>Bit-Encodings\<close>
Chengsong
parents:
diff changeset
     7
Chengsong
parents:
diff changeset
     8
datatype bit = Z | S
Chengsong
parents:
diff changeset
     9
Chengsong
parents:
diff changeset
    10
fun code :: "val \<Rightarrow> bit list"
Chengsong
parents:
diff changeset
    11
where
Chengsong
parents:
diff changeset
    12
  "code Void = []"
Chengsong
parents:
diff changeset
    13
| "code (Char c) = []"
Chengsong
parents:
diff changeset
    14
| "code (Left v) = Z # (code v)"
Chengsong
parents:
diff changeset
    15
| "code (Right v) = S # (code v)"
Chengsong
parents:
diff changeset
    16
| "code (Seq v1 v2) = (code v1) @ (code v2)"
Chengsong
parents:
diff changeset
    17
| "code (Stars []) = [S]"
Chengsong
parents:
diff changeset
    18
| "code (Stars (v # vs)) =  (Z # code v) @ code (Stars vs)"
Chengsong
parents:
diff changeset
    19
Chengsong
parents:
diff changeset
    20
Chengsong
parents:
diff changeset
    21
fun 
Chengsong
parents:
diff changeset
    22
  Stars_add :: "val \<Rightarrow> val \<Rightarrow> val"
Chengsong
parents:
diff changeset
    23
where
Chengsong
parents:
diff changeset
    24
  "Stars_add v (Stars vs) = Stars (v # vs)"
Chengsong
parents:
diff changeset
    25
Chengsong
parents:
diff changeset
    26
function
Chengsong
parents:
diff changeset
    27
  decode' :: "bit list \<Rightarrow> rexp \<Rightarrow> (val * bit list)"
Chengsong
parents:
diff changeset
    28
where
Chengsong
parents:
diff changeset
    29
  "decode' bs ZERO = (undefined, bs)"
Chengsong
parents:
diff changeset
    30
| "decode' bs ONE = (Void, bs)"
Chengsong
parents:
diff changeset
    31
| "decode' bs (CH d) = (Char d, bs)"
Chengsong
parents:
diff changeset
    32
| "decode' [] (ALT r1 r2) = (Void, [])"
Chengsong
parents:
diff changeset
    33
| "decode' (Z # bs) (ALT r1 r2) = (let (v, bs') = decode' bs r1 in (Left v, bs'))"
Chengsong
parents:
diff changeset
    34
| "decode' (S # bs) (ALT r1 r2) = (let (v, bs') = decode' bs r2 in (Right v, bs'))"
Chengsong
parents:
diff changeset
    35
| "decode' bs (SEQ r1 r2) = (let (v1, bs') = decode' bs r1 in
Chengsong
parents:
diff changeset
    36
                             let (v2, bs'') = decode' bs' r2 in (Seq v1 v2, bs''))"
Chengsong
parents:
diff changeset
    37
| "decode' [] (STAR r) = (Void, [])"
Chengsong
parents:
diff changeset
    38
| "decode' (S # bs) (STAR r) = (Stars [], bs)"
Chengsong
parents:
diff changeset
    39
| "decode' (Z # bs) (STAR r) = (let (v, bs') = decode' bs r in
Chengsong
parents:
diff changeset
    40
                                    let (vs, bs'') = decode' bs' (STAR r) 
Chengsong
parents:
diff changeset
    41
                                    in (Stars_add v vs, bs''))"
Chengsong
parents:
diff changeset
    42
by pat_completeness auto
Chengsong
parents:
diff changeset
    43
Chengsong
parents:
diff changeset
    44
lemma decode'_smaller:
Chengsong
parents:
diff changeset
    45
  assumes "decode'_dom (bs, r)"
Chengsong
parents:
diff changeset
    46
  shows "length (snd (decode' bs r)) \<le> length bs"
Chengsong
parents:
diff changeset
    47
using assms
Chengsong
parents:
diff changeset
    48
apply(induct bs r)
Chengsong
parents:
diff changeset
    49
apply(auto simp add: decode'.psimps split: prod.split)
Chengsong
parents:
diff changeset
    50
using dual_order.trans apply blast
Chengsong
parents:
diff changeset
    51
by (meson dual_order.trans le_SucI)
Chengsong
parents:
diff changeset
    52
Chengsong
parents:
diff changeset
    53
termination "decode'"  
Chengsong
parents:
diff changeset
    54
apply(relation "inv_image (measure(%cs. size cs) <*lex*> measure(%s. size s)) (%(ds,r). (r,ds))") 
Chengsong
parents:
diff changeset
    55
apply(auto dest!: decode'_smaller)
Chengsong
parents:
diff changeset
    56
by (metis less_Suc_eq_le snd_conv)
Chengsong
parents:
diff changeset
    57
Chengsong
parents:
diff changeset
    58
definition
Chengsong
parents:
diff changeset
    59
  decode :: "bit list \<Rightarrow> rexp \<Rightarrow> val option"
Chengsong
parents:
diff changeset
    60
where
Chengsong
parents:
diff changeset
    61
  "decode ds r \<equiv> (let (v, ds') = decode' ds r 
Chengsong
parents:
diff changeset
    62
                  in (if ds' = [] then Some v else None))"
Chengsong
parents:
diff changeset
    63
Chengsong
parents:
diff changeset
    64
lemma decode'_code_Stars:
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> []" 
Chengsong
parents:
diff changeset
    66
  shows "decode' (code (Stars vs) @ ds) (STAR r) = (Stars vs, ds)"
Chengsong
parents:
diff changeset
    67
  using assms
Chengsong
parents:
diff changeset
    68
  apply(induct vs)
Chengsong
parents:
diff changeset
    69
  apply(auto)
Chengsong
parents:
diff changeset
    70
  done
Chengsong
parents:
diff changeset
    71
Chengsong
parents:
diff changeset
    72
lemma decode'_code:
Chengsong
parents:
diff changeset
    73
  assumes "\<Turnstile> v : r"
Chengsong
parents:
diff changeset
    74
  shows "decode' ((code v) @ ds) r = (v, ds)"
Chengsong
parents:
diff changeset
    75
using assms
Chengsong
parents:
diff changeset
    76
  apply(induct v r arbitrary: ds) 
Chengsong
parents:
diff changeset
    77
  apply(auto)
Chengsong
parents:
diff changeset
    78
  using decode'_code_Stars by blast
Chengsong
parents:
diff changeset
    79
Chengsong
parents:
diff changeset
    80
lemma decode_code:
Chengsong
parents:
diff changeset
    81
  assumes "\<Turnstile> v : r"
Chengsong
parents:
diff changeset
    82
  shows "decode (code v) r = Some v"
Chengsong
parents:
diff changeset
    83
  using assms unfolding decode_def
Chengsong
parents:
diff changeset
    84
  by (smt append_Nil2 decode'_code old.prod.case)
Chengsong
parents:
diff changeset
    85
Chengsong
parents:
diff changeset
    86
Chengsong
parents:
diff changeset
    87
section {* Annotated Regular Expressions *}
Chengsong
parents:
diff changeset
    88
Chengsong
parents:
diff changeset
    89
datatype arexp = 
Chengsong
parents:
diff changeset
    90
  AZERO
Chengsong
parents:
diff changeset
    91
| AONE "bit list"
Chengsong
parents:
diff changeset
    92
| ACHAR "bit list" char
Chengsong
parents:
diff changeset
    93
| ASEQ "bit list" arexp arexp
Chengsong
parents:
diff changeset
    94
| AALTs "bit list" "arexp list"
Chengsong
parents:
diff changeset
    95
| ASTAR "bit list" arexp
Chengsong
parents:
diff changeset
    96
Chengsong
parents:
diff changeset
    97
abbreviation
Chengsong
parents:
diff changeset
    98
  "AALT bs r1 r2 \<equiv> AALTs bs [r1, r2]"
Chengsong
parents:
diff changeset
    99
Chengsong
parents:
diff changeset
   100
fun asize :: "arexp \<Rightarrow> nat" where
Chengsong
parents:
diff changeset
   101
  "asize AZERO = 1"
Chengsong
parents:
diff changeset
   102
| "asize (AONE cs) = 1" 
Chengsong
parents:
diff changeset
   103
| "asize (ACHAR cs c) = 1"
Chengsong
parents:
diff changeset
   104
| "asize (AALTs cs rs) = Suc (sum_list (map asize rs))"
Chengsong
parents:
diff changeset
   105
| "asize (ASEQ cs r1 r2) = Suc (asize r1 + asize r2)"
Chengsong
parents:
diff changeset
   106
| "asize (ASTAR cs r) = Suc (asize r)"
Chengsong
parents:
diff changeset
   107
Chengsong
parents:
diff changeset
   108
fun 
Chengsong
parents:
diff changeset
   109
  erase :: "arexp \<Rightarrow> rexp"
Chengsong
parents:
diff changeset
   110
where
Chengsong
parents:
diff changeset
   111
  "erase AZERO = ZERO"
Chengsong
parents:
diff changeset
   112
| "erase (AONE _) = ONE"
Chengsong
parents:
diff changeset
   113
| "erase (ACHAR _ c) = CH c"
Chengsong
parents:
diff changeset
   114
| "erase (AALTs _ []) = ZERO"
Chengsong
parents:
diff changeset
   115
| "erase (AALTs _ [r]) = (erase r)"
Chengsong
parents:
diff changeset
   116
| "erase (AALTs bs (r#rs)) = ALT (erase r) (erase (AALTs bs rs))"
Chengsong
parents:
diff changeset
   117
| "erase (ASEQ _ r1 r2) = SEQ (erase r1) (erase r2)"
Chengsong
parents:
diff changeset
   118
| "erase (ASTAR _ r) = STAR (erase r)"
Chengsong
parents:
diff changeset
   119
Chengsong
parents:
diff changeset
   120
Chengsong
parents:
diff changeset
   121
fun fuse :: "bit list \<Rightarrow> arexp \<Rightarrow> arexp" where
Chengsong
parents:
diff changeset
   122
  "fuse bs AZERO = AZERO"
Chengsong
parents:
diff changeset
   123
| "fuse bs (AONE cs) = AONE (bs @ cs)" 
Chengsong
parents:
diff changeset
   124
| "fuse bs (ACHAR cs c) = ACHAR (bs @ cs) c"
Chengsong
parents:
diff changeset
   125
| "fuse bs (AALTs cs rs) = AALTs (bs @ cs) rs"
Chengsong
parents:
diff changeset
   126
| "fuse bs (ASEQ cs r1 r2) = ASEQ (bs @ cs) r1 r2"
Chengsong
parents:
diff changeset
   127
| "fuse bs (ASTAR cs r) = ASTAR (bs @ cs) r"
Chengsong
parents:
diff changeset
   128
Chengsong
parents:
diff changeset
   129
lemma fuse_append:
Chengsong
parents:
diff changeset
   130
  shows "fuse (bs1 @ bs2) r = fuse bs1 (fuse bs2 r)"
Chengsong
parents:
diff changeset
   131
  apply(induct r)
Chengsong
parents:
diff changeset
   132
  apply(auto)
Chengsong
parents:
diff changeset
   133
  done
Chengsong
parents:
diff changeset
   134
Chengsong
parents:
diff changeset
   135
Chengsong
parents:
diff changeset
   136
fun intern :: "rexp \<Rightarrow> arexp" where
Chengsong
parents:
diff changeset
   137
  "intern ZERO = AZERO"
Chengsong
parents:
diff changeset
   138
| "intern ONE = AONE []"
Chengsong
parents:
diff changeset
   139
| "intern (CH c) = ACHAR [] c"
Chengsong
parents:
diff changeset
   140
| "intern (ALT r1 r2) = AALT [] (fuse [Z] (intern r1)) 
Chengsong
parents:
diff changeset
   141
                                (fuse [S]  (intern r2))"
Chengsong
parents:
diff changeset
   142
| "intern (SEQ r1 r2) = ASEQ [] (intern r1) (intern r2)"
Chengsong
parents:
diff changeset
   143
| "intern (STAR r) = ASTAR [] (intern r)"
Chengsong
parents:
diff changeset
   144
Chengsong
parents:
diff changeset
   145
Chengsong
parents:
diff changeset
   146
fun retrieve :: "arexp \<Rightarrow> val \<Rightarrow> bit list" where
Chengsong
parents:
diff changeset
   147
  "retrieve (AONE bs) Void = bs"
Chengsong
parents:
diff changeset
   148
| "retrieve (ACHAR bs c) (Char d) = bs"
Chengsong
parents:
diff changeset
   149
| "retrieve (AALTs bs [r]) v = bs @ retrieve r v"
Chengsong
parents:
diff changeset
   150
| "retrieve (AALTs bs (r#rs)) (Left v) = bs @ retrieve r v"
Chengsong
parents:
diff changeset
   151
| "retrieve (AALTs bs (r#rs)) (Right v) = bs @ retrieve (AALTs [] rs) v"
Chengsong
parents:
diff changeset
   152
| "retrieve (ASEQ bs r1 r2) (Seq v1 v2) = bs @ retrieve r1 v1 @ retrieve r2 v2"
Chengsong
parents:
diff changeset
   153
| "retrieve (ASTAR bs r) (Stars []) = bs @ [S]"
Chengsong
parents:
diff changeset
   154
| "retrieve (ASTAR bs r) (Stars (v#vs)) = 
Chengsong
parents:
diff changeset
   155
     bs @ [Z] @ retrieve r v @ retrieve (ASTAR [] r) (Stars vs)"
Chengsong
parents:
diff changeset
   156
Chengsong
parents:
diff changeset
   157
Chengsong
parents:
diff changeset
   158
Chengsong
parents:
diff changeset
   159
fun
Chengsong
parents:
diff changeset
   160
 bnullable :: "arexp \<Rightarrow> bool"
Chengsong
parents:
diff changeset
   161
where
Chengsong
parents:
diff changeset
   162
  "bnullable (AZERO) = False"
Chengsong
parents:
diff changeset
   163
| "bnullable (AONE bs) = True"
Chengsong
parents:
diff changeset
   164
| "bnullable (ACHAR bs c) = False"
Chengsong
parents:
diff changeset
   165
| "bnullable (AALTs bs rs) = (\<exists>r \<in> set rs. bnullable r)"
Chengsong
parents:
diff changeset
   166
| "bnullable (ASEQ bs r1 r2) = (bnullable r1 \<and> bnullable r2)"
Chengsong
parents:
diff changeset
   167
| "bnullable (ASTAR bs r) = True"
Chengsong
parents:
diff changeset
   168
Chengsong
parents:
diff changeset
   169
abbreviation
Chengsong
parents:
diff changeset
   170
  bnullables :: "arexp list \<Rightarrow> bool"
Chengsong
parents:
diff changeset
   171
where
Chengsong
parents:
diff changeset
   172
  "bnullables rs \<equiv> (\<exists>r \<in> set rs. bnullable r)"
Chengsong
parents:
diff changeset
   173
Chengsong
parents:
diff changeset
   174
fun 
Chengsong
parents:
diff changeset
   175
  bmkeps :: "arexp \<Rightarrow> bit list" and
Chengsong
parents:
diff changeset
   176
  bmkepss :: "arexp list \<Rightarrow> bit list"
Chengsong
parents:
diff changeset
   177
where
Chengsong
parents:
diff changeset
   178
  "bmkeps(AONE bs) = bs"
Chengsong
parents:
diff changeset
   179
| "bmkeps(ASEQ bs r1 r2) = bs @ (bmkeps r1) @ (bmkeps r2)"
Chengsong
parents:
diff changeset
   180
| "bmkeps(AALTs bs rs) = bs @ (bmkepss rs)"
Chengsong
parents:
diff changeset
   181
| "bmkeps(ASTAR bs r) = bs @ [S]"
Chengsong
parents:
diff changeset
   182
| "bmkepss [] = []"
Chengsong
parents:
diff changeset
   183
| "bmkepss (r # rs) = (if bnullable(r) then (bmkeps r) else (bmkepss rs))"
Chengsong
parents:
diff changeset
   184
Chengsong
parents:
diff changeset
   185
lemma bmkepss1:
Chengsong
parents:
diff changeset
   186
  assumes "\<not> bnullables rs1"
Chengsong
parents:
diff changeset
   187
  shows "bmkepss (rs1 @ rs2) = bmkepss rs2"
Chengsong
parents:
diff changeset
   188
  using assms
Chengsong
parents:
diff changeset
   189
  by (induct rs1) (auto)
Chengsong
parents:
diff changeset
   190
Chengsong
parents:
diff changeset
   191
lemma bmkepss2:
Chengsong
parents:
diff changeset
   192
  assumes "bnullables rs1"
Chengsong
parents:
diff changeset
   193
  shows "bmkepss (rs1 @ rs2) = bmkepss rs1"
Chengsong
parents:
diff changeset
   194
  using assms
Chengsong
parents:
diff changeset
   195
  by (induct rs1) (auto)
Chengsong
parents:
diff changeset
   196
Chengsong
parents:
diff changeset
   197
Chengsong
parents:
diff changeset
   198
fun
Chengsong
parents:
diff changeset
   199
 bder :: "char \<Rightarrow> arexp \<Rightarrow> arexp"
Chengsong
parents:
diff changeset
   200
where
Chengsong
parents:
diff changeset
   201
  "bder c (AZERO) = AZERO"
Chengsong
parents:
diff changeset
   202
| "bder c (AONE bs) = AZERO"
Chengsong
parents:
diff changeset
   203
| "bder c (ACHAR bs d) = (if c = d then AONE bs else AZERO)"
Chengsong
parents:
diff changeset
   204
| "bder c (AALTs bs rs) = AALTs bs (map (bder c) rs)"
Chengsong
parents:
diff changeset
   205
| "bder c (ASEQ bs r1 r2) = 
Chengsong
parents:
diff changeset
   206
     (if bnullable r1
Chengsong
parents:
diff changeset
   207
      then AALT bs (ASEQ [] (bder c r1) r2) (fuse (bmkeps r1) (bder c r2))
Chengsong
parents:
diff changeset
   208
      else ASEQ bs (bder c r1) r2)"
Chengsong
parents:
diff changeset
   209
| "bder c (ASTAR bs r) = ASEQ bs (fuse [Z] (bder c r)) (ASTAR [] r)"
Chengsong
parents:
diff changeset
   210
Chengsong
parents:
diff changeset
   211
Chengsong
parents:
diff changeset
   212
fun 
Chengsong
parents:
diff changeset
   213
  bders :: "arexp \<Rightarrow> string \<Rightarrow> arexp"
Chengsong
parents:
diff changeset
   214
where
Chengsong
parents:
diff changeset
   215
  "bders r [] = r"
Chengsong
parents:
diff changeset
   216
| "bders r (c#s) = bders (bder c r) s"
Chengsong
parents:
diff changeset
   217
Chengsong
parents:
diff changeset
   218
lemma bders_append:
Chengsong
parents:
diff changeset
   219
  "bders c (s1 @ s2) = bders (bders c s1) s2"
Chengsong
parents:
diff changeset
   220
  apply(induct s1 arbitrary: c s2)
Chengsong
parents:
diff changeset
   221
  apply(simp_all)
Chengsong
parents:
diff changeset
   222
  done
Chengsong
parents:
diff changeset
   223
Chengsong
parents:
diff changeset
   224
lemma bnullable_correctness:
Chengsong
parents:
diff changeset
   225
  shows "nullable (erase r) = bnullable r"
Chengsong
parents:
diff changeset
   226
  apply(induct r rule: erase.induct)
Chengsong
parents:
diff changeset
   227
  apply(simp_all)
Chengsong
parents:
diff changeset
   228
  done
Chengsong
parents:
diff changeset
   229
Chengsong
parents:
diff changeset
   230
lemma erase_fuse:
Chengsong
parents:
diff changeset
   231
  shows "erase (fuse bs r) = erase r"
Chengsong
parents:
diff changeset
   232
  apply(induct r rule: erase.induct)
Chengsong
parents:
diff changeset
   233
  apply(simp_all)
Chengsong
parents:
diff changeset
   234
  done
Chengsong
parents:
diff changeset
   235
Chengsong
parents:
diff changeset
   236
lemma erase_intern [simp]:
Chengsong
parents:
diff changeset
   237
  shows "erase (intern r) = r"
Chengsong
parents:
diff changeset
   238
  apply(induct r)
Chengsong
parents:
diff changeset
   239
  apply(simp_all add: erase_fuse)
Chengsong
parents:
diff changeset
   240
  done
Chengsong
parents:
diff changeset
   241
Chengsong
parents:
diff changeset
   242
lemma erase_bder [simp]:
Chengsong
parents:
diff changeset
   243
  shows "erase (bder a r) = der a (erase r)"
Chengsong
parents:
diff changeset
   244
  apply(induct r rule: erase.induct)
Chengsong
parents:
diff changeset
   245
  apply(simp_all add: erase_fuse bnullable_correctness)
Chengsong
parents:
diff changeset
   246
  done
Chengsong
parents:
diff changeset
   247
Chengsong
parents:
diff changeset
   248
lemma erase_bders [simp]:
Chengsong
parents:
diff changeset
   249
  shows "erase (bders r s) = ders s (erase r)"
Chengsong
parents:
diff changeset
   250
  apply(induct s arbitrary: r )
Chengsong
parents:
diff changeset
   251
  apply(simp_all)
Chengsong
parents:
diff changeset
   252
  done
Chengsong
parents:
diff changeset
   253
Chengsong
parents:
diff changeset
   254
lemma bnullable_fuse:
Chengsong
parents:
diff changeset
   255
  shows "bnullable (fuse bs r) = bnullable r"
Chengsong
parents:
diff changeset
   256
  apply(induct r arbitrary: bs)
Chengsong
parents:
diff changeset
   257
  apply(auto)
Chengsong
parents:
diff changeset
   258
  done
Chengsong
parents:
diff changeset
   259
Chengsong
parents:
diff changeset
   260
lemma retrieve_encode_STARS:
Chengsong
parents:
diff changeset
   261
  assumes "\<forall>v\<in>set vs. \<Turnstile> v : r \<and> code v = retrieve (intern r) v"
Chengsong
parents:
diff changeset
   262
  shows "code (Stars vs) = retrieve (ASTAR [] (intern r)) (Stars vs)"
Chengsong
parents:
diff changeset
   263
  using assms
Chengsong
parents:
diff changeset
   264
  apply(induct vs)
Chengsong
parents:
diff changeset
   265
  apply(simp_all)
Chengsong
parents:
diff changeset
   266
  done
Chengsong
parents:
diff changeset
   267
Chengsong
parents:
diff changeset
   268
lemma retrieve_fuse2:
Chengsong
parents:
diff changeset
   269
  assumes "\<Turnstile> v : (erase r)"
Chengsong
parents:
diff changeset
   270
  shows "retrieve (fuse bs r) v = bs @ retrieve r v"
Chengsong
parents:
diff changeset
   271
  using assms
Chengsong
parents:
diff changeset
   272
  apply(induct r arbitrary: v bs)
Chengsong
parents:
diff changeset
   273
  apply(auto elim: Prf_elims)[4]
Chengsong
parents:
diff changeset
   274
  apply(case_tac x2a)
Chengsong
parents:
diff changeset
   275
  apply(simp)
Chengsong
parents:
diff changeset
   276
  using Prf_elims(1) apply blast
Chengsong
parents:
diff changeset
   277
  apply(case_tac x2a)
Chengsong
parents:
diff changeset
   278
  apply(simp)
Chengsong
parents:
diff changeset
   279
  apply(simp)
Chengsong
parents:
diff changeset
   280
  apply(case_tac list)
Chengsong
parents:
diff changeset
   281
  apply(simp)
Chengsong
parents:
diff changeset
   282
  apply(simp)
Chengsong
parents:
diff changeset
   283
  apply (smt (verit, best) Prf_elims(3) append_assoc retrieve.simps(4) retrieve.simps(5))
Chengsong
parents:
diff changeset
   284
  apply(simp)
Chengsong
parents:
diff changeset
   285
  using retrieve_encode_STARS
Chengsong
parents:
diff changeset
   286
  apply(auto elim!: Prf_elims)[1]
Chengsong
parents:
diff changeset
   287
  apply(case_tac vs)
Chengsong
parents:
diff changeset
   288
  apply(simp)
Chengsong
parents:
diff changeset
   289
  apply(simp)
Chengsong
parents:
diff changeset
   290
  done
Chengsong
parents:
diff changeset
   291
Chengsong
parents:
diff changeset
   292
lemma retrieve_fuse:
Chengsong
parents:
diff changeset
   293
  assumes "\<Turnstile> v : r"
Chengsong
parents:
diff changeset
   294
  shows "retrieve (fuse bs (intern r)) v = bs @ retrieve (intern r) v"
Chengsong
parents:
diff changeset
   295
  using assms 
Chengsong
parents:
diff changeset
   296
  by (simp_all add: retrieve_fuse2)
Chengsong
parents:
diff changeset
   297
Chengsong
parents:
diff changeset
   298
Chengsong
parents:
diff changeset
   299
lemma retrieve_code:
Chengsong
parents:
diff changeset
   300
  assumes "\<Turnstile> v : r"
Chengsong
parents:
diff changeset
   301
  shows "code v = retrieve (intern r) v"
Chengsong
parents:
diff changeset
   302
  using assms
Chengsong
parents:
diff changeset
   303
  apply(induct v r )
Chengsong
parents:
diff changeset
   304
  apply(simp_all add: retrieve_fuse retrieve_encode_STARS)
Chengsong
parents:
diff changeset
   305
  done
Chengsong
parents:
diff changeset
   306
Chengsong
parents:
diff changeset
   307
Chengsong
parents:
diff changeset
   308
lemma retrieve_AALTs_bnullable1:
Chengsong
parents:
diff changeset
   309
  assumes "bnullable r"
Chengsong
parents:
diff changeset
   310
  shows "retrieve (AALTs bs (r # rs)) (mkeps (erase (AALTs bs (r # rs))))
Chengsong
parents:
diff changeset
   311
         = bs @ retrieve r (mkeps (erase r))"
Chengsong
parents:
diff changeset
   312
  using assms
Chengsong
parents:
diff changeset
   313
  apply(case_tac rs)
Chengsong
parents:
diff changeset
   314
  apply(auto simp add: bnullable_correctness)
Chengsong
parents:
diff changeset
   315
  done
Chengsong
parents:
diff changeset
   316
Chengsong
parents:
diff changeset
   317
lemma retrieve_AALTs_bnullable2:
Chengsong
parents:
diff changeset
   318
  assumes "\<not>bnullable r" "bnullables rs"
Chengsong
parents:
diff changeset
   319
  shows "retrieve (AALTs bs (r # rs)) (mkeps (erase (AALTs bs (r # rs))))
Chengsong
parents:
diff changeset
   320
         = retrieve (AALTs bs rs) (mkeps (erase (AALTs bs rs)))"
Chengsong
parents:
diff changeset
   321
  using assms
Chengsong
parents:
diff changeset
   322
  apply(induct rs arbitrary: r bs)
Chengsong
parents:
diff changeset
   323
  apply(auto)
Chengsong
parents:
diff changeset
   324
  using bnullable_correctness apply blast
Chengsong
parents:
diff changeset
   325
  apply(case_tac rs)
Chengsong
parents:
diff changeset
   326
  apply(auto)
Chengsong
parents:
diff changeset
   327
  using bnullable_correctness apply blast
Chengsong
parents:
diff changeset
   328
  apply(case_tac rs)
Chengsong
parents:
diff changeset
   329
  apply(auto)
Chengsong
parents:
diff changeset
   330
  done
Chengsong
parents:
diff changeset
   331
Chengsong
parents:
diff changeset
   332
lemma bmkeps_retrieve_AALTs: 
Chengsong
parents:
diff changeset
   333
  assumes "\<forall>r \<in> set rs. bnullable r \<longrightarrow> bmkeps r = retrieve r (mkeps (erase r))" 
Chengsong
parents:
diff changeset
   334
          "bnullables rs"
Chengsong
parents:
diff changeset
   335
  shows "bs @ bmkepss rs = retrieve (AALTs bs rs) (mkeps (erase (AALTs bs rs)))"
Chengsong
parents:
diff changeset
   336
 using assms
Chengsong
parents:
diff changeset
   337
  apply(induct rs arbitrary: bs)
Chengsong
parents:
diff changeset
   338
  apply(auto)
Chengsong
parents:
diff changeset
   339
  using retrieve_AALTs_bnullable1 apply presburger
Chengsong
parents:
diff changeset
   340
  apply (metis retrieve_AALTs_bnullable2)
Chengsong
parents:
diff changeset
   341
  apply (simp add: retrieve_AALTs_bnullable1)
Chengsong
parents:
diff changeset
   342
  by (metis retrieve_AALTs_bnullable2)
Chengsong
parents:
diff changeset
   343
Chengsong
parents:
diff changeset
   344
    
Chengsong
parents:
diff changeset
   345
lemma bmkeps_retrieve:
Chengsong
parents:
diff changeset
   346
  assumes "bnullable r"
Chengsong
parents:
diff changeset
   347
  shows "bmkeps r = retrieve r (mkeps (erase r))"
Chengsong
parents:
diff changeset
   348
  using assms
Chengsong
parents:
diff changeset
   349
  apply(induct r)
Chengsong
parents:
diff changeset
   350
  apply(auto)  
Chengsong
parents:
diff changeset
   351
  using bmkeps_retrieve_AALTs by auto
Chengsong
parents:
diff changeset
   352
Chengsong
parents:
diff changeset
   353
lemma bder_retrieve:
Chengsong
parents:
diff changeset
   354
  assumes "\<Turnstile> v : der c (erase r)"
Chengsong
parents:
diff changeset
   355
  shows "retrieve (bder c r) v = retrieve r (injval (erase r) c v)"
Chengsong
parents:
diff changeset
   356
  using assms  
Chengsong
parents:
diff changeset
   357
  apply(induct r arbitrary: v rule: erase.induct)
Chengsong
parents:
diff changeset
   358
  using Prf_elims(1) apply auto[1]
Chengsong
parents:
diff changeset
   359
  using Prf_elims(1) apply auto[1]
Chengsong
parents:
diff changeset
   360
  apply(auto)[1]
Chengsong
parents:
diff changeset
   361
  apply (metis Prf_elims(4) injval.simps(1) retrieve.simps(1) retrieve.simps(2))
Chengsong
parents:
diff changeset
   362
  using Prf_elims(1) apply blast
Chengsong
parents:
diff changeset
   363
  (* AALTs case *)
Chengsong
parents:
diff changeset
   364
  apply(simp)
Chengsong
parents:
diff changeset
   365
  apply(erule Prf_elims)
Chengsong
parents:
diff changeset
   366
  apply(simp)
Chengsong
parents:
diff changeset
   367
  apply(simp)
Chengsong
parents:
diff changeset
   368
  apply(rename_tac "r\<^sub>1" "r\<^sub>2" rs v)
Chengsong
parents:
diff changeset
   369
  apply(erule Prf_elims)
Chengsong
parents:
diff changeset
   370
  apply(simp)
Chengsong
parents:
diff changeset
   371
  apply(simp)
Chengsong
parents:
diff changeset
   372
  apply(case_tac rs)
Chengsong
parents:
diff changeset
   373
  apply(simp)
Chengsong
parents:
diff changeset
   374
  apply(simp)
Chengsong
parents:
diff changeset
   375
  using Prf_elims(3) apply fastforce
Chengsong
parents:
diff changeset
   376
  (* ASEQ case *) 
Chengsong
parents:
diff changeset
   377
  apply(simp)
Chengsong
parents:
diff changeset
   378
  apply(case_tac "nullable (erase r1)")
Chengsong
parents:
diff changeset
   379
  apply(simp)
Chengsong
parents:
diff changeset
   380
  apply(erule Prf_elims)
Chengsong
parents:
diff changeset
   381
  using Prf_elims(2) bnullable_correctness apply force
Chengsong
parents:
diff changeset
   382
  apply (simp add: bmkeps_retrieve bnullable_correctness retrieve_fuse2)
Chengsong
parents:
diff changeset
   383
  apply (simp add: bmkeps_retrieve bnullable_correctness retrieve_fuse2)
Chengsong
parents:
diff changeset
   384
  using Prf_elims(2) apply force
Chengsong
parents:
diff changeset
   385
  (* ASTAR case *)  
Chengsong
parents:
diff changeset
   386
  apply(rename_tac bs r v)
Chengsong
parents:
diff changeset
   387
  apply(simp)  
Chengsong
parents:
diff changeset
   388
  apply(erule Prf_elims)
Chengsong
parents:
diff changeset
   389
  apply(clarify)
Chengsong
parents:
diff changeset
   390
  apply(erule Prf_elims)
Chengsong
parents:
diff changeset
   391
  apply(clarify)
Chengsong
parents:
diff changeset
   392
  by (simp add: retrieve_fuse2)
Chengsong
parents:
diff changeset
   393
Chengsong
parents:
diff changeset
   394
Chengsong
parents:
diff changeset
   395
lemma MAIN_decode:
Chengsong
parents:
diff changeset
   396
  assumes "\<Turnstile> v : ders s r"
Chengsong
parents:
diff changeset
   397
  shows "Some (flex r id s v) = decode (retrieve (bders (intern r) s) v) r"
Chengsong
parents:
diff changeset
   398
  using assms
Chengsong
parents:
diff changeset
   399
proof (induct s arbitrary: v rule: rev_induct)
Chengsong
parents:
diff changeset
   400
  case Nil
Chengsong
parents:
diff changeset
   401
  have "\<Turnstile> v : ders [] r" by fact
Chengsong
parents:
diff changeset
   402
  then have "\<Turnstile> v : r" by simp
Chengsong
parents:
diff changeset
   403
  then have "Some v = decode (retrieve (intern r) v) r"
Chengsong
parents:
diff changeset
   404
    using decode_code retrieve_code by auto
Chengsong
parents:
diff changeset
   405
  then show "Some (flex r id [] v) = decode (retrieve (bders (intern r) []) v) r"
Chengsong
parents:
diff changeset
   406
    by simp
Chengsong
parents:
diff changeset
   407
next
Chengsong
parents:
diff changeset
   408
  case (snoc c s v)
Chengsong
parents:
diff changeset
   409
  have IH: "\<And>v. \<Turnstile> v : ders s r \<Longrightarrow> 
Chengsong
parents:
diff changeset
   410
     Some (flex r id s v) = decode (retrieve (bders (intern r) s) v) r" by fact
Chengsong
parents:
diff changeset
   411
  have asm: "\<Turnstile> v : ders (s @ [c]) r" by fact
Chengsong
parents:
diff changeset
   412
  then have asm2: "\<Turnstile> injval (ders s r) c v : ders s r" 
Chengsong
parents:
diff changeset
   413
    by (simp add: Prf_injval ders_append)
Chengsong
parents:
diff changeset
   414
  have "Some (flex r id (s @ [c]) v) = Some (flex r id s (injval (ders s r) c v))"
Chengsong
parents:
diff changeset
   415
    by (simp add: flex_append)
Chengsong
parents:
diff changeset
   416
  also have "... = decode (retrieve (bders (intern r) s) (injval (ders s r) c v)) r"
Chengsong
parents:
diff changeset
   417
    using asm2 IH by simp
Chengsong
parents:
diff changeset
   418
  also have "... = decode (retrieve (bder c (bders (intern r) s)) v) r"
Chengsong
parents:
diff changeset
   419
    using asm by (simp_all add: bder_retrieve ders_append)
Chengsong
parents:
diff changeset
   420
  finally show "Some (flex r id (s @ [c]) v) = 
Chengsong
parents:
diff changeset
   421
                 decode (retrieve (bders (intern r) (s @ [c])) v) r" by (simp add: bders_append)
Chengsong
parents:
diff changeset
   422
qed
Chengsong
parents:
diff changeset
   423
Chengsong
parents:
diff changeset
   424
definition blexer where
Chengsong
parents:
diff changeset
   425
 "blexer r s \<equiv> if bnullable (bders (intern r) s) then 
Chengsong
parents:
diff changeset
   426
                decode (bmkeps (bders (intern r) s)) r else None"
Chengsong
parents:
diff changeset
   427
Chengsong
parents:
diff changeset
   428
lemma blexer_correctness:
Chengsong
parents:
diff changeset
   429
  shows "blexer r s = lexer r s"
Chengsong
parents:
diff changeset
   430
proof -
Chengsong
parents:
diff changeset
   431
  { define bds where "bds \<equiv> bders (intern r) s"
Chengsong
parents:
diff changeset
   432
    define ds  where "ds \<equiv> ders s r"
Chengsong
parents:
diff changeset
   433
    assume asm: "nullable ds"
Chengsong
parents:
diff changeset
   434
    have era: "erase bds = ds" 
Chengsong
parents:
diff changeset
   435
      unfolding ds_def bds_def by simp
Chengsong
parents:
diff changeset
   436
    have mke: "\<Turnstile> mkeps ds : ds"
Chengsong
parents:
diff changeset
   437
      using asm by (simp add: mkeps_nullable)
Chengsong
parents:
diff changeset
   438
    have "decode (bmkeps bds) r = decode (retrieve bds (mkeps ds)) r"
Chengsong
parents:
diff changeset
   439
      using bmkeps_retrieve
Chengsong
parents:
diff changeset
   440
      using asm era
Chengsong
parents:
diff changeset
   441
      using bnullable_correctness by force 
Chengsong
parents:
diff changeset
   442
    also have "... =  Some (flex r id s (mkeps ds))"
Chengsong
parents:
diff changeset
   443
      using mke by (simp_all add: MAIN_decode ds_def bds_def)
Chengsong
parents:
diff changeset
   444
    finally have "decode (bmkeps bds) r = Some (flex r id s (mkeps ds))" 
Chengsong
parents:
diff changeset
   445
      unfolding bds_def ds_def .
Chengsong
parents:
diff changeset
   446
  }
Chengsong
parents:
diff changeset
   447
  then show "blexer r s = lexer r s"
Chengsong
parents:
diff changeset
   448
    unfolding blexer_def lexer_flex
Chengsong
parents:
diff changeset
   449
    by (auto simp add: bnullable_correctness[symmetric])
Chengsong
parents:
diff changeset
   450
qed
Chengsong
parents:
diff changeset
   451
Chengsong
parents:
diff changeset
   452
Chengsong
parents:
diff changeset
   453
fun distinctBy :: "'a list \<Rightarrow> ('a \<Rightarrow> 'b) \<Rightarrow> 'b set \<Rightarrow> 'a list"
Chengsong
parents:
diff changeset
   454
  where
Chengsong
parents:
diff changeset
   455
  "distinctBy [] f acc = []"
Chengsong
parents:
diff changeset
   456
| "distinctBy (x#xs) f acc = 
Chengsong
parents:
diff changeset
   457
     (if (f x) \<in> acc then distinctBy xs f acc 
Chengsong
parents:
diff changeset
   458
      else x # (distinctBy xs f ({f x} \<union> acc)))"
Chengsong
parents:
diff changeset
   459
Chengsong
parents:
diff changeset
   460
  
Chengsong
parents:
diff changeset
   461
Chengsong
parents:
diff changeset
   462
fun flts :: "arexp list \<Rightarrow> arexp list"
Chengsong
parents:
diff changeset
   463
  where 
Chengsong
parents:
diff changeset
   464
  "flts [] = []"
Chengsong
parents:
diff changeset
   465
| "flts (AZERO # rs) = flts rs"
Chengsong
parents:
diff changeset
   466
| "flts ((AALTs bs  rs1) # rs) = (map (fuse bs) rs1) @ flts rs"
Chengsong
parents:
diff changeset
   467
| "flts (r1 # rs) = r1 # flts rs"
Chengsong
parents:
diff changeset
   468
Chengsong
parents:
diff changeset
   469
Chengsong
parents:
diff changeset
   470
Chengsong
parents:
diff changeset
   471
fun bsimp_ASEQ :: "bit list \<Rightarrow> arexp \<Rightarrow> arexp \<Rightarrow> arexp"
Chengsong
parents:
diff changeset
   472
  where
Chengsong
parents:
diff changeset
   473
  "bsimp_ASEQ _ AZERO _ = AZERO"
Chengsong
parents:
diff changeset
   474
| "bsimp_ASEQ _ _ AZERO = AZERO"
Chengsong
parents:
diff changeset
   475
| "bsimp_ASEQ bs1 (AONE bs2) r2 = fuse (bs1 @ bs2) r2"
Chengsong
parents:
diff changeset
   476
| "bsimp_ASEQ bs1 r1 r2 = ASEQ  bs1 r1 r2"
Chengsong
parents:
diff changeset
   477
Chengsong
parents:
diff changeset
   478
lemma bsimp_ASEQ0[simp]:
Chengsong
parents:
diff changeset
   479
  shows "bsimp_ASEQ bs r1 AZERO = AZERO"
Chengsong
parents:
diff changeset
   480
  by (case_tac r1)(simp_all)
Chengsong
parents:
diff changeset
   481
Chengsong
parents:
diff changeset
   482
lemma bsimp_ASEQ1:
Chengsong
parents:
diff changeset
   483
  assumes "r1 \<noteq> AZERO" "r2 \<noteq> AZERO" "\<nexists>bs. r1 = AONE bs"
Chengsong
parents:
diff changeset
   484
  shows "bsimp_ASEQ bs r1 r2 = ASEQ bs r1 r2"
Chengsong
parents:
diff changeset
   485
  using assms
Chengsong
parents:
diff changeset
   486
  apply(induct bs r1 r2 rule: bsimp_ASEQ.induct)
Chengsong
parents:
diff changeset
   487
  apply(auto)
Chengsong
parents:
diff changeset
   488
  done
Chengsong
parents:
diff changeset
   489
Chengsong
parents:
diff changeset
   490
lemma bsimp_ASEQ2[simp]:
Chengsong
parents:
diff changeset
   491
  shows "bsimp_ASEQ bs1 (AONE bs2) r2 = fuse (bs1 @ bs2) r2"
Chengsong
parents:
diff changeset
   492
  by (case_tac r2) (simp_all)
Chengsong
parents:
diff changeset
   493
Chengsong
parents:
diff changeset
   494
Chengsong
parents:
diff changeset
   495
fun bsimp_AALTs :: "bit list \<Rightarrow> arexp list \<Rightarrow> arexp"
Chengsong
parents:
diff changeset
   496
  where
Chengsong
parents:
diff changeset
   497
  "bsimp_AALTs _ [] = AZERO"
Chengsong
parents:
diff changeset
   498
| "bsimp_AALTs bs1 [r] = fuse bs1 r"
Chengsong
parents:
diff changeset
   499
| "bsimp_AALTs bs1 rs = AALTs bs1 rs"
Chengsong
parents:
diff changeset
   500
Chengsong
parents:
diff changeset
   501
Chengsong
parents:
diff changeset
   502
fun bsimp :: "arexp \<Rightarrow> arexp" 
Chengsong
parents:
diff changeset
   503
  where
Chengsong
parents:
diff changeset
   504
  "bsimp (ASEQ bs1 r1 r2) = bsimp_ASEQ bs1 (bsimp r1) (bsimp r2)"
Chengsong
parents:
diff changeset
   505
| "bsimp (AALTs bs1 rs) = bsimp_AALTs bs1 (distinctBy (flts (map bsimp rs)) erase {}) "
Chengsong
parents:
diff changeset
   506
| "bsimp r = r"
Chengsong
parents:
diff changeset
   507
Chengsong
parents:
diff changeset
   508
Chengsong
parents:
diff changeset
   509
fun 
Chengsong
parents:
diff changeset
   510
  bders_simp :: "arexp \<Rightarrow> string \<Rightarrow> arexp"
Chengsong
parents:
diff changeset
   511
where
Chengsong
parents:
diff changeset
   512
  "bders_simp r [] = r"
Chengsong
parents:
diff changeset
   513
| "bders_simp r (c # s) = bders_simp (bsimp (bder c r)) s"
Chengsong
parents:
diff changeset
   514
Chengsong
parents:
diff changeset
   515
definition blexer_simp where
Chengsong
parents:
diff changeset
   516
 "blexer_simp r s \<equiv> if bnullable (bders_simp (intern r) s) then 
Chengsong
parents:
diff changeset
   517
                    decode (bmkeps (bders_simp (intern r) s)) r else None"
Chengsong
parents:
diff changeset
   518
Chengsong
parents:
diff changeset
   519
Chengsong
parents:
diff changeset
   520
Chengsong
parents:
diff changeset
   521
lemma bders_simp_append:
Chengsong
parents:
diff changeset
   522
  shows "bders_simp r (s1 @ s2) = bders_simp (bders_simp r s1) s2"
Chengsong
parents:
diff changeset
   523
  apply(induct s1 arbitrary: r s2)
Chengsong
parents:
diff changeset
   524
  apply(simp_all)
Chengsong
parents:
diff changeset
   525
  done
Chengsong
parents:
diff changeset
   526
Chengsong
parents:
diff changeset
   527
Chengsong
parents:
diff changeset
   528
lemma bmkeps_fuse:
Chengsong
parents:
diff changeset
   529
  assumes "bnullable r"
Chengsong
parents:
diff changeset
   530
  shows "bmkeps (fuse bs r) = bs @ bmkeps r"
Chengsong
parents:
diff changeset
   531
  using assms
Chengsong
parents:
diff changeset
   532
  by (metis bmkeps_retrieve bnullable_correctness erase_fuse mkeps_nullable retrieve_fuse2)
Chengsong
parents:
diff changeset
   533
Chengsong
parents:
diff changeset
   534
lemma bmkepss_fuse: 
Chengsong
parents:
diff changeset
   535
  assumes "bnullables rs"
Chengsong
parents:
diff changeset
   536
  shows "bmkepss (map (fuse bs) rs) = bs @ bmkepss rs"
Chengsong
parents:
diff changeset
   537
  using assms
Chengsong
parents:
diff changeset
   538
  apply(induct rs arbitrary: bs)
Chengsong
parents:
diff changeset
   539
  apply(auto simp add: bmkeps_fuse bnullable_fuse)
Chengsong
parents:
diff changeset
   540
  done
Chengsong
parents:
diff changeset
   541
Chengsong
parents:
diff changeset
   542
lemma bder_fuse:
Chengsong
parents:
diff changeset
   543
  shows "bder c (fuse bs a) = fuse bs  (bder c a)"
Chengsong
parents:
diff changeset
   544
  apply(induct a arbitrary: bs c)
Chengsong
parents:
diff changeset
   545
  apply(simp_all)
Chengsong
parents:
diff changeset
   546
  done
Chengsong
parents:
diff changeset
   547
Chengsong
parents:
diff changeset
   548
Chengsong
parents:
diff changeset
   549
Chengsong
parents:
diff changeset
   550
Chengsong
parents:
diff changeset
   551
inductive 
Chengsong
parents:
diff changeset
   552
  rrewrite:: "arexp \<Rightarrow> arexp \<Rightarrow> bool" ("_ \<leadsto> _" [99, 99] 99)
Chengsong
parents:
diff changeset
   553
and 
Chengsong
parents:
diff changeset
   554
  srewrite:: "arexp list \<Rightarrow> arexp list \<Rightarrow> bool" (" _ s\<leadsto> _" [100, 100] 100)
Chengsong
parents:
diff changeset
   555
where
Chengsong
parents:
diff changeset
   556
  bs1: "ASEQ bs AZERO r2 \<leadsto> AZERO"
Chengsong
parents:
diff changeset
   557
| bs2: "ASEQ bs r1 AZERO \<leadsto> AZERO"
Chengsong
parents:
diff changeset
   558
| bs3: "ASEQ bs1 (AONE bs2) r \<leadsto> fuse (bs1@bs2) r"
Chengsong
parents:
diff changeset
   559
| bs4: "r1 \<leadsto> r2 \<Longrightarrow> ASEQ bs r1 r3 \<leadsto> ASEQ bs r2 r3"
Chengsong
parents:
diff changeset
   560
| bs5: "r3 \<leadsto> r4 \<Longrightarrow> ASEQ bs r1 r3 \<leadsto> ASEQ bs r1 r4"
Chengsong
parents:
diff changeset
   561
| bs6: "AALTs bs [] \<leadsto> AZERO"
Chengsong
parents:
diff changeset
   562
| bs7: "AALTs bs [r] \<leadsto> fuse bs r"
Chengsong
parents:
diff changeset
   563
| bs8: "rs1 s\<leadsto> rs2 \<Longrightarrow> AALTs bs rs1 \<leadsto> AALTs bs rs2"
Chengsong
parents:
diff changeset
   564
(*| ss1:  "[] s\<leadsto> []"*)
Chengsong
parents:
diff changeset
   565
| ss2:  "rs1 s\<leadsto> rs2 \<Longrightarrow> (r # rs1) s\<leadsto> (r # rs2)"
Chengsong
parents:
diff changeset
   566
| ss3:  "r1 \<leadsto> r2 \<Longrightarrow> (r1 # rs) s\<leadsto> (r2 # rs)"
Chengsong
parents:
diff changeset
   567
| ss4:  "(AZERO # rs) s\<leadsto> rs"
Chengsong
parents:
diff changeset
   568
| ss5:  "(AALTs bs1 rs1 # rsb) s\<leadsto> ((map (fuse bs1) rs1) @ rsb)"
Chengsong
parents:
diff changeset
   569
| ss6:  "erase a1 = erase a2 \<Longrightarrow> (rsa@[a1]@rsb@[a2]@rsc) s\<leadsto> (rsa@[a1]@rsb@rsc)"
Chengsong
parents:
diff changeset
   570
Chengsong
parents:
diff changeset
   571
Chengsong
parents:
diff changeset
   572
inductive 
Chengsong
parents:
diff changeset
   573
  rrewrites:: "arexp \<Rightarrow> arexp \<Rightarrow> bool" ("_ \<leadsto>* _" [100, 100] 100)
Chengsong
parents:
diff changeset
   574
where 
Chengsong
parents:
diff changeset
   575
  rs1[intro, simp]:"r \<leadsto>* r"
Chengsong
parents:
diff changeset
   576
| rs2[intro]: "\<lbrakk>r1 \<leadsto>* r2; r2 \<leadsto> r3\<rbrakk> \<Longrightarrow> r1 \<leadsto>* r3"
Chengsong
parents:
diff changeset
   577
Chengsong
parents:
diff changeset
   578
inductive 
Chengsong
parents:
diff changeset
   579
  srewrites:: "arexp list \<Rightarrow> arexp list \<Rightarrow> bool" ("_ s\<leadsto>* _" [100, 100] 100)
Chengsong
parents:
diff changeset
   580
where 
Chengsong
parents:
diff changeset
   581
  sss1[intro, simp]:"rs s\<leadsto>* rs"
Chengsong
parents:
diff changeset
   582
| sss2[intro]: "\<lbrakk>rs1 s\<leadsto> rs2; rs2 s\<leadsto>* rs3\<rbrakk> \<Longrightarrow> rs1 s\<leadsto>* rs3"
Chengsong
parents:
diff changeset
   583
Chengsong
parents:
diff changeset
   584
Chengsong
parents:
diff changeset
   585
lemma r_in_rstar: 
Chengsong
parents:
diff changeset
   586
  shows "r1 \<leadsto> r2 \<Longrightarrow> r1 \<leadsto>* r2"
Chengsong
parents:
diff changeset
   587
  using rrewrites.intros(1) rrewrites.intros(2) by blast
Chengsong
parents:
diff changeset
   588
Chengsong
parents:
diff changeset
   589
lemma rrewrites_trans[trans]: 
Chengsong
parents:
diff changeset
   590
  assumes a1: "r1 \<leadsto>* r2"  and a2: "r2 \<leadsto>* r3"
Chengsong
parents:
diff changeset
   591
  shows "r1 \<leadsto>* r3"
Chengsong
parents:
diff changeset
   592
  using a2 a1
Chengsong
parents:
diff changeset
   593
  apply(induct r2 r3 arbitrary: r1 rule: rrewrites.induct) 
Chengsong
parents:
diff changeset
   594
  apply(auto)
Chengsong
parents:
diff changeset
   595
  done
Chengsong
parents:
diff changeset
   596
Chengsong
parents:
diff changeset
   597
lemma srewrites_trans[trans]: 
Chengsong
parents:
diff changeset
   598
  assumes a1: "r1 s\<leadsto>* r2"  and a2: "r2 s\<leadsto>* r3"
Chengsong
parents:
diff changeset
   599
  shows "r1 s\<leadsto>* r3"
Chengsong
parents:
diff changeset
   600
  using a1 a2
Chengsong
parents:
diff changeset
   601
  apply(induct r1 r2 arbitrary: r3 rule: srewrites.induct) 
Chengsong
parents:
diff changeset
   602
   apply(auto)
Chengsong
parents:
diff changeset
   603
  done
Chengsong
parents:
diff changeset
   604
Chengsong
parents:
diff changeset
   605
Chengsong
parents:
diff changeset
   606
Chengsong
parents:
diff changeset
   607
lemma contextrewrites0: 
Chengsong
parents:
diff changeset
   608
  "rs1 s\<leadsto>* rs2 \<Longrightarrow> AALTs bs rs1 \<leadsto>* AALTs bs rs2"
Chengsong
parents:
diff changeset
   609
  apply(induct rs1 rs2 rule: srewrites.inducts)
Chengsong
parents:
diff changeset
   610
   apply simp
Chengsong
parents:
diff changeset
   611
  using bs8 r_in_rstar rrewrites_trans by blast
Chengsong
parents:
diff changeset
   612
Chengsong
parents:
diff changeset
   613
lemma contextrewrites1: 
Chengsong
parents:
diff changeset
   614
  "r \<leadsto>* r' \<Longrightarrow> AALTs bs (r # rs) \<leadsto>* AALTs bs (r' # rs)"
Chengsong
parents:
diff changeset
   615
  apply(induct r r' rule: rrewrites.induct)
Chengsong
parents:
diff changeset
   616
   apply simp
Chengsong
parents:
diff changeset
   617
  using bs8 ss3 by blast
Chengsong
parents:
diff changeset
   618
Chengsong
parents:
diff changeset
   619
lemma srewrite1: 
Chengsong
parents:
diff changeset
   620
  shows "rs1 s\<leadsto> rs2 \<Longrightarrow> (rs @ rs1) s\<leadsto> (rs @ rs2)"
Chengsong
parents:
diff changeset
   621
  apply(induct rs)
Chengsong
parents:
diff changeset
   622
   apply(auto)
Chengsong
parents:
diff changeset
   623
  using ss2 by auto
Chengsong
parents:
diff changeset
   624
Chengsong
parents:
diff changeset
   625
lemma srewrites1: 
Chengsong
parents:
diff changeset
   626
  shows "rs1 s\<leadsto>* rs2 \<Longrightarrow> (rs @ rs1) s\<leadsto>* (rs @ rs2)"
Chengsong
parents:
diff changeset
   627
  apply(induct rs1 rs2 rule: srewrites.induct)
Chengsong
parents:
diff changeset
   628
   apply(auto)
Chengsong
parents:
diff changeset
   629
  using srewrite1 by blast
Chengsong
parents:
diff changeset
   630
Chengsong
parents:
diff changeset
   631
lemma srewrite2: 
Chengsong
parents:
diff changeset
   632
  shows  "r1 \<leadsto> r2 \<Longrightarrow> True"
Chengsong
parents:
diff changeset
   633
  and "rs1 s\<leadsto> rs2 \<Longrightarrow> (rs1 @ rs) s\<leadsto>* (rs2 @ rs)"
Chengsong
parents:
diff changeset
   634
  apply(induct rule: rrewrite_srewrite.inducts)
Chengsong
parents:
diff changeset
   635
  apply(auto)
Chengsong
parents:
diff changeset
   636
  apply (metis append_Cons append_Nil srewrites1)
Chengsong
parents:
diff changeset
   637
  apply(meson srewrites.simps ss3)
Chengsong
parents:
diff changeset
   638
  apply (meson srewrites.simps ss4)
Chengsong
parents:
diff changeset
   639
  apply (meson srewrites.simps ss5)
Chengsong
parents:
diff changeset
   640
  by (metis append_Cons append_Nil srewrites.simps ss6)
Chengsong
parents:
diff changeset
   641
  
Chengsong
parents:
diff changeset
   642
Chengsong
parents:
diff changeset
   643
lemma srewrites3: 
Chengsong
parents:
diff changeset
   644
  shows "rs1 s\<leadsto>* rs2 \<Longrightarrow> (rs1 @ rs) s\<leadsto>* (rs2 @ rs)"
Chengsong
parents:
diff changeset
   645
  apply(induct rs1 rs2 arbitrary: rs rule: srewrites.induct)
Chengsong
parents:
diff changeset
   646
   apply(auto)
Chengsong
parents:
diff changeset
   647
  by (meson srewrite2(2) srewrites_trans)
Chengsong
parents:
diff changeset
   648
Chengsong
parents:
diff changeset
   649
(*
Chengsong
parents:
diff changeset
   650
lemma srewrites4:
Chengsong
parents:
diff changeset
   651
  assumes "rs3 s\<leadsto>* rs4" "rs1 s\<leadsto>* rs2" 
Chengsong
parents:
diff changeset
   652
  shows "(rs1 @ rs3) s\<leadsto>* (rs2 @ rs4)"
Chengsong
parents:
diff changeset
   653
  using assms
Chengsong
parents:
diff changeset
   654
  apply(induct rs3 rs4 arbitrary: rs1 rs2 rule: srewrites.induct)
Chengsong
parents:
diff changeset
   655
  apply (simp add: srewrites3)
Chengsong
parents:
diff changeset
   656
  using srewrite1 by blast
Chengsong
parents:
diff changeset
   657
*)
Chengsong
parents:
diff changeset
   658
Chengsong
parents:
diff changeset
   659
lemma srewrites6:
Chengsong
parents:
diff changeset
   660
  assumes "r1 \<leadsto>* r2" 
Chengsong
parents:
diff changeset
   661
  shows "[r1] s\<leadsto>* [r2]"
Chengsong
parents:
diff changeset
   662
  using assms
Chengsong
parents:
diff changeset
   663
  apply(induct r1 r2 rule: rrewrites.induct)
Chengsong
parents:
diff changeset
   664
  apply(auto)
Chengsong
parents:
diff changeset
   665
  by (meson srewrites.simps srewrites_trans ss3)
Chengsong
parents:
diff changeset
   666
Chengsong
parents:
diff changeset
   667
lemma srewrites7:
Chengsong
parents:
diff changeset
   668
  assumes "rs3 s\<leadsto>* rs4" "r1 \<leadsto>* r2" 
Chengsong
parents:
diff changeset
   669
  shows "(r1 # rs3) s\<leadsto>* (r2 # rs4)"
Chengsong
parents:
diff changeset
   670
  using assms
Chengsong
parents:
diff changeset
   671
  by (smt (verit, del_insts) append.simps srewrites1 srewrites3 srewrites6 srewrites_trans)
Chengsong
parents:
diff changeset
   672
  
Chengsong
parents:
diff changeset
   673
lemma ss6_stronger_aux:
Chengsong
parents:
diff changeset
   674
  shows "(rs1 @ rs2) s\<leadsto>* (rs1 @ distinctBy rs2 erase (set (map erase rs1)))"
Chengsong
parents:
diff changeset
   675
  apply(induct rs2 arbitrary: rs1)
Chengsong
parents:
diff changeset
   676
   apply(auto)
Chengsong
parents:
diff changeset
   677
  apply (smt (verit, best) append.assoc append.right_neutral append_Cons append_Nil split_list srewrite2(2) srewrites_trans ss6)
Chengsong
parents:
diff changeset
   678
  apply(drule_tac x="rs1 @ [a]" in meta_spec)
Chengsong
parents:
diff changeset
   679
  apply(simp)
Chengsong
parents:
diff changeset
   680
  done
Chengsong
parents:
diff changeset
   681
Chengsong
parents:
diff changeset
   682
lemma ss6_stronger:
Chengsong
parents:
diff changeset
   683
  shows "rs1 s\<leadsto>* distinctBy rs1 erase {}"
Chengsong
parents:
diff changeset
   684
  using ss6_stronger_aux[of "[]" _] by auto
Chengsong
parents:
diff changeset
   685
Chengsong
parents:
diff changeset
   686
lemma rewrite_preserves_fuse: 
Chengsong
parents:
diff changeset
   687
  shows "r2 \<leadsto> r3 \<Longrightarrow> fuse bs r2 \<leadsto> fuse bs r3"
Chengsong
parents:
diff changeset
   688
  and   "rs2 s\<leadsto> rs3 \<Longrightarrow> map (fuse bs) rs2 s\<leadsto> map (fuse bs) rs3"
Chengsong
parents:
diff changeset
   689
proof(induct rule: rrewrite_srewrite.inducts)
Chengsong
parents:
diff changeset
   690
  case (bs3 bs1 bs2 r)
Chengsong
parents:
diff changeset
   691
  then show "fuse bs (ASEQ bs1 (AONE bs2) r) \<leadsto> fuse bs (fuse (bs1 @ bs2) r)"
Chengsong
parents:
diff changeset
   692
    by (metis fuse.simps(5) fuse_append rrewrite_srewrite.bs3) 
Chengsong
parents:
diff changeset
   693
next
Chengsong
parents:
diff changeset
   694
  case (bs7 bs1 r)
Chengsong
parents:
diff changeset
   695
  then show "fuse bs (AALTs bs1 [r]) \<leadsto> fuse bs (fuse bs1 r)"
Chengsong
parents:
diff changeset
   696
    by (metis fuse.simps(4) fuse_append rrewrite_srewrite.bs7) 
Chengsong
parents:
diff changeset
   697
next
Chengsong
parents:
diff changeset
   698
  case (ss2 rs1 rs2 r)
Chengsong
parents:
diff changeset
   699
  then show "map (fuse bs) (r # rs1) s\<leadsto> map (fuse bs) (r # rs2)"
Chengsong
parents:
diff changeset
   700
    by (simp add: rrewrite_srewrite.ss2)
Chengsong
parents:
diff changeset
   701
next
Chengsong
parents:
diff changeset
   702
  case (ss3 r1 r2 rs)
Chengsong
parents:
diff changeset
   703
  then show "map (fuse bs) (r1 # rs) s\<leadsto> map (fuse bs) (r2 # rs)"
Chengsong
parents:
diff changeset
   704
    by (simp add: rrewrite_srewrite.ss3)
Chengsong
parents:
diff changeset
   705
next
Chengsong
parents:
diff changeset
   706
  case (ss5 bs1 rs1 rsb)
Chengsong
parents:
diff changeset
   707
  have "map (fuse bs) (AALTs bs1 rs1 # rsb) = AALTs (bs @ bs1) rs1 # (map (fuse bs) rsb)" by simp
Chengsong
parents:
diff changeset
   708
  also have "... s\<leadsto> ((map (fuse (bs @ bs1)) rs1) @ (map (fuse bs) rsb))"
Chengsong
parents:
diff changeset
   709
    by (simp add: rrewrite_srewrite.ss5)  
Chengsong
parents:
diff changeset
   710
  finally show "map (fuse bs) (AALTs bs1 rs1 # rsb) s\<leadsto> map (fuse bs) (map (fuse bs1) rs1 @ rsb)"
Chengsong
parents:
diff changeset
   711
    by (simp add: comp_def fuse_append)
Chengsong
parents:
diff changeset
   712
next
Chengsong
parents:
diff changeset
   713
  case (ss6 a1 a2 rsa rsb rsc)
Chengsong
parents:
diff changeset
   714
  then show "map (fuse bs) (rsa @ [a1] @ rsb @ [a2] @ rsc) s\<leadsto> map (fuse bs) (rsa @ [a1] @ rsb @ rsc)"
Chengsong
parents:
diff changeset
   715
    apply(simp)
Chengsong
parents:
diff changeset
   716
    apply(rule rrewrite_srewrite.ss6[simplified])
Chengsong
parents:
diff changeset
   717
    apply(simp add: erase_fuse)
Chengsong
parents:
diff changeset
   718
    done
Chengsong
parents:
diff changeset
   719
qed (auto intro: rrewrite_srewrite.intros)
Chengsong
parents:
diff changeset
   720
Chengsong
parents:
diff changeset
   721
lemma rewrites_fuse:  
Chengsong
parents:
diff changeset
   722
  assumes "r1 \<leadsto>* r2"
Chengsong
parents:
diff changeset
   723
  shows "fuse bs r1 \<leadsto>* fuse bs r2"
Chengsong
parents:
diff changeset
   724
using assms
Chengsong
parents:
diff changeset
   725
apply(induction r1 r2 arbitrary: bs rule: rrewrites.induct)
Chengsong
parents:
diff changeset
   726
apply(auto intro: rewrite_preserves_fuse)
Chengsong
parents:
diff changeset
   727
done
Chengsong
parents:
diff changeset
   728
Chengsong
parents:
diff changeset
   729
Chengsong
parents:
diff changeset
   730
lemma star_seq:  
Chengsong
parents:
diff changeset
   731
  assumes "r1 \<leadsto>* r2"
Chengsong
parents:
diff changeset
   732
  shows "ASEQ bs r1 r3 \<leadsto>* ASEQ bs r2 r3"
Chengsong
parents:
diff changeset
   733
using assms
Chengsong
parents:
diff changeset
   734
apply(induct r1 r2 arbitrary: r3 rule: rrewrites.induct)
Chengsong
parents:
diff changeset
   735
apply(auto intro: rrewrite_srewrite.intros)
Chengsong
parents:
diff changeset
   736
done
Chengsong
parents:
diff changeset
   737
Chengsong
parents:
diff changeset
   738
lemma star_seq2:  
Chengsong
parents:
diff changeset
   739
  assumes "r3 \<leadsto>* r4"
Chengsong
parents:
diff changeset
   740
  shows "ASEQ bs r1 r3 \<leadsto>* ASEQ bs r1 r4"
Chengsong
parents:
diff changeset
   741
  using assms
Chengsong
parents:
diff changeset
   742
apply(induct r3 r4 arbitrary: r1 rule: rrewrites.induct)
Chengsong
parents:
diff changeset
   743
apply(auto intro: rrewrite_srewrite.intros)
Chengsong
parents:
diff changeset
   744
done
Chengsong
parents:
diff changeset
   745
Chengsong
parents:
diff changeset
   746
lemma continuous_rewrite: 
Chengsong
parents:
diff changeset
   747
  assumes "r1 \<leadsto>* AZERO"
Chengsong
parents:
diff changeset
   748
  shows "ASEQ bs1 r1 r2 \<leadsto>* AZERO"
Chengsong
parents:
diff changeset
   749
using assms bs1 star_seq by blast
Chengsong
parents:
diff changeset
   750
Chengsong
parents:
diff changeset
   751
(*
Chengsong
parents:
diff changeset
   752
lemma continuous_rewrite2: 
Chengsong
parents:
diff changeset
   753
  assumes "r1 \<leadsto>* AONE bs"
Chengsong
parents:
diff changeset
   754
  shows "ASEQ bs1 r1 r2 \<leadsto>* (fuse (bs1 @ bs) r2)"
Chengsong
parents:
diff changeset
   755
  using assms  by (meson bs3 rrewrites.simps star_seq)
Chengsong
parents:
diff changeset
   756
*)
Chengsong
parents:
diff changeset
   757
Chengsong
parents:
diff changeset
   758
lemma bsimp_aalts_simpcases: 
Chengsong
parents:
diff changeset
   759
  shows "AONE bs \<leadsto>* bsimp (AONE bs)"  
Chengsong
parents:
diff changeset
   760
  and   "AZERO \<leadsto>* bsimp AZERO" 
Chengsong
parents:
diff changeset
   761
  and   "ACHAR bs c \<leadsto>* bsimp (ACHAR bs c)"
Chengsong
parents:
diff changeset
   762
  by (simp_all)
Chengsong
parents:
diff changeset
   763
Chengsong
parents:
diff changeset
   764
lemma bsimp_AALTs_rewrites: 
Chengsong
parents:
diff changeset
   765
  shows "AALTs bs1 rs \<leadsto>* bsimp_AALTs bs1 rs"
Chengsong
parents:
diff changeset
   766
  by (smt (verit) bs6 bs7 bsimp_AALTs.elims rrewrites.simps)
Chengsong
parents:
diff changeset
   767
Chengsong
parents:
diff changeset
   768
lemma trivialbsimp_srewrites: 
Chengsong
parents:
diff changeset
   769
  assumes "\<And>x. x \<in> set rs \<Longrightarrow> x \<leadsto>* f x"
Chengsong
parents:
diff changeset
   770
  shows "rs s\<leadsto>* (map f rs)"
Chengsong
parents:
diff changeset
   771
using assms
Chengsong
parents:
diff changeset
   772
  apply(induction rs)
Chengsong
parents:
diff changeset
   773
  apply(simp_all add: srewrites7)
Chengsong
parents:
diff changeset
   774
  done
Chengsong
parents:
diff changeset
   775
Chengsong
parents:
diff changeset
   776
lemma fltsfrewrites: "rs s\<leadsto>* flts rs"
Chengsong
parents:
diff changeset
   777
  apply(induction rs rule: flts.induct)
Chengsong
parents:
diff changeset
   778
  apply(auto intro: rrewrite_srewrite.intros)
Chengsong
parents:
diff changeset
   779
  apply (meson srewrites.simps srewrites1 ss5)
Chengsong
parents:
diff changeset
   780
  using rs1 srewrites7 apply presburger
Chengsong
parents:
diff changeset
   781
  using srewrites7 apply force
Chengsong
parents:
diff changeset
   782
  apply (simp add: srewrites7)
Chengsong
parents:
diff changeset
   783
  by (simp add: srewrites7)
Chengsong
parents:
diff changeset
   784
Chengsong
parents:
diff changeset
   785
lemma bnullable0:
Chengsong
parents:
diff changeset
   786
shows "r1 \<leadsto> r2 \<Longrightarrow> bnullable r1 = bnullable r2" 
Chengsong
parents:
diff changeset
   787
  and "rs1 s\<leadsto> rs2 \<Longrightarrow> bnullables rs1 = bnullables rs2" 
Chengsong
parents:
diff changeset
   788
  apply(induct rule: rrewrite_srewrite.inducts)
Chengsong
parents:
diff changeset
   789
  apply(auto simp add:  bnullable_fuse)
Chengsong
parents:
diff changeset
   790
  apply (meson UnCI bnullable_fuse imageI)
Chengsong
parents:
diff changeset
   791
  by (metis bnullable_correctness)
Chengsong
parents:
diff changeset
   792
Chengsong
parents:
diff changeset
   793
Chengsong
parents:
diff changeset
   794
lemma rewrites_bnullable_eq: 
Chengsong
parents:
diff changeset
   795
  assumes "r1 \<leadsto>* r2" 
Chengsong
parents:
diff changeset
   796
  shows "bnullable r1 = bnullable r2"
Chengsong
parents:
diff changeset
   797
using assms 
Chengsong
parents:
diff changeset
   798
  apply(induction r1 r2 rule: rrewrites.induct)
Chengsong
parents:
diff changeset
   799
  apply simp
Chengsong
parents:
diff changeset
   800
  using bnullable0(1) by auto
Chengsong
parents:
diff changeset
   801
Chengsong
parents:
diff changeset
   802
lemma rewrite_bmkeps_aux: 
Chengsong
parents:
diff changeset
   803
  shows "r1 \<leadsto> r2 \<Longrightarrow> bnullable r1 \<Longrightarrow> bmkeps r1 = bmkeps r2"
Chengsong
parents:
diff changeset
   804
  and   "rs1 s\<leadsto> rs2 \<Longrightarrow> bnullables rs1 \<Longrightarrow> bmkepss rs1 = bmkepss rs2" 
Chengsong
parents:
diff changeset
   805
proof (induct rule: rrewrite_srewrite.inducts)
Chengsong
parents:
diff changeset
   806
  case (bs3 bs1 bs2 r)
Chengsong
parents:
diff changeset
   807
  have IH2: "bnullable (ASEQ bs1 (AONE bs2) r)" by fact
Chengsong
parents:
diff changeset
   808
  then show "bmkeps (ASEQ bs1 (AONE bs2) r) = bmkeps (fuse (bs1 @ bs2) r)"
Chengsong
parents:
diff changeset
   809
    by (simp add: bmkeps_fuse)
Chengsong
parents:
diff changeset
   810
next
Chengsong
parents:
diff changeset
   811
  case (bs7 bs r)
Chengsong
parents:
diff changeset
   812
  have IH2: "bnullable (AALTs bs [r])" by fact
Chengsong
parents:
diff changeset
   813
  then show "bmkeps (AALTs bs [r]) = bmkeps (fuse bs r)" 
Chengsong
parents:
diff changeset
   814
    by (simp add: bmkeps_fuse)
Chengsong
parents:
diff changeset
   815
next
Chengsong
parents:
diff changeset
   816
  case (ss3 r1 r2 rs)
Chengsong
parents:
diff changeset
   817
  have IH1: "bnullable r1 \<Longrightarrow> bmkeps r1 = bmkeps r2" by fact
Chengsong
parents:
diff changeset
   818
  have as: "r1 \<leadsto> r2" by fact
Chengsong
parents:
diff changeset
   819
  from IH1 as show "bmkepss (r1 # rs) = bmkepss (r2 # rs)"
Chengsong
parents:
diff changeset
   820
    by (simp add: bnullable0)
Chengsong
parents:
diff changeset
   821
next
Chengsong
parents:
diff changeset
   822
  case (ss5 bs1 rs1 rsb)
Chengsong
parents:
diff changeset
   823
  have "bnullables (AALTs bs1 rs1 # rsb)" by fact
Chengsong
parents:
diff changeset
   824
  then show "bmkepss (AALTs bs1 rs1 # rsb) = bmkepss (map (fuse bs1) rs1 @ rsb)"
Chengsong
parents:
diff changeset
   825
    by (simp add: bmkepss1 bmkepss2 bmkepss_fuse bnullable_fuse)
Chengsong
parents:
diff changeset
   826
next
Chengsong
parents:
diff changeset
   827
  case (ss6 a1 a2 rsa rsb rsc)
Chengsong
parents:
diff changeset
   828
  have as1: "erase a1 = erase a2" by fact
Chengsong
parents:
diff changeset
   829
  have as3: "bnullables (rsa @ [a1] @ rsb @ [a2] @ rsc)" by fact
Chengsong
parents:
diff changeset
   830
  show "bmkepss (rsa @ [a1] @ rsb @ [a2] @ rsc) = bmkepss (rsa @ [a1] @ rsb @ rsc)" using as1 as3
Chengsong
parents:
diff changeset
   831
    by (smt (verit, best) append_Cons bmkeps.simps(3) bmkepss.simps(2) bmkepss1 bmkepss2 bnullable_correctness)
Chengsong
parents:
diff changeset
   832
qed (auto)
Chengsong
parents:
diff changeset
   833
Chengsong
parents:
diff changeset
   834
lemma rewrites_bmkeps: 
Chengsong
parents:
diff changeset
   835
  assumes "r1 \<leadsto>* r2" "bnullable r1" 
Chengsong
parents:
diff changeset
   836
  shows "bmkeps r1 = bmkeps r2"
Chengsong
parents:
diff changeset
   837
  using assms
Chengsong
parents:
diff changeset
   838
proof(induction r1 r2 rule: rrewrites.induct)
Chengsong
parents:
diff changeset
   839
  case (rs1 r)
Chengsong
parents:
diff changeset
   840
  then show "bmkeps r = bmkeps r" by simp
Chengsong
parents:
diff changeset
   841
next
Chengsong
parents:
diff changeset
   842
  case (rs2 r1 r2 r3)
Chengsong
parents:
diff changeset
   843
  then have IH: "bmkeps r1 = bmkeps r2" by simp
Chengsong
parents:
diff changeset
   844
  have a1: "bnullable r1" by fact
Chengsong
parents:
diff changeset
   845
  have a2: "r1 \<leadsto>* r2" by fact
Chengsong
parents:
diff changeset
   846
  have a3: "r2 \<leadsto> r3" by fact
Chengsong
parents:
diff changeset
   847
  have a4: "bnullable r2" using a1 a2 by (simp add: rewrites_bnullable_eq) 
Chengsong
parents:
diff changeset
   848
  then have "bmkeps r2 = bmkeps r3"
Chengsong
parents:
diff changeset
   849
    using a3 bnullable0(1) rewrite_bmkeps_aux(1) by blast 
Chengsong
parents:
diff changeset
   850
  then show "bmkeps r1 = bmkeps r3" using IH by simp
Chengsong
parents:
diff changeset
   851
qed
Chengsong
parents:
diff changeset
   852
Chengsong
parents:
diff changeset
   853
Chengsong
parents:
diff changeset
   854
lemma rewrites_to_bsimp: 
Chengsong
parents:
diff changeset
   855
  shows "r \<leadsto>* bsimp r"
Chengsong
parents:
diff changeset
   856
proof (induction r rule: bsimp.induct)
Chengsong
parents:
diff changeset
   857
  case (1 bs1 r1 r2)
Chengsong
parents:
diff changeset
   858
  have IH1: "r1 \<leadsto>* bsimp r1" by fact
Chengsong
parents:
diff changeset
   859
  have IH2: "r2 \<leadsto>* bsimp r2" by fact
Chengsong
parents:
diff changeset
   860
  { assume as: "bsimp r1 = AZERO \<or> bsimp r2 = AZERO"
Chengsong
parents:
diff changeset
   861
    with IH1 IH2 have "r1 \<leadsto>* AZERO \<or> r2 \<leadsto>* AZERO" by auto
Chengsong
parents:
diff changeset
   862
    then have "ASEQ bs1 r1 r2 \<leadsto>* AZERO"
Chengsong
parents:
diff changeset
   863
      by (metis bs2 continuous_rewrite rrewrites.simps star_seq2)  
Chengsong
parents:
diff changeset
   864
    then have "ASEQ bs1 r1 r2 \<leadsto>* bsimp (ASEQ bs1 r1 r2)" using as by auto
Chengsong
parents:
diff changeset
   865
  }
Chengsong
parents:
diff changeset
   866
  moreover
Chengsong
parents:
diff changeset
   867
  { assume "\<exists>bs. bsimp r1 = AONE bs"
Chengsong
parents:
diff changeset
   868
    then obtain bs where as: "bsimp r1 = AONE bs" by blast
Chengsong
parents:
diff changeset
   869
    with IH1 have "r1 \<leadsto>* AONE bs" by simp
Chengsong
parents:
diff changeset
   870
    then have "ASEQ bs1 r1 r2 \<leadsto>* fuse (bs1 @ bs) r2" using bs3 star_seq by blast
Chengsong
parents:
diff changeset
   871
    with IH2 have "ASEQ bs1 r1 r2 \<leadsto>* fuse (bs1 @ bs) (bsimp r2)"
Chengsong
parents:
diff changeset
   872
      using rewrites_fuse by (meson rrewrites_trans) 
Chengsong
parents:
diff changeset
   873
    then have "ASEQ bs1 r1 r2 \<leadsto>* bsimp (ASEQ bs1 (AONE bs) r2)" by simp
Chengsong
parents:
diff changeset
   874
    then have "ASEQ bs1 r1 r2 \<leadsto>* bsimp (ASEQ bs1 r1 r2)" by (simp add: as) 
Chengsong
parents:
diff changeset
   875
  } 
Chengsong
parents:
diff changeset
   876
  moreover
Chengsong
parents:
diff changeset
   877
  { assume as1: "bsimp r1 \<noteq> AZERO" "bsimp r2 \<noteq> AZERO" and as2: "(\<nexists>bs. bsimp r1 = AONE bs)" 
Chengsong
parents:
diff changeset
   878
    then have "bsimp_ASEQ bs1 (bsimp r1) (bsimp r2) = ASEQ bs1 (bsimp r1) (bsimp r2)" 
Chengsong
parents:
diff changeset
   879
      by (simp add: bsimp_ASEQ1) 
Chengsong
parents:
diff changeset
   880
    then have "ASEQ bs1 r1 r2 \<leadsto>* bsimp_ASEQ bs1 (bsimp r1) (bsimp r2)" using as1 as2 IH1 IH2
Chengsong
parents:
diff changeset
   881
      by (metis rrewrites_trans star_seq star_seq2) 
Chengsong
parents:
diff changeset
   882
    then have "ASEQ bs1 r1 r2 \<leadsto>* bsimp (ASEQ bs1 r1 r2)" by simp
Chengsong
parents:
diff changeset
   883
  } 
Chengsong
parents:
diff changeset
   884
  ultimately show "ASEQ bs1 r1 r2 \<leadsto>* bsimp (ASEQ bs1 r1 r2)" by blast
Chengsong
parents:
diff changeset
   885
next
Chengsong
parents:
diff changeset
   886
  case (2 bs1 rs)
Chengsong
parents:
diff changeset
   887
  have IH: "\<And>x. x \<in> set rs \<Longrightarrow> x \<leadsto>* bsimp x" by fact
Chengsong
parents:
diff changeset
   888
  then have "rs s\<leadsto>* (map bsimp rs)" by (simp add: trivialbsimp_srewrites)
Chengsong
parents:
diff changeset
   889
  also have "... s\<leadsto>* flts (map bsimp rs)" by (simp add: fltsfrewrites) 
Chengsong
parents:
diff changeset
   890
  also have "... s\<leadsto>* distinctBy (flts (map bsimp rs)) erase {}" by (simp add: ss6_stronger) 
Chengsong
parents:
diff changeset
   891
  finally have "AALTs bs1 rs \<leadsto>* AALTs bs1 (distinctBy (flts (map bsimp rs)) erase {})"
Chengsong
parents:
diff changeset
   892
    using contextrewrites0 by blast
Chengsong
parents:
diff changeset
   893
  also have "... \<leadsto>* bsimp_AALTs  bs1 (distinctBy (flts (map bsimp rs)) erase {})"
Chengsong
parents:
diff changeset
   894
    by (simp add: bsimp_AALTs_rewrites)     
Chengsong
parents:
diff changeset
   895
  finally show "AALTs bs1 rs \<leadsto>* bsimp (AALTs bs1 rs)" by simp
Chengsong
parents:
diff changeset
   896
qed (simp_all)
Chengsong
parents:
diff changeset
   897
Chengsong
parents:
diff changeset
   898
Chengsong
parents:
diff changeset
   899
lemma to_zero_in_alt: 
Chengsong
parents:
diff changeset
   900
  shows "AALT bs (ASEQ [] AZERO r) r2 \<leadsto> AALT bs AZERO r2"
Chengsong
parents:
diff changeset
   901
  by (simp add: bs1 bs8 ss3)
Chengsong
parents:
diff changeset
   902
Chengsong
parents:
diff changeset
   903
Chengsong
parents:
diff changeset
   904
Chengsong
parents:
diff changeset
   905
lemma  bder_fuse_list: 
Chengsong
parents:
diff changeset
   906
  shows "map (bder c \<circ> fuse bs1) rs1 = map (fuse bs1 \<circ> bder c) rs1"
Chengsong
parents:
diff changeset
   907
  apply(induction rs1)
Chengsong
parents:
diff changeset
   908
  apply(simp_all add: bder_fuse)
Chengsong
parents:
diff changeset
   909
  done
Chengsong
parents:
diff changeset
   910
Chengsong
parents:
diff changeset
   911
lemma rewrite_preserves_bder: 
Chengsong
parents:
diff changeset
   912
  shows "r1 \<leadsto> r2 \<Longrightarrow> bder c r1 \<leadsto>* bder c r2"
Chengsong
parents:
diff changeset
   913
  and   "rs1 s\<leadsto> rs2 \<Longrightarrow> map (bder c) rs1 s\<leadsto>* map (bder c) rs2"
Chengsong
parents:
diff changeset
   914
proof(induction rule: rrewrite_srewrite.inducts)
Chengsong
parents:
diff changeset
   915
  case (bs1 bs r2)
Chengsong
parents:
diff changeset
   916
  show "bder c (ASEQ bs AZERO r2) \<leadsto>* bder c AZERO"
Chengsong
parents:
diff changeset
   917
    by (simp add: continuous_rewrite) 
Chengsong
parents:
diff changeset
   918
next
Chengsong
parents:
diff changeset
   919
  case (bs2 bs r1)
Chengsong
parents:
diff changeset
   920
  show "bder c (ASEQ bs r1 AZERO) \<leadsto>* bder c AZERO"
Chengsong
parents:
diff changeset
   921
    apply(auto)
Chengsong
parents:
diff changeset
   922
    apply (meson bs6 contextrewrites0 rrewrite_srewrite.bs2 rs2 ss3 ss4 sss1 sss2)
Chengsong
parents:
diff changeset
   923
    by (simp add: r_in_rstar rrewrite_srewrite.bs2)
Chengsong
parents:
diff changeset
   924
next
Chengsong
parents:
diff changeset
   925
  case (bs3 bs1 bs2 r)
Chengsong
parents:
diff changeset
   926
  show "bder c (ASEQ bs1 (AONE bs2) r) \<leadsto>* bder c (fuse (bs1 @ bs2) r)"
Chengsong
parents:
diff changeset
   927
    apply(simp)
Chengsong
parents:
diff changeset
   928
    by (metis (no_types, lifting) bder_fuse bs8 bs7 fuse_append rrewrites.simps ss4 to_zero_in_alt)
Chengsong
parents:
diff changeset
   929
next
Chengsong
parents:
diff changeset
   930
  case (bs4 r1 r2 bs r3)
Chengsong
parents:
diff changeset
   931
  have as: "r1 \<leadsto> r2" by fact
Chengsong
parents:
diff changeset
   932
  have IH: "bder c r1 \<leadsto>* bder c r2" by fact
Chengsong
parents:
diff changeset
   933
  from as IH show "bder c (ASEQ bs r1 r3) \<leadsto>* bder c (ASEQ bs r2 r3)"
Chengsong
parents:
diff changeset
   934
    by (metis bder.simps(5) bnullable0(1) contextrewrites1 rewrite_bmkeps_aux(1) star_seq)
Chengsong
parents:
diff changeset
   935
next
Chengsong
parents:
diff changeset
   936
  case (bs5 r3 r4 bs r1)
Chengsong
parents:
diff changeset
   937
  have as: "r3 \<leadsto> r4" by fact 
Chengsong
parents:
diff changeset
   938
  have IH: "bder c r3 \<leadsto>* bder c r4" by fact 
Chengsong
parents:
diff changeset
   939
  from as IH show "bder c (ASEQ bs r1 r3) \<leadsto>* bder c (ASEQ bs r1 r4)"
Chengsong
parents:
diff changeset
   940
    apply(simp)
Chengsong
parents:
diff changeset
   941
    apply(auto)
Chengsong
parents:
diff changeset
   942
    using contextrewrites0 r_in_rstar rewrites_fuse srewrites6 srewrites7 star_seq2 apply presburger
Chengsong
parents:
diff changeset
   943
    using star_seq2 by blast
Chengsong
parents:
diff changeset
   944
next
Chengsong
parents:
diff changeset
   945
  case (bs6 bs)
Chengsong
parents:
diff changeset
   946
  show "bder c (AALTs bs []) \<leadsto>* bder c AZERO"
Chengsong
parents:
diff changeset
   947
    using rrewrite_srewrite.bs6 by force 
Chengsong
parents:
diff changeset
   948
next
Chengsong
parents:
diff changeset
   949
  case (bs7 bs r)
Chengsong
parents:
diff changeset
   950
  show "bder c (AALTs bs [r]) \<leadsto>* bder c (fuse bs r)"
Chengsong
parents:
diff changeset
   951
    by (simp add: bder_fuse r_in_rstar rrewrite_srewrite.bs7) 
Chengsong
parents:
diff changeset
   952
next
Chengsong
parents:
diff changeset
   953
  case (bs8 rs1 rs2 bs)
Chengsong
parents:
diff changeset
   954
  have IH1: "map (bder c) rs1 s\<leadsto>* map (bder c) rs2" by fact
Chengsong
parents:
diff changeset
   955
  then show "bder c (AALTs bs rs1) \<leadsto>* bder c (AALTs bs rs2)" 
Chengsong
parents:
diff changeset
   956
    using contextrewrites0 by force    
Chengsong
parents:
diff changeset
   957
(*next
Chengsong
parents:
diff changeset
   958
  case ss1
Chengsong
parents:
diff changeset
   959
  show "map (bder c) [] s\<leadsto>* map (bder c) []" by simp*)
Chengsong
parents:
diff changeset
   960
next
Chengsong
parents:
diff changeset
   961
  case (ss2 rs1 rs2 r)
Chengsong
parents:
diff changeset
   962
  have IH1: "map (bder c) rs1 s\<leadsto>* map (bder c) rs2" by fact
Chengsong
parents:
diff changeset
   963
  then show "map (bder c) (r # rs1) s\<leadsto>* map (bder c) (r # rs2)"
Chengsong
parents:
diff changeset
   964
    by (simp add: srewrites7) 
Chengsong
parents:
diff changeset
   965
next
Chengsong
parents:
diff changeset
   966
  case (ss3 r1 r2 rs)
Chengsong
parents:
diff changeset
   967
  have IH: "bder c r1 \<leadsto>* bder c r2" by fact
Chengsong
parents:
diff changeset
   968
  then show "map (bder c) (r1 # rs) s\<leadsto>* map (bder c) (r2 # rs)"
Chengsong
parents:
diff changeset
   969
    by (simp add: srewrites7) 
Chengsong
parents:
diff changeset
   970
next
Chengsong
parents:
diff changeset
   971
  case (ss4 rs)
Chengsong
parents:
diff changeset
   972
  show "map (bder c) (AZERO # rs) s\<leadsto>* map (bder c) rs"
Chengsong
parents:
diff changeset
   973
    using rrewrite_srewrite.ss4 by fastforce 
Chengsong
parents:
diff changeset
   974
next
Chengsong
parents:
diff changeset
   975
  case (ss5 bs1 rs1 rsb)
Chengsong
parents:
diff changeset
   976
  show "map (bder c) (AALTs bs1 rs1 # rsb) s\<leadsto>* map (bder c) (map (fuse bs1) rs1 @ rsb)"
Chengsong
parents:
diff changeset
   977
    apply(simp)
Chengsong
parents:
diff changeset
   978
    using bder_fuse_list map_map rrewrite_srewrite.ss5 srewrites.simps by blast
Chengsong
parents:
diff changeset
   979
next
Chengsong
parents:
diff changeset
   980
  case (ss6 a1 a2 bs rsa rsb)
Chengsong
parents:
diff changeset
   981
  have as: "erase a1 = erase a2" by fact
Chengsong
parents:
diff changeset
   982
  show "map (bder c) (bs @ [a1] @ rsa @ [a2] @ rsb) s\<leadsto>* map (bder c) (bs @ [a1] @ rsa @ rsb)"
Chengsong
parents:
diff changeset
   983
    apply(simp only: map_append)
Chengsong
parents:
diff changeset
   984
    by (smt (verit, best) erase_bder list.simps(8) list.simps(9) as rrewrite_srewrite.ss6 srewrites.simps)
Chengsong
parents:
diff changeset
   985
qed
Chengsong
parents:
diff changeset
   986
Chengsong
parents:
diff changeset
   987
lemma rewrites_preserves_bder: 
Chengsong
parents:
diff changeset
   988
  assumes "r1 \<leadsto>* r2"
Chengsong
parents:
diff changeset
   989
  shows "bder c r1 \<leadsto>* bder c r2"
Chengsong
parents:
diff changeset
   990
using assms  
Chengsong
parents:
diff changeset
   991
apply(induction r1 r2 rule: rrewrites.induct)
Chengsong
parents:
diff changeset
   992
apply(simp_all add: rewrite_preserves_bder rrewrites_trans)
Chengsong
parents:
diff changeset
   993
done
Chengsong
parents:
diff changeset
   994
Chengsong
parents:
diff changeset
   995
Chengsong
parents:
diff changeset
   996
lemma central:  
Chengsong
parents:
diff changeset
   997
  shows "bders r s \<leadsto>* bders_simp r s"
Chengsong
parents:
diff changeset
   998
proof(induct s arbitrary: r rule: rev_induct)
Chengsong
parents:
diff changeset
   999
  case Nil
Chengsong
parents:
diff changeset
  1000
  then show "bders r [] \<leadsto>* bders_simp r []" by simp
Chengsong
parents:
diff changeset
  1001
next
Chengsong
parents:
diff changeset
  1002
  case (snoc x xs)
Chengsong
parents:
diff changeset
  1003
  have IH: "\<And>r. bders r xs \<leadsto>* bders_simp r xs" by fact
Chengsong
parents:
diff changeset
  1004
  have "bders r (xs @ [x]) = bders (bders r xs) [x]" by (simp add: bders_append)
Chengsong
parents:
diff changeset
  1005
  also have "... \<leadsto>* bders (bders_simp r xs) [x]" using IH
Chengsong
parents:
diff changeset
  1006
    by (simp add: rewrites_preserves_bder)
Chengsong
parents:
diff changeset
  1007
  also have "... \<leadsto>* bders_simp (bders_simp r xs) [x]" using IH
Chengsong
parents:
diff changeset
  1008
    by (simp add: rewrites_to_bsimp)
Chengsong
parents:
diff changeset
  1009
  finally show "bders r (xs @ [x]) \<leadsto>* bders_simp r (xs @ [x])" 
Chengsong
parents:
diff changeset
  1010
    by (simp add: bders_simp_append)
Chengsong
parents:
diff changeset
  1011
qed
Chengsong
parents:
diff changeset
  1012
Chengsong
parents:
diff changeset
  1013
lemma main_aux: 
Chengsong
parents:
diff changeset
  1014
  assumes "bnullable (bders r s)"
Chengsong
parents:
diff changeset
  1015
  shows "bmkeps (bders r s) = bmkeps (bders_simp r s)"
Chengsong
parents:
diff changeset
  1016
proof -
Chengsong
parents:
diff changeset
  1017
  have "bders r s \<leadsto>* bders_simp r s" by (rule central)
Chengsong
parents:
diff changeset
  1018
  then 
Chengsong
parents:
diff changeset
  1019
  show "bmkeps (bders r s) = bmkeps (bders_simp r s)" using assms
Chengsong
parents:
diff changeset
  1020
    by (rule rewrites_bmkeps)
Chengsong
parents:
diff changeset
  1021
qed  
Chengsong
parents:
diff changeset
  1022
Chengsong
parents:
diff changeset
  1023
Chengsong
parents:
diff changeset
  1024
theorem main_blexer_simp: 
Chengsong
parents:
diff changeset
  1025
  shows "blexer r s = blexer_simp r s"
Chengsong
parents:
diff changeset
  1026
  unfolding blexer_def blexer_simp_def
Chengsong
parents:
diff changeset
  1027
  by (metis central main_aux rewrites_bnullable_eq)
Chengsong
parents:
diff changeset
  1028
Chengsong
parents:
diff changeset
  1029
Chengsong
parents:
diff changeset
  1030
theorem blexersimp_correctness: 
Chengsong
parents:
diff changeset
  1031
  shows "lexer r s = blexer_simp r s"
Chengsong
parents:
diff changeset
  1032
  using blexer_correctness main_blexer_simp by simp
Chengsong
parents:
diff changeset
  1033
Chengsong
parents:
diff changeset
  1034
Chengsong
parents:
diff changeset
  1035
(* some tests *)
Chengsong
parents:
diff changeset
  1036
Chengsong
parents:
diff changeset
  1037
lemma asize_fuse:
Chengsong
parents:
diff changeset
  1038
  shows "asize (fuse bs r) = asize r"
Chengsong
parents:
diff changeset
  1039
  apply(induct r arbitrary: bs)
Chengsong
parents:
diff changeset
  1040
  apply(auto)
Chengsong
parents:
diff changeset
  1041
  done
Chengsong
parents:
diff changeset
  1042
Chengsong
parents:
diff changeset
  1043
lemma asize_rewrite2:
Chengsong
parents:
diff changeset
  1044
  shows "r1 \<leadsto> r2 \<Longrightarrow> asize r1 \<ge> asize r2"
Chengsong
parents:
diff changeset
  1045
  and   "rs1 s\<leadsto> rs2 \<Longrightarrow> (sum_list (map asize rs1)) \<ge> (sum_list (map asize rs2))"
Chengsong
parents:
diff changeset
  1046
   apply(induct rule: rrewrite_srewrite.inducts)
Chengsong
parents:
diff changeset
  1047
   apply(auto simp add: asize_fuse comp_def)
Chengsong
parents:
diff changeset
  1048
  done
Chengsong
parents:
diff changeset
  1049
Chengsong
parents:
diff changeset
  1050
lemma asize_rrewrites:
Chengsong
parents:
diff changeset
  1051
  assumes "r1 \<leadsto>* r2"
Chengsong
parents:
diff changeset
  1052
  shows "asize r1 \<ge> asize r2"
Chengsong
parents:
diff changeset
  1053
  using assms
Chengsong
parents:
diff changeset
  1054
  apply(induct rule: rrewrites.induct)
Chengsong
parents:
diff changeset
  1055
   apply(auto)
Chengsong
parents:
diff changeset
  1056
  using asize_rewrite2(1) le_trans by blast
Chengsong
parents:
diff changeset
  1057
  
Chengsong
parents:
diff changeset
  1058
Chengsong
parents:
diff changeset
  1059
Chengsong
parents:
diff changeset
  1060
fun asize2 :: "arexp \<Rightarrow> nat" where
Chengsong
parents:
diff changeset
  1061
  "asize2 AZERO = 1"
Chengsong
parents:
diff changeset
  1062
| "asize2 (AONE cs) = 1" 
Chengsong
parents:
diff changeset
  1063
| "asize2 (ACHAR cs c) = 1"
Chengsong
parents:
diff changeset
  1064
| "asize2 (AALTs cs rs) = Suc (Suc (sum_list (map asize2 rs)))"
Chengsong
parents:
diff changeset
  1065
| "asize2 (ASEQ cs r1 r2) = Suc (asize2 r1 + asize2 r2)"
Chengsong
parents:
diff changeset
  1066
| "asize2 (ASTAR cs r) = Suc (asize2 r)"
Chengsong
parents:
diff changeset
  1067
Chengsong
parents:
diff changeset
  1068
Chengsong
parents:
diff changeset
  1069
lemma asize2_fuse:
Chengsong
parents:
diff changeset
  1070
  shows "asize2 (fuse bs r) = asize2 r"
Chengsong
parents:
diff changeset
  1071
  apply(induct r arbitrary: bs)
Chengsong
parents:
diff changeset
  1072
  apply(auto)
Chengsong
parents:
diff changeset
  1073
  done
Chengsong
parents:
diff changeset
  1074
Chengsong
parents:
diff changeset
  1075
lemma asize2_not_zero:
Chengsong
parents:
diff changeset
  1076
  shows "0 < asize2 r"
Chengsong
parents:
diff changeset
  1077
  apply(induct r)
Chengsong
parents:
diff changeset
  1078
  apply(auto)
Chengsong
parents:
diff changeset
  1079
  done
Chengsong
parents:
diff changeset
  1080
Chengsong
parents:
diff changeset
  1081
lemma asize_rewrite:
Chengsong
parents:
diff changeset
  1082
  shows "r1 \<leadsto> r2 \<Longrightarrow> asize2 r1 > asize2 r2"
Chengsong
parents:
diff changeset
  1083
  and   "rs1 s\<leadsto> rs2 \<Longrightarrow> (sum_list (map asize2 rs1)) > (sum_list (map asize2 rs2))"
Chengsong
parents:
diff changeset
  1084
   apply(induct rule: rrewrite_srewrite.inducts)
Chengsong
parents:
diff changeset
  1085
   apply(auto simp add: asize2_fuse comp_def)
Chengsong
parents:
diff changeset
  1086
  apply(simp add: asize2_not_zero) 
Chengsong
parents:
diff changeset
  1087
  done
Chengsong
parents:
diff changeset
  1088
Chengsong
parents:
diff changeset
  1089
lemma asize2_bsimp_ASEQ:
Chengsong
parents:
diff changeset
  1090
  shows "asize2 (bsimp_ASEQ bs r1 r2) \<le> Suc (asize2 r1 + asize2 r2)"
Chengsong
parents:
diff changeset
  1091
  apply(induct bs r1 r2 rule: bsimp_ASEQ.induct)
Chengsong
parents:
diff changeset
  1092
  apply(auto)
Chengsong
parents:
diff changeset
  1093
  done
Chengsong
parents:
diff changeset
  1094
Chengsong
parents:
diff changeset
  1095
lemma asize2_bsimp_AALTs:
Chengsong
parents:
diff changeset
  1096
  shows "asize2 (bsimp_AALTs bs rs) \<le> Suc (Suc (sum_list (map asize2 rs)))"
Chengsong
parents:
diff changeset
  1097
  apply(induct bs rs rule: bsimp_AALTs.induct)
Chengsong
parents:
diff changeset
  1098
  apply(auto simp add: asize2_fuse)
Chengsong
parents:
diff changeset
  1099
  done
Chengsong
parents:
diff changeset
  1100
Chengsong
parents:
diff changeset
  1101
lemma distinctBy_asize2:
Chengsong
parents:
diff changeset
  1102
  shows "sum_list (map asize2 (distinctBy rs f acc)) \<le> sum_list (map asize2 rs)"
Chengsong
parents:
diff changeset
  1103
  apply(induct rs f acc rule: distinctBy.induct)
Chengsong
parents:
diff changeset
  1104
  apply(auto)
Chengsong
parents:
diff changeset
  1105
  done
Chengsong
parents:
diff changeset
  1106
Chengsong
parents:
diff changeset
  1107
lemma flts_asize2:
Chengsong
parents:
diff changeset
  1108
  shows "sum_list (map asize2 (flts rs)) \<le> sum_list (map asize2 rs)"
Chengsong
parents:
diff changeset
  1109
  apply(induct rs rule: flts.induct)
Chengsong
parents:
diff changeset
  1110
  apply(auto simp add: comp_def asize2_fuse)
Chengsong
parents:
diff changeset
  1111
  done
Chengsong
parents:
diff changeset
  1112
Chengsong
parents:
diff changeset
  1113
lemma sumlist_asize2:
Chengsong
parents:
diff changeset
  1114
  assumes "\<And>x. x \<in> set rs \<Longrightarrow> asize2 (f x) \<le> asize2 x"
Chengsong
parents:
diff changeset
  1115
  shows "sum_list (map asize2 (map f rs)) \<le> sum_list (map asize2 rs)"
Chengsong
parents:
diff changeset
  1116
  using assms
Chengsong
parents:
diff changeset
  1117
  apply(induct rs)
Chengsong
parents:
diff changeset
  1118
   apply(auto simp add: comp_def)
Chengsong
parents:
diff changeset
  1119
  by (simp add: add_le_mono)
Chengsong
parents:
diff changeset
  1120
Chengsong
parents:
diff changeset
  1121
lemma test0:
Chengsong
parents:
diff changeset
  1122
  assumes "r1 \<leadsto>* r2"
Chengsong
parents:
diff changeset
  1123
  shows "r1 = r2 \<or> (\<exists>r3. r1 \<leadsto> r3 \<and> r3 \<leadsto>* r2)"
Chengsong
parents:
diff changeset
  1124
  using assms
Chengsong
parents:
diff changeset
  1125
  apply(induct r1 r2 rule: rrewrites.induct)
Chengsong
parents:
diff changeset
  1126
   apply(auto)
Chengsong
parents:
diff changeset
  1127
  done
Chengsong
parents:
diff changeset
  1128
Chengsong
parents:
diff changeset
  1129
lemma test2:
Chengsong
parents:
diff changeset
  1130
  assumes "r1 \<leadsto>* r2"
Chengsong
parents:
diff changeset
  1131
  shows "asize2 r1 \<ge> asize2 r2"
Chengsong
parents:
diff changeset
  1132
using assms
Chengsong
parents:
diff changeset
  1133
  apply(induct r1 r2 rule: rrewrites.induct)
Chengsong
parents:
diff changeset
  1134
  apply(auto)
Chengsong
parents:
diff changeset
  1135
  using asize_rewrite(1) by fastforce
Chengsong
parents:
diff changeset
  1136
  
Chengsong
parents:
diff changeset
  1137
Chengsong
parents:
diff changeset
  1138
lemma test3:
Chengsong
parents:
diff changeset
  1139
  shows "r = bsimp r \<or> (asize2 (bsimp r) < asize2 r)"
Chengsong
parents:
diff changeset
  1140
proof -
Chengsong
parents:
diff changeset
  1141
  have "r \<leadsto>* bsimp r"
Chengsong
parents:
diff changeset
  1142
    by (simp add: rewrites_to_bsimp)
Chengsong
parents:
diff changeset
  1143
  then have "r = bsimp r \<or> (\<exists>r3. r \<leadsto> r3 \<and> r3 \<leadsto>* bsimp r)"
Chengsong
parents:
diff changeset
  1144
    using test0 by blast
Chengsong
parents:
diff changeset
  1145
  then show ?thesis
Chengsong
parents:
diff changeset
  1146
    by (meson asize_rewrite(1) dual_order.strict_trans2 test2)
Chengsong
parents:
diff changeset
  1147
qed
Chengsong
parents:
diff changeset
  1148
Chengsong
parents:
diff changeset
  1149
lemma test3Q:
Chengsong
parents:
diff changeset
  1150
  shows "r = bsimp r \<or> (asize (bsimp r) \<le> asize r)"
Chengsong
parents:
diff changeset
  1151
proof -
Chengsong
parents:
diff changeset
  1152
  have "r \<leadsto>* bsimp r"
Chengsong
parents:
diff changeset
  1153
    by (simp add: rewrites_to_bsimp)
Chengsong
parents:
diff changeset
  1154
  then have "r = bsimp r \<or> (\<exists>r3. r \<leadsto> r3 \<and> r3 \<leadsto>* bsimp r)"
Chengsong
parents:
diff changeset
  1155
    using test0 by blast
Chengsong
parents:
diff changeset
  1156
  then show ?thesis
Chengsong
parents:
diff changeset
  1157
    using asize_rewrite2(1) asize_rrewrites le_trans by blast
Chengsong
parents:
diff changeset
  1158
qed
Chengsong
parents:
diff changeset
  1159
Chengsong
parents:
diff changeset
  1160
lemma test4:
Chengsong
parents:
diff changeset
  1161
  shows "asize2 (bsimp (bsimp r)) \<le> asize2 (bsimp r)"
Chengsong
parents:
diff changeset
  1162
  apply(induct r rule: bsimp.induct)
Chengsong
parents:
diff changeset
  1163
       apply(auto)
Chengsong
parents:
diff changeset
  1164
  using rewrites_to_bsimp test2 apply fastforce
Chengsong
parents:
diff changeset
  1165
  using rewrites_to_bsimp test2 by presburger
Chengsong
parents:
diff changeset
  1166
Chengsong
parents:
diff changeset
  1167
lemma test4Q:
Chengsong
parents:
diff changeset
  1168
  shows "asize (bsimp (bsimp r)) \<le> asize (bsimp r)"
Chengsong
parents:
diff changeset
  1169
  apply(induct r rule: bsimp.induct)
Chengsong
parents:
diff changeset
  1170
       apply(auto)
Chengsong
parents:
diff changeset
  1171
  apply (metis order_refl test3Q)
Chengsong
parents:
diff changeset
  1172
  by (metis le_refl test3Q)
Chengsong
parents:
diff changeset
  1173
Chengsong
parents:
diff changeset
  1174
Chengsong
parents:
diff changeset
  1175
Chengsong
parents:
diff changeset
  1176
lemma testb0:
Chengsong
parents:
diff changeset
  1177
  shows "fuse bs1 (bsimp_ASEQ bs r1 r2) =  bsimp_ASEQ (bs1 @ bs) r1 r2"
Chengsong
parents:
diff changeset
  1178
  apply(induct bs r1 r2 arbitrary: bs1 rule: bsimp_ASEQ.induct)
Chengsong
parents:
diff changeset
  1179
  apply(auto)
Chengsong
parents:
diff changeset
  1180
  done
Chengsong
parents:
diff changeset
  1181
Chengsong
parents:
diff changeset
  1182
lemma testb1:
Chengsong
parents:
diff changeset
  1183
  shows "fuse bs1 (bsimp_AALTs bs rs) =  bsimp_AALTs (bs1 @ bs) rs"
Chengsong
parents:
diff changeset
  1184
  apply(induct bs rs arbitrary: bs1 rule: bsimp_AALTs.induct)
Chengsong
parents:
diff changeset
  1185
  apply(auto simp add: fuse_append)
Chengsong
parents:
diff changeset
  1186
  done
Chengsong
parents:
diff changeset
  1187
Chengsong
parents:
diff changeset
  1188
lemma testb2:
Chengsong
parents:
diff changeset
  1189
  shows "bsimp (bsimp_ASEQ bs r1 r2) =  bsimp_ASEQ bs (bsimp r1) (bsimp r2)"
Chengsong
parents:
diff changeset
  1190
  apply(induct bs r1 r2 rule: bsimp_ASEQ.induct)
Chengsong
parents:
diff changeset
  1191
  apply(auto simp add: testb0 testb1)
Chengsong
parents:
diff changeset
  1192
  done  
Chengsong
parents:
diff changeset
  1193
Chengsong
parents:
diff changeset
  1194
lemma testb3:
Chengsong
parents:
diff changeset
  1195
  shows "\<nexists>r'. (bsimp r \<leadsto> r') \<and> asize2 (bsimp r) > asize2 r'"
Chengsong
parents:
diff changeset
  1196
apply(induct r rule: bsimp.induct)
Chengsong
parents:
diff changeset
  1197
       apply(auto)
Chengsong
parents:
diff changeset
  1198
       defer
Chengsong
parents:
diff changeset
  1199
       defer
Chengsong
parents:
diff changeset
  1200
  using rrewrite.cases apply blast
Chengsong
parents:
diff changeset
  1201
  using rrewrite.cases apply blast
Chengsong
parents:
diff changeset
  1202
  using rrewrite.cases apply blast
Chengsong
parents:
diff changeset
  1203
  using rrewrite.cases apply blast
Chengsong
parents:
diff changeset
  1204
  oops
Chengsong
parents:
diff changeset
  1205
Chengsong
parents:
diff changeset
  1206
lemma testb4:
Chengsong
parents:
diff changeset
  1207
  assumes "sum_list (map asize rs1) \<le> sum_list (map asize rs2)"
Chengsong
parents:
diff changeset
  1208
  shows "asize (bsimp_AALTs bs1 rs1) \<le> Suc (asize (bsimp_AALTs bs1 rs2))"
Chengsong
parents:
diff changeset
  1209
  using assms 
Chengsong
parents:
diff changeset
  1210
apply(induct bs1 rs2 arbitrary: rs1 rule: bsimp_AALTs.induct)
Chengsong
parents:
diff changeset
  1211
    apply(auto)
Chengsong
parents:
diff changeset
  1212
    apply(case_tac rs1)
Chengsong
parents:
diff changeset
  1213
     apply(auto)
Chengsong
parents:
diff changeset
  1214
  using asize2.elims apply auto[1]
Chengsong
parents:
diff changeset
  1215
  apply (metis One_nat_def Zero_not_Suc asize.elims)
Chengsong
parents:
diff changeset
  1216
      apply(case_tac rs1)
Chengsong
parents:
diff changeset
  1217
    apply(auto)
Chengsong
parents:
diff changeset
  1218
   apply(case_tac list)
Chengsong
parents:
diff changeset
  1219
    apply(auto)
Chengsong
parents:
diff changeset
  1220
  using asize_fuse apply force
Chengsong
parents:
diff changeset
  1221
  apply (simp add: asize_fuse)
Chengsong
parents:
diff changeset
  1222
  by (smt (verit, ccfv_threshold) One_nat_def add.right_neutral asize.simps(1) asize.simps(4) asize_fuse bsimp_AALTs.elims le_Suc_eq list.map(1) list.map(2) not_less_eq_eq sum_list_simps(1) sum_list_simps(2))
Chengsong
parents:
diff changeset
  1223
Chengsong
parents:
diff changeset
  1224
lemma flts_asize:
Chengsong
parents:
diff changeset
  1225
  shows "sum_list (map asize (flts rs)) \<le> sum_list (map asize rs)"
Chengsong
parents:
diff changeset
  1226
  apply(induct rs rule: flts.induct)
Chengsong
parents:
diff changeset
  1227
  apply(auto simp add: comp_def asize_fuse)
Chengsong
parents:
diff changeset
  1228
  done
Chengsong
parents:
diff changeset
  1229
Chengsong
parents:
diff changeset
  1230
Chengsong
parents:
diff changeset
  1231
lemma test5:
Chengsong
parents:
diff changeset
  1232
  shows "asize2 r \<ge> asize2 (bsimp r)"
Chengsong
parents:
diff changeset
  1233
  apply(induct r rule: bsimp.induct)
Chengsong
parents:
diff changeset
  1234
       apply(auto)
Chengsong
parents:
diff changeset
  1235
  apply (meson Suc_le_mono add_le_mono asize2_bsimp_ASEQ order_trans)
Chengsong
parents:
diff changeset
  1236
  apply(rule order_trans)
Chengsong
parents:
diff changeset
  1237
   apply(rule asize2_bsimp_AALTs)
Chengsong
parents:
diff changeset
  1238
  apply(simp)
Chengsong
parents:
diff changeset
  1239
  apply(rule order_trans)
Chengsong
parents:
diff changeset
  1240
   apply(rule distinctBy_asize2)
Chengsong
parents:
diff changeset
  1241
  apply(rule order_trans)
Chengsong
parents:
diff changeset
  1242
   apply(rule flts_asize2)
Chengsong
parents:
diff changeset
  1243
  using sumlist_asize2 by force
Chengsong
parents:
diff changeset
  1244
  
Chengsong
parents:
diff changeset
  1245
Chengsong
parents:
diff changeset
  1246
fun awidth :: "arexp \<Rightarrow> nat" where
Chengsong
parents:
diff changeset
  1247
  "awidth AZERO = 1"
Chengsong
parents:
diff changeset
  1248
| "awidth (AONE cs) = 1" 
Chengsong
parents:
diff changeset
  1249
| "awidth (ACHAR cs c) = 1"
Chengsong
parents:
diff changeset
  1250
| "awidth (AALTs cs rs) = (sum_list (map awidth rs))"
Chengsong
parents:
diff changeset
  1251
| "awidth (ASEQ cs r1 r2) = (awidth r1 + awidth r2)"
Chengsong
parents:
diff changeset
  1252
| "awidth (ASTAR cs r) = (awidth r)"
Chengsong
parents:
diff changeset
  1253
Chengsong
parents:
diff changeset
  1254
Chengsong
parents:
diff changeset
  1255
Chengsong
parents:
diff changeset
  1256
lemma 
Chengsong
parents:
diff changeset
  1257
  shows "s \<notin> L r \<Longrightarrow> blexer_simp r s = None"
Chengsong
parents:
diff changeset
  1258
  by (simp add: blexersimp_correctness lexer_correct_None)
Chengsong
parents:
diff changeset
  1259
Chengsong
parents:
diff changeset
  1260
lemma g1:
Chengsong
parents:
diff changeset
  1261
  "bders_simp AZERO s = AZERO"
Chengsong
parents:
diff changeset
  1262
 apply(induct s)
Chengsong
parents:
diff changeset
  1263
 apply(simp)
Chengsong
parents:
diff changeset
  1264
 apply(simp)
Chengsong
parents:
diff changeset
  1265
  done
Chengsong
parents:
diff changeset
  1266
Chengsong
parents:
diff changeset
  1267
lemma g2:
Chengsong
parents:
diff changeset
  1268
  "s \<noteq> Nil \<Longrightarrow> bders_simp (AONE bs) s = AZERO"
Chengsong
parents:
diff changeset
  1269
 apply(induct s)
Chengsong
parents:
diff changeset
  1270
 apply(simp)
Chengsong
parents:
diff changeset
  1271
  apply(simp)
Chengsong
parents:
diff changeset
  1272
  apply(case_tac s)
Chengsong
parents:
diff changeset
  1273
  apply(simp)
Chengsong
parents:
diff changeset
  1274
       apply(simp)
Chengsong
parents:
diff changeset
  1275
  done
Chengsong
parents:
diff changeset
  1276
Chengsong
parents:
diff changeset
  1277
lemma finite_pder:
Chengsong
parents:
diff changeset
  1278
  shows "finite (pder c r)"
Chengsong
parents:
diff changeset
  1279
  apply(induct c r rule: pder.induct)
Chengsong
parents:
diff changeset
  1280
  apply(auto)
Chengsong
parents:
diff changeset
  1281
  done
Chengsong
parents:
diff changeset
  1282
Chengsong
parents:
diff changeset
  1283
Chengsong
parents:
diff changeset
  1284
Chengsong
parents:
diff changeset
  1285
lemma awidth_fuse:
Chengsong
parents:
diff changeset
  1286
  shows "awidth (fuse bs r) = awidth r"
Chengsong
parents:
diff changeset
  1287
  apply(induct r arbitrary: bs)
Chengsong
parents:
diff changeset
  1288
  apply(auto)
Chengsong
parents:
diff changeset
  1289
  done
Chengsong
parents:
diff changeset
  1290
Chengsong
parents:
diff changeset
  1291
lemma pders_SEQs:
Chengsong
parents:
diff changeset
  1292
  assumes "finite A"
Chengsong
parents:
diff changeset
  1293
  shows "card (SEQs A (STAR r)) \<le> card A"
Chengsong
parents:
diff changeset
  1294
  using assms
Chengsong
parents:
diff changeset
  1295
  by (simp add: SEQs_eq_image card_image_le)
Chengsong
parents:
diff changeset
  1296
Chengsong
parents:
diff changeset
  1297
lemma binullable_intern:
Chengsong
parents:
diff changeset
  1298
  shows "bnullable (intern r) = nullable r"
Chengsong
parents:
diff changeset
  1299
  apply(induct r)
Chengsong
parents:
diff changeset
  1300
  apply(auto simp add: bnullable_fuse)
Chengsong
parents:
diff changeset
  1301
  done
Chengsong
parents:
diff changeset
  1302
Chengsong
parents:
diff changeset
  1303
lemma
Chengsong
parents:
diff changeset
  1304
  "card (pder c r) \<le> awidth (bder c (intern r))"
Chengsong
parents:
diff changeset
  1305
  apply(induct c r rule: pder.induct)
Chengsong
parents:
diff changeset
  1306
  apply(simp)
Chengsong
parents:
diff changeset
  1307
      apply(simp)
Chengsong
parents:
diff changeset
  1308
     apply(simp)
Chengsong
parents:
diff changeset
  1309
    apply(simp)
Chengsong
parents:
diff changeset
  1310
  apply(rule order_trans)
Chengsong
parents:
diff changeset
  1311
     apply(rule card_Un_le)
Chengsong
parents:
diff changeset
  1312
  apply (simp add: awidth_fuse bder_fuse)
Chengsong
parents:
diff changeset
  1313
   defer
Chengsong
parents:
diff changeset
  1314
   apply(simp)
Chengsong
parents:
diff changeset
  1315
  apply(rule order_trans)
Chengsong
parents:
diff changeset
  1316
    apply(rule pders_SEQs)
Chengsong
parents:
diff changeset
  1317
  using finite_pder apply presburger
Chengsong
parents:
diff changeset
  1318
  apply (simp add: awidth_fuse)
Chengsong
parents:
diff changeset
  1319
  apply(auto)
Chengsong
parents:
diff changeset
  1320
     apply(rule order_trans)
Chengsong
parents:
diff changeset
  1321
      apply(rule card_Un_le)
Chengsong
parents:
diff changeset
  1322
     apply(simp add: awidth_fuse)
Chengsong
parents:
diff changeset
  1323
     defer
Chengsong
parents:
diff changeset
  1324
  using binullable_intern apply blast
Chengsong
parents:
diff changeset
  1325
  using binullable_intern apply blast
Chengsong
parents:
diff changeset
  1326
  apply (smt (verit, best) SEQs_eq_image add.commute add_Suc_right card_image_le dual_order.trans finite_pder trans_le_add2)
Chengsong
parents:
diff changeset
  1327
  apply(subgoal_tac "card (SEQs (pder c r1) r2) \<le> card (pder c r1)")
Chengsong
parents:
diff changeset
  1328
  apply(linarith)
Chengsong
parents:
diff changeset
  1329
    by (simp add: UNION_singleton_eq_range card_image_le finite_pder)
Chengsong
parents:
diff changeset
  1330
  
Chengsong
parents:
diff changeset
  1331
lemma
Chengsong
parents:
diff changeset
  1332
  "card (pder c r) \<le> asize (bder c (intern r))"
Chengsong
parents:
diff changeset
  1333
  apply(induct c r rule: pder.induct)
Chengsong
parents:
diff changeset
  1334
       apply(simp)
Chengsong
parents:
diff changeset
  1335
  apply(simp)
Chengsong
parents:
diff changeset
  1336
     apply(simp)
Chengsong
parents:
diff changeset
  1337
    apply(simp)
Chengsong
parents:
diff changeset
  1338
  apply (metis add_mono_thms_linordered_semiring(1) asize_fuse bder_fuse card_Un_le le_Suc_eq order_trans)
Chengsong
parents:
diff changeset
  1339
  defer 
Chengsong
parents:
diff changeset
  1340
   apply(simp)
Chengsong
parents:
diff changeset
  1341
   apply(rule order_trans)
Chengsong
parents:
diff changeset
  1342
    apply(rule pders_SEQs)
Chengsong
parents:
diff changeset
  1343
  using finite_pder apply presburger
Chengsong
parents:
diff changeset
  1344
  apply (simp add: asize_fuse)
Chengsong
parents:
diff changeset
  1345
  apply(simp)
Chengsong
parents:
diff changeset
  1346
  apply(auto)
Chengsong
parents:
diff changeset
  1347
  apply(rule order_trans)
Chengsong
parents:
diff changeset
  1348
      apply(rule card_Un_le)
Chengsong
parents:
diff changeset
  1349
  apply (smt (z3) SEQs_eq_image add.commute add_Suc_right add_mono_thms_linordered_semiring(1) asize_fuse card_image_le dual_order.trans finite_pder le_add1)
Chengsong
parents:
diff changeset
  1350
    apply(rule order_trans)
Chengsong
parents:
diff changeset
  1351
     apply(rule card_Un_le)
Chengsong
parents:
diff changeset
  1352
  using binullable_intern apply blast
Chengsong
parents:
diff changeset
  1353
  using binullable_intern apply blast
Chengsong
parents:
diff changeset
  1354
  by (smt (verit, best) SEQs_eq_image add.commute add_Suc_right card_image_le dual_order.trans finite_pder trans_le_add2)
Chengsong
parents:
diff changeset
  1355
  
Chengsong
parents:
diff changeset
  1356
lemma
Chengsong
parents:
diff changeset
  1357
  "card (pder c r) \<le> asize (bsimp (bder c (intern r)))"
Chengsong
parents:
diff changeset
  1358
  apply(induct c r rule: pder.induct)
Chengsong
parents:
diff changeset
  1359
       apply(simp)
Chengsong
parents:
diff changeset
  1360
      apply(simp)
Chengsong
parents:
diff changeset
  1361
     apply(simp)
Chengsong
parents:
diff changeset
  1362
    apply(simp)
Chengsong
parents:
diff changeset
  1363
  apply(rule order_trans)
Chengsong
parents:
diff changeset
  1364
     apply(rule card_Un_le)
Chengsong
parents:
diff changeset
  1365
    prefer 3
Chengsong
parents:
diff changeset
  1366
    apply(simp)
Chengsong
parents:
diff changeset
  1367
  apply(rule order_trans)
Chengsong
parents:
diff changeset
  1368
     apply(rule pders_SEQs)
Chengsong
parents:
diff changeset
  1369
  using finite_pder apply blast
Chengsong
parents:
diff changeset
  1370
  oops
Chengsong
parents:
diff changeset
  1371
  
Chengsong
parents:
diff changeset
  1372
Chengsong
parents:
diff changeset
  1373
(* below is the idempotency of bsimp *)
Chengsong
parents:
diff changeset
  1374
Chengsong
parents:
diff changeset
  1375
lemma bsimp_ASEQ_fuse:
Chengsong
parents:
diff changeset
  1376
  shows "fuse bs1 (bsimp_ASEQ bs2 r1 r2) = bsimp_ASEQ (bs1 @ bs2) r1 r2"
Chengsong
parents:
diff changeset
  1377
  apply(induct r1 r2 arbitrary: bs1 bs2 rule: bsimp_ASEQ.induct)
Chengsong
parents:
diff changeset
  1378
  apply(auto)
Chengsong
parents:
diff changeset
  1379
  done
Chengsong
parents:
diff changeset
  1380
Chengsong
parents:
diff changeset
  1381
lemma bsimp_AALTs_fuse:
Chengsong
parents:
diff changeset
  1382
  assumes "\<forall>r \<in> set rs. fuse bs1 (fuse bs2 r) = fuse (bs1 @ bs2) r"
Chengsong
parents:
diff changeset
  1383
  shows "fuse bs1 (bsimp_AALTs bs2 rs) = bsimp_AALTs (bs1 @ bs2) rs"
Chengsong
parents:
diff changeset
  1384
  using assms
Chengsong
parents:
diff changeset
  1385
  apply(induct bs2 rs arbitrary: bs1 rule: bsimp_AALTs.induct)
Chengsong
parents:
diff changeset
  1386
  apply(auto)
Chengsong
parents:
diff changeset
  1387
  done
Chengsong
parents:
diff changeset
  1388
Chengsong
parents:
diff changeset
  1389
lemma bsimp_fuse:
Chengsong
parents:
diff changeset
  1390
  shows "fuse bs (bsimp r) = bsimp (fuse bs r)"
Chengsong
parents:
diff changeset
  1391
  apply(induct r arbitrary: bs)
Chengsong
parents:
diff changeset
  1392
  apply(simp_all add: bsimp_ASEQ_fuse bsimp_AALTs_fuse fuse_append)
Chengsong
parents:
diff changeset
  1393
  done
Chengsong
parents:
diff changeset
  1394
Chengsong
parents:
diff changeset
  1395
lemma bsimp_ASEQ_idem:
Chengsong
parents:
diff changeset
  1396
  assumes "bsimp (bsimp r1) = bsimp r1" "bsimp (bsimp r2) = bsimp r2"
Chengsong
parents:
diff changeset
  1397
  shows "bsimp (bsimp_ASEQ x1 (bsimp r1) (bsimp r2)) = bsimp_ASEQ x1 (bsimp r1) (bsimp r2)"
Chengsong
parents:
diff changeset
  1398
  using assms
Chengsong
parents:
diff changeset
  1399
  apply(case_tac "bsimp r1 = AZERO")
Chengsong
parents:
diff changeset
  1400
  apply(simp)
Chengsong
parents:
diff changeset
  1401
  apply(case_tac "bsimp r2 = AZERO")
Chengsong
parents:
diff changeset
  1402
  apply(simp)
Chengsong
parents:
diff changeset
  1403
  apply(case_tac "\<exists>bs. bsimp r1 = AONE bs")
Chengsong
parents:
diff changeset
  1404
  apply(auto)[1]
Chengsong
parents:
diff changeset
  1405
  apply (metis bsimp_fuse)
Chengsong
parents:
diff changeset
  1406
  apply(simp add: bsimp_ASEQ1)
Chengsong
parents:
diff changeset
  1407
  done  
Chengsong
parents:
diff changeset
  1408
Chengsong
parents:
diff changeset
  1409
lemma bsimp_AALTs_idem:
Chengsong
parents:
diff changeset
  1410
  assumes "\<forall>r \<in> set rs. bsimp (bsimp r) = bsimp r" 
Chengsong
parents:
diff changeset
  1411
  shows "bsimp (bsimp_AALTs bs rs) = bsimp_AALTs bs (map bsimp rs)" 
Chengsong
parents:
diff changeset
  1412
  using assms
Chengsong
parents:
diff changeset
  1413
  apply(induct bs rs rule: bsimp_AALTs.induct)
Chengsong
parents:
diff changeset
  1414
  apply(simp)
Chengsong
parents:
diff changeset
  1415
   apply(simp)
Chengsong
parents:
diff changeset
  1416
  using bsimp_fuse apply presburger
Chengsong
parents:
diff changeset
  1417
  oops   
Chengsong
parents:
diff changeset
  1418
  
Chengsong
parents:
diff changeset
  1419
lemma bsimp_idem_rev:
Chengsong
parents:
diff changeset
  1420
  shows "\<nexists>r2. bsimp r1 \<leadsto> r2"
Chengsong
parents:
diff changeset
  1421
  apply(induct r1 rule: bsimp.induct)
Chengsong
parents:
diff changeset
  1422
  apply(auto)
Chengsong
parents:
diff changeset
  1423
  defer
Chengsong
parents:
diff changeset
  1424
  defer
Chengsong
parents:
diff changeset
  1425
  using rrewrite.simps apply blast
Chengsong
parents:
diff changeset
  1426
  using rrewrite.cases apply blast
Chengsong
parents:
diff changeset
  1427
  using rrewrite.simps apply blast
Chengsong
parents:
diff changeset
  1428
  using rrewrite.cases apply blast
Chengsong
parents:
diff changeset
  1429
  apply(case_tac "bsimp r1 = AZERO")
Chengsong
parents:
diff changeset
  1430
  apply(simp)
Chengsong
parents:
diff changeset
  1431
  apply(case_tac "bsimp r2 = AZERO")
Chengsong
parents:
diff changeset
  1432
  apply(simp)
Chengsong
parents:
diff changeset
  1433
  apply(case_tac "\<exists>bs. bsimp r1 = AONE bs")
Chengsong
parents:
diff changeset
  1434
  apply(auto)[1]
Chengsong
parents:
diff changeset
  1435
  prefer 2
Chengsong
parents:
diff changeset
  1436
  apply (smt (verit, best) arexp.distinct(25) arexp.inject(3) bsimp_ASEQ1 rrewrite.simps)
Chengsong
parents:
diff changeset
  1437
  defer
Chengsong
parents:
diff changeset
  1438
  oops
Chengsong
parents:
diff changeset
  1439
Chengsong
parents:
diff changeset
  1440
lemma bsimp_idem:
Chengsong
parents:
diff changeset
  1441
  shows "bsimp (bsimp r) = bsimp r"
Chengsong
parents:
diff changeset
  1442
  apply(induct r rule: bsimp.induct)
Chengsong
parents:
diff changeset
  1443
  apply(auto)
Chengsong
parents:
diff changeset
  1444
  using bsimp_ASEQ_idem apply presburger
417
a2887a9e8539 rdersetc.
Chengsong
parents: 409
diff changeset
  1445
  sorry
a2887a9e8539 rdersetc.
Chengsong
parents: 409
diff changeset
  1446
409
Chengsong
parents:
diff changeset
  1447
Chengsong
parents:
diff changeset
  1448
lemma neg:
Chengsong
parents:
diff changeset
  1449
  shows " \<not>(\<exists>r2. r1 \<leadsto> r2 \<and>  (r2 \<leadsto>* bsimp r1) )"
Chengsong
parents:
diff changeset
  1450
  apply(rule notI)
Chengsong
parents:
diff changeset
  1451
  apply(erule exE)
Chengsong
parents:
diff changeset
  1452
  apply(erule conjE)
Chengsong
parents:
diff changeset
  1453
  oops
Chengsong
parents:
diff changeset
  1454
Chengsong
parents:
diff changeset
  1455
Chengsong
parents:
diff changeset
  1456
Chengsong
parents:
diff changeset
  1457
lemma reduction_always_in_bsimp:
Chengsong
parents:
diff changeset
  1458
  shows " \<lbrakk> r1 \<leadsto> r2 ; \<not>(r2 \<leadsto>* bsimp r1)\<rbrakk> \<Longrightarrow> False"
Chengsong
parents:
diff changeset
  1459
  apply(erule rrewrite.cases)
Chengsong
parents:
diff changeset
  1460
         apply simp
Chengsong
parents:
diff changeset
  1461
        apply auto
Chengsong
parents:
diff changeset
  1462
Chengsong
parents:
diff changeset
  1463
  oops
Chengsong
parents:
diff changeset
  1464
417
a2887a9e8539 rdersetc.
Chengsong
parents: 409
diff changeset
  1465
a2887a9e8539 rdersetc.
Chengsong
parents: 409
diff changeset
  1466
409
Chengsong
parents:
diff changeset
  1467
(*
Chengsong
parents:
diff changeset
  1468
AALTs [] [AZERO, AALTs(bs1, [a, b]) ] 
Chengsong
parents:
diff changeset
  1469
rewrite seq 1: \<leadsto> AALTs [] [ AALTs(bs1, [a, b]) ] \<leadsto>
Chengsong
parents:
diff changeset
  1470
fuse [] (AALTs bs1, [a, b])
Chengsong
parents:
diff changeset
  1471
rewrite seq 2: \<leadsto> AALTs [] [AZERO, (fuse bs1 a), (fuse bs1 b)]) ]
Chengsong
parents:
diff changeset
  1472
Chengsong
parents:
diff changeset
  1473
*)
Chengsong
parents:
diff changeset
  1474
Chengsong
parents:
diff changeset
  1475
lemma normal_bsimp: 
Chengsong
parents:
diff changeset
  1476
  shows "\<nexists>r'. bsimp r \<leadsto> r'"
Chengsong
parents:
diff changeset
  1477
  oops
Chengsong
parents:
diff changeset
  1478
Chengsong
parents:
diff changeset
  1479
  (*r' size bsimp r > size r' 
Chengsong
parents:
diff changeset
  1480
    r' \<leadsto>* bsimp bsimp r
Chengsong
parents:
diff changeset
  1481
size bsimp r > size r' \<ge> size bsimp bsimp r*)
Chengsong
parents:
diff changeset
  1482
417
a2887a9e8539 rdersetc.
Chengsong
parents: 409
diff changeset
  1483
fun orderedSufAux :: "nat \<Rightarrow> char list \<Rightarrow> char list list"
a2887a9e8539 rdersetc.
Chengsong
parents: 409
diff changeset
  1484
  where
421
Chengsong
parents: 417
diff changeset
  1485
 "orderedSufAux (Suc i) ss = (drop i ss) # (orderedSufAux i ss)"
417
a2887a9e8539 rdersetc.
Chengsong
parents: 409
diff changeset
  1486
|"orderedSufAux 0 ss = Nil"
a2887a9e8539 rdersetc.
Chengsong
parents: 409
diff changeset
  1487
a2887a9e8539 rdersetc.
Chengsong
parents: 409
diff changeset
  1488
fun 
a2887a9e8539 rdersetc.
Chengsong
parents: 409
diff changeset
  1489
orderedSuf :: "char list \<Rightarrow> char list list"
a2887a9e8539 rdersetc.
Chengsong
parents: 409
diff changeset
  1490
where
a2887a9e8539 rdersetc.
Chengsong
parents: 409
diff changeset
  1491
"orderedSuf s = orderedSufAux (length s) s"
a2887a9e8539 rdersetc.
Chengsong
parents: 409
diff changeset
  1492
421
Chengsong
parents: 417
diff changeset
  1493
fun orderedPrefAux :: "nat \<Rightarrow> char list \<Rightarrow> char list list"
Chengsong
parents: 417
diff changeset
  1494
  where
Chengsong
parents: 417
diff changeset
  1495
"orderedPrefAux (Suc i) ss = (take i ss) # (orderedPrefAux i ss)"
Chengsong
parents: 417
diff changeset
  1496
|"orderedPrefAux 0 ss = Nil"
Chengsong
parents: 417
diff changeset
  1497
Chengsong
parents: 417
diff changeset
  1498
Chengsong
parents: 417
diff changeset
  1499
fun orderedPref :: "char list \<Rightarrow> char list list"
Chengsong
parents: 417
diff changeset
  1500
  where
Chengsong
parents: 417
diff changeset
  1501
"orderedPref s = orderedPrefAux (length s) s"
Chengsong
parents: 417
diff changeset
  1502
Chengsong
parents: 417
diff changeset
  1503
lemma shape_of_pref_1list:
Chengsong
parents: 417
diff changeset
  1504
  shows "orderedPref [c] = [[]]"
417
a2887a9e8539 rdersetc.
Chengsong
parents: 409
diff changeset
  1505
  apply auto
a2887a9e8539 rdersetc.
Chengsong
parents: 409
diff changeset
  1506
  done
a2887a9e8539 rdersetc.
Chengsong
parents: 409
diff changeset
  1507
421
Chengsong
parents: 417
diff changeset
  1508
lemma shape_of_suf_1list:
Chengsong
parents: 417
diff changeset
  1509
  shows "orderedSuf [c] = [[c]]"
Chengsong
parents: 417
diff changeset
  1510
  by auto
Chengsong
parents: 417
diff changeset
  1511
Chengsong
parents: 417
diff changeset
  1512
lemma shape_of_suf_2list:
Chengsong
parents: 417
diff changeset
  1513
  shows "orderedSuf [c2, c3] = [[c3], [c2,c3]]"
Chengsong
parents: 417
diff changeset
  1514
  by auto
Chengsong
parents: 417
diff changeset
  1515
Chengsong
parents: 417
diff changeset
  1516
lemma shape_of_prf_2list:
Chengsong
parents: 417
diff changeset
  1517
  shows "orderedPref [c1, c2] = [[c1], []]"
Chengsong
parents: 417
diff changeset
  1518
  by auto
Chengsong
parents: 417
diff changeset
  1519
417
a2887a9e8539 rdersetc.
Chengsong
parents: 409
diff changeset
  1520
a2887a9e8539 rdersetc.
Chengsong
parents: 409
diff changeset
  1521
lemma shape_of_suf_3list:
421
Chengsong
parents: 417
diff changeset
  1522
  shows "orderedSuf [c1, c2, c3] = [[c3], [c2, c3], [c1, c2, c3]]"
Chengsong
parents: 417
diff changeset
  1523
  by auto
Chengsong
parents: 417
diff changeset
  1524
Chengsong
parents: 417
diff changeset
  1525
lemma throwing_elem_around:
Chengsong
parents: 417
diff changeset
  1526
  shows "orderedSuf (s1 @ [a] @ s) = (orderedSuf s) @ (map (\<lambda>s11. s11 @ s) (orderedSuf ( s1 @ [a]) ))"
Chengsong
parents: 417
diff changeset
  1527
and "orderedSuf (s1 @ [a] @ s) = (orderedSuf ([a] @ s) @ (map (\<lambda>s11. s11 @ ([a] @ s))) (orderedSuf s1) )"
Chengsong
parents: 417
diff changeset
  1528
  sorry
Chengsong
parents: 417
diff changeset
  1529
Chengsong
parents: 417
diff changeset
  1530
Chengsong
parents: 417
diff changeset
  1531
lemma suf_cons:
Chengsong
parents: 417
diff changeset
  1532
  shows "orderedSuf (s1 @ s) = (orderedSuf s) @ (map (\<lambda>s11. s11 @ s) (orderedSuf s1))"
Chengsong
parents: 417
diff changeset
  1533
  apply(induct s arbitrary: s1)
Chengsong
parents: 417
diff changeset
  1534
   apply simp
Chengsong
parents: 417
diff changeset
  1535
  apply(subgoal_tac "s1 @ a # s = (s1 @ [a]) @ s")
Chengsong
parents: 417
diff changeset
  1536
  prefer 2
Chengsong
parents: 417
diff changeset
  1537
   apply simp
Chengsong
parents: 417
diff changeset
  1538
  apply(subgoal_tac "orderedSuf (s1 @ a # s) = orderedSuf ((s1 @ [a]) @ s)")
Chengsong
parents: 417
diff changeset
  1539
  prefer 2
Chengsong
parents: 417
diff changeset
  1540
   apply presburger
Chengsong
parents: 417
diff changeset
  1541
  apply(drule_tac x="s1 @ [a]" in meta_spec)
Chengsong
parents: 417
diff changeset
  1542
  sorry
Chengsong
parents: 417
diff changeset
  1543
Chengsong
parents: 417
diff changeset
  1544
Chengsong
parents: 417
diff changeset
  1545
Chengsong
parents: 417
diff changeset
  1546
lemma shape_of_prf_3list:
Chengsong
parents: 417
diff changeset
  1547
  shows "orderedPref [c1, c2, c3] = [[c1, c2], [c1], []]"
Chengsong
parents: 417
diff changeset
  1548
  by auto
Chengsong
parents: 417
diff changeset
  1549
Chengsong
parents: 417
diff changeset
  1550
fun zip_concat :: "char list list \<Rightarrow> char list list \<Rightarrow> char list list"
Chengsong
parents: 417
diff changeset
  1551
  where 
Chengsong
parents: 417
diff changeset
  1552
    "zip_concat (s1#ss1) (s2#ss2) = (s1@s2) # (zip_concat ss1 ss2)"
Chengsong
parents: 417
diff changeset
  1553
  |   "zip_concat [] [] = []"
Chengsong
parents: 417
diff changeset
  1554
  | "zip_concat [] (s2#ss2) = s2 # (zip_concat [] ss2)"
Chengsong
parents: 417
diff changeset
  1555
  | "zip_concat (s1#ss1) [] = s1 # (zip_concat ss1 [])"
Chengsong
parents: 417
diff changeset
  1556
Chengsong
parents: 417
diff changeset
  1557
Chengsong
parents: 417
diff changeset
  1558
Chengsong
parents: 417
diff changeset
  1559
lemma compliment_pref_suf:
Chengsong
parents: 417
diff changeset
  1560
  shows "zip_concat (orderedPref s) (orderedSuf s) = replicate (length s) s "
Chengsong
parents: 417
diff changeset
  1561
  apply(induct s)
Chengsong
parents: 417
diff changeset
  1562
   apply auto[1]
Chengsong
parents: 417
diff changeset
  1563
  sorry
Chengsong
parents: 417
diff changeset
  1564
417
a2887a9e8539 rdersetc.
Chengsong
parents: 409
diff changeset
  1565
a2887a9e8539 rdersetc.
Chengsong
parents: 409
diff changeset
  1566
a2887a9e8539 rdersetc.
Chengsong
parents: 409
diff changeset
  1567
a2887a9e8539 rdersetc.
Chengsong
parents: 409
diff changeset
  1568
datatype rrexp = 
a2887a9e8539 rdersetc.
Chengsong
parents: 409
diff changeset
  1569
  RZERO
a2887a9e8539 rdersetc.
Chengsong
parents: 409
diff changeset
  1570
| RONE 
a2887a9e8539 rdersetc.
Chengsong
parents: 409
diff changeset
  1571
| RCHAR char
a2887a9e8539 rdersetc.
Chengsong
parents: 409
diff changeset
  1572
| RSEQ rrexp rrexp
a2887a9e8539 rdersetc.
Chengsong
parents: 409
diff changeset
  1573
| RALTS "rrexp list"
a2887a9e8539 rdersetc.
Chengsong
parents: 409
diff changeset
  1574
| RSTAR rrexp
a2887a9e8539 rdersetc.
Chengsong
parents: 409
diff changeset
  1575
a2887a9e8539 rdersetc.
Chengsong
parents: 409
diff changeset
  1576
abbreviation
a2887a9e8539 rdersetc.
Chengsong
parents: 409
diff changeset
  1577
  "RALT r1 r2 \<equiv> RALTS [r1, r2]"
a2887a9e8539 rdersetc.
Chengsong
parents: 409
diff changeset
  1578
a2887a9e8539 rdersetc.
Chengsong
parents: 409
diff changeset
  1579
fun 
a2887a9e8539 rdersetc.
Chengsong
parents: 409
diff changeset
  1580
  rerase :: "arexp \<Rightarrow> rrexp"
a2887a9e8539 rdersetc.
Chengsong
parents: 409
diff changeset
  1581
where
a2887a9e8539 rdersetc.
Chengsong
parents: 409
diff changeset
  1582
  "rerase AZERO = RZERO"
a2887a9e8539 rdersetc.
Chengsong
parents: 409
diff changeset
  1583
| "rerase (AONE _) = RONE"
a2887a9e8539 rdersetc.
Chengsong
parents: 409
diff changeset
  1584
| "rerase (ACHAR _ c) = RCHAR c"
a2887a9e8539 rdersetc.
Chengsong
parents: 409
diff changeset
  1585
| "rerase (AALTs bs rs) = RALTS (map rerase rs)"
a2887a9e8539 rdersetc.
Chengsong
parents: 409
diff changeset
  1586
| "rerase (ASEQ _ r1 r2) = RSEQ (rerase r1) (rerase r2)"
a2887a9e8539 rdersetc.
Chengsong
parents: 409
diff changeset
  1587
| "rerase (ASTAR _ r) = RSTAR (rerase r)"
a2887a9e8539 rdersetc.
Chengsong
parents: 409
diff changeset
  1588
a2887a9e8539 rdersetc.
Chengsong
parents: 409
diff changeset
  1589
a2887a9e8539 rdersetc.
Chengsong
parents: 409
diff changeset
  1590
a2887a9e8539 rdersetc.
Chengsong
parents: 409
diff changeset
  1591
a2887a9e8539 rdersetc.
Chengsong
parents: 409
diff changeset
  1592
fun
a2887a9e8539 rdersetc.
Chengsong
parents: 409
diff changeset
  1593
 rnullable :: "rrexp \<Rightarrow> bool"
a2887a9e8539 rdersetc.
Chengsong
parents: 409
diff changeset
  1594
where
a2887a9e8539 rdersetc.
Chengsong
parents: 409
diff changeset
  1595
  "rnullable (RZERO) = False"
a2887a9e8539 rdersetc.
Chengsong
parents: 409
diff changeset
  1596
| "rnullable (RONE  ) = True"
a2887a9e8539 rdersetc.
Chengsong
parents: 409
diff changeset
  1597
| "rnullable (RCHAR   c) = False"
a2887a9e8539 rdersetc.
Chengsong
parents: 409
diff changeset
  1598
| "rnullable (RALTS   rs) = (\<exists>r \<in> set rs. rnullable r)"
a2887a9e8539 rdersetc.
Chengsong
parents: 409
diff changeset
  1599
| "rnullable (RSEQ  r1 r2) = (rnullable r1 \<and> rnullable r2)"
a2887a9e8539 rdersetc.
Chengsong
parents: 409
diff changeset
  1600
| "rnullable (RSTAR   r) = True"
a2887a9e8539 rdersetc.
Chengsong
parents: 409
diff changeset
  1601
a2887a9e8539 rdersetc.
Chengsong
parents: 409
diff changeset
  1602
a2887a9e8539 rdersetc.
Chengsong
parents: 409
diff changeset
  1603
fun
a2887a9e8539 rdersetc.
Chengsong
parents: 409
diff changeset
  1604
 rder :: "char \<Rightarrow> rrexp \<Rightarrow> rrexp"
a2887a9e8539 rdersetc.
Chengsong
parents: 409
diff changeset
  1605
where
a2887a9e8539 rdersetc.
Chengsong
parents: 409
diff changeset
  1606
  "rder c (RZERO) = RZERO"
a2887a9e8539 rdersetc.
Chengsong
parents: 409
diff changeset
  1607
| "rder c (RONE) = RZERO"
a2887a9e8539 rdersetc.
Chengsong
parents: 409
diff changeset
  1608
| "rder c (RCHAR d) = (if c = d then RONE else RZERO)"
a2887a9e8539 rdersetc.
Chengsong
parents: 409
diff changeset
  1609
| "rder c (RALTS rs) = RALTS (map (rder c) rs)"
a2887a9e8539 rdersetc.
Chengsong
parents: 409
diff changeset
  1610
| "rder c (RSEQ r1 r2) = 
a2887a9e8539 rdersetc.
Chengsong
parents: 409
diff changeset
  1611
     (if rnullable r1
a2887a9e8539 rdersetc.
Chengsong
parents: 409
diff changeset
  1612
      then RALT   (RSEQ (rder c r1) r2) (rder c r2)
a2887a9e8539 rdersetc.
Chengsong
parents: 409
diff changeset
  1613
      else RSEQ   (rder c r1) r2)"
a2887a9e8539 rdersetc.
Chengsong
parents: 409
diff changeset
  1614
| "rder c (RSTAR r) = RSEQ  (rder c r) (RSTAR r)"
a2887a9e8539 rdersetc.
Chengsong
parents: 409
diff changeset
  1615
a2887a9e8539 rdersetc.
Chengsong
parents: 409
diff changeset
  1616
a2887a9e8539 rdersetc.
Chengsong
parents: 409
diff changeset
  1617
fun 
a2887a9e8539 rdersetc.
Chengsong
parents: 409
diff changeset
  1618
  rders :: "rrexp \<Rightarrow> string \<Rightarrow> rrexp"
a2887a9e8539 rdersetc.
Chengsong
parents: 409
diff changeset
  1619
where
a2887a9e8539 rdersetc.
Chengsong
parents: 409
diff changeset
  1620
  "rders r [] = r"
a2887a9e8539 rdersetc.
Chengsong
parents: 409
diff changeset
  1621
| "rders r (c#s) = rders (rder c r) s"
a2887a9e8539 rdersetc.
Chengsong
parents: 409
diff changeset
  1622
a2887a9e8539 rdersetc.
Chengsong
parents: 409
diff changeset
  1623
fun rdistinct :: "'a list \<Rightarrow>'a set \<Rightarrow> 'a list"
a2887a9e8539 rdersetc.
Chengsong
parents: 409
diff changeset
  1624
  where
a2887a9e8539 rdersetc.
Chengsong
parents: 409
diff changeset
  1625
  "rdistinct [] acc = []"
a2887a9e8539 rdersetc.
Chengsong
parents: 409
diff changeset
  1626
| "rdistinct (x#xs)  acc = 
a2887a9e8539 rdersetc.
Chengsong
parents: 409
diff changeset
  1627
     (if x \<in> acc then rdistinct xs  acc 
a2887a9e8539 rdersetc.
Chengsong
parents: 409
diff changeset
  1628
      else x # (rdistinct xs  ({x} \<union> acc)))"
a2887a9e8539 rdersetc.
Chengsong
parents: 409
diff changeset
  1629
a2887a9e8539 rdersetc.
Chengsong
parents: 409
diff changeset
  1630
a2887a9e8539 rdersetc.
Chengsong
parents: 409
diff changeset
  1631
fun rflts :: "rrexp list \<Rightarrow> rrexp list"
a2887a9e8539 rdersetc.
Chengsong
parents: 409
diff changeset
  1632
  where 
a2887a9e8539 rdersetc.
Chengsong
parents: 409
diff changeset
  1633
  "rflts [] = []"
a2887a9e8539 rdersetc.
Chengsong
parents: 409
diff changeset
  1634
| "rflts (RZERO # rs) = rflts rs"
a2887a9e8539 rdersetc.
Chengsong
parents: 409
diff changeset
  1635
| "rflts ((RALTS rs1) # rs) = rs1 @ rflts rs"
a2887a9e8539 rdersetc.
Chengsong
parents: 409
diff changeset
  1636
| "rflts (r1 # rs) = r1 # rflts rs"
a2887a9e8539 rdersetc.
Chengsong
parents: 409
diff changeset
  1637
a2887a9e8539 rdersetc.
Chengsong
parents: 409
diff changeset
  1638
a2887a9e8539 rdersetc.
Chengsong
parents: 409
diff changeset
  1639
fun rsimp_ALTs :: " rrexp list \<Rightarrow> rrexp"
a2887a9e8539 rdersetc.
Chengsong
parents: 409
diff changeset
  1640
  where
a2887a9e8539 rdersetc.
Chengsong
parents: 409
diff changeset
  1641
  "rsimp_ALTs  [] = RZERO"
a2887a9e8539 rdersetc.
Chengsong
parents: 409
diff changeset
  1642
| "rsimp_ALTs [r] =  r"
a2887a9e8539 rdersetc.
Chengsong
parents: 409
diff changeset
  1643
| "rsimp_ALTs rs = RALTS rs"
a2887a9e8539 rdersetc.
Chengsong
parents: 409
diff changeset
  1644
a2887a9e8539 rdersetc.
Chengsong
parents: 409
diff changeset
  1645
fun rsimp_SEQ :: " rrexp \<Rightarrow> rrexp \<Rightarrow> rrexp"
a2887a9e8539 rdersetc.
Chengsong
parents: 409
diff changeset
  1646
  where
a2887a9e8539 rdersetc.
Chengsong
parents: 409
diff changeset
  1647
  "rsimp_SEQ  RZERO _ = RZERO"
a2887a9e8539 rdersetc.
Chengsong
parents: 409
diff changeset
  1648
| "rsimp_SEQ  _ RZERO = RZERO"
a2887a9e8539 rdersetc.
Chengsong
parents: 409
diff changeset
  1649
| "rsimp_SEQ RONE r2 = r2"
a2887a9e8539 rdersetc.
Chengsong
parents: 409
diff changeset
  1650
| "rsimp_SEQ r1 r2 = RSEQ r1 r2"
a2887a9e8539 rdersetc.
Chengsong
parents: 409
diff changeset
  1651
a2887a9e8539 rdersetc.
Chengsong
parents: 409
diff changeset
  1652
a2887a9e8539 rdersetc.
Chengsong
parents: 409
diff changeset
  1653
fun rsimp :: "rrexp \<Rightarrow> rrexp" 
a2887a9e8539 rdersetc.
Chengsong
parents: 409
diff changeset
  1654
  where
a2887a9e8539 rdersetc.
Chengsong
parents: 409
diff changeset
  1655
  "rsimp (RSEQ r1 r2) = rsimp_SEQ  (rsimp r1) (rsimp r2)"
a2887a9e8539 rdersetc.
Chengsong
parents: 409
diff changeset
  1656
| "rsimp (RALTS rs) = rsimp_ALTs  (rdistinct (rflts (map rsimp rs))  {}) "
a2887a9e8539 rdersetc.
Chengsong
parents: 409
diff changeset
  1657
| "rsimp r = r"
a2887a9e8539 rdersetc.
Chengsong
parents: 409
diff changeset
  1658
a2887a9e8539 rdersetc.
Chengsong
parents: 409
diff changeset
  1659
a2887a9e8539 rdersetc.
Chengsong
parents: 409
diff changeset
  1660
fun 
a2887a9e8539 rdersetc.
Chengsong
parents: 409
diff changeset
  1661
  rders_simp :: "rrexp \<Rightarrow> string \<Rightarrow> rrexp"
a2887a9e8539 rdersetc.
Chengsong
parents: 409
diff changeset
  1662
where
a2887a9e8539 rdersetc.
Chengsong
parents: 409
diff changeset
  1663
  "rders_simp r [] = r"
a2887a9e8539 rdersetc.
Chengsong
parents: 409
diff changeset
  1664
| "rders_simp r (c#s) = rders_simp (rsimp (rder c r)) s"
a2887a9e8539 rdersetc.
Chengsong
parents: 409
diff changeset
  1665
421
Chengsong
parents: 417
diff changeset
  1666
fun rsize :: "rrexp \<Rightarrow> nat" where
Chengsong
parents: 417
diff changeset
  1667
  "rsize RZERO = 1"
Chengsong
parents: 417
diff changeset
  1668
| "rsize (RONE) = 1" 
Chengsong
parents: 417
diff changeset
  1669
| "rsize (RCHAR  c) = 1"
Chengsong
parents: 417
diff changeset
  1670
| "rsize (RALTS  rs) = Suc (sum_list (map rsize rs))"
Chengsong
parents: 417
diff changeset
  1671
| "rsize (RSEQ  r1 r2) = Suc (rsize r1 + rsize r2)"
Chengsong
parents: 417
diff changeset
  1672
| "rsize (RSTAR  r) = Suc (rsize r)"
Chengsong
parents: 417
diff changeset
  1673
417
a2887a9e8539 rdersetc.
Chengsong
parents: 409
diff changeset
  1674
427
Chengsong
parents: 422
diff changeset
  1675
Chengsong
parents: 422
diff changeset
  1676
Chengsong
parents: 422
diff changeset
  1677
lemma rsimp_aalts_smaller:
Chengsong
parents: 422
diff changeset
  1678
  shows "rsize (rsimp_ALTs  rs) \<le> rsize (RALTS rs)"
Chengsong
parents: 422
diff changeset
  1679
  apply(induct rs)
Chengsong
parents: 422
diff changeset
  1680
   apply simp
Chengsong
parents: 422
diff changeset
  1681
  sorry
Chengsong
parents: 422
diff changeset
  1682
Chengsong
parents: 422
diff changeset
  1683
lemma finite_list_of_ders:
Chengsong
parents: 422
diff changeset
  1684
  shows"\<exists>dersset. ( (finite dersset) \<and> (\<forall>s. (rders_simp r s) \<in> dersset) )"
Chengsong
parents: 422
diff changeset
  1685
  sorry
Chengsong
parents: 422
diff changeset
  1686
Chengsong
parents: 422
diff changeset
  1687
Chengsong
parents: 422
diff changeset
  1688
417
a2887a9e8539 rdersetc.
Chengsong
parents: 409
diff changeset
  1689
lemma rerase_bsimp:
a2887a9e8539 rdersetc.
Chengsong
parents: 409
diff changeset
  1690
  shows "rerase (bsimp r) = rsimp (rerase r)"
a2887a9e8539 rdersetc.
Chengsong
parents: 409
diff changeset
  1691
  apply(induct r)
a2887a9e8539 rdersetc.
Chengsong
parents: 409
diff changeset
  1692
       apply auto
a2887a9e8539 rdersetc.
Chengsong
parents: 409
diff changeset
  1693
a2887a9e8539 rdersetc.
Chengsong
parents: 409
diff changeset
  1694
a2887a9e8539 rdersetc.
Chengsong
parents: 409
diff changeset
  1695
  sorry
a2887a9e8539 rdersetc.
Chengsong
parents: 409
diff changeset
  1696
421
Chengsong
parents: 417
diff changeset
  1697
417
a2887a9e8539 rdersetc.
Chengsong
parents: 409
diff changeset
  1698
lemma rerase_bder:
a2887a9e8539 rdersetc.
Chengsong
parents: 409
diff changeset
  1699
  shows "rerase (bder c r) = rder c (rerase r)"
a2887a9e8539 rdersetc.
Chengsong
parents: 409
diff changeset
  1700
  apply(induct r)
a2887a9e8539 rdersetc.
Chengsong
parents: 409
diff changeset
  1701
       apply auto
a2887a9e8539 rdersetc.
Chengsong
parents: 409
diff changeset
  1702
  sorry
421
Chengsong
parents: 417
diff changeset
  1703
(*
417
a2887a9e8539 rdersetc.
Chengsong
parents: 409
diff changeset
  1704
lemma rders_shape:
421
Chengsong
parents: 417
diff changeset
  1705
  shows "s \<noteq> [] \<Longrightarrow> rders_simp (RSEQ r1 r2) s = 
417
a2887a9e8539 rdersetc.
Chengsong
parents: 409
diff changeset
  1706
         rsimp (RALTS  ((RSEQ (rders r1 s) r2) #
a2887a9e8539 rdersetc.
Chengsong
parents: 409
diff changeset
  1707
           (map (rders r2) (orderedSuf s))) )"
421
Chengsong
parents: 417
diff changeset
  1708
  apply(induct s arbitrary: r1 r2 rule: rev_induct)
Chengsong
parents: 417
diff changeset
  1709
   apply simp
Chengsong
parents: 417
diff changeset
  1710
  apply simp
Chengsong
parents: 417
diff changeset
  1711
417
a2887a9e8539 rdersetc.
Chengsong
parents: 409
diff changeset
  1712
  sorry
421
Chengsong
parents: 417
diff changeset
  1713
*)
Chengsong
parents: 417
diff changeset
  1714
427
Chengsong
parents: 422
diff changeset
  1715
421
Chengsong
parents: 417
diff changeset
  1716
Chengsong
parents: 417
diff changeset
  1717
fun rders_cond_list :: "rrexp \<Rightarrow> bool list \<Rightarrow> char list list \<Rightarrow> rrexp list"
Chengsong
parents: 417
diff changeset
  1718
  where
Chengsong
parents: 417
diff changeset
  1719
"rders_cond_list r2 (True # bs) (s # strs) = (rders r2 s) # (rders_cond_list r2 bs strs)"
Chengsong
parents: 417
diff changeset
  1720
| "rders_cond_list r2 (False # bs) (s # strs) = rders_cond_list r2 bs strs"
Chengsong
parents: 417
diff changeset
  1721
| "rders_cond_list r2 [] s = []"
Chengsong
parents: 417
diff changeset
  1722
| "rders_cond_list r2 bs [] = []"
Chengsong
parents: 417
diff changeset
  1723
Chengsong
parents: 417
diff changeset
  1724
fun nullable_bools :: "rrexp \<Rightarrow> char list list \<Rightarrow> bool list"
Chengsong
parents: 417
diff changeset
  1725
  where
Chengsong
parents: 417
diff changeset
  1726
"nullable_bools r (s#strs) = (rnullable (rders r s)) # (nullable_bools r strs) "
Chengsong
parents: 417
diff changeset
  1727
|"nullable_bools r [] = []"
417
a2887a9e8539 rdersetc.
Chengsong
parents: 409
diff changeset
  1728
427
Chengsong
parents: 422
diff changeset
  1729
thm rsimp_SEQ.simps
Chengsong
parents: 422
diff changeset
  1730
Chengsong
parents: 422
diff changeset
  1731
lemma idiot:
Chengsong
parents: 422
diff changeset
  1732
  shows "rsimp_SEQ RONE r = r"
Chengsong
parents: 422
diff changeset
  1733
  apply(case_tac r)
Chengsong
parents: 422
diff changeset
  1734
       apply simp_all
Chengsong
parents: 422
diff changeset
  1735
  done
Chengsong
parents: 422
diff changeset
  1736
Chengsong
parents: 422
diff changeset
  1737
lemma no_dup_after_simp:
Chengsong
parents: 422
diff changeset
  1738
  shows "RALTS rs = rsimp r \<Longrightarrow> distinct rs"
Chengsong
parents: 422
diff changeset
  1739
  sorry
Chengsong
parents: 422
diff changeset
  1740
Chengsong
parents: 422
diff changeset
  1741
lemma no_further_dB_after_simp:
Chengsong
parents: 422
diff changeset
  1742
  shows "RALTS rs = rsimp r \<Longrightarrow> rdistinct rs {} = rs"
Chengsong
parents: 422
diff changeset
  1743
  sorry
Chengsong
parents: 422
diff changeset
  1744
Chengsong
parents: 422
diff changeset
  1745
lemma longlist_withstands_rsimp_alts:
Chengsong
parents: 422
diff changeset
  1746
  shows "length rs \<ge> 2 \<Longrightarrow> rsimp_ALTs rs = RALTS rs"
Chengsong
parents: 422
diff changeset
  1747
  sorry
Chengsong
parents: 422
diff changeset
  1748
Chengsong
parents: 422
diff changeset
  1749
lemma no_alt_short_list_after_simp:
Chengsong
parents: 422
diff changeset
  1750
  shows "RALTS rs = rsimp r \<Longrightarrow> rsimp_ALTs rs = RALTS rs"
Chengsong
parents: 422
diff changeset
  1751
  sorry
Chengsong
parents: 422
diff changeset
  1752
Chengsong
parents: 422
diff changeset
  1753
lemma idiot2:
Chengsong
parents: 422
diff changeset
  1754
  shows " \<lbrakk>r1 \<noteq> RZERO; r1 \<noteq> RONE;r2 \<noteq> RZERO\<rbrakk>
Chengsong
parents: 422
diff changeset
  1755
    \<Longrightarrow> rsimp_SEQ r1 r2 = RSEQ r1 r2"
Chengsong
parents: 422
diff changeset
  1756
  apply(case_tac r1)
Chengsong
parents: 422
diff changeset
  1757
       apply(case_tac r2)
Chengsong
parents: 422
diff changeset
  1758
  apply simp_all
Chengsong
parents: 422
diff changeset
  1759
     apply(case_tac r2)
Chengsong
parents: 422
diff changeset
  1760
  apply simp_all
Chengsong
parents: 422
diff changeset
  1761
     apply(case_tac r2)
Chengsong
parents: 422
diff changeset
  1762
  apply simp_all
Chengsong
parents: 422
diff changeset
  1763
   apply(case_tac r2)
Chengsong
parents: 422
diff changeset
  1764
  apply simp_all
Chengsong
parents: 422
diff changeset
  1765
  apply(case_tac r2)
Chengsong
parents: 422
diff changeset
  1766
       apply simp_all
Chengsong
parents: 422
diff changeset
  1767
  done
Chengsong
parents: 422
diff changeset
  1768
Chengsong
parents: 422
diff changeset
  1769
lemma rsimp_aalts_another:
Chengsong
parents: 422
diff changeset
  1770
  shows "\<forall>r \<in> (set  (map rsimp  ((RSEQ (rders r1 s) r2) #
Chengsong
parents: 422
diff changeset
  1771
           (rders_cond_list r2 (nullable_bools r1 (orderedPref s))  (orderedSuf s))  )) ). (rsize r) < N "
Chengsong
parents: 422
diff changeset
  1772
  sorry
Chengsong
parents: 422
diff changeset
  1773
Chengsong
parents: 422
diff changeset
  1774
Chengsong
parents: 422
diff changeset
  1775
Chengsong
parents: 422
diff changeset
  1776
lemma shape_derssimpseq_onechar:
Chengsong
parents: 422
diff changeset
  1777
  shows " rerase  (bders_simp r [c]) = rerase (bsimp (bders r [c]))"
Chengsong
parents: 422
diff changeset
  1778
and "rders_simp (RSEQ r1 r2) [c] = 
Chengsong
parents: 422
diff changeset
  1779
         rsimp (RALTS  ((RSEQ (rders r1 [c]) r2) #
Chengsong
parents: 422
diff changeset
  1780
           (rders_cond_list r2 (nullable_bools r1 (orderedPref [c]))  (orderedSuf [c]))) )"
Chengsong
parents: 422
diff changeset
  1781
   apply simp
Chengsong
parents: 422
diff changeset
  1782
  apply(simp add: rders.simps)
Chengsong
parents: 422
diff changeset
  1783
  apply(case_tac "rsimp (rder c r1) = RZERO")
Chengsong
parents: 422
diff changeset
  1784
   apply auto
Chengsong
parents: 422
diff changeset
  1785
  apply(case_tac "rsimp (rder c r1) = RONE")
Chengsong
parents: 422
diff changeset
  1786
   apply auto
Chengsong
parents: 422
diff changeset
  1787
   apply(subgoal_tac "rsimp_SEQ RONE (rsimp r2) = rsimp r2")
Chengsong
parents: 422
diff changeset
  1788
  prefer 2
Chengsong
parents: 422
diff changeset
  1789
  using idiot
Chengsong
parents: 422
diff changeset
  1790
    apply simp
Chengsong
parents: 422
diff changeset
  1791
   apply(subgoal_tac "rsimp_SEQ RONE (rsimp r2) = rsimp_ALTs (rdistinct (rflts [rsimp r2]) {})")
Chengsong
parents: 422
diff changeset
  1792
    prefer 2
Chengsong
parents: 422
diff changeset
  1793
    apply auto
Chengsong
parents: 422
diff changeset
  1794
   apply(case_tac "rsimp r2")
Chengsong
parents: 422
diff changeset
  1795
        apply auto
Chengsong
parents: 422
diff changeset
  1796
   apply(subgoal_tac "rdistinct x5 {} = x5")
Chengsong
parents: 422
diff changeset
  1797
  prefer 2
Chengsong
parents: 422
diff changeset
  1798
  using no_further_dB_after_simp
Chengsong
parents: 422
diff changeset
  1799
    apply metis
Chengsong
parents: 422
diff changeset
  1800
   apply(subgoal_tac "rsimp_ALTs (rdistinct x5 {}) = rsimp_ALTs x5")
Chengsong
parents: 422
diff changeset
  1801
    prefer 2
Chengsong
parents: 422
diff changeset
  1802
    apply fastforce  
Chengsong
parents: 422
diff changeset
  1803
   apply auto
Chengsong
parents: 422
diff changeset
  1804
   apply (metis no_alt_short_list_after_simp)
Chengsong
parents: 422
diff changeset
  1805
  apply (case_tac "rsimp r2 = RZERO")
Chengsong
parents: 422
diff changeset
  1806
   apply(subgoal_tac "rsimp_SEQ (rsimp (rder c r1)) (rsimp r2) = RZERO")
Chengsong
parents: 422
diff changeset
  1807
    prefer 2
Chengsong
parents: 422
diff changeset
  1808
    apply(case_tac "rsimp ( rder c r1)")
Chengsong
parents: 422
diff changeset
  1809
         apply auto
Chengsong
parents: 422
diff changeset
  1810
  apply(subgoal_tac "rsimp_SEQ (rsimp (rder c r1)) (rsimp r2) = RSEQ (rsimp (rder c r1)) (rsimp r2)")
Chengsong
parents: 422
diff changeset
  1811
   prefer 2
Chengsong
parents: 422
diff changeset
  1812
   apply auto
Chengsong
parents: 422
diff changeset
  1813
  apply(metis idiot2)
Chengsong
parents: 422
diff changeset
  1814
  done
Chengsong
parents: 422
diff changeset
  1815
Chengsong
parents: 422
diff changeset
  1816
lemma rders__onechar:
Chengsong
parents: 422
diff changeset
  1817
  shows " (rders_simp r [c]) =  (rsimp (rders r [c]))"
Chengsong
parents: 422
diff changeset
  1818
  by simp
Chengsong
parents: 422
diff changeset
  1819
Chengsong
parents: 422
diff changeset
  1820
lemma rders_append:
Chengsong
parents: 422
diff changeset
  1821
  "rders c (s1 @ s2) = rders (rders c s1) s2"
Chengsong
parents: 422
diff changeset
  1822
  apply(induct s1 arbitrary: c s2)
Chengsong
parents: 422
diff changeset
  1823
  apply(simp_all)
Chengsong
parents: 422
diff changeset
  1824
  done
Chengsong
parents: 422
diff changeset
  1825
Chengsong
parents: 422
diff changeset
  1826
lemma rders_simp_append:
Chengsong
parents: 422
diff changeset
  1827
  "rders_simp c (s1 @ s2) = rders_simp (rders_simp c s1) s2"
Chengsong
parents: 422
diff changeset
  1828
  apply(induct s1 arbitrary: c s2)
Chengsong
parents: 422
diff changeset
  1829
  apply(simp_all)
Chengsong
parents: 422
diff changeset
  1830
  done
Chengsong
parents: 422
diff changeset
  1831
Chengsong
parents: 422
diff changeset
  1832
lemma inside_simp_removal:
Chengsong
parents: 422
diff changeset
  1833
  shows " rsimp (rder x (rsimp r)) = rsimp (rder x r)"
417
a2887a9e8539 rdersetc.
Chengsong
parents: 409
diff changeset
  1834
  
427
Chengsong
parents: 422
diff changeset
  1835
  sorry
Chengsong
parents: 422
diff changeset
  1836
Chengsong
parents: 422
diff changeset
  1837
lemma set_related_list:
Chengsong
parents: 422
diff changeset
  1838
  shows "distinct rs  \<Longrightarrow> length rs = card (set rs)"
Chengsong
parents: 422
diff changeset
  1839
  by (simp add: distinct_card)
Chengsong
parents: 422
diff changeset
  1840
(*this section deals with the property of distinctBy: creates a list without duplicates*)
Chengsong
parents: 422
diff changeset
  1841
lemma rdistinct_never_added_twice:
Chengsong
parents: 422
diff changeset
  1842
  shows "rdistinct (a # rs) {a} = rdistinct rs {a}"
Chengsong
parents: 422
diff changeset
  1843
  by force
Chengsong
parents: 422
diff changeset
  1844
Chengsong
parents: 422
diff changeset
  1845
Chengsong
parents: 422
diff changeset
  1846
lemma rdistinct_does_the_job:
Chengsong
parents: 422
diff changeset
  1847
  shows "distinct (rdistinct rs s)"
Chengsong
parents: 422
diff changeset
  1848
  apply(induct rs arbitrary: s)
Chengsong
parents: 422
diff changeset
  1849
   apply simp
Chengsong
parents: 422
diff changeset
  1850
  apply simp
Chengsong
parents: 422
diff changeset
  1851
  sorry
Chengsong
parents: 422
diff changeset
  1852
Chengsong
parents: 422
diff changeset
  1853
Chengsong
parents: 422
diff changeset
  1854
Chengsong
parents: 422
diff changeset
  1855
Chengsong
parents: 422
diff changeset
  1856
(*this section deals with the property of distinctBy: creates a list without duplicates*)
Chengsong
parents: 422
diff changeset
  1857
Chengsong
parents: 422
diff changeset
  1858
lemma rders_simp_same_simpders:
Chengsong
parents: 422
diff changeset
  1859
  shows "s \<noteq> [] \<Longrightarrow> rders_simp r s = rsimp (rders r s)"
Chengsong
parents: 422
diff changeset
  1860
  apply(induct s rule: rev_induct)
Chengsong
parents: 422
diff changeset
  1861
   apply simp
Chengsong
parents: 422
diff changeset
  1862
  apply(case_tac "xs = []")
Chengsong
parents: 422
diff changeset
  1863
   apply simp
Chengsong
parents: 422
diff changeset
  1864
  apply(simp add: rders_append rders_simp_append)
Chengsong
parents: 422
diff changeset
  1865
  using inside_simp_removal by blast
Chengsong
parents: 422
diff changeset
  1866
422
Chengsong
parents: 421
diff changeset
  1867
lemma shape_derssimp_seq:
427
Chengsong
parents: 422
diff changeset
  1868
  shows "\<lbrakk>s \<noteq>[] \<rbrakk> \<Longrightarrow>  (rders_simp r s) = (rsimp (rders r s))"
421
Chengsong
parents: 417
diff changeset
  1869
and "\<lbrakk>s \<noteq> []\<rbrakk> \<Longrightarrow> rders_simp (RSEQ r1 r2) s = 
Chengsong
parents: 417
diff changeset
  1870
         rsimp (RALTS  ((RSEQ (rders r1 s) r2) #
Chengsong
parents: 417
diff changeset
  1871
           (rders_cond_list r2 (nullable_bools r1 (orderedPref s))  (orderedSuf s))) )"
Chengsong
parents: 417
diff changeset
  1872
  apply(induct s arbitrary: r r1 r2 rule: rev_induct)
Chengsong
parents: 417
diff changeset
  1873
     apply simp
Chengsong
parents: 417
diff changeset
  1874
  apply simp
Chengsong
parents: 417
diff changeset
  1875
   apply(case_tac "xs = []")
Chengsong
parents: 417
diff changeset
  1876
Chengsong
parents: 417
diff changeset
  1877
   apply (simp add: bders_simp_append )
Chengsong
parents: 417
diff changeset
  1878
   apply(subgoal_tac "rerase (bsimp (bder x (bders_simp r xs))) = (rsimp (rerase (bder x (bders_simp r xs)))) ")
Chengsong
parents: 417
diff changeset
  1879
    prefer 2
Chengsong
parents: 417
diff changeset
  1880
    apply (simp add: rerase_bsimp)
Chengsong
parents: 417
diff changeset
  1881
   apply(subgoal_tac "(rsimp (rerase (bder x (bders_simp r xs)))) = (rsimp (rder x (rerase (bders_simp r xs))))")
Chengsong
parents: 417
diff changeset
  1882
   
Chengsong
parents: 417
diff changeset
  1883
    apply(subgoal_tac "xs \<noteq> [] \<Longrightarrow> rsimp (rder x (rerase (bders_simp r xs))) = rsimp (rder x (rerase (bsimp (bders r xs))))")
Chengsong
parents: 417
diff changeset
  1884
  prefer 2
427
Chengsong
parents: 422
diff changeset
  1885
     apply presburger
Chengsong
parents: 422
diff changeset
  1886
  apply(case_tac "xs = []")
421
Chengsong
parents: 417
diff changeset
  1887
  sorry
417
a2887a9e8539 rdersetc.
Chengsong
parents: 409
diff changeset
  1888
427
Chengsong
parents: 422
diff changeset
  1889
422
Chengsong
parents: 421
diff changeset
  1890
lemma shape_derssimp_alts:
427
Chengsong
parents: 422
diff changeset
  1891
  shows "s \<noteq> [] \<Longrightarrow> rders_simp (RALTS rs) s = rsimp (RALTS (map (\<lambda>r. rders r s) rs))"
Chengsong
parents: 422
diff changeset
  1892
  apply(case_tac "s")
Chengsong
parents: 422
diff changeset
  1893
   apply simp
Chengsong
parents: 422
diff changeset
  1894
  apply simp
Chengsong
parents: 422
diff changeset
  1895
  sorry
428
Chengsong
parents: 427
diff changeset
  1896
(*
Chengsong
parents: 427
diff changeset
  1897
fun rexp_encode :: "rrexp \<Rightarrow> nat"
Chengsong
parents: 427
diff changeset
  1898
  where
Chengsong
parents: 427
diff changeset
  1899
"rexp_encode RZERO = 0"
Chengsong
parents: 427
diff changeset
  1900
|"rexp_encode RONE = 1"
Chengsong
parents: 427
diff changeset
  1901
|"rexp_encode (RCHAR c) = 2"
Chengsong
parents: 427
diff changeset
  1902
|"rexp_encode (RSEQ r1 r2) = ( 2 ^ (rexp_encode r1)) "
Chengsong
parents: 427
diff changeset
  1903
*)
Chengsong
parents: 427
diff changeset
  1904
lemma finite_chars:
Chengsong
parents: 427
diff changeset
  1905
  shows " \<exists>N. ( (\<forall>r \<in> (set rs). \<exists>c. r = RCHAR c) \<and> (distinct rs) \<longrightarrow> length rs < N)"
Chengsong
parents: 427
diff changeset
  1906
  apply(rule_tac x = "Suc 256" in exI)
Chengsong
parents: 427
diff changeset
  1907
  sorry
Chengsong
parents: 427
diff changeset
  1908
430
Chengsong
parents: 428
diff changeset
  1909
definition all_chars :: "int \<Rightarrow> char list"
Chengsong
parents: 428
diff changeset
  1910
  where "all_chars n = map char_of [0..n]"
428
Chengsong
parents: 427
diff changeset
  1911
Chengsong
parents: 427
diff changeset
  1912
fun rexp_enum :: "nat \<Rightarrow> rrexp list"
Chengsong
parents: 427
diff changeset
  1913
  where 
Chengsong
parents: 427
diff changeset
  1914
"rexp_enum 0 = []"
430
Chengsong
parents: 428
diff changeset
  1915
|"rexp_enum (Suc 0) =  RALTS [] # RZERO # (RONE # (map RCHAR (all_chars 255)))"
Chengsong
parents: 428
diff changeset
  1916
|"rexp_enum (Suc n) = [(RSEQ r1 r2). r1 \<in> set (rexp_enum i) \<and> r2 \<in> set (rexp_enum j) \<and> i + j = n]"
Chengsong
parents: 428
diff changeset
  1917
428
Chengsong
parents: 427
diff changeset
  1918
Chengsong
parents: 427
diff changeset
  1919
lemma finite_sized_rexp_forms_finite_set:
Chengsong
parents: 427
diff changeset
  1920
  shows " \<exists>SN. ( \<forall>r.( rsize r < N \<longrightarrow> r \<in> SN)) \<and> (finite SN)"
Chengsong
parents: 427
diff changeset
  1921
  apply(induct N)
Chengsong
parents: 427
diff changeset
  1922
   apply simp
Chengsong
parents: 427
diff changeset
  1923
   apply auto
Chengsong
parents: 427
diff changeset
  1924
 (*\<lbrakk>\<forall>r. rsize r < N \<longrightarrow> r \<in> SN; finite SN\<rbrakk> \<Longrightarrow> \<exists>SN. (\<forall>r. rsize r < Suc N \<longrightarrow> r \<in> SN) \<and> finite SN*)
Chengsong
parents: 427
diff changeset
  1925
 (* \<And>N. \<exists>SN. (\<forall>r. rsize r < N \<longrightarrow> r \<in> SN) \<and> finite SN \<Longrightarrow> \<exists>SN. (\<forall>r. rsize r < Suc N \<longrightarrow> r \<in> SN) \<and> finite SN*)
Chengsong
parents: 427
diff changeset
  1926
  sorry
422
Chengsong
parents: 421
diff changeset
  1927
Chengsong
parents: 421
diff changeset
  1928
421
Chengsong
parents: 417
diff changeset
  1929
lemma finite_size_finite_regx:
428
Chengsong
parents: 427
diff changeset
  1930
  shows " \<exists>l. \<forall>rs. ((\<forall>r \<in> (set rs). rsize r < N) \<and> (distinct rs) \<longrightarrow> (length rs) < l) "
430
Chengsong
parents: 428
diff changeset
  1931
  sorry
421
Chengsong
parents: 417
diff changeset
  1932
Chengsong
parents: 417
diff changeset
  1933
(*below  probably needs proved concurrently*)
Chengsong
parents: 417
diff changeset
  1934
Chengsong
parents: 417
diff changeset
  1935
lemma finite_r1r2_ders_list:
427
Chengsong
parents: 422
diff changeset
  1936
  shows "(\<forall>s. rsize (rders_simp r1 s) < N1 \<and> rsize (rders_simp r2 s) < N2)
Chengsong
parents: 422
diff changeset
  1937
           \<Longrightarrow>  \<exists>l. \<forall>s.
Chengsong
parents: 422
diff changeset
  1938
(length (rdistinct  (map rsimp (rders_cond_list r2 (nullable_bools r1 (orderedPref s))  (orderedSuf s))) {}) )  < l "
421
Chengsong
parents: 417
diff changeset
  1939
  sorry
Chengsong
parents: 417
diff changeset
  1940
427
Chengsong
parents: 422
diff changeset
  1941
(*
Chengsong
parents: 422
diff changeset
  1942
\<lbrakk>s \<noteq> []\<rbrakk> \<Longrightarrow> rders_simp (RSEQ r1 r2) s = 
Chengsong
parents: 422
diff changeset
  1943
         rsimp (RALTS  ((RSEQ (rders r1 s) r2) #
Chengsong
parents: 422
diff changeset
  1944
           (rders_cond_list r2 (nullable_bools r1 (orderedPref s))  (orderedSuf s))) )
Chengsong
parents: 422
diff changeset
  1945
*)
Chengsong
parents: 422
diff changeset
  1946
Chengsong
parents: 422
diff changeset
  1947
lemma finite_width_alt:
Chengsong
parents: 422
diff changeset
  1948
  shows "(\<forall>s. rsize (rders_simp r1 s) < N1 \<and> rsize (rders_simp r2 s) < N2) 
Chengsong
parents: 422
diff changeset
  1949
      \<Longrightarrow> \<exists>N3. \<forall>s.  rsize (rsimp (RALTS  ((RSEQ (rders r1 s) r2) #
Chengsong
parents: 422
diff changeset
  1950
           (rders_cond_list r2 (nullable_bools r1 (orderedPref s))  (orderedSuf s))) )) < N3"
Chengsong
parents: 422
diff changeset
  1951
Chengsong
parents: 422
diff changeset
  1952
  sorry
Chengsong
parents: 422
diff changeset
  1953
Chengsong
parents: 422
diff changeset
  1954
Chengsong
parents: 422
diff changeset
  1955
lemma empty_diff:
Chengsong
parents: 422
diff changeset
  1956
  shows "s = [] \<Longrightarrow>
Chengsong
parents: 422
diff changeset
  1957
        (rsize (rders_simp (RSEQ r1 r2) s)) \<le> 
Chengsong
parents: 422
diff changeset
  1958
        (max 
Chengsong
parents: 422
diff changeset
  1959
        (rsize (rsimp (RALTS (RSEQ (rders r1 s) r2 # rders_cond_list r2 (nullable_bools r1 (orderedPref s)) (orderedSuf s)))))
Chengsong
parents: 422
diff changeset
  1960
        (Suc (rsize r1 + rsize r2)) ) "
Chengsong
parents: 422
diff changeset
  1961
  apply simp
Chengsong
parents: 422
diff changeset
  1962
  done
Chengsong
parents: 422
diff changeset
  1963
421
Chengsong
parents: 417
diff changeset
  1964
lemma finite_seq:
Chengsong
parents: 417
diff changeset
  1965
  shows "(\<forall>s. rsize (rders_simp r1 s) < N1 \<and> rsize (rders_simp r2 s) < N2)
Chengsong
parents: 417
diff changeset
  1966
           \<Longrightarrow> \<exists>N3.\<forall>s.(rsize (rders_simp (RSEQ r1 r2) s)) < N3"
427
Chengsong
parents: 422
diff changeset
  1967
  apply(frule finite_width_alt)
Chengsong
parents: 422
diff changeset
  1968
  apply(erule exE)
Chengsong
parents: 422
diff changeset
  1969
  apply(rule_tac x = "max (N3+2) (Suc (Suc (rsize r1) + (rsize r2)))" in exI)
Chengsong
parents: 422
diff changeset
  1970
  apply(rule allI)
Chengsong
parents: 422
diff changeset
  1971
  apply(case_tac "s = []")
Chengsong
parents: 422
diff changeset
  1972
  prefer 2
Chengsong
parents: 422
diff changeset
  1973
   apply (simp add: less_SucI shape_derssimp_seq(2))
Chengsong
parents: 422
diff changeset
  1974
   apply (meson less_SucI less_max_iff_disj)
Chengsong
parents: 422
diff changeset
  1975
  apply simp
Chengsong
parents: 422
diff changeset
  1976
  done
Chengsong
parents: 422
diff changeset
  1977
Chengsong
parents: 422
diff changeset
  1978
Chengsong
parents: 422
diff changeset
  1979
(*For star related error bound*)
Chengsong
parents: 422
diff changeset
  1980
Chengsong
parents: 422
diff changeset
  1981
lemma star_is_a_singleton_list_derc:
Chengsong
parents: 422
diff changeset
  1982
  shows " \<exists>Ss.  rders_simp (RSTAR r) [c] = rsimp_ALTs (map (\<lambda>s1.  rsimp_SEQ (rders_simp r s1) (RSTAR r)) Ss)"
Chengsong
parents: 422
diff changeset
  1983
  apply simp
Chengsong
parents: 422
diff changeset
  1984
  apply(rule_tac x = "[[c]]" in exI)
Chengsong
parents: 422
diff changeset
  1985
  apply auto
Chengsong
parents: 422
diff changeset
  1986
  done
Chengsong
parents: 422
diff changeset
  1987
Chengsong
parents: 422
diff changeset
  1988
lemma rder_rsimp_ALTs_commute:
Chengsong
parents: 422
diff changeset
  1989
  shows "  (rder x (rsimp_ALTs rs)) = rsimp_ALTs (map (rder x) rs)"
Chengsong
parents: 422
diff changeset
  1990
  apply(induct rs)
Chengsong
parents: 422
diff changeset
  1991
   apply simp
Chengsong
parents: 422
diff changeset
  1992
  apply(case_tac rs)
Chengsong
parents: 422
diff changeset
  1993
   apply simp
Chengsong
parents: 422
diff changeset
  1994
  apply auto
Chengsong
parents: 422
diff changeset
  1995
  done
Chengsong
parents: 422
diff changeset
  1996
Chengsong
parents: 422
diff changeset
  1997
lemma double_nested_ALTs_under_rsimp:
Chengsong
parents: 422
diff changeset
  1998
  shows "rsimp (rsimp_ALTs ((RALTS rs1) # rs)) = rsimp (RALTS (rs1 @ rs))"
Chengsong
parents: 422
diff changeset
  1999
  apply(case_tac rs1)
Chengsong
parents: 422
diff changeset
  2000
  apply simp
Chengsong
parents: 422
diff changeset
  2001
  
Chengsong
parents: 422
diff changeset
  2002
   apply (metis list.simps(8) list.simps(9) neq_Nil_conv rdistinct.simps(1) rflts.simps(1) rflts.simps(2) rsimp.simps(2) rsimp_ALTs.simps(1) rsimp_ALTs.simps(2) rsimp_ALTs.simps(3))
Chengsong
parents: 422
diff changeset
  2003
  apply(case_tac rs)
Chengsong
parents: 422
diff changeset
  2004
   apply simp
Chengsong
parents: 422
diff changeset
  2005
  apply auto
421
Chengsong
parents: 417
diff changeset
  2006
  sorry
Chengsong
parents: 417
diff changeset
  2007
427
Chengsong
parents: 422
diff changeset
  2008
lemma star_seqs_produce_star_seqs:
Chengsong
parents: 422
diff changeset
  2009
  shows "rsimp (rsimp_ALTs (map (rder x \<circ> (\<lambda>s1. rsimp_SEQ (rders_simp r s1) (RSTAR r))) Ss))
Chengsong
parents: 422
diff changeset
  2010
       = rsimp (rsimp_ALTs (map ( (\<lambda>s1. rder x (rsimp_SEQ (rders_simp r s1) (RSTAR r)))) Ss))"
Chengsong
parents: 422
diff changeset
  2011
  by (meson comp_apply)
Chengsong
parents: 422
diff changeset
  2012
Chengsong
parents: 422
diff changeset
  2013
lemma der_seqstar_res:
428
Chengsong
parents: 427
diff changeset
  2014
  shows "rder x (RSEQ r1 r2) = RSEQ r3 r4"
427
Chengsong
parents: 422
diff changeset
  2015
Chengsong
parents: 422
diff changeset
  2016
Chengsong
parents: 422
diff changeset
  2017
lemma linearity_of_list_of_star_or_starseqs:
Chengsong
parents: 422
diff changeset
  2018
  shows "\<exists>Ssa. rsimp (rder x (rsimp_ALTs (map (\<lambda>s1. rsimp_SEQ (rders_simp r s1) (RSTAR r)) Ss))) =
Chengsong
parents: 422
diff changeset
  2019
                 rsimp_ALTs (map (\<lambda>s1. rsimp_SEQ (rders_simp r s1) (RSTAR r)) Ssa)"
Chengsong
parents: 422
diff changeset
  2020
  apply(simp add: rder_rsimp_ALTs_commute)
Chengsong
parents: 422
diff changeset
  2021
  apply(induct Ss)
Chengsong
parents: 422
diff changeset
  2022
   apply simp
Chengsong
parents: 422
diff changeset
  2023
   apply (metis list.simps(8) rsimp_ALTs.simps(1))
Chengsong
parents: 422
diff changeset
  2024
428
Chengsong
parents: 427
diff changeset
  2025
427
Chengsong
parents: 422
diff changeset
  2026
  sorry
Chengsong
parents: 422
diff changeset
  2027
Chengsong
parents: 422
diff changeset
  2028
lemma starder_is_a_list_of_stars_or_starseqs:
Chengsong
parents: 422
diff changeset
  2029
  shows "s \<noteq> [] \<Longrightarrow> \<exists>Ss.  rders_simp (RSTAR r) s = rsimp_ALTs (map (\<lambda>s1.  rsimp_SEQ (rders_simp r s1) (RSTAR r)) Ss)"
Chengsong
parents: 422
diff changeset
  2030
  apply(induct s rule: rev_induct)
Chengsong
parents: 422
diff changeset
  2031
  apply simp
Chengsong
parents: 422
diff changeset
  2032
  apply(case_tac "xs = []")
Chengsong
parents: 422
diff changeset
  2033
  using star_is_a_singleton_list_derc
Chengsong
parents: 422
diff changeset
  2034
  apply(simp)
Chengsong
parents: 422
diff changeset
  2035
  apply auto
Chengsong
parents: 422
diff changeset
  2036
  apply(simp add: rders_simp_append)
Chengsong
parents: 422
diff changeset
  2037
  using linearity_of_list_of_star_or_starseqs by blast
Chengsong
parents: 422
diff changeset
  2038
421
Chengsong
parents: 417
diff changeset
  2039
422
Chengsong
parents: 421
diff changeset
  2040
lemma finite_star:
Chengsong
parents: 421
diff changeset
  2041
  shows "(\<forall>s. rsize (rders_simp r0 s) < N0 )
Chengsong
parents: 421
diff changeset
  2042
           \<Longrightarrow> \<exists>N3. \<forall>s.(rsize (rders_simp (RSTAR r0) s)) < N3"
427
Chengsong
parents: 422
diff changeset
  2043
422
Chengsong
parents: 421
diff changeset
  2044
  sorry
Chengsong
parents: 421
diff changeset
  2045
Chengsong
parents: 421
diff changeset
  2046
Chengsong
parents: 421
diff changeset
  2047
lemma rderssimp_zero:
Chengsong
parents: 421
diff changeset
  2048
  shows"rders_simp RZERO s = RZERO"
Chengsong
parents: 421
diff changeset
  2049
  apply(induction s)
Chengsong
parents: 421
diff changeset
  2050
  apply simp
Chengsong
parents: 421
diff changeset
  2051
  by simp
Chengsong
parents: 421
diff changeset
  2052
Chengsong
parents: 421
diff changeset
  2053
lemma rderssimp_one:
Chengsong
parents: 421
diff changeset
  2054
  shows"rders_simp RONE (a # s) = RZERO"
Chengsong
parents: 421
diff changeset
  2055
  apply(induction s)
Chengsong
parents: 421
diff changeset
  2056
  apply simp
Chengsong
parents: 421
diff changeset
  2057
  by simp
Chengsong
parents: 421
diff changeset
  2058
Chengsong
parents: 421
diff changeset
  2059
lemma rderssimp_char:
Chengsong
parents: 421
diff changeset
  2060
  shows "rders_simp (RCHAR c) s = RONE \<or> rders_simp (RCHAR c) s = RZERO \<or> rders_simp (RCHAR c) s = (RCHAR c)"
Chengsong
parents: 421
diff changeset
  2061
  apply auto
Chengsong
parents: 421
diff changeset
  2062
  by (metis rder.simps(2) rder.simps(3) rders_simp.elims rders_simp.simps(2) rderssimp_one rsimp.simps(4))
Chengsong
parents: 421
diff changeset
  2063
421
Chengsong
parents: 417
diff changeset
  2064
lemma finite_size_ders:
422
Chengsong
parents: 421
diff changeset
  2065
  shows " \<exists>Nr. \<forall>s. rsize (rders_simp r s) < Nr"
Chengsong
parents: 421
diff changeset
  2066
  apply(induct r rule: rrexp.induct)
Chengsong
parents: 421
diff changeset
  2067
       apply auto
Chengsong
parents: 421
diff changeset
  2068
  apply(rule_tac x = "2" in exI)
Chengsong
parents: 421
diff changeset
  2069
  using rderssimp_zero rsize.simps(1) apply presburger
Chengsong
parents: 421
diff changeset
  2070
      apply(rule_tac x = "2" in exI)
Chengsong
parents: 421
diff changeset
  2071
      apply (metis Suc_1 lessI rders_simp.elims rderssimp_one rsize.simps(1) rsize.simps(2))
Chengsong
parents: 421
diff changeset
  2072
     apply(rule_tac x = "2" in meta_spec)
Chengsong
parents: 421
diff changeset
  2073
     apply (metis lessI rderssimp_char rsize.simps(1) rsize.simps(2) rsize.simps(3))
Chengsong
parents: 421
diff changeset
  2074
  
Chengsong
parents: 421
diff changeset
  2075
  using finite_seq apply blast
Chengsong
parents: 421
diff changeset
  2076
   prefer 2
Chengsong
parents: 421
diff changeset
  2077
Chengsong
parents: 421
diff changeset
  2078
   apply (simp add: finite_star)
421
Chengsong
parents: 417
diff changeset
  2079
  sorry
409
Chengsong
parents:
diff changeset
  2080
Chengsong
parents:
diff changeset
  2081
Chengsong
parents:
diff changeset
  2082
unused_thms
417
a2887a9e8539 rdersetc.
Chengsong
parents: 409
diff changeset
  2083
lemma seq_ders_shape:
a2887a9e8539 rdersetc.
Chengsong
parents: 409
diff changeset
  2084
  shows "E"
a2887a9e8539 rdersetc.
Chengsong
parents: 409
diff changeset
  2085
a2887a9e8539 rdersetc.
Chengsong
parents: 409
diff changeset
  2086
  oops
a2887a9e8539 rdersetc.
Chengsong
parents: 409
diff changeset
  2087
a2887a9e8539 rdersetc.
Chengsong
parents: 409
diff changeset
  2088
(*rsimp (rders (RSEQ r1 r2) s) =
a2887a9e8539 rdersetc.
Chengsong
parents: 409
diff changeset
  2089
         rsimp RALT [RSEQ (rders r1 s) r2, rders r2 si, ...]
a2887a9e8539 rdersetc.
Chengsong
parents: 409
diff changeset
  2090
         where si is the i-th shortest suffix of s such that si \<in> L r2"
a2887a9e8539 rdersetc.
Chengsong
parents: 409
diff changeset
  2091
*)
409
Chengsong
parents:
diff changeset
  2092
Chengsong
parents:
diff changeset
  2093
Chengsong
parents:
diff changeset
  2094
inductive aggressive:: "arexp \<Rightarrow> arexp \<Rightarrow> bool" ("_ \<leadsto>? _" [99, 99] 99)
Chengsong
parents:
diff changeset
  2095
  where
Chengsong
parents:
diff changeset
  2096
 "ASEQ bs (AALTs bs1 rs) r \<leadsto>? AALTs (bs@bs1) (map (\<lambda>r'. ASEQ [] r' r) rs) "
Chengsong
parents:
diff changeset
  2097
Chengsong
parents:
diff changeset
  2098
Chengsong
parents:
diff changeset
  2099
Chengsong
parents:
diff changeset
  2100
end