thys3/BlexerSimp.thy
author Chengsong
Thu, 23 Jun 2022 16:59:58 +0100
changeset 546 6e97f4aa7cd0
parent 545 333013923c5a
child 547 feae84f66472
permissions -rw-r--r--
beforeBig changes
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
544
Chengsong
parents:
diff changeset
     1
theory BlexerSimp
Chengsong
parents:
diff changeset
     2
  imports Blexer 
Chengsong
parents:
diff changeset
     3
begin
Chengsong
parents:
diff changeset
     4
Chengsong
parents:
diff changeset
     5
fun distinctWith :: "'a list \<Rightarrow> ('a \<Rightarrow> 'a \<Rightarrow> bool) \<Rightarrow> 'a set \<Rightarrow> 'a list"
Chengsong
parents:
diff changeset
     6
  where
Chengsong
parents:
diff changeset
     7
  "distinctWith [] eq acc = []"
Chengsong
parents:
diff changeset
     8
| "distinctWith (x # xs) eq acc = 
Chengsong
parents:
diff changeset
     9
     (if (\<exists> y \<in> acc. eq x y) then distinctWith xs eq acc 
Chengsong
parents:
diff changeset
    10
      else x # (distinctWith xs eq ({x} \<union> acc)))"
Chengsong
parents:
diff changeset
    11
Chengsong
parents:
diff changeset
    12
Chengsong
parents:
diff changeset
    13
fun eq1 ("_ ~1 _" [80, 80] 80) where  
Chengsong
parents:
diff changeset
    14
  "AZERO ~1 AZERO = True"
Chengsong
parents:
diff changeset
    15
| "(AONE bs1) ~1 (AONE bs2) = True"
Chengsong
parents:
diff changeset
    16
| "(ACHAR bs1 c) ~1 (ACHAR bs2 d) = (if c = d then True else False)"
Chengsong
parents:
diff changeset
    17
| "(ASEQ bs1 ra1 ra2) ~1 (ASEQ bs2 rb1 rb2) = (ra1 ~1 rb1 \<and> ra2 ~1 rb2)"
Chengsong
parents:
diff changeset
    18
| "(AALTs bs1 []) ~1 (AALTs bs2 []) = True"
Chengsong
parents:
diff changeset
    19
| "(AALTs bs1 (r1 # rs1)) ~1 (AALTs bs2 (r2 # rs2)) = (r1 ~1 r2 \<and> (AALTs bs1 rs1) ~1 (AALTs bs2 rs2))"
Chengsong
parents:
diff changeset
    20
| "(ASTAR bs1 r1) ~1 (ASTAR bs2 r2) = r1 ~1 r2"
Chengsong
parents:
diff changeset
    21
| "_ ~1 _ = False"
Chengsong
parents:
diff changeset
    22
Chengsong
parents:
diff changeset
    23
Chengsong
parents:
diff changeset
    24
Chengsong
parents:
diff changeset
    25
lemma eq1_L:
Chengsong
parents:
diff changeset
    26
  assumes "x ~1 y"
Chengsong
parents:
diff changeset
    27
  shows "L (erase x) = L (erase y)"
Chengsong
parents:
diff changeset
    28
  using assms
Chengsong
parents:
diff changeset
    29
  apply(induct rule: eq1.induct)
Chengsong
parents:
diff changeset
    30
  apply(auto elim: eq1.elims)
Chengsong
parents:
diff changeset
    31
  apply presburger
Chengsong
parents:
diff changeset
    32
  done
Chengsong
parents:
diff changeset
    33
Chengsong
parents:
diff changeset
    34
fun flts :: "arexp list \<Rightarrow> arexp list"
Chengsong
parents:
diff changeset
    35
  where 
Chengsong
parents:
diff changeset
    36
  "flts [] = []"
Chengsong
parents:
diff changeset
    37
| "flts (AZERO # rs) = flts rs"
Chengsong
parents:
diff changeset
    38
| "flts ((AALTs bs  rs1) # rs) = (map (fuse bs) rs1) @ flts rs"
Chengsong
parents:
diff changeset
    39
| "flts (r1 # rs) = r1 # flts rs"
Chengsong
parents:
diff changeset
    40
Chengsong
parents:
diff changeset
    41
Chengsong
parents:
diff changeset
    42
Chengsong
parents:
diff changeset
    43
fun bsimp_ASEQ :: "bit list \<Rightarrow> arexp \<Rightarrow> arexp \<Rightarrow> arexp"
Chengsong
parents:
diff changeset
    44
  where
Chengsong
parents:
diff changeset
    45
  "bsimp_ASEQ _ AZERO _ = AZERO"
Chengsong
parents:
diff changeset
    46
| "bsimp_ASEQ _ _ AZERO = AZERO"
Chengsong
parents:
diff changeset
    47
| "bsimp_ASEQ bs1 (AONE bs2) r2 = fuse (bs1 @ bs2) r2"
Chengsong
parents:
diff changeset
    48
| "bsimp_ASEQ bs1 r1 r2 = ASEQ  bs1 r1 r2"
Chengsong
parents:
diff changeset
    49
Chengsong
parents:
diff changeset
    50
lemma bsimp_ASEQ0[simp]:
Chengsong
parents:
diff changeset
    51
  shows "bsimp_ASEQ bs r1 AZERO = AZERO"
Chengsong
parents:
diff changeset
    52
  by (case_tac r1)(simp_all)
Chengsong
parents:
diff changeset
    53
Chengsong
parents:
diff changeset
    54
lemma bsimp_ASEQ1:
Chengsong
parents:
diff changeset
    55
  assumes "r1 \<noteq> AZERO" "r2 \<noteq> AZERO" "\<nexists>bs. r1 = AONE bs"
Chengsong
parents:
diff changeset
    56
  shows "bsimp_ASEQ bs r1 r2 = ASEQ bs r1 r2"
Chengsong
parents:
diff changeset
    57
  using assms
Chengsong
parents:
diff changeset
    58
  apply(induct bs r1 r2 rule: bsimp_ASEQ.induct)
Chengsong
parents:
diff changeset
    59
  apply(auto)
Chengsong
parents:
diff changeset
    60
  done
Chengsong
parents:
diff changeset
    61
Chengsong
parents:
diff changeset
    62
lemma bsimp_ASEQ2[simp]:
Chengsong
parents:
diff changeset
    63
  shows "bsimp_ASEQ bs1 (AONE bs2) r2 = fuse (bs1 @ bs2) r2"
Chengsong
parents:
diff changeset
    64
  by (case_tac r2) (simp_all)
Chengsong
parents:
diff changeset
    65
Chengsong
parents:
diff changeset
    66
Chengsong
parents:
diff changeset
    67
fun bsimp_AALTs :: "bit list \<Rightarrow> arexp list \<Rightarrow> arexp"
Chengsong
parents:
diff changeset
    68
  where
Chengsong
parents:
diff changeset
    69
  "bsimp_AALTs _ [] = AZERO"
Chengsong
parents:
diff changeset
    70
| "bsimp_AALTs bs1 [r] = fuse bs1 r"
Chengsong
parents:
diff changeset
    71
| "bsimp_AALTs bs1 rs = AALTs bs1 rs"
Chengsong
parents:
diff changeset
    72
Chengsong
parents:
diff changeset
    73
Chengsong
parents:
diff changeset
    74
Chengsong
parents:
diff changeset
    75
Chengsong
parents:
diff changeset
    76
fun bsimp :: "arexp \<Rightarrow> arexp" 
Chengsong
parents:
diff changeset
    77
  where
Chengsong
parents:
diff changeset
    78
  "bsimp (ASEQ bs1 r1 r2) = bsimp_ASEQ bs1 (bsimp r1) (bsimp r2)"
Chengsong
parents:
diff changeset
    79
| "bsimp (AALTs bs1 rs) = bsimp_AALTs bs1 (distinctWith (flts (map bsimp rs)) eq1 {}) "
Chengsong
parents:
diff changeset
    80
| "bsimp r = r"
Chengsong
parents:
diff changeset
    81
Chengsong
parents:
diff changeset
    82
Chengsong
parents:
diff changeset
    83
fun 
Chengsong
parents:
diff changeset
    84
  bders_simp :: "arexp \<Rightarrow> string \<Rightarrow> arexp"
Chengsong
parents:
diff changeset
    85
where
Chengsong
parents:
diff changeset
    86
  "bders_simp r [] = r"
Chengsong
parents:
diff changeset
    87
| "bders_simp r (c # s) = bders_simp (bsimp (bder c r)) s"
Chengsong
parents:
diff changeset
    88
Chengsong
parents:
diff changeset
    89
definition blexer_simp where
Chengsong
parents:
diff changeset
    90
 "blexer_simp r s \<equiv> if bnullable (bders_simp (intern r) s) then 
Chengsong
parents:
diff changeset
    91
                    decode (bmkeps (bders_simp (intern r) s)) r else None"
Chengsong
parents:
diff changeset
    92
Chengsong
parents:
diff changeset
    93
Chengsong
parents:
diff changeset
    94
Chengsong
parents:
diff changeset
    95
lemma bders_simp_append:
Chengsong
parents:
diff changeset
    96
  shows "bders_simp r (s1 @ s2) = bders_simp (bders_simp r s1) s2"
Chengsong
parents:
diff changeset
    97
  apply(induct s1 arbitrary: r s2)
Chengsong
parents:
diff changeset
    98
  apply(simp_all)
Chengsong
parents:
diff changeset
    99
  done
Chengsong
parents:
diff changeset
   100
Chengsong
parents:
diff changeset
   101
lemma bmkeps_fuse:
Chengsong
parents:
diff changeset
   102
  assumes "bnullable r"
Chengsong
parents:
diff changeset
   103
  shows "bmkeps (fuse bs r) = bs @ bmkeps r"
Chengsong
parents:
diff changeset
   104
  using assms
Chengsong
parents:
diff changeset
   105
  by (induct r rule: bnullable.induct) (auto)
Chengsong
parents:
diff changeset
   106
Chengsong
parents:
diff changeset
   107
lemma bmkepss_fuse: 
Chengsong
parents:
diff changeset
   108
  assumes "bnullables rs"
Chengsong
parents:
diff changeset
   109
  shows "bmkepss (map (fuse bs) rs) = bs @ bmkepss rs"
Chengsong
parents:
diff changeset
   110
  using assms
Chengsong
parents:
diff changeset
   111
  apply(induct rs arbitrary: bs)
Chengsong
parents:
diff changeset
   112
  apply(auto simp add: bmkeps_fuse bnullable_fuse)
Chengsong
parents:
diff changeset
   113
  done
Chengsong
parents:
diff changeset
   114
Chengsong
parents:
diff changeset
   115
lemma bder_fuse:
Chengsong
parents:
diff changeset
   116
  shows "bder c (fuse bs a) = fuse bs  (bder c a)"
Chengsong
parents:
diff changeset
   117
  apply(induct a arbitrary: bs c)
Chengsong
parents:
diff changeset
   118
  apply(simp_all)
Chengsong
parents:
diff changeset
   119
  done
Chengsong
parents:
diff changeset
   120
Chengsong
parents:
diff changeset
   121
Chengsong
parents:
diff changeset
   122
Chengsong
parents:
diff changeset
   123
Chengsong
parents:
diff changeset
   124
inductive 
Chengsong
parents:
diff changeset
   125
  rrewrite:: "arexp \<Rightarrow> arexp \<Rightarrow> bool" ("_ \<leadsto> _" [99, 99] 99)
Chengsong
parents:
diff changeset
   126
and 
Chengsong
parents:
diff changeset
   127
  srewrite:: "arexp list \<Rightarrow> arexp list \<Rightarrow> bool" (" _ s\<leadsto> _" [100, 100] 100)
Chengsong
parents:
diff changeset
   128
where
Chengsong
parents:
diff changeset
   129
  bs1: "ASEQ bs AZERO r2 \<leadsto> AZERO"
Chengsong
parents:
diff changeset
   130
| bs2: "ASEQ bs r1 AZERO \<leadsto> AZERO"
Chengsong
parents:
diff changeset
   131
| bs3: "ASEQ bs1 (AONE bs2) r \<leadsto> fuse (bs1@bs2) r"
Chengsong
parents:
diff changeset
   132
| bs4: "r1 \<leadsto> r2 \<Longrightarrow> ASEQ bs r1 r3 \<leadsto> ASEQ bs r2 r3"
Chengsong
parents:
diff changeset
   133
| bs5: "r3 \<leadsto> r4 \<Longrightarrow> ASEQ bs r1 r3 \<leadsto> ASEQ bs r1 r4"
Chengsong
parents:
diff changeset
   134
| bs6: "AALTs bs [] \<leadsto> AZERO"
Chengsong
parents:
diff changeset
   135
| bs7: "AALTs bs [r] \<leadsto> fuse bs r"
Chengsong
parents:
diff changeset
   136
| bs10: "rs1 s\<leadsto> rs2 \<Longrightarrow> AALTs bs rs1 \<leadsto> AALTs bs rs2"
Chengsong
parents:
diff changeset
   137
| ss1:  "[] s\<leadsto> []"
Chengsong
parents:
diff changeset
   138
| ss2:  "rs1 s\<leadsto> rs2 \<Longrightarrow> (r # rs1) s\<leadsto> (r # rs2)"
Chengsong
parents:
diff changeset
   139
| ss3:  "r1 \<leadsto> r2 \<Longrightarrow> (r1 # rs) s\<leadsto> (r2 # rs)"
Chengsong
parents:
diff changeset
   140
| ss4:  "(AZERO # rs) s\<leadsto> rs"
Chengsong
parents:
diff changeset
   141
| ss5:  "(AALTs bs1 rs1 # rsb) s\<leadsto> ((map (fuse bs1) rs1) @ rsb)"
Chengsong
parents:
diff changeset
   142
| ss6:  "L (erase a2) \<subseteq> L (erase a1) \<Longrightarrow> (rsa@[a1]@rsb@[a2]@rsc) s\<leadsto> (rsa@[a1]@rsb@rsc)"
Chengsong
parents:
diff changeset
   143
Chengsong
parents:
diff changeset
   144
Chengsong
parents:
diff changeset
   145
inductive 
Chengsong
parents:
diff changeset
   146
  rrewrites:: "arexp \<Rightarrow> arexp \<Rightarrow> bool" ("_ \<leadsto>* _" [100, 100] 100)
Chengsong
parents:
diff changeset
   147
where 
Chengsong
parents:
diff changeset
   148
  rs1[intro, simp]:"r \<leadsto>* r"
Chengsong
parents:
diff changeset
   149
| rs2[intro]: "\<lbrakk>r1 \<leadsto>* r2; r2 \<leadsto> r3\<rbrakk> \<Longrightarrow> r1 \<leadsto>* r3"
Chengsong
parents:
diff changeset
   150
Chengsong
parents:
diff changeset
   151
inductive 
Chengsong
parents:
diff changeset
   152
  srewrites:: "arexp list \<Rightarrow> arexp list \<Rightarrow> bool" ("_ s\<leadsto>* _" [100, 100] 100)
Chengsong
parents:
diff changeset
   153
where 
Chengsong
parents:
diff changeset
   154
  sss1[intro, simp]:"rs s\<leadsto>* rs"
Chengsong
parents:
diff changeset
   155
| sss2[intro]: "\<lbrakk>rs1 s\<leadsto> rs2; rs2 s\<leadsto>* rs3\<rbrakk> \<Longrightarrow> rs1 s\<leadsto>* rs3"
Chengsong
parents:
diff changeset
   156
Chengsong
parents:
diff changeset
   157
Chengsong
parents:
diff changeset
   158
lemma r_in_rstar : "r1 \<leadsto> r2 \<Longrightarrow> r1 \<leadsto>* r2"
Chengsong
parents:
diff changeset
   159
  using rrewrites.intros(1) rrewrites.intros(2) by blast
Chengsong
parents:
diff changeset
   160
Chengsong
parents:
diff changeset
   161
lemma rs_in_rstar: 
Chengsong
parents:
diff changeset
   162
  shows "r1 s\<leadsto> r2 \<Longrightarrow> r1 s\<leadsto>* r2"
Chengsong
parents:
diff changeset
   163
  using rrewrites.intros(1) rrewrites.intros(2) by blast
Chengsong
parents:
diff changeset
   164
Chengsong
parents:
diff changeset
   165
Chengsong
parents:
diff changeset
   166
lemma rrewrites_trans[trans]: 
Chengsong
parents:
diff changeset
   167
  assumes a1: "r1 \<leadsto>* r2"  and a2: "r2 \<leadsto>* r3"
Chengsong
parents:
diff changeset
   168
  shows "r1 \<leadsto>* r3"
Chengsong
parents:
diff changeset
   169
  using a2 a1
Chengsong
parents:
diff changeset
   170
  apply(induct r2 r3 arbitrary: r1 rule: rrewrites.induct) 
Chengsong
parents:
diff changeset
   171
  apply(auto)
Chengsong
parents:
diff changeset
   172
  done
Chengsong
parents:
diff changeset
   173
Chengsong
parents:
diff changeset
   174
lemma srewrites_trans[trans]: 
Chengsong
parents:
diff changeset
   175
  assumes a1: "r1 s\<leadsto>* r2"  and a2: "r2 s\<leadsto>* r3"
Chengsong
parents:
diff changeset
   176
  shows "r1 s\<leadsto>* r3"
Chengsong
parents:
diff changeset
   177
  using a1 a2
Chengsong
parents:
diff changeset
   178
  apply(induct r1 r2 arbitrary: r3 rule: srewrites.induct) 
Chengsong
parents:
diff changeset
   179
   apply(auto)
Chengsong
parents:
diff changeset
   180
  done
Chengsong
parents:
diff changeset
   181
Chengsong
parents:
diff changeset
   182
Chengsong
parents:
diff changeset
   183
Chengsong
parents:
diff changeset
   184
lemma contextrewrites0: 
Chengsong
parents:
diff changeset
   185
  "rs1 s\<leadsto>* rs2 \<Longrightarrow> AALTs bs rs1 \<leadsto>* AALTs bs rs2"
Chengsong
parents:
diff changeset
   186
  apply(induct rs1 rs2 rule: srewrites.inducts)
Chengsong
parents:
diff changeset
   187
   apply simp
Chengsong
parents:
diff changeset
   188
  using bs10 r_in_rstar rrewrites_trans by blast
Chengsong
parents:
diff changeset
   189
Chengsong
parents:
diff changeset
   190
lemma contextrewrites1: 
Chengsong
parents:
diff changeset
   191
  "r \<leadsto>* r' \<Longrightarrow> AALTs bs (r # rs) \<leadsto>* AALTs bs (r' # rs)"
Chengsong
parents:
diff changeset
   192
  apply(induct r r' rule: rrewrites.induct)
Chengsong
parents:
diff changeset
   193
   apply simp
Chengsong
parents:
diff changeset
   194
  using bs10 ss3 by blast
Chengsong
parents:
diff changeset
   195
Chengsong
parents:
diff changeset
   196
lemma srewrite1: 
Chengsong
parents:
diff changeset
   197
  shows "rs1 s\<leadsto> rs2 \<Longrightarrow> (rs @ rs1) s\<leadsto> (rs @ rs2)"
Chengsong
parents:
diff changeset
   198
  apply(induct rs)
Chengsong
parents:
diff changeset
   199
   apply(auto)
Chengsong
parents:
diff changeset
   200
  using ss2 by auto
Chengsong
parents:
diff changeset
   201
Chengsong
parents:
diff changeset
   202
lemma srewrites1: 
Chengsong
parents:
diff changeset
   203
  shows "rs1 s\<leadsto>* rs2 \<Longrightarrow> (rs @ rs1) s\<leadsto>* (rs @ rs2)"
Chengsong
parents:
diff changeset
   204
  apply(induct rs1 rs2 rule: srewrites.induct)
Chengsong
parents:
diff changeset
   205
   apply(auto)
Chengsong
parents:
diff changeset
   206
  using srewrite1 by blast
Chengsong
parents:
diff changeset
   207
Chengsong
parents:
diff changeset
   208
lemma srewrite2: 
Chengsong
parents:
diff changeset
   209
  shows  "r1 \<leadsto> r2 \<Longrightarrow> True"
Chengsong
parents:
diff changeset
   210
  and "rs1 s\<leadsto> rs2 \<Longrightarrow> (rs1 @ rs) s\<leadsto>* (rs2 @ rs)"
Chengsong
parents:
diff changeset
   211
  apply(induct rule: rrewrite_srewrite.inducts)
Chengsong
parents:
diff changeset
   212
  apply(auto)
Chengsong
parents:
diff changeset
   213
  apply (metis append_Cons append_Nil srewrites1)
Chengsong
parents:
diff changeset
   214
  apply(meson srewrites.simps ss3)
Chengsong
parents:
diff changeset
   215
  apply (meson srewrites.simps ss4)
Chengsong
parents:
diff changeset
   216
  apply (meson srewrites.simps ss5)
Chengsong
parents:
diff changeset
   217
  by (metis append_Cons append_Nil srewrites.simps ss6)
Chengsong
parents:
diff changeset
   218
  
Chengsong
parents:
diff changeset
   219
Chengsong
parents:
diff changeset
   220
lemma srewrites3: 
Chengsong
parents:
diff changeset
   221
  shows "rs1 s\<leadsto>* rs2 \<Longrightarrow> (rs1 @ rs) s\<leadsto>* (rs2 @ rs)"
Chengsong
parents:
diff changeset
   222
  apply(induct rs1 rs2 arbitrary: rs rule: srewrites.induct)
Chengsong
parents:
diff changeset
   223
   apply(auto)
Chengsong
parents:
diff changeset
   224
  by (meson srewrite2(2) srewrites_trans)
Chengsong
parents:
diff changeset
   225
Chengsong
parents:
diff changeset
   226
(*
Chengsong
parents:
diff changeset
   227
lemma srewrites4:
Chengsong
parents:
diff changeset
   228
  assumes "rs3 s\<leadsto>* rs4" "rs1 s\<leadsto>* rs2" 
Chengsong
parents:
diff changeset
   229
  shows "(rs1 @ rs3) s\<leadsto>* (rs2 @ rs4)"
Chengsong
parents:
diff changeset
   230
  using assms
Chengsong
parents:
diff changeset
   231
  apply(induct rs3 rs4 arbitrary: rs1 rs2 rule: srewrites.induct)
Chengsong
parents:
diff changeset
   232
  apply (simp add: srewrites3)
Chengsong
parents:
diff changeset
   233
  using srewrite1 by blast
Chengsong
parents:
diff changeset
   234
*)
Chengsong
parents:
diff changeset
   235
Chengsong
parents:
diff changeset
   236
lemma srewrites6:
Chengsong
parents:
diff changeset
   237
  assumes "r1 \<leadsto>* r2" 
Chengsong
parents:
diff changeset
   238
  shows "[r1] s\<leadsto>* [r2]"
Chengsong
parents:
diff changeset
   239
  using assms
Chengsong
parents:
diff changeset
   240
  apply(induct r1 r2 rule: rrewrites.induct)
Chengsong
parents:
diff changeset
   241
   apply(auto)
Chengsong
parents:
diff changeset
   242
  by (meson srewrites.simps srewrites_trans ss3)
Chengsong
parents:
diff changeset
   243
Chengsong
parents:
diff changeset
   244
lemma srewrites7:
Chengsong
parents:
diff changeset
   245
  assumes "rs3 s\<leadsto>* rs4" "r1 \<leadsto>* r2" 
Chengsong
parents:
diff changeset
   246
  shows "(r1 # rs3) s\<leadsto>* (r2 # rs4)"
Chengsong
parents:
diff changeset
   247
  using assms
Chengsong
parents:
diff changeset
   248
  by (smt (verit, best) append_Cons append_Nil srewrites1 srewrites3 srewrites6 srewrites_trans)
Chengsong
parents:
diff changeset
   249
Chengsong
parents:
diff changeset
   250
lemma ss6_stronger_aux:
Chengsong
parents:
diff changeset
   251
  shows "(rs1 @ rs2) s\<leadsto>* (rs1 @ distinctWith rs2 eq1 (set rs1))"
Chengsong
parents:
diff changeset
   252
  apply(induct rs2 arbitrary: rs1)
Chengsong
parents:
diff changeset
   253
  apply(auto)
Chengsong
parents:
diff changeset
   254
  prefer 2
Chengsong
parents:
diff changeset
   255
  apply(drule_tac x="rs1 @ [a]" in meta_spec)
Chengsong
parents:
diff changeset
   256
  apply(simp)
Chengsong
parents:
diff changeset
   257
  apply(drule_tac x="rs1" in meta_spec)
Chengsong
parents:
diff changeset
   258
  apply(subgoal_tac "(rs1 @ a # rs2) s\<leadsto>* (rs1 @ rs2)")
Chengsong
parents:
diff changeset
   259
  using srewrites_trans apply blast
Chengsong
parents:
diff changeset
   260
  apply(subgoal_tac "\<exists>rs1a rs1b. rs1 = rs1a @ [x] @ rs1b")
Chengsong
parents:
diff changeset
   261
  prefer 2
Chengsong
parents:
diff changeset
   262
  apply (simp add: split_list)
Chengsong
parents:
diff changeset
   263
  apply(erule exE)+
Chengsong
parents:
diff changeset
   264
  apply(simp)
Chengsong
parents:
diff changeset
   265
  using eq1_L rs_in_rstar ss6 by force
Chengsong
parents:
diff changeset
   266
Chengsong
parents:
diff changeset
   267
lemma ss6_stronger:
Chengsong
parents:
diff changeset
   268
  shows "rs1 s\<leadsto>* distinctWith rs1 eq1 {}"
Chengsong
parents:
diff changeset
   269
  by (metis append_Nil list.set(1) ss6_stronger_aux)
Chengsong
parents:
diff changeset
   270
Chengsong
parents:
diff changeset
   271
Chengsong
parents:
diff changeset
   272
lemma rewrite_preserves_fuse: 
Chengsong
parents:
diff changeset
   273
  shows "r2 \<leadsto> r3 \<Longrightarrow> fuse bs r2 \<leadsto> fuse bs r3"
Chengsong
parents:
diff changeset
   274
  and   "rs2 s\<leadsto> rs3 \<Longrightarrow> map (fuse bs) rs2 s\<leadsto>* map (fuse bs) rs3"
Chengsong
parents:
diff changeset
   275
proof(induct rule: rrewrite_srewrite.inducts)
Chengsong
parents:
diff changeset
   276
  case (bs3 bs1 bs2 r)
Chengsong
parents:
diff changeset
   277
  then show ?case
Chengsong
parents:
diff changeset
   278
    by (metis fuse.simps(5) fuse_append rrewrite_srewrite.bs3) 
Chengsong
parents:
diff changeset
   279
next
Chengsong
parents:
diff changeset
   280
  case (bs7 bs r)
Chengsong
parents:
diff changeset
   281
  then show ?case
Chengsong
parents:
diff changeset
   282
    by (metis fuse.simps(4) fuse_append rrewrite_srewrite.bs7) 
Chengsong
parents:
diff changeset
   283
next
Chengsong
parents:
diff changeset
   284
  case (ss2 rs1 rs2 r)
Chengsong
parents:
diff changeset
   285
  then show ?case
Chengsong
parents:
diff changeset
   286
    using srewrites7 by force 
Chengsong
parents:
diff changeset
   287
next
Chengsong
parents:
diff changeset
   288
  case (ss3 r1 r2 rs)
Chengsong
parents:
diff changeset
   289
  then show ?case by (simp add: r_in_rstar srewrites7)
Chengsong
parents:
diff changeset
   290
next
Chengsong
parents:
diff changeset
   291
  case (ss5 bs1 rs1 rsb)
Chengsong
parents:
diff changeset
   292
  then show ?case 
Chengsong
parents:
diff changeset
   293
    apply(simp)
Chengsong
parents:
diff changeset
   294
    by (metis (mono_tags, lifting) comp_def fuse_append map_eq_conv rrewrite_srewrite.ss5 srewrites.simps)
Chengsong
parents:
diff changeset
   295
next
Chengsong
parents:
diff changeset
   296
  case (ss6 a1 a2 rsa rsb rsc)
Chengsong
parents:
diff changeset
   297
  then show ?case 
Chengsong
parents:
diff changeset
   298
    apply(simp only: map_append)
Chengsong
parents:
diff changeset
   299
    by (smt (verit, best) erase_fuse list.simps(8) list.simps(9) rrewrite_srewrite.ss6 srewrites.simps)
Chengsong
parents:
diff changeset
   300
qed (auto intro: rrewrite_srewrite.intros)
Chengsong
parents:
diff changeset
   301
Chengsong
parents:
diff changeset
   302
Chengsong
parents:
diff changeset
   303
lemma rewrites_fuse:  
Chengsong
parents:
diff changeset
   304
  assumes "r1 \<leadsto>* r2"
Chengsong
parents:
diff changeset
   305
  shows "fuse bs r1 \<leadsto>* fuse bs r2"
Chengsong
parents:
diff changeset
   306
using assms
Chengsong
parents:
diff changeset
   307
apply(induction r1 r2 arbitrary: bs rule: rrewrites.induct)
Chengsong
parents:
diff changeset
   308
apply(auto intro: rewrite_preserves_fuse rrewrites_trans)
Chengsong
parents:
diff changeset
   309
done
Chengsong
parents:
diff changeset
   310
Chengsong
parents:
diff changeset
   311
Chengsong
parents:
diff changeset
   312
lemma star_seq:  
Chengsong
parents:
diff changeset
   313
  assumes "r1 \<leadsto>* r2"
Chengsong
parents:
diff changeset
   314
  shows "ASEQ bs r1 r3 \<leadsto>* ASEQ bs r2 r3"
Chengsong
parents:
diff changeset
   315
using assms
Chengsong
parents:
diff changeset
   316
apply(induct r1 r2 arbitrary: r3 rule: rrewrites.induct)
Chengsong
parents:
diff changeset
   317
apply(auto intro: rrewrite_srewrite.intros)
Chengsong
parents:
diff changeset
   318
done
Chengsong
parents:
diff changeset
   319
Chengsong
parents:
diff changeset
   320
lemma star_seq2:  
Chengsong
parents:
diff changeset
   321
  assumes "r3 \<leadsto>* r4"
Chengsong
parents:
diff changeset
   322
  shows "ASEQ bs r1 r3 \<leadsto>* ASEQ bs r1 r4"
Chengsong
parents:
diff changeset
   323
  using assms
Chengsong
parents:
diff changeset
   324
apply(induct r3 r4 arbitrary: r1 rule: rrewrites.induct)
Chengsong
parents:
diff changeset
   325
apply(auto intro: rrewrite_srewrite.intros)
Chengsong
parents:
diff changeset
   326
done
Chengsong
parents:
diff changeset
   327
Chengsong
parents:
diff changeset
   328
lemma continuous_rewrite: 
Chengsong
parents:
diff changeset
   329
  assumes "r1 \<leadsto>* AZERO"
Chengsong
parents:
diff changeset
   330
  shows "ASEQ bs1 r1 r2 \<leadsto>* AZERO"
Chengsong
parents:
diff changeset
   331
using assms bs1 star_seq by blast
Chengsong
parents:
diff changeset
   332
Chengsong
parents:
diff changeset
   333
(*
Chengsong
parents:
diff changeset
   334
lemma continuous_rewrite2: 
Chengsong
parents:
diff changeset
   335
  assumes "r1 \<leadsto>* AONE bs"
Chengsong
parents:
diff changeset
   336
  shows "ASEQ bs1 r1 r2 \<leadsto>* (fuse (bs1 @ bs) r2)"
Chengsong
parents:
diff changeset
   337
  using assms  by (meson bs3 rrewrites.simps star_seq)
Chengsong
parents:
diff changeset
   338
*)
Chengsong
parents:
diff changeset
   339
Chengsong
parents:
diff changeset
   340
lemma bsimp_aalts_simpcases: 
Chengsong
parents:
diff changeset
   341
  shows "AONE bs \<leadsto>* bsimp (AONE bs)"  
Chengsong
parents:
diff changeset
   342
  and   "AZERO \<leadsto>* bsimp AZERO" 
Chengsong
parents:
diff changeset
   343
  and   "ACHAR bs c \<leadsto>* bsimp (ACHAR bs c)"
Chengsong
parents:
diff changeset
   344
  by (simp_all)
Chengsong
parents:
diff changeset
   345
Chengsong
parents:
diff changeset
   346
lemma bsimp_AALTs_rewrites: 
Chengsong
parents:
diff changeset
   347
  shows "AALTs bs1 rs \<leadsto>* bsimp_AALTs bs1 rs"
Chengsong
parents:
diff changeset
   348
  by (smt (verit) bs6 bs7 bsimp_AALTs.elims rrewrites.simps)
Chengsong
parents:
diff changeset
   349
Chengsong
parents:
diff changeset
   350
lemma trivialbsimp_srewrites: 
Chengsong
parents:
diff changeset
   351
  "\<lbrakk>\<And>x. x \<in> set rs \<Longrightarrow> x \<leadsto>* f x \<rbrakk> \<Longrightarrow> rs s\<leadsto>* (map f rs)"
Chengsong
parents:
diff changeset
   352
  apply(induction rs)
Chengsong
parents:
diff changeset
   353
   apply simp
Chengsong
parents:
diff changeset
   354
  apply(simp)
Chengsong
parents:
diff changeset
   355
  using srewrites7 by auto
Chengsong
parents:
diff changeset
   356
Chengsong
parents:
diff changeset
   357
Chengsong
parents:
diff changeset
   358
Chengsong
parents:
diff changeset
   359
lemma fltsfrewrites: "rs s\<leadsto>* flts rs"
Chengsong
parents:
diff changeset
   360
  apply(induction rs rule: flts.induct)
Chengsong
parents:
diff changeset
   361
  apply(auto intro: rrewrite_srewrite.intros)
Chengsong
parents:
diff changeset
   362
  apply (meson srewrites.simps srewrites1 ss5)
Chengsong
parents:
diff changeset
   363
  using rs1 srewrites7 apply presburger
Chengsong
parents:
diff changeset
   364
  using srewrites7 apply force
Chengsong
parents:
diff changeset
   365
  apply (simp add: srewrites7)
Chengsong
parents:
diff changeset
   366
  by (simp add: srewrites7)
Chengsong
parents:
diff changeset
   367
Chengsong
parents:
diff changeset
   368
lemma bnullable0:
Chengsong
parents:
diff changeset
   369
shows "r1 \<leadsto> r2 \<Longrightarrow> bnullable r1 = bnullable r2" 
Chengsong
parents:
diff changeset
   370
  and "rs1 s\<leadsto> rs2 \<Longrightarrow> bnullables rs1 = bnullables rs2" 
Chengsong
parents:
diff changeset
   371
  apply(induct rule: rrewrite_srewrite.inducts)
Chengsong
parents:
diff changeset
   372
  apply(auto simp add:  bnullable_fuse)
Chengsong
parents:
diff changeset
   373
   apply (meson UnCI bnullable_fuse imageI)
Chengsong
parents:
diff changeset
   374
  using bnullable_correctness nullable_correctness by blast 
Chengsong
parents:
diff changeset
   375
Chengsong
parents:
diff changeset
   376
Chengsong
parents:
diff changeset
   377
lemma rewritesnullable: 
Chengsong
parents:
diff changeset
   378
  assumes "r1 \<leadsto>* r2" 
Chengsong
parents:
diff changeset
   379
  shows "bnullable r1 = bnullable r2"
Chengsong
parents:
diff changeset
   380
using assms 
Chengsong
parents:
diff changeset
   381
  apply(induction r1 r2 rule: rrewrites.induct)
Chengsong
parents:
diff changeset
   382
  apply simp
Chengsong
parents:
diff changeset
   383
  using bnullable0(1) by auto
Chengsong
parents:
diff changeset
   384
Chengsong
parents:
diff changeset
   385
lemma rewrite_bmkeps_aux: 
Chengsong
parents:
diff changeset
   386
  shows "r1 \<leadsto> r2 \<Longrightarrow> (bnullable r1 \<and> bnullable r2 \<Longrightarrow> bmkeps r1 = bmkeps r2)"
Chengsong
parents:
diff changeset
   387
  and   "rs1 s\<leadsto> rs2 \<Longrightarrow> (bnullables rs1 \<and> bnullables rs2 \<Longrightarrow> bmkepss rs1 = bmkepss rs2)" 
Chengsong
parents:
diff changeset
   388
proof (induct rule: rrewrite_srewrite.inducts)
Chengsong
parents:
diff changeset
   389
  case (bs3 bs1 bs2 r)
Chengsong
parents:
diff changeset
   390
  then show ?case by (simp add: bmkeps_fuse) 
Chengsong
parents:
diff changeset
   391
next
Chengsong
parents:
diff changeset
   392
  case (bs7 bs r)
Chengsong
parents:
diff changeset
   393
  then show ?case by (simp add: bmkeps_fuse) 
Chengsong
parents:
diff changeset
   394
next
Chengsong
parents:
diff changeset
   395
  case (ss3 r1 r2 rs)
Chengsong
parents:
diff changeset
   396
  then show ?case
Chengsong
parents:
diff changeset
   397
    using bmkepss.simps bnullable0(1) by presburger
Chengsong
parents:
diff changeset
   398
next
Chengsong
parents:
diff changeset
   399
  case (ss5 bs1 rs1 rsb)
Chengsong
parents:
diff changeset
   400
  then show ?case
Chengsong
parents:
diff changeset
   401
    by (simp add: bmkepss1 bmkepss2 bmkepss_fuse bnullable_fuse)
Chengsong
parents:
diff changeset
   402
next
Chengsong
parents:
diff changeset
   403
  case (ss6 a1 a2 rsa rsb rsc)
Chengsong
parents:
diff changeset
   404
  then show ?case
Chengsong
parents:
diff changeset
   405
    by (smt (verit, best) Nil_is_append_conv bmkepss1 bmkepss2 bnullable_correctness in_set_conv_decomp list.distinct(1) list.set_intros(1) nullable_correctness set_ConsD subsetD)
Chengsong
parents:
diff changeset
   406
qed (auto)
Chengsong
parents:
diff changeset
   407
Chengsong
parents:
diff changeset
   408
lemma rewrites_bmkeps: 
Chengsong
parents:
diff changeset
   409
  assumes "r1 \<leadsto>* r2" "bnullable r1" 
Chengsong
parents:
diff changeset
   410
  shows "bmkeps r1 = bmkeps r2"
Chengsong
parents:
diff changeset
   411
  using assms
Chengsong
parents:
diff changeset
   412
proof(induction r1 r2 rule: rrewrites.induct)
Chengsong
parents:
diff changeset
   413
  case (rs1 r)
Chengsong
parents:
diff changeset
   414
  then show "bmkeps r = bmkeps r" by simp
Chengsong
parents:
diff changeset
   415
next
Chengsong
parents:
diff changeset
   416
  case (rs2 r1 r2 r3)
Chengsong
parents:
diff changeset
   417
  then have IH: "bmkeps r1 = bmkeps r2" by simp
Chengsong
parents:
diff changeset
   418
  have a1: "bnullable r1" by fact
Chengsong
parents:
diff changeset
   419
  have a2: "r1 \<leadsto>* r2" by fact
Chengsong
parents:
diff changeset
   420
  have a3: "r2 \<leadsto> r3" by fact
Chengsong
parents:
diff changeset
   421
  have a4: "bnullable r2" using a1 a2 by (simp add: rewritesnullable) 
Chengsong
parents:
diff changeset
   422
  then have "bmkeps r2 = bmkeps r3"
Chengsong
parents:
diff changeset
   423
    using a3 bnullable0(1) rewrite_bmkeps_aux(1) by blast 
Chengsong
parents:
diff changeset
   424
  then show "bmkeps r1 = bmkeps r3" using IH by simp
Chengsong
parents:
diff changeset
   425
qed
Chengsong
parents:
diff changeset
   426
Chengsong
parents:
diff changeset
   427
Chengsong
parents:
diff changeset
   428
lemma rewrites_to_bsimp: 
Chengsong
parents:
diff changeset
   429
  shows "r \<leadsto>* bsimp r"
Chengsong
parents:
diff changeset
   430
proof (induction r rule: bsimp.induct)
Chengsong
parents:
diff changeset
   431
  case (1 bs1 r1 r2)
Chengsong
parents:
diff changeset
   432
  have IH1: "r1 \<leadsto>* bsimp r1" by fact
Chengsong
parents:
diff changeset
   433
  have IH2: "r2 \<leadsto>* bsimp r2" by fact
Chengsong
parents:
diff changeset
   434
  { assume as: "bsimp r1 = AZERO \<or> bsimp r2 = AZERO"
Chengsong
parents:
diff changeset
   435
    with IH1 IH2 have "r1 \<leadsto>* AZERO \<or> r2 \<leadsto>* AZERO" by auto
Chengsong
parents:
diff changeset
   436
    then have "ASEQ bs1 r1 r2 \<leadsto>* AZERO"
Chengsong
parents:
diff changeset
   437
      by (metis bs2 continuous_rewrite rrewrites.simps star_seq2)  
Chengsong
parents:
diff changeset
   438
    then have "ASEQ bs1 r1 r2 \<leadsto>* bsimp (ASEQ bs1 r1 r2)" using as by auto
Chengsong
parents:
diff changeset
   439
  }
Chengsong
parents:
diff changeset
   440
  moreover
Chengsong
parents:
diff changeset
   441
  { assume "\<exists>bs. bsimp r1 = AONE bs"
Chengsong
parents:
diff changeset
   442
    then obtain bs where as: "bsimp r1 = AONE bs" by blast
Chengsong
parents:
diff changeset
   443
    with IH1 have "r1 \<leadsto>* AONE bs" by simp
Chengsong
parents:
diff changeset
   444
    then have "ASEQ bs1 r1 r2 \<leadsto>* fuse (bs1 @ bs) r2" using bs3 star_seq by blast
Chengsong
parents:
diff changeset
   445
    with IH2 have "ASEQ bs1 r1 r2 \<leadsto>* fuse (bs1 @ bs) (bsimp r2)"
Chengsong
parents:
diff changeset
   446
      using rewrites_fuse by (meson rrewrites_trans) 
Chengsong
parents:
diff changeset
   447
    then have "ASEQ bs1 r1 r2 \<leadsto>* bsimp (ASEQ bs1 (AONE bs) r2)" by simp
Chengsong
parents:
diff changeset
   448
    then have "ASEQ bs1 r1 r2 \<leadsto>* bsimp (ASEQ bs1 r1 r2)" by (simp add: as) 
Chengsong
parents:
diff changeset
   449
  } 
Chengsong
parents:
diff changeset
   450
  moreover
Chengsong
parents:
diff changeset
   451
  { assume as1: "bsimp r1 \<noteq> AZERO" "bsimp r2 \<noteq> AZERO" and as2: "(\<nexists>bs. bsimp r1 = AONE bs)" 
Chengsong
parents:
diff changeset
   452
    then have "bsimp_ASEQ bs1 (bsimp r1) (bsimp r2) = ASEQ bs1 (bsimp r1) (bsimp r2)" 
Chengsong
parents:
diff changeset
   453
      by (simp add: bsimp_ASEQ1) 
Chengsong
parents:
diff changeset
   454
    then have "ASEQ bs1 r1 r2 \<leadsto>* bsimp_ASEQ bs1 (bsimp r1) (bsimp r2)" using as1 as2 IH1 IH2
Chengsong
parents:
diff changeset
   455
      by (metis rrewrites_trans star_seq star_seq2) 
Chengsong
parents:
diff changeset
   456
    then have "ASEQ bs1 r1 r2 \<leadsto>* bsimp (ASEQ bs1 r1 r2)" by simp
Chengsong
parents:
diff changeset
   457
  } 
Chengsong
parents:
diff changeset
   458
  ultimately show "ASEQ bs1 r1 r2 \<leadsto>* bsimp (ASEQ bs1 r1 r2)" by blast
Chengsong
parents:
diff changeset
   459
next
Chengsong
parents:
diff changeset
   460
  case (2 bs1 rs)
Chengsong
parents:
diff changeset
   461
  have IH: "\<And>x. x \<in> set rs \<Longrightarrow> x \<leadsto>* bsimp x" by fact
Chengsong
parents:
diff changeset
   462
  then have "rs s\<leadsto>* (map bsimp rs)" by (simp add: trivialbsimp_srewrites)
Chengsong
parents:
diff changeset
   463
  also have "... s\<leadsto>* flts (map bsimp rs)" by (simp add: fltsfrewrites) 
Chengsong
parents:
diff changeset
   464
  also have "... s\<leadsto>* distinctWith (flts (map bsimp rs)) eq1 {}" by (simp add: ss6_stronger)
Chengsong
parents:
diff changeset
   465
  finally have "AALTs bs1 rs \<leadsto>* AALTs bs1 (distinctWith (flts (map bsimp rs)) eq1 {})"
Chengsong
parents:
diff changeset
   466
    using contextrewrites0 by auto
Chengsong
parents:
diff changeset
   467
  also have "... \<leadsto>* bsimp_AALTs  bs1 (distinctWith (flts (map bsimp rs)) eq1 {})"
Chengsong
parents:
diff changeset
   468
    by (simp add: bsimp_AALTs_rewrites)     
Chengsong
parents:
diff changeset
   469
  finally show "AALTs bs1 rs \<leadsto>* bsimp (AALTs bs1 rs)" by simp
Chengsong
parents:
diff changeset
   470
qed (simp_all)
Chengsong
parents:
diff changeset
   471
Chengsong
parents:
diff changeset
   472
Chengsong
parents:
diff changeset
   473
lemma to_zero_in_alt: 
Chengsong
parents:
diff changeset
   474
  shows "AALT bs (ASEQ [] AZERO r) r2 \<leadsto> AALT bs AZERO r2"
Chengsong
parents:
diff changeset
   475
  by (simp add: bs1 bs10 ss3)
Chengsong
parents:
diff changeset
   476
Chengsong
parents:
diff changeset
   477
Chengsong
parents:
diff changeset
   478
Chengsong
parents:
diff changeset
   479
lemma  bder_fuse_list: 
Chengsong
parents:
diff changeset
   480
  shows "map (bder c \<circ> fuse bs1) rs1 = map (fuse bs1 \<circ> bder c) rs1"
Chengsong
parents:
diff changeset
   481
  apply(induction rs1)
Chengsong
parents:
diff changeset
   482
  apply(simp_all add: bder_fuse)
Chengsong
parents:
diff changeset
   483
  done
Chengsong
parents:
diff changeset
   484
Chengsong
parents:
diff changeset
   485
lemma map1:
Chengsong
parents:
diff changeset
   486
  shows "(map f [a]) = [f a]"
Chengsong
parents:
diff changeset
   487
  by (simp)
Chengsong
parents:
diff changeset
   488
Chengsong
parents:
diff changeset
   489
lemma rewrite_preserves_bder: 
Chengsong
parents:
diff changeset
   490
  shows "r1 \<leadsto> r2 \<Longrightarrow> (bder c r1) \<leadsto>* (bder c r2)"
Chengsong
parents:
diff changeset
   491
  and   "rs1 s\<leadsto> rs2 \<Longrightarrow> map (bder c) rs1 s\<leadsto>* map (bder c) rs2"
Chengsong
parents:
diff changeset
   492
proof(induction rule: rrewrite_srewrite.inducts)
Chengsong
parents:
diff changeset
   493
  case (bs1 bs r2)
Chengsong
parents:
diff changeset
   494
  then show ?case
Chengsong
parents:
diff changeset
   495
    by (simp add: continuous_rewrite) 
Chengsong
parents:
diff changeset
   496
next
Chengsong
parents:
diff changeset
   497
  case (bs2 bs r1)
Chengsong
parents:
diff changeset
   498
  then show ?case 
Chengsong
parents:
diff changeset
   499
    apply(auto)
Chengsong
parents:
diff changeset
   500
    apply (meson bs6 contextrewrites0 rrewrite_srewrite.bs2 rs2 ss3 ss4 sss1 sss2)
Chengsong
parents:
diff changeset
   501
    by (simp add: r_in_rstar rrewrite_srewrite.bs2)
Chengsong
parents:
diff changeset
   502
next
Chengsong
parents:
diff changeset
   503
  case (bs3 bs1 bs2 r)
Chengsong
parents:
diff changeset
   504
  then show ?case 
Chengsong
parents:
diff changeset
   505
    apply(simp)
Chengsong
parents:
diff changeset
   506
    
Chengsong
parents:
diff changeset
   507
    by (metis (no_types, lifting) bder_fuse bs10 bs7 fuse_append rrewrites.simps ss4 to_zero_in_alt)
Chengsong
parents:
diff changeset
   508
next
Chengsong
parents:
diff changeset
   509
  case (bs4 r1 r2 bs r3)
Chengsong
parents:
diff changeset
   510
  have as: "r1 \<leadsto> r2" by fact
Chengsong
parents:
diff changeset
   511
  have IH: "bder c r1 \<leadsto>* bder c r2" by fact
Chengsong
parents:
diff changeset
   512
  from as IH show "bder c (ASEQ bs r1 r3) \<leadsto>* bder c (ASEQ bs r2 r3)"
Chengsong
parents:
diff changeset
   513
    by (metis bder.simps(5) bnullable0(1) contextrewrites1 rewrite_bmkeps_aux(1) star_seq)
Chengsong
parents:
diff changeset
   514
next
Chengsong
parents:
diff changeset
   515
  case (bs5 r3 r4 bs r1)
Chengsong
parents:
diff changeset
   516
  have as: "r3 \<leadsto> r4" by fact 
Chengsong
parents:
diff changeset
   517
  have IH: "bder c r3 \<leadsto>* bder c r4" by fact 
Chengsong
parents:
diff changeset
   518
  from as IH show "bder c (ASEQ bs r1 r3) \<leadsto>* bder c (ASEQ bs r1 r4)"
Chengsong
parents:
diff changeset
   519
    apply(simp)
Chengsong
parents:
diff changeset
   520
    apply(auto)
Chengsong
parents:
diff changeset
   521
    using contextrewrites0 r_in_rstar rewrites_fuse srewrites6 srewrites7 star_seq2 apply presburger
Chengsong
parents:
diff changeset
   522
    using star_seq2 by blast
Chengsong
parents:
diff changeset
   523
next
Chengsong
parents:
diff changeset
   524
  case (bs6 bs)
Chengsong
parents:
diff changeset
   525
  then show ?case
Chengsong
parents:
diff changeset
   526
    using rrewrite_srewrite.bs6 by force 
Chengsong
parents:
diff changeset
   527
next
Chengsong
parents:
diff changeset
   528
  case (bs7 bs r)
Chengsong
parents:
diff changeset
   529
  then show ?case
Chengsong
parents:
diff changeset
   530
    by (simp add: bder_fuse r_in_rstar rrewrite_srewrite.bs7) 
Chengsong
parents:
diff changeset
   531
next
Chengsong
parents:
diff changeset
   532
  case (bs10 rs1 rs2 bs)
Chengsong
parents:
diff changeset
   533
  then show ?case
Chengsong
parents:
diff changeset
   534
    using contextrewrites0 by force    
Chengsong
parents:
diff changeset
   535
next
Chengsong
parents:
diff changeset
   536
  case ss1
Chengsong
parents:
diff changeset
   537
  then show ?case by simp
Chengsong
parents:
diff changeset
   538
next
Chengsong
parents:
diff changeset
   539
  case (ss2 rs1 rs2 r)
Chengsong
parents:
diff changeset
   540
  then show ?case
Chengsong
parents:
diff changeset
   541
    by (simp add: srewrites7) 
Chengsong
parents:
diff changeset
   542
next
Chengsong
parents:
diff changeset
   543
  case (ss3 r1 r2 rs)
Chengsong
parents:
diff changeset
   544
  then show ?case
Chengsong
parents:
diff changeset
   545
    by (simp add: srewrites7) 
Chengsong
parents:
diff changeset
   546
next
Chengsong
parents:
diff changeset
   547
  case (ss4 rs)
Chengsong
parents:
diff changeset
   548
  then show ?case
Chengsong
parents:
diff changeset
   549
    using rrewrite_srewrite.ss4 by fastforce 
Chengsong
parents:
diff changeset
   550
next
Chengsong
parents:
diff changeset
   551
  case (ss5 bs1 rs1 rsb)
Chengsong
parents:
diff changeset
   552
  then show ?case 
Chengsong
parents:
diff changeset
   553
    apply(simp)
Chengsong
parents:
diff changeset
   554
    using bder_fuse_list map_map rrewrite_srewrite.ss5 srewrites.simps by blast
Chengsong
parents:
diff changeset
   555
next
Chengsong
parents:
diff changeset
   556
  case (ss6 a1 a2 bs rsa rsb)
Chengsong
parents:
diff changeset
   557
  then show ?case
Chengsong
parents:
diff changeset
   558
    apply(simp only: map_append map1)
Chengsong
parents:
diff changeset
   559
    apply(rule srewrites_trans)
Chengsong
parents:
diff changeset
   560
    apply(rule rs_in_rstar)
Chengsong
parents:
diff changeset
   561
    apply(rule_tac rrewrite_srewrite.ss6)
Chengsong
parents:
diff changeset
   562
    using Der_def der_correctness apply auto[1]
Chengsong
parents:
diff changeset
   563
    by blast
Chengsong
parents:
diff changeset
   564
qed
Chengsong
parents:
diff changeset
   565
Chengsong
parents:
diff changeset
   566
lemma rewrites_preserves_bder: 
Chengsong
parents:
diff changeset
   567
  assumes "r1 \<leadsto>* r2"
Chengsong
parents:
diff changeset
   568
  shows "bder c r1 \<leadsto>* bder c r2"
Chengsong
parents:
diff changeset
   569
using assms  
Chengsong
parents:
diff changeset
   570
apply(induction r1 r2 rule: rrewrites.induct)
Chengsong
parents:
diff changeset
   571
apply(simp_all add: rewrite_preserves_bder rrewrites_trans)
Chengsong
parents:
diff changeset
   572
done
Chengsong
parents:
diff changeset
   573
Chengsong
parents:
diff changeset
   574
Chengsong
parents:
diff changeset
   575
lemma central:  
Chengsong
parents:
diff changeset
   576
  shows "bders r s \<leadsto>* bders_simp r s"
Chengsong
parents:
diff changeset
   577
proof(induct s arbitrary: r rule: rev_induct)
Chengsong
parents:
diff changeset
   578
  case Nil
Chengsong
parents:
diff changeset
   579
  then show "bders r [] \<leadsto>* bders_simp r []" by simp
Chengsong
parents:
diff changeset
   580
next
Chengsong
parents:
diff changeset
   581
  case (snoc x xs)
Chengsong
parents:
diff changeset
   582
  have IH: "\<And>r. bders r xs \<leadsto>* bders_simp r xs" by fact
Chengsong
parents:
diff changeset
   583
  have "bders r (xs @ [x]) = bders (bders r xs) [x]" by (simp add: bders_append)
Chengsong
parents:
diff changeset
   584
  also have "... \<leadsto>* bders (bders_simp r xs) [x]" using IH
Chengsong
parents:
diff changeset
   585
    by (simp add: rewrites_preserves_bder)
Chengsong
parents:
diff changeset
   586
  also have "... \<leadsto>* bders_simp (bders_simp r xs) [x]" using IH
Chengsong
parents:
diff changeset
   587
    by (simp add: rewrites_to_bsimp)
Chengsong
parents:
diff changeset
   588
  finally show "bders r (xs @ [x]) \<leadsto>* bders_simp r (xs @ [x])" 
Chengsong
parents:
diff changeset
   589
    by (simp add: bders_simp_append)
Chengsong
parents:
diff changeset
   590
qed
Chengsong
parents:
diff changeset
   591
Chengsong
parents:
diff changeset
   592
lemma main_aux: 
Chengsong
parents:
diff changeset
   593
  assumes "bnullable (bders r s)"
Chengsong
parents:
diff changeset
   594
  shows "bmkeps (bders r s) = bmkeps (bders_simp r s)"
Chengsong
parents:
diff changeset
   595
proof -
Chengsong
parents:
diff changeset
   596
  have "bders r s \<leadsto>* bders_simp r s" by (rule central)
Chengsong
parents:
diff changeset
   597
  then 
Chengsong
parents:
diff changeset
   598
  show "bmkeps (bders r s) = bmkeps (bders_simp r s)" using assms
Chengsong
parents:
diff changeset
   599
    by (rule rewrites_bmkeps)
Chengsong
parents:
diff changeset
   600
qed  
Chengsong
parents:
diff changeset
   601
Chengsong
parents:
diff changeset
   602
Chengsong
parents:
diff changeset
   603
Chengsong
parents:
diff changeset
   604
Chengsong
parents:
diff changeset
   605
theorem main_blexer_simp: 
Chengsong
parents:
diff changeset
   606
  shows "blexer r s = blexer_simp r s"
Chengsong
parents:
diff changeset
   607
  unfolding blexer_def blexer_simp_def
Chengsong
parents:
diff changeset
   608
  by (metis central main_aux rewritesnullable)
Chengsong
parents:
diff changeset
   609
Chengsong
parents:
diff changeset
   610
theorem blexersimp_correctness: 
Chengsong
parents:
diff changeset
   611
  shows "lexer r s = blexer_simp r s"
Chengsong
parents:
diff changeset
   612
  using blexer_correctness main_blexer_simp by simp
Chengsong
parents:
diff changeset
   613
Chengsong
parents:
diff changeset
   614
Chengsong
parents:
diff changeset
   615
Chengsong
parents:
diff changeset
   616
Chengsong
parents:
diff changeset
   617
Chengsong
parents:
diff changeset
   618
fun ABIncludedByC :: "'a \<Rightarrow> 'b \<Rightarrow> 'c \<Rightarrow> ('a \<Rightarrow> 'b \<Rightarrow> 'c) \<Rightarrow> ('c \<Rightarrow> 'c \<Rightarrow> bool) \<Rightarrow> bool" where
Chengsong
parents:
diff changeset
   619
  "ABIncludedByC a b c f subseteqPred = subseteqPred (f a b) c"
Chengsong
parents:
diff changeset
   620
Chengsong
parents:
diff changeset
   621
fun furtherSEQ :: "rexp \<Rightarrow> rexp \<Rightarrow> rexp list" and 
Chengsong
parents:
diff changeset
   622
   turnIntoTerms :: "rexp \<Rightarrow> rexp list "
Chengsong
parents:
diff changeset
   623
   where
Chengsong
parents:
diff changeset
   624
  "furtherSEQ ONE r2 =  turnIntoTerms r2 "
Chengsong
parents:
diff changeset
   625
| "furtherSEQ r11 r2 = [SEQ r11 r2]"
Chengsong
parents:
diff changeset
   626
| "turnIntoTerms (SEQ ONE r2) =  turnIntoTerms r2"
Chengsong
parents:
diff changeset
   627
| "turnIntoTerms (SEQ r1 r2) = concat (map (\<lambda>r11. furtherSEQ r11 r2) (turnIntoTerms r1))"
Chengsong
parents:
diff changeset
   628
| "turnIntoTerms r = [r]"
Chengsong
parents:
diff changeset
   629
Chengsong
parents:
diff changeset
   630
fun regConcat :: "rexp \<Rightarrow> rexp list \<Rightarrow> rexp" where
Chengsong
parents:
diff changeset
   631
  "regConcat acc [] = acc"
Chengsong
parents:
diff changeset
   632
| "regConcat ONE (r # rs1) = regConcat r rs1"
Chengsong
parents:
diff changeset
   633
| "regConcat acc (r # rs1) = regConcat (SEQ acc r) rs1"
Chengsong
parents:
diff changeset
   634
Chengsong
parents:
diff changeset
   635
fun attachCtx :: "arexp \<Rightarrow> rexp list \<Rightarrow> rexp set" where
Chengsong
parents:
diff changeset
   636
  "attachCtx r ctx = set (turnIntoTerms (regConcat (erase r) ctx))"
Chengsong
parents:
diff changeset
   637
Chengsong
parents:
diff changeset
   638
Chengsong
parents:
diff changeset
   639
Chengsong
parents:
diff changeset
   640
fun rs1_subseteq_rs2 :: "rexp set \<Rightarrow> rexp set \<Rightarrow> bool" where
Chengsong
parents:
diff changeset
   641
  "rs1_subseteq_rs2 rs1 rs2 = (rs1 \<subseteq> rs2)"
Chengsong
parents:
diff changeset
   642
545
333013923c5a more changes to blexersimp.thy
Chengsong
parents: 544
diff changeset
   643
fun notZero :: "arexp \<Rightarrow> bool" where
333013923c5a more changes to blexersimp.thy
Chengsong
parents: 544
diff changeset
   644
  "notZero AZERO = True"
333013923c5a more changes to blexersimp.thy
Chengsong
parents: 544
diff changeset
   645
| "notZero _ = False"
333013923c5a more changes to blexersimp.thy
Chengsong
parents: 544
diff changeset
   646
544
Chengsong
parents:
diff changeset
   647
fun prune6 :: "rexp set \<Rightarrow> arexp \<Rightarrow> rexp list \<Rightarrow> arexp" where
Chengsong
parents:
diff changeset
   648
  "prune6 acc a ctx = (if (ABIncludedByC a ctx acc attachCtx rs1_subseteq_rs2) then AZERO else 
Chengsong
parents:
diff changeset
   649
                        (case a of (ASEQ bs r1 r2) \<Rightarrow> bsimp_ASEQ bs (prune6 acc r1 (erase r2 # ctx)) r2
545
333013923c5a more changes to blexersimp.thy
Chengsong
parents: 544
diff changeset
   650
                                 | AALTs bs rs0 \<Rightarrow> bsimp_AALTs bs (filter notZero (map (\<lambda>r.(prune6 acc r ctx)) rs0)))  )"
333013923c5a more changes to blexersimp.thy
Chengsong
parents: 544
diff changeset
   651
333013923c5a more changes to blexersimp.thy
Chengsong
parents: 544
diff changeset
   652
544
Chengsong
parents:
diff changeset
   653
fun dB6 :: "arexp list \<Rightarrow> rexp set \<Rightarrow> arexp list" where
Chengsong
parents:
diff changeset
   654
  "dB6 [] acc = []"
Chengsong
parents:
diff changeset
   655
| "dB6 (a # as) acc = (if (erase a \<in> acc) then (dB6 as acc) 
545
333013923c5a more changes to blexersimp.thy
Chengsong
parents: 544
diff changeset
   656
                       else (let pruned = prune6 acc a [] in 
544
Chengsong
parents:
diff changeset
   657
                              (case pruned of
Chengsong
parents:
diff changeset
   658
                                 AZERO \<Rightarrow> dB6 as acc
545
333013923c5a more changes to blexersimp.thy
Chengsong
parents: 544
diff changeset
   659
                               |xPrime \<Rightarrow> xPrime # (dB6 as ( (set (turnIntoTerms (erase pruned))) \<union> acc)  ) ) ))   "
333013923c5a more changes to blexersimp.thy
Chengsong
parents: 544
diff changeset
   660
333013923c5a more changes to blexersimp.thy
Chengsong
parents: 544
diff changeset
   661
333013923c5a more changes to blexersimp.thy
Chengsong
parents: 544
diff changeset
   662
fun bsimpStrong6 :: "arexp \<Rightarrow> arexp" 
333013923c5a more changes to blexersimp.thy
Chengsong
parents: 544
diff changeset
   663
  where
333013923c5a more changes to blexersimp.thy
Chengsong
parents: 544
diff changeset
   664
  "bsimpStrong6 (ASEQ bs1 r1 r2) = bsimp_ASEQ bs1 (bsimpStrong6 r1) (bsimpStrong6 r2)"
333013923c5a more changes to blexersimp.thy
Chengsong
parents: 544
diff changeset
   665
| "bsimpStrong6 (AALTs bs1 rs) = bsimp_AALTs bs1 (dB6 (flts (map bsimpStrong6 rs)) {}) "
333013923c5a more changes to blexersimp.thy
Chengsong
parents: 544
diff changeset
   666
| "bsimpStrong6 r = r"
333013923c5a more changes to blexersimp.thy
Chengsong
parents: 544
diff changeset
   667
333013923c5a more changes to blexersimp.thy
Chengsong
parents: 544
diff changeset
   668
333013923c5a more changes to blexersimp.thy
Chengsong
parents: 544
diff changeset
   669
fun 
333013923c5a more changes to blexersimp.thy
Chengsong
parents: 544
diff changeset
   670
  bdersStrong6 :: "arexp \<Rightarrow> string \<Rightarrow> arexp"
333013923c5a more changes to blexersimp.thy
Chengsong
parents: 544
diff changeset
   671
where
333013923c5a more changes to blexersimp.thy
Chengsong
parents: 544
diff changeset
   672
  "bdersStrong6 r [] = r"
333013923c5a more changes to blexersimp.thy
Chengsong
parents: 544
diff changeset
   673
| "bdersStrong6 r (c # s) = bdersStrong6 (bsimpStrong6 (bder c r)) s"
333013923c5a more changes to blexersimp.thy
Chengsong
parents: 544
diff changeset
   674
333013923c5a more changes to blexersimp.thy
Chengsong
parents: 544
diff changeset
   675
definition blexerStrong where
333013923c5a more changes to blexersimp.thy
Chengsong
parents: 544
diff changeset
   676
 "blexerStrong r s \<equiv> if bnullable (bdersStrong6 (intern r) s) then 
333013923c5a more changes to blexersimp.thy
Chengsong
parents: 544
diff changeset
   677
                    decode (bmkeps (bdersStrong6 (intern r) s)) r else None"
333013923c5a more changes to blexersimp.thy
Chengsong
parents: 544
diff changeset
   678
333013923c5a more changes to blexersimp.thy
Chengsong
parents: 544
diff changeset
   679
546
6e97f4aa7cd0 beforeBig changes
Chengsong
parents: 545
diff changeset
   680
(*
6e97f4aa7cd0 beforeBig changes
Chengsong
parents: 545
diff changeset
   681
lemma rewrite_preserves_bder: 
6e97f4aa7cd0 beforeBig changes
Chengsong
parents: 545
diff changeset
   682
  shows "r1 \<leadsto> r2 \<Longrightarrow> (bder c r1) \<leadsto>* (bder c r2)"
6e97f4aa7cd0 beforeBig changes
Chengsong
parents: 545
diff changeset
   683
  and   "rs1 s\<leadsto> rs2 \<Longrightarrow> map (bder c) rs1 s\<leadsto>* map (bder c) rs2"
6e97f4aa7cd0 beforeBig changes
Chengsong
parents: 545
diff changeset
   684
proof(induction rule: rrewrite_srewrite.inducts)
6e97f4aa7cd0 beforeBig changes
Chengsong
parents: 545
diff changeset
   685
  case (bs1 bs r2)
6e97f4aa7cd0 beforeBig changes
Chengsong
parents: 545
diff changeset
   686
  then show ?case
6e97f4aa7cd0 beforeBig changes
Chengsong
parents: 545
diff changeset
   687
    by (simp add: continuous_rewrite) 
6e97f4aa7cd0 beforeBig changes
Chengsong
parents: 545
diff changeset
   688
next
6e97f4aa7cd0 beforeBig changes
Chengsong
parents: 545
diff changeset
   689
  case (bs2 bs r1)
6e97f4aa7cd0 beforeBig changes
Chengsong
parents: 545
diff changeset
   690
  then show ?case 
6e97f4aa7cd0 beforeBig changes
Chengsong
parents: 545
diff changeset
   691
    apply(auto)
6e97f4aa7cd0 beforeBig changes
Chengsong
parents: 545
diff changeset
   692
    apply (meson bs6 contextrewrites0 rrewrite_srewrite.bs2 rs2 ss3 ss4 sss1 sss2)
6e97f4aa7cd0 beforeBig changes
Chengsong
parents: 545
diff changeset
   693
    by (simp add: r_in_rstar rrewrite_srewrite.bs2)
6e97f4aa7cd0 beforeBig changes
Chengsong
parents: 545
diff changeset
   694
next
6e97f4aa7cd0 beforeBig changes
Chengsong
parents: 545
diff changeset
   695
  case (bs3 bs1 bs2 r)
6e97f4aa7cd0 beforeBig changes
Chengsong
parents: 545
diff changeset
   696
  then show ?case 
6e97f4aa7cd0 beforeBig changes
Chengsong
parents: 545
diff changeset
   697
    apply(simp)
6e97f4aa7cd0 beforeBig changes
Chengsong
parents: 545
diff changeset
   698
    
6e97f4aa7cd0 beforeBig changes
Chengsong
parents: 545
diff changeset
   699
    by (metis (no_types, lifting) bder_fuse bs10 bs7 fuse_append rrewrites.simps ss4 to_zero_in_alt)
6e97f4aa7cd0 beforeBig changes
Chengsong
parents: 545
diff changeset
   700
next
6e97f4aa7cd0 beforeBig changes
Chengsong
parents: 545
diff changeset
   701
  case (bs4 r1 r2 bs r3)
6e97f4aa7cd0 beforeBig changes
Chengsong
parents: 545
diff changeset
   702
  have as: "r1 \<leadsto> r2" by fact
6e97f4aa7cd0 beforeBig changes
Chengsong
parents: 545
diff changeset
   703
  have IH: "bder c r1 \<leadsto>* bder c r2" by fact
6e97f4aa7cd0 beforeBig changes
Chengsong
parents: 545
diff changeset
   704
  from as IH show "bder c (ASEQ bs r1 r3) \<leadsto>* bder c (ASEQ bs r2 r3)"
6e97f4aa7cd0 beforeBig changes
Chengsong
parents: 545
diff changeset
   705
    by (metis bder.simps(5) bnullable0(1) contextrewrites1 rewrite_bmkeps_aux(1) star_seq)
6e97f4aa7cd0 beforeBig changes
Chengsong
parents: 545
diff changeset
   706
next
6e97f4aa7cd0 beforeBig changes
Chengsong
parents: 545
diff changeset
   707
  case (bs5 r3 r4 bs r1)
6e97f4aa7cd0 beforeBig changes
Chengsong
parents: 545
diff changeset
   708
  have as: "r3 \<leadsto> r4" by fact 
6e97f4aa7cd0 beforeBig changes
Chengsong
parents: 545
diff changeset
   709
  have IH: "bder c r3 \<leadsto>* bder c r4" by fact 
6e97f4aa7cd0 beforeBig changes
Chengsong
parents: 545
diff changeset
   710
  from as IH show "bder c (ASEQ bs r1 r3) \<leadsto>* bder c (ASEQ bs r1 r4)"
6e97f4aa7cd0 beforeBig changes
Chengsong
parents: 545
diff changeset
   711
    apply(simp)
6e97f4aa7cd0 beforeBig changes
Chengsong
parents: 545
diff changeset
   712
    apply(auto)
6e97f4aa7cd0 beforeBig changes
Chengsong
parents: 545
diff changeset
   713
    using contextrewrites0 r_in_rstar rewrites_fuse srewrites6 srewrites7 star_seq2 apply presburger
6e97f4aa7cd0 beforeBig changes
Chengsong
parents: 545
diff changeset
   714
    using star_seq2 by blast
6e97f4aa7cd0 beforeBig changes
Chengsong
parents: 545
diff changeset
   715
next
6e97f4aa7cd0 beforeBig changes
Chengsong
parents: 545
diff changeset
   716
  case (bs6 bs)
6e97f4aa7cd0 beforeBig changes
Chengsong
parents: 545
diff changeset
   717
  then show ?case
6e97f4aa7cd0 beforeBig changes
Chengsong
parents: 545
diff changeset
   718
    using rrewrite_srewrite.bs6 by force 
6e97f4aa7cd0 beforeBig changes
Chengsong
parents: 545
diff changeset
   719
next
6e97f4aa7cd0 beforeBig changes
Chengsong
parents: 545
diff changeset
   720
  case (bs7 bs r)
6e97f4aa7cd0 beforeBig changes
Chengsong
parents: 545
diff changeset
   721
  then show ?case
6e97f4aa7cd0 beforeBig changes
Chengsong
parents: 545
diff changeset
   722
    by (simp add: bder_fuse r_in_rstar rrewrite_srewrite.bs7) 
6e97f4aa7cd0 beforeBig changes
Chengsong
parents: 545
diff changeset
   723
next
6e97f4aa7cd0 beforeBig changes
Chengsong
parents: 545
diff changeset
   724
  case (bs10 rs1 rs2 bs)
6e97f4aa7cd0 beforeBig changes
Chengsong
parents: 545
diff changeset
   725
  then show ?case
6e97f4aa7cd0 beforeBig changes
Chengsong
parents: 545
diff changeset
   726
    using contextrewrites0 by force    
6e97f4aa7cd0 beforeBig changes
Chengsong
parents: 545
diff changeset
   727
next
6e97f4aa7cd0 beforeBig changes
Chengsong
parents: 545
diff changeset
   728
  case ss1
6e97f4aa7cd0 beforeBig changes
Chengsong
parents: 545
diff changeset
   729
  then show ?case by simp
6e97f4aa7cd0 beforeBig changes
Chengsong
parents: 545
diff changeset
   730
next
6e97f4aa7cd0 beforeBig changes
Chengsong
parents: 545
diff changeset
   731
  case (ss2 rs1 rs2 r)
6e97f4aa7cd0 beforeBig changes
Chengsong
parents: 545
diff changeset
   732
  then show ?case
6e97f4aa7cd0 beforeBig changes
Chengsong
parents: 545
diff changeset
   733
    by (simp add: srewrites7) 
6e97f4aa7cd0 beforeBig changes
Chengsong
parents: 545
diff changeset
   734
next
6e97f4aa7cd0 beforeBig changes
Chengsong
parents: 545
diff changeset
   735
  case (ss3 r1 r2 rs)
6e97f4aa7cd0 beforeBig changes
Chengsong
parents: 545
diff changeset
   736
  then show ?case
6e97f4aa7cd0 beforeBig changes
Chengsong
parents: 545
diff changeset
   737
    by (simp add: srewrites7) 
6e97f4aa7cd0 beforeBig changes
Chengsong
parents: 545
diff changeset
   738
next
6e97f4aa7cd0 beforeBig changes
Chengsong
parents: 545
diff changeset
   739
  case (ss4 rs)
6e97f4aa7cd0 beforeBig changes
Chengsong
parents: 545
diff changeset
   740
  then show ?case
6e97f4aa7cd0 beforeBig changes
Chengsong
parents: 545
diff changeset
   741
    using rrewrite_srewrite.ss4 by fastforce 
6e97f4aa7cd0 beforeBig changes
Chengsong
parents: 545
diff changeset
   742
next
6e97f4aa7cd0 beforeBig changes
Chengsong
parents: 545
diff changeset
   743
  case (ss5 bs1 rs1 rsb)
6e97f4aa7cd0 beforeBig changes
Chengsong
parents: 545
diff changeset
   744
  then show ?case 
6e97f4aa7cd0 beforeBig changes
Chengsong
parents: 545
diff changeset
   745
    apply(simp)
6e97f4aa7cd0 beforeBig changes
Chengsong
parents: 545
diff changeset
   746
    using bder_fuse_list map_map rrewrite_srewrite.ss5 srewrites.simps by blast
6e97f4aa7cd0 beforeBig changes
Chengsong
parents: 545
diff changeset
   747
next
6e97f4aa7cd0 beforeBig changes
Chengsong
parents: 545
diff changeset
   748
  case (ss6 a1 a2 bs rsa rsb)
6e97f4aa7cd0 beforeBig changes
Chengsong
parents: 545
diff changeset
   749
  then show ?case
6e97f4aa7cd0 beforeBig changes
Chengsong
parents: 545
diff changeset
   750
    apply(simp only: map_append map1)
6e97f4aa7cd0 beforeBig changes
Chengsong
parents: 545
diff changeset
   751
    apply(rule srewrites_trans)
6e97f4aa7cd0 beforeBig changes
Chengsong
parents: 545
diff changeset
   752
    apply(rule rs_in_rstar)
6e97f4aa7cd0 beforeBig changes
Chengsong
parents: 545
diff changeset
   753
    apply(rule_tac rrewrite_srewrite.ss6)
6e97f4aa7cd0 beforeBig changes
Chengsong
parents: 545
diff changeset
   754
    using Der_def der_correctness apply auto[1]
6e97f4aa7cd0 beforeBig changes
Chengsong
parents: 545
diff changeset
   755
    by blast
6e97f4aa7cd0 beforeBig changes
Chengsong
parents: 545
diff changeset
   756
qed
6e97f4aa7cd0 beforeBig changes
Chengsong
parents: 545
diff changeset
   757
*)
6e97f4aa7cd0 beforeBig changes
Chengsong
parents: 545
diff changeset
   758
6e97f4aa7cd0 beforeBig changes
Chengsong
parents: 545
diff changeset
   759
6e97f4aa7cd0 beforeBig changes
Chengsong
parents: 545
diff changeset
   760
545
333013923c5a more changes to blexersimp.thy
Chengsong
parents: 544
diff changeset
   761
lemma centralStrong:  
546
6e97f4aa7cd0 beforeBig changes
Chengsong
parents: 545
diff changeset
   762
  shows "bders r s \<leadsto>* bdersStrong6 r s"
545
333013923c5a more changes to blexersimp.thy
Chengsong
parents: 544
diff changeset
   763
proof(induct s arbitrary: r rule: rev_induct)
333013923c5a more changes to blexersimp.thy
Chengsong
parents: 544
diff changeset
   764
  case Nil
546
6e97f4aa7cd0 beforeBig changes
Chengsong
parents: 545
diff changeset
   765
  then show "bders r [] \<leadsto>* bdersStrong6 r []" by simp
545
333013923c5a more changes to blexersimp.thy
Chengsong
parents: 544
diff changeset
   766
next
333013923c5a more changes to blexersimp.thy
Chengsong
parents: 544
diff changeset
   767
  case (snoc x xs)
546
6e97f4aa7cd0 beforeBig changes
Chengsong
parents: 545
diff changeset
   768
  have IH: "\<And>r. bders r xs \<leadsto>* bdersStrong6 r xs" by fact
6e97f4aa7cd0 beforeBig changes
Chengsong
parents: 545
diff changeset
   769
  have "bders r (xs @ [x]) = bders (bders r xs) [x]" by (simp add: bders_append)
6e97f4aa7cd0 beforeBig changes
Chengsong
parents: 545
diff changeset
   770
  also have "... \<leadsto>* bders (bdersStrong6 r xs) [x]" using IH
545
333013923c5a more changes to blexersimp.thy
Chengsong
parents: 544
diff changeset
   771
    by (simp add: rewrites_preserves_bder)
546
6e97f4aa7cd0 beforeBig changes
Chengsong
parents: 545
diff changeset
   772
  also have "... \<leadsto>* bdersStrong6 (bdersStrong6 r xs) [x]" using IH
545
333013923c5a more changes to blexersimp.thy
Chengsong
parents: 544
diff changeset
   773
    by (simp add: rewrites_to_bsimp)
333013923c5a more changes to blexersimp.thy
Chengsong
parents: 544
diff changeset
   774
  finally show "bders r (xs @ [x]) \<leadsto>* bders_simp r (xs @ [x])" 
333013923c5a more changes to blexersimp.thy
Chengsong
parents: 544
diff changeset
   775
    by (simp add: bders_simp_append)
333013923c5a more changes to blexersimp.thy
Chengsong
parents: 544
diff changeset
   776
qed
333013923c5a more changes to blexersimp.thy
Chengsong
parents: 544
diff changeset
   777
333013923c5a more changes to blexersimp.thy
Chengsong
parents: 544
diff changeset
   778
lemma mainStrong: 
333013923c5a more changes to blexersimp.thy
Chengsong
parents: 544
diff changeset
   779
  assumes "bnullable (bders r s)"
546
6e97f4aa7cd0 beforeBig changes
Chengsong
parents: 545
diff changeset
   780
  shows "bmkeps (bders r s) = bmkeps (bdersStrong6 r s)"
545
333013923c5a more changes to blexersimp.thy
Chengsong
parents: 544
diff changeset
   781
proof -
333013923c5a more changes to blexersimp.thy
Chengsong
parents: 544
diff changeset
   782
  have "bders_simp r s \<leadsto>* bdersStrong6 r s" sorry
333013923c5a more changes to blexersimp.thy
Chengsong
parents: 544
diff changeset
   783
  then 
546
6e97f4aa7cd0 beforeBig changes
Chengsong
parents: 545
diff changeset
   784
  show "bmkeps (bders r s) = bmkeps (bdersStrong6 r s)" 
545
333013923c5a more changes to blexersimp.thy
Chengsong
parents: 544
diff changeset
   785
333013923c5a more changes to blexersimp.thy
Chengsong
parents: 544
diff changeset
   786
  sorry
333013923c5a more changes to blexersimp.thy
Chengsong
parents: 544
diff changeset
   787
qed
333013923c5a more changes to blexersimp.thy
Chengsong
parents: 544
diff changeset
   788
333013923c5a more changes to blexersimp.thy
Chengsong
parents: 544
diff changeset
   789
333013923c5a more changes to blexersimp.thy
Chengsong
parents: 544
diff changeset
   790
333013923c5a more changes to blexersimp.thy
Chengsong
parents: 544
diff changeset
   791
333013923c5a more changes to blexersimp.thy
Chengsong
parents: 544
diff changeset
   792
theorem blexerStrong_correct :
333013923c5a more changes to blexersimp.thy
Chengsong
parents: 544
diff changeset
   793
  shows "blexerStrong r s = blexer_simp r s"
333013923c5a more changes to blexersimp.thy
Chengsong
parents: 544
diff changeset
   794
  
333013923c5a more changes to blexersimp.thy
Chengsong
parents: 544
diff changeset
   795
  sorry
333013923c5a more changes to blexersimp.thy
Chengsong
parents: 544
diff changeset
   796
544
Chengsong
parents:
diff changeset
   797
Chengsong
parents:
diff changeset
   798
Chengsong
parents:
diff changeset
   799
end