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