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