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