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