thys2/SizeBound.thy
author Chengsong
Sun, 10 Oct 2021 18:35:21 +0100
changeset 365 ec5e4fe4cc70
child 373 320f923c77b9
permissions -rw-r--r--
for new journal/conf paper!
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
365
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
     1
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
     2
theory SizeBound
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
     3
  imports "Lexer" 
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
     4
begin
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
     5
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
     6
section \<open>Bit-Encodings\<close>
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
     7
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
     8
datatype bit = Z | S
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
     9
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    10
fun code :: "val \<Rightarrow> bit list"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    11
where
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    12
  "code Void = []"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    13
| "code (Char c) = []"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    14
| "code (Left v) = Z # (code v)"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    15
| "code (Right v) = S # (code v)"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    16
| "code (Seq v1 v2) = (code v1) @ (code v2)"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    17
| "code (Stars []) = [S]"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    18
| "code (Stars (v # vs)) =  (Z # code v) @ code (Stars vs)"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    19
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    20
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    21
fun 
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    22
  Stars_add :: "val \<Rightarrow> val \<Rightarrow> val"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    23
where
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    24
  "Stars_add v (Stars vs) = Stars (v # vs)"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    25
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    26
function
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    27
  decode' :: "bit list \<Rightarrow> rexp \<Rightarrow> (val * bit list)"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    28
where
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    29
  "decode' ds ZERO = (Void, [])"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    30
| "decode' ds ONE = (Void, ds)"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    31
| "decode' ds (CH d) = (Char d, ds)"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    32
| "decode' [] (ALT r1 r2) = (Void, [])"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    33
| "decode' (Z # ds) (ALT r1 r2) = (let (v, ds') = decode' ds r1 in (Left v, ds'))"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    34
| "decode' (S # ds) (ALT r1 r2) = (let (v, ds') = decode' ds r2 in (Right v, ds'))"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    35
| "decode' ds (SEQ r1 r2) = (let (v1, ds') = decode' ds r1 in
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    36
                             let (v2, ds'') = decode' ds' r2 in (Seq v1 v2, ds''))"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    37
| "decode' [] (STAR r) = (Void, [])"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    38
| "decode' (S # ds) (STAR r) = (Stars [], ds)"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    39
| "decode' (Z # ds) (STAR r) = (let (v, ds') = decode' ds r in
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    40
                                    let (vs, ds'') = decode' ds' (STAR r) 
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    41
                                    in (Stars_add v vs, ds''))"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    42
by pat_completeness auto
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    43
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    44
lemma decode'_smaller:
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    45
  assumes "decode'_dom (ds, r)"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    46
  shows "length (snd (decode' ds r)) \<le> length ds"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    47
using assms
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    48
apply(induct ds r)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    49
apply(auto simp add: decode'.psimps split: prod.split)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    50
using dual_order.trans apply blast
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    51
by (meson dual_order.trans le_SucI)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    52
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    53
termination "decode'"  
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    54
apply(relation "inv_image (measure(%cs. size cs) <*lex*> measure(%s. size s)) (%(ds,r). (r,ds))") 
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    55
apply(auto dest!: decode'_smaller)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    56
by (metis less_Suc_eq_le snd_conv)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    57
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    58
definition
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    59
  decode :: "bit list \<Rightarrow> rexp \<Rightarrow> val option"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    60
where
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    61
  "decode ds r \<equiv> (let (v, ds') = decode' ds r 
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    62
                  in (if ds' = [] then Some v else None))"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    63
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    64
lemma decode'_code_Stars:
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    65
  assumes "\<forall>v\<in>set vs. \<Turnstile> v : r \<and> (\<forall>x. decode' (code v @ x) r = (v, x)) \<and> flat v \<noteq> []" 
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    66
  shows "decode' (code (Stars vs) @ ds) (STAR r) = (Stars vs, ds)"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    67
  using assms
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    68
  apply(induct vs)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    69
  apply(auto)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    70
  done
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    71
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    72
lemma decode'_code:
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    73
  assumes "\<Turnstile> v : r"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    74
  shows "decode' ((code v) @ ds) r = (v, ds)"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    75
using assms
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    76
  apply(induct v r arbitrary: ds) 
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    77
  apply(auto)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    78
  using decode'_code_Stars by blast
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    79
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    80
lemma decode_code:
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    81
  assumes "\<Turnstile> v : r"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    82
  shows "decode (code v) r = Some v"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    83
  using assms unfolding decode_def
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    84
  by (smt append_Nil2 decode'_code old.prod.case)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    85
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    86
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    87
section {* Annotated Regular Expressions *}
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    88
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    89
datatype arexp = 
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    90
  AZERO
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    91
| AONE "bit list"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    92
| ACHAR "bit list" char
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    93
| ASEQ "bit list" arexp arexp
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    94
| AALTs "bit list" "arexp list"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    95
| ASTAR "bit list" arexp
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    96
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    97
abbreviation
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    98
  "AALT bs r1 r2 \<equiv> AALTs bs [r1, r2]"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    99
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   100
fun asize :: "arexp \<Rightarrow> nat" where
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   101
  "asize AZERO = 1"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   102
| "asize (AONE cs) = 1" 
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   103
| "asize (ACHAR cs c) = 1"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   104
| "asize (AALTs cs rs) = Suc (sum_list (map asize rs))"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   105
| "asize (ASEQ cs r1 r2) = Suc (asize r1 + asize r2)"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   106
| "asize (ASTAR cs r) = Suc (asize r)"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   107
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   108
fun 
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   109
  erase :: "arexp \<Rightarrow> rexp"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   110
where
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   111
  "erase AZERO = ZERO"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   112
| "erase (AONE _) = ONE"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   113
| "erase (ACHAR _ c) = CH c"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   114
| "erase (AALTs _ []) = ZERO"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   115
| "erase (AALTs _ [r]) = (erase r)"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   116
| "erase (AALTs bs (r#rs)) = ALT (erase r) (erase (AALTs bs rs))"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   117
| "erase (ASEQ _ r1 r2) = SEQ (erase r1) (erase r2)"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   118
| "erase (ASTAR _ r) = STAR (erase r)"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   119
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   120
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   121
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   122
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   123
fun nonalt :: "arexp \<Rightarrow> bool"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   124
  where
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   125
  "nonalt (AALTs bs2 rs) = False"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   126
| "nonalt r = True"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   127
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   128
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   129
fun good :: "arexp \<Rightarrow> bool" where
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   130
  "good AZERO = False"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   131
| "good (AONE cs) = True" 
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   132
| "good (ACHAR cs c) = True"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   133
| "good (AALTs cs []) = False"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   134
| "good (AALTs cs [r]) = False"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   135
| "good (AALTs cs (r1#r2#rs)) = (\<forall>r' \<in> set (r1#r2#rs). good r' \<and> nonalt r')"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   136
| "good (ASEQ _ AZERO _) = False"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   137
| "good (ASEQ _ (AONE _) _) = False"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   138
| "good (ASEQ _ _ AZERO) = False"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   139
| "good (ASEQ cs r1 r2) = (good r1 \<and> good r2)"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   140
| "good (ASTAR cs r) = True"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   141
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   142
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   143
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   144
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   145
fun fuse :: "bit list \<Rightarrow> arexp \<Rightarrow> arexp" where
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   146
  "fuse bs AZERO = AZERO"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   147
| "fuse bs (AONE cs) = AONE (bs @ cs)" 
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   148
| "fuse bs (ACHAR cs c) = ACHAR (bs @ cs) c"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   149
| "fuse bs (AALTs cs rs) = AALTs (bs @ cs) rs"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   150
| "fuse bs (ASEQ cs r1 r2) = ASEQ (bs @ cs) r1 r2"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   151
| "fuse bs (ASTAR cs r) = ASTAR (bs @ cs) r"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   152
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   153
lemma fuse_append:
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   154
  shows "fuse (bs1 @ bs2) r = fuse bs1 (fuse bs2 r)"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   155
  apply(induct r)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   156
  apply(auto)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   157
  done
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   158
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   159
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   160
fun intern :: "rexp \<Rightarrow> arexp" where
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   161
  "intern ZERO = AZERO"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   162
| "intern ONE = AONE []"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   163
| "intern (CH c) = ACHAR [] c"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   164
| "intern (ALT r1 r2) = AALT [] (fuse [Z] (intern r1)) 
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   165
                                (fuse [S]  (intern r2))"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   166
| "intern (SEQ r1 r2) = ASEQ [] (intern r1) (intern r2)"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   167
| "intern (STAR r) = ASTAR [] (intern r)"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   168
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   169
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   170
fun retrieve :: "arexp \<Rightarrow> val \<Rightarrow> bit list" where
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   171
  "retrieve (AONE bs) Void = bs"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   172
| "retrieve (ACHAR bs c) (Char d) = bs"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   173
| "retrieve (AALTs bs [r]) v = bs @ retrieve r v" 
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   174
| "retrieve (AALTs bs (r#rs)) (Left v) = bs @ retrieve r v"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   175
| "retrieve (AALTs bs (r#rs)) (Right v) = bs @ retrieve (AALTs [] rs) v"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   176
| "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
   177
| "retrieve (ASTAR bs r) (Stars []) = bs @ [S]"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   178
| "retrieve (ASTAR bs r) (Stars (v#vs)) = 
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   179
     bs @ [Z] @ retrieve r v @ retrieve (ASTAR [] r) (Stars vs)"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   180
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   181
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   182
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   183
fun
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   184
 bnullable :: "arexp \<Rightarrow> bool"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   185
where
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   186
  "bnullable (AZERO) = False"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   187
| "bnullable (AONE bs) = True"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   188
| "bnullable (ACHAR bs c) = False"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   189
| "bnullable (AALTs bs rs) = (\<exists>r \<in> set rs. bnullable r)"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   190
| "bnullable (ASEQ bs r1 r2) = (bnullable r1 \<and> bnullable r2)"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   191
| "bnullable (ASTAR bs r) = True"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   192
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   193
fun 
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   194
  bmkeps :: "arexp \<Rightarrow> bit list"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   195
where
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   196
  "bmkeps(AONE bs) = bs"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   197
| "bmkeps(ASEQ bs r1 r2) = bs @ (bmkeps r1) @ (bmkeps r2)"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   198
| "bmkeps(AALTs bs [r]) = bs @ (bmkeps r)"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   199
| "bmkeps(AALTs bs (r#rs)) = (if bnullable(r) then bs @ (bmkeps r) else (bmkeps (AALTs bs rs)))"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   200
| "bmkeps(ASTAR bs r) = bs @ [S]"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   201
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   202
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   203
fun
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   204
 bder :: "char \<Rightarrow> arexp \<Rightarrow> arexp"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   205
where
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   206
  "bder c (AZERO) = AZERO"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   207
| "bder c (AONE bs) = AZERO"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   208
| "bder c (ACHAR bs d) = (if c = d then AONE bs else AZERO)"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   209
| "bder c (AALTs bs rs) = AALTs bs (map (bder c) rs)"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   210
| "bder c (ASEQ bs r1 r2) = 
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   211
     (if bnullable r1
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   212
      then AALT bs (ASEQ [] (bder c r1) r2) (fuse (bmkeps r1) (bder c r2))
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   213
      else ASEQ bs (bder c r1) r2)"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   214
| "bder c (ASTAR bs r) = ASEQ bs (fuse [Z] (bder c r)) (ASTAR [] r)"
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
  bders :: "arexp \<Rightarrow> string \<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
  "bders r [] = r"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   221
| "bders r (c#s) = bders (bder c r) s"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   222
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   223
lemma bders_append:
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   224
  "bders r (s1 @ s2) = bders (bders r s1) s2"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   225
  apply(induct s1 arbitrary: r s2)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   226
  apply(simp_all)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   227
  done
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   228
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   229
lemma bnullable_correctness:
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   230
  shows "nullable (erase r) = bnullable r"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   231
  apply(induct r rule: erase.induct)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   232
  apply(simp_all)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   233
  done
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   234
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   235
lemma erase_fuse:
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   236
  shows "erase (fuse bs r) = erase r"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   237
  apply(induct r rule: erase.induct)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   238
  apply(simp_all)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   239
  done
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   240
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   241
thm Posix.induct
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   242
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   243
lemma erase_intern [simp]:
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   244
  shows "erase (intern r) = r"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   245
  apply(induct r)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   246
  apply(simp_all add: erase_fuse)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   247
  done
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   248
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   249
lemma erase_bder [simp]:
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   250
  shows "erase (bder a r) = der a (erase r)"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   251
  apply(induct r rule: erase.induct)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   252
  apply(simp_all add: erase_fuse bnullable_correctness)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   253
  done
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   254
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   255
lemma erase_bders [simp]:
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   256
  shows "erase (bders r s) = ders s (erase r)"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   257
  apply(induct s arbitrary: r )
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   258
  apply(simp_all)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   259
  done
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   260
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   261
lemma retrieve_encode_STARS:
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   262
  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
   263
  shows "code (Stars vs) = retrieve (ASTAR [] (intern r)) (Stars vs)"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   264
  using assms
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   265
  apply(induct vs)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   266
  apply(simp_all)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   267
  done
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   268
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   269
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   270
lemma retrieve_fuse2:
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   271
  assumes "\<Turnstile> v : (erase r)"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   272
  shows "retrieve (fuse bs r) v = bs @ retrieve r v"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   273
  using assms
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   274
  apply(induct r arbitrary: v bs)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   275
         apply(auto elim: Prf_elims)[4]
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   276
   defer
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   277
  using retrieve_encode_STARS
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   278
   apply(auto elim!: Prf_elims)[1]
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   279
   apply(case_tac vs)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   280
    apply(simp)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   281
   apply(simp)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   282
  (* AALTs  case *)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   283
  apply(simp)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   284
  apply(case_tac x2a)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   285
   apply(simp)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   286
   apply(auto elim!: Prf_elims)[1]
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   287
  apply(simp)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   288
   apply(case_tac list)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   289
   apply(simp)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   290
  apply(auto)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   291
  apply(auto elim!: Prf_elims)[1]
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   292
  done
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   293
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   294
lemma retrieve_fuse:
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   295
  assumes "\<Turnstile> v : r"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   296
  shows "retrieve (fuse bs (intern r)) v = bs @ retrieve (intern r) v"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   297
  using assms 
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   298
  by (simp_all add: retrieve_fuse2)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   299
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   300
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   301
lemma retrieve_code:
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   302
  assumes "\<Turnstile> v : r"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   303
  shows "code v = retrieve (intern r) v"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   304
  using assms
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   305
  apply(induct v r )
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   306
  apply(simp_all add: retrieve_fuse retrieve_encode_STARS)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   307
  done
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   308
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   309
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   310
lemma bnullable_Hdbmkeps_Hd:
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   311
  assumes "bnullable a" 
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   312
  shows  "bmkeps (AALTs bs (a # rs)) = bs @ (bmkeps a)"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   313
  using assms
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   314
  by (metis bmkeps.simps(3) bmkeps.simps(4) list.exhaust)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   315
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   316
lemma r1:
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   317
  assumes "\<not> bnullable a" "bnullable (AALTs bs rs)"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   318
  shows  "bmkeps (AALTs bs (a # rs)) = bmkeps (AALTs bs rs)"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   319
  using assms
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   320
  apply(induct rs)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   321
   apply(auto)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   322
  done
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   323
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   324
lemma r2:
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   325
  assumes "x \<in> set rs" "bnullable x"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   326
  shows "bnullable (AALTs bs rs)"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   327
  using assms
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   328
  apply(induct rs)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   329
   apply(auto)
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  r3:
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   333
  assumes "\<not> bnullable r" 
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   334
          " \<exists> x \<in> set rs. bnullable x"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   335
  shows "retrieve (AALTs bs rs) (mkeps (erase (AALTs bs rs))) =
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   336
         retrieve (AALTs bs (r # rs)) (mkeps (erase (AALTs bs (r # rs))))"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   337
  using assms
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   338
  apply(induct rs arbitrary: r bs)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   339
   apply(auto)[1]
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   340
  apply(auto)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   341
  using bnullable_correctness apply blast
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   342
    apply(auto simp add: bnullable_correctness mkeps_nullable retrieve_fuse2)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   343
   apply(subst retrieve_fuse2[symmetric])
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   344
  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
   345
   apply(simp)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   346
  apply(case_tac "bnullable a")
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   347
  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
   348
  apply(drule_tac x="a" in meta_spec)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   349
  apply(drule_tac x="bs" in meta_spec)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   350
  apply(drule meta_mp)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   351
   apply(simp)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   352
  apply(drule meta_mp)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   353
   apply(auto)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   354
  apply(subst retrieve_fuse2[symmetric])
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   355
  apply(case_tac rs)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   356
    apply(simp)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   357
   apply(auto)[1]
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   358
      apply (simp add: bnullable_correctness)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   359
  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
   360
    apply (simp add: bnullable_correctness)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   361
  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
   362
  apply(simp)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   363
  done
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   364
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   365
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   366
lemma t: 
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   367
  assumes "\<forall>r \<in> set rs. nullable (erase r) \<longrightarrow> bmkeps r = retrieve r (mkeps (erase r))" 
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   368
          "nullable (erase (AALTs bs rs))"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   369
  shows " bmkeps (AALTs bs rs) = retrieve (AALTs bs rs) (mkeps (erase (AALTs bs rs)))"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   370
  using assms
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   371
  apply(induct rs arbitrary: bs)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   372
   apply(simp)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   373
  apply(auto simp add: bnullable_correctness)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   374
   apply(case_tac rs)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   375
     apply(auto simp add: bnullable_correctness)[2]
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   376
   apply(subst r1)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   377
     apply(simp)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   378
    apply(rule r2)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   379
     apply(assumption)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   380
    apply(simp)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   381
   apply(drule_tac x="bs" in meta_spec)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   382
   apply(drule meta_mp)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   383
    apply(auto)[1]
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   384
   prefer 2
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   385
  apply(case_tac "bnullable a")
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   386
    apply(subst bnullable_Hdbmkeps_Hd)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   387
     apply blast
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   388
    apply(subgoal_tac "nullable (erase a)")
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   389
  prefer 2
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   390
  using bnullable_correctness apply blast
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   391
  apply (metis (no_types, lifting) erase.simps(5) erase.simps(6) list.exhaust mkeps.simps(3) retrieve.simps(3) retrieve.simps(4))
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   392
  apply(subst r1)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   393
     apply(simp)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   394
  using r2 apply blast
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   395
  apply(drule_tac x="bs" in meta_spec)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   396
   apply(drule meta_mp)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   397
    apply(auto)[1]
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   398
   apply(simp)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   399
  using r3 apply blast
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   400
  apply(auto)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   401
  using r3 by blast
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   402
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   403
lemma bmkeps_retrieve:
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   404
  assumes "nullable (erase r)"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   405
  shows "bmkeps r = retrieve r (mkeps (erase r))"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   406
  using assms
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   407
  apply(induct r)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   408
         apply(simp)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   409
        apply(simp)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   410
       apply(simp)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   411
    apply(simp)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   412
   defer
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   413
   apply(simp)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   414
  apply(rule t)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   415
   apply(auto)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   416
  done
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   417
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   418
lemma bder_retrieve:
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   419
  assumes "\<Turnstile> v : der c (erase r)"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   420
  shows "retrieve (bder c r) v = retrieve r (injval (erase r) c v)"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   421
  using assms
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   422
  apply(induct r arbitrary: v rule: erase.induct)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   423
         apply(simp)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   424
         apply(erule Prf_elims)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   425
        apply(simp)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   426
        apply(erule Prf_elims) 
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   427
        apply(simp)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   428
      apply(case_tac "c = ca")
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   429
       apply(simp)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   430
       apply(erule Prf_elims)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   431
       apply(simp)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   432
      apply(simp)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   433
       apply(erule Prf_elims)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   434
  apply(simp)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   435
      apply(erule Prf_elims)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   436
     apply(simp)
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(rename_tac "r\<^sub>1" "r\<^sub>2" rs v)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   439
    apply(erule Prf_elims)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   440
     apply(simp)
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(case_tac rs)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   443
     apply(simp)
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 (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
   446
   apply(simp)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   447
   apply(case_tac "nullable (erase r1)")
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   448
    apply(simp)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   449
  apply(erule Prf_elims)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   450
     apply(subgoal_tac "bnullable r1")
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   451
  prefer 2
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   452
  using bnullable_correctness apply blast
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   453
    apply(simp)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   454
     apply(erule Prf_elims)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   455
     apply(simp)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   456
   apply(subgoal_tac "bnullable r1")
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   457
  prefer 2
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   458
  using bnullable_correctness apply blast
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   459
    apply(simp)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   460
    apply(simp add: retrieve_fuse2)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   461
    apply(simp add: bmkeps_retrieve)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   462
   apply(simp)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   463
   apply(erule Prf_elims)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   464
   apply(simp)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   465
  using bnullable_correctness apply blast
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   466
  apply(rename_tac bs r v)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   467
  apply(simp)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   468
  apply(erule Prf_elims)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   469
     apply(clarify)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   470
  apply(erule Prf_elims)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   471
  apply(clarify)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   472
  apply(subst injval.simps)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   473
  apply(simp del: retrieve.simps)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   474
  apply(subst 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(simp)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   477
  apply(simp add: retrieve_fuse2)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   478
  done
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   479
  
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
lemma MAIN_decode:
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   483
  assumes "\<Turnstile> v : ders s r"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   484
  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
   485
  using assms
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   486
proof (induct s arbitrary: v rule: rev_induct)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   487
  case Nil
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   488
  have "\<Turnstile> v : ders [] r" by fact
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   489
  then have "\<Turnstile> v : r" by simp
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   490
  then have "Some v = decode (retrieve (intern r) v) r"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   491
    using decode_code retrieve_code by auto
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   492
  then show "Some (flex r id [] v) = decode (retrieve (bders (intern r) []) v) r"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   493
    by simp
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   494
next
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   495
  case (snoc c s v)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   496
  have IH: "\<And>v. \<Turnstile> v : ders s r \<Longrightarrow> 
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   497
     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
   498
  have asm: "\<Turnstile> v : ders (s @ [c]) r" by fact
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   499
  then have asm2: "\<Turnstile> injval (ders s r) c v : ders s r" 
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   500
    by (simp add: Prf_injval ders_append)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   501
  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
   502
    by (simp add: flex_append)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   503
  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
   504
    using asm2 IH by simp
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   505
  also have "... = decode (retrieve (bder c (bders (intern r) s)) v) r"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   506
    using asm by (simp_all add: bder_retrieve ders_append)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   507
  finally show "Some (flex r id (s @ [c]) v) = 
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   508
                 decode (retrieve (bders (intern r) (s @ [c])) v) r" by (simp add: bders_append)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   509
qed
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   510
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   511
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   512
definition blex where
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   513
 "blex a s \<equiv> if bnullable (bders a s) then Some (bmkeps (bders a s)) else None"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   514
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   515
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   516
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   517
definition blexer where
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   518
 "blexer r s \<equiv> if bnullable (bders (intern r) s) then 
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   519
                decode (bmkeps (bders (intern r) s)) r else None"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   520
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   521
lemma blexer_correctness:
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   522
  shows "blexer r s = lexer r s"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   523
proof -
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   524
  { define bds where "bds \<equiv> bders (intern r) s"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   525
    define ds  where "ds \<equiv> ders s r"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   526
    assume asm: "nullable ds"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   527
    have era: "erase bds = ds" 
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   528
      unfolding ds_def bds_def by simp
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   529
    have mke: "\<Turnstile> mkeps ds : ds"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   530
      using asm by (simp add: mkeps_nullable)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   531
    have "decode (bmkeps bds) r = decode (retrieve bds (mkeps ds)) r"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   532
      using bmkeps_retrieve
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   533
      using asm era by (simp add: bmkeps_retrieve)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   534
    also have "... =  Some (flex r id s (mkeps ds))"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   535
      using mke by (simp_all add: MAIN_decode ds_def bds_def)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   536
    finally have "decode (bmkeps bds) r = Some (flex r id s (mkeps ds))" 
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   537
      unfolding bds_def ds_def .
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   538
  }
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   539
  then show "blexer r s = lexer r s"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   540
    unfolding blexer_def lexer_flex
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   541
    apply(subst bnullable_correctness[symmetric])
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   542
    apply(simp)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   543
    done
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   544
qed
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   545
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   546
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   547
fun distinctBy :: "'a list \<Rightarrow> ('a \<Rightarrow> 'b) \<Rightarrow> 'b set \<Rightarrow> 'a list"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   548
  where
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   549
  "distinctBy [] f acc = []"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   550
| "distinctBy (x#xs) f acc = 
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   551
     (if (f x) \<in> acc then distinctBy xs f acc 
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   552
      else x # (distinctBy xs f ({f x} \<union> acc)))"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   553
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   554
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   555
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   556
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   557
fun flts :: "arexp list \<Rightarrow> arexp list"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   558
  where 
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   559
  "flts [] = []"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   560
| "flts (AZERO # rs) = flts rs"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   561
| "flts ((AALTs bs  rs1) # rs) = (map (fuse bs) rs1) @ flts rs"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   562
| "flts (r1 # rs) = r1 # flts rs"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   563
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   564
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   565
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   566
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   567
fun li :: "bit list \<Rightarrow> arexp list \<Rightarrow> arexp"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   568
  where
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   569
  "li _ [] = AZERO"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   570
| "li bs [a] = fuse bs a"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   571
| "li bs as = AALTs bs as"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   572
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   573
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   574
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   575
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   576
fun bsimp_ASEQ :: "bit list \<Rightarrow> arexp \<Rightarrow> arexp \<Rightarrow> arexp"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   577
  where
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   578
  "bsimp_ASEQ _ AZERO _ = AZERO"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   579
| "bsimp_ASEQ _ _ AZERO = AZERO"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   580
| "bsimp_ASEQ bs1 (AONE bs2) r2 = fuse (bs1 @ bs2) r2"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   581
| "bsimp_ASEQ bs1 r1 r2 = ASEQ  bs1 r1 r2"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   582
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   583
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   584
fun bsimp_AALTs :: "bit list \<Rightarrow> arexp list \<Rightarrow> arexp"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   585
  where
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   586
  "bsimp_AALTs _ [] = AZERO"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   587
| "bsimp_AALTs bs1 [r] = fuse bs1 r"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   588
| "bsimp_AALTs bs1 rs = AALTs bs1 rs"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   589
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   590
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   591
fun bsimp :: "arexp \<Rightarrow> arexp" 
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   592
  where
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   593
  "bsimp (ASEQ bs1 r1 r2) = bsimp_ASEQ bs1 (bsimp r1) (bsimp r2)"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   594
| "bsimp (AALTs bs1 rs) = bsimp_AALTs bs1 (distinctBy  (flts (map bsimp rs)) erase {} ) "
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   595
| "bsimp r = r"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   596
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
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   600
fun 
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   601
  bders_simp :: "arexp \<Rightarrow> string \<Rightarrow> arexp"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   602
where
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   603
  "bders_simp r [] = r"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   604
| "bders_simp r (c # s) = bders_simp (bsimp (bder c r)) s"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   605
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   606
definition blexer_simp where
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   607
 "blexer_simp r s \<equiv> if bnullable (bders_simp (intern r) s) then 
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   608
                decode (bmkeps (bders_simp (intern r) s)) r else None"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   609
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   610
export_code bders_simp in Scala module_name Example
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   611
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   612
lemma bders_simp_append:
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   613
  shows "bders_simp r (s1 @ s2) = bders_simp (bders_simp r s1) s2"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   614
  apply(induct s1 arbitrary: r s2)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   615
   apply(simp)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   616
  apply(simp)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   617
  done
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   618
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   619
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   620
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   621
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   622
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   623
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   624
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   625
lemma L_bsimp_ASEQ:
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   626
  "L (SEQ (erase r1) (erase r2)) = L (erase (bsimp_ASEQ bs r1 r2))"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   627
  apply(induct bs r1 r2 rule: bsimp_ASEQ.induct)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   628
  apply(simp_all)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   629
  by (metis erase_fuse fuse.simps(4))
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   630
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   631
lemma L_bsimp_AALTs:
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   632
  "L (erase (AALTs bs rs)) = L (erase (bsimp_AALTs bs rs))"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   633
  apply(induct bs rs rule: bsimp_AALTs.induct)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   634
  apply(simp_all add: erase_fuse)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   635
  done
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   636
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   637
lemma L_erase_AALTs:
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   638
  shows "L (erase (AALTs bs rs)) = \<Union> (L ` erase ` (set rs))"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   639
  apply(induct rs)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   640
   apply(simp)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   641
  apply(simp)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   642
  apply(case_tac rs)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   643
   apply(simp)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   644
  apply(simp)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   645
  done
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   646
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   647
lemma L_erase_flts:
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   648
  shows "\<Union> (L ` erase ` (set (flts rs))) = \<Union> (L ` erase ` (set rs))"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   649
  apply(induct rs rule: flts.induct)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   650
        apply(simp_all)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   651
  apply(auto)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   652
  using L_erase_AALTs erase_fuse apply auto[1]
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   653
  by (simp add: L_erase_AALTs erase_fuse)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   654
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   655
lemma L_erase_dB_acc:
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   656
  shows "( \<Union>(L ` acc) \<union> ( \<Union> (L ` erase ` (set (distinctBy rs erase acc) ) ) )) = \<Union>(L ` acc) \<union>  \<Union> (L ` erase ` (set rs))"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   657
  apply(induction rs arbitrary: acc)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   658
   apply simp
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   659
  apply simp
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   660
  by (smt (z3) SUP_absorb UN_insert sup_assoc sup_commute)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   661
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   662
lemma L_erase_dB:
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   663
  shows " ( \<Union> (L ` erase ` (set (distinctBy rs erase {}) ) ) ) = \<Union> (L ` erase ` (set rs))"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   664
  by (metis L_erase_dB_acc Un_commute Union_image_empty)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   665
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   666
lemma L_bsimp_erase:
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   667
  shows "L (erase r) = L (erase (bsimp r))"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   668
  apply(induct r)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   669
  apply(simp)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   670
  apply(simp)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   671
  apply(simp)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   672
  apply(auto simp add: Sequ_def)[1]
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   673
  apply(subst L_bsimp_ASEQ[symmetric])
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   674
  apply(auto simp add: Sequ_def)[1]
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   675
  apply(subst (asm)  L_bsimp_ASEQ[symmetric])
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   676
  apply(auto simp add: Sequ_def)[1]
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   677
   apply(simp)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   678
   apply(subst L_bsimp_AALTs[symmetric])
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   679
   defer
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   680
   apply(simp)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   681
  apply(subst (2)L_erase_AALTs)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   682
  apply(subst L_erase_dB)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   683
  apply(subst L_erase_flts)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   684
  apply(auto)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   685
   apply (simp add: L_erase_AALTs)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   686
  using L_erase_AALTs by blast
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   687
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   688
lemma bsimp_ASEQ0:
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   689
  shows "bsimp_ASEQ bs r1 AZERO = AZERO"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   690
  apply(induct r1)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   691
  apply(auto)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   692
  done
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   693
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   694
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   695
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   696
lemma bsimp_ASEQ1:
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   697
  assumes "r1 \<noteq> AZERO" "r2 \<noteq> AZERO" "\<forall>bs. r1 \<noteq> AONE bs"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   698
  shows "bsimp_ASEQ bs r1 r2 = ASEQ bs r1 r2"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   699
  using assms
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   700
  apply(induct bs r1 r2 rule: bsimp_ASEQ.induct)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   701
  apply(auto)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   702
  done
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   703
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   704
lemma bsimp_ASEQ2:
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   705
  shows "bsimp_ASEQ bs (AONE bs1) r2 = fuse (bs @ bs1) r2"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   706
  apply(induct r2)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   707
  apply(auto)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   708
  done
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   709
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   710
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   711
lemma L_bders_simp:
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   712
  shows "L (erase (bders_simp r s)) = L (erase (bders r s))"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   713
  apply(induct s arbitrary: r rule: rev_induct)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   714
   apply(simp)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   715
  apply(simp)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   716
  apply(simp add: ders_append)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   717
  apply(simp add: bders_simp_append)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   718
  apply(simp add: L_bsimp_erase[symmetric])
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   719
  by (simp add: der_correctness)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   720
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   721
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   722
lemma b2:
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   723
  assumes "bnullable r"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   724
  shows "bmkeps (fuse bs r) = bs @ bmkeps r"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   725
  by (simp add: assms bmkeps_retrieve bnullable_correctness erase_fuse mkeps_nullable retrieve_fuse2)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   726
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   727
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   728
lemma b4:
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   729
  shows "bnullable (bders_simp r s) = bnullable (bders r s)"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   730
  by (metis L_bders_simp bnullable_correctness lexer.simps(1) lexer_correct_None option.distinct(1))
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   731
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   732
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   733
lemma qq1:
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   734
  assumes "\<exists>r \<in> set rs. bnullable r"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   735
  shows "bmkeps (AALTs bs (rs @ rs1)) = bmkeps (AALTs bs rs)"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   736
  using assms
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   737
  apply(induct rs arbitrary: rs1 bs)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   738
  apply(simp)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   739
  apply(simp)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   740
  by (metis Nil_is_append_conv bmkeps.simps(4) neq_Nil_conv bnullable_Hdbmkeps_Hd split_list_last)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   741
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   742
lemma qq2:
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   743
  assumes "\<forall>r \<in> set rs. \<not> bnullable r" "\<exists>r \<in> set rs1. bnullable r"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   744
  shows "bmkeps (AALTs bs (rs @ rs1)) = bmkeps (AALTs bs rs1)"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   745
  using assms
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   746
  apply(induct rs arbitrary: rs1 bs)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   747
  apply(simp)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   748
  apply(simp)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   749
  by (metis append_assoc in_set_conv_decomp r1 r2)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   750
  
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   751
lemma qq3:
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   752
  shows "bnullable (AALTs bs rs) = (\<exists>r \<in> set rs. bnullable r)"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   753
  apply(induct rs arbitrary: bs)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   754
  apply(simp)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   755
  apply(simp)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   756
  done
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   757
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   758
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   759
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   760
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   761
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   762
fun nonnested :: "arexp \<Rightarrow> bool"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   763
  where
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   764
  "nonnested (AALTs bs2 []) = True"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   765
| "nonnested (AALTs bs2 ((AALTs bs1 rs1) # rs2)) = False"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   766
| "nonnested (AALTs bs2 (r # rs2)) = nonnested (AALTs bs2 rs2)"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   767
| "nonnested r = True"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   768
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   769
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   770
lemma  k0:
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   771
  shows "flts (r # rs1) = flts [r] @ flts rs1"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   772
  apply(induct r arbitrary: rs1)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   773
   apply(auto)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   774
  done
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   775
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   776
lemma  k00:
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   777
  shows "flts (rs1 @ rs2) = flts rs1 @ flts rs2"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   778
  apply(induct rs1 arbitrary: rs2)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   779
   apply(auto)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   780
  by (metis append.assoc k0)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   781
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   782
lemma  k0a:
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   783
  shows "flts [AALTs bs rs] = map (fuse bs)  rs"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   784
  apply(simp)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   785
  done
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   786
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   787
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   788
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   789
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   790
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   791
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   792
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   793
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   794
lemma bsimp_AALTs_qq:
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   795
  assumes "1 < length rs"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   796
  shows "bsimp_AALTs bs rs = AALTs bs  rs"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   797
  using  assms
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   798
  apply(case_tac rs)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   799
   apply(simp)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   800
  apply(case_tac list)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   801
   apply(simp_all)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   802
  done
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   803
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 bbbbs1:
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   807
  shows "nonalt r \<or> (\<exists>bs rs. r  = AALTs bs rs)"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   808
  using nonalt.elims(3) by auto
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   809
  
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   810
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   811
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   812
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   813
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   814
lemma flts_append:
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   815
  "flts (xs1 @ xs2) = flts xs1 @ flts xs2"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   816
  apply(induct xs1  arbitrary: xs2  rule: rev_induct)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   817
   apply(auto)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   818
  apply(case_tac xs)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   819
   apply(auto)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   820
   apply(case_tac x)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   821
        apply(auto)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   822
  apply(case_tac x)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   823
        apply(auto)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   824
  done
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   825
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   826
fun nonazero :: "arexp \<Rightarrow> bool"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   827
  where
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   828
  "nonazero AZERO = False"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   829
| "nonazero r = True"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   830
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   831
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   832
lemma flts_single1:
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   833
  assumes "nonalt r" "nonazero r"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   834
  shows "flts [r] = [r]"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   835
  using assms
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   836
  apply(induct r)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   837
  apply(auto)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   838
  done
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   839
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   840
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   841
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   842
lemma q3a:
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   843
  assumes "\<exists>r \<in> set rs. bnullable r"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   844
  shows "bmkeps (AALTs bs (map (fuse bs1) rs)) = bmkeps (AALTs (bs@bs1) rs)"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   845
  using assms
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   846
  apply(induct rs arbitrary: bs bs1)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   847
   apply(simp)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   848
  apply(simp)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   849
  apply(auto)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   850
   apply (metis append_assoc b2 bnullable_correctness erase_fuse bnullable_Hdbmkeps_Hd)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   851
  apply(case_tac "bnullable a")
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   852
   apply (metis append.assoc b2 bnullable_correctness erase_fuse bnullable_Hdbmkeps_Hd)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   853
  apply(case_tac rs)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   854
  apply(simp)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   855
  apply(simp)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   856
  apply(auto)[1]
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   857
   apply (metis bnullable_correctness erase_fuse)+
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   858
  done
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   859
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   860
lemma qq4:
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   861
  assumes "\<exists>x\<in>set list. bnullable x"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   862
  shows "\<exists>x\<in>set (flts list). bnullable x"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   863
  using assms
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   864
  apply(induct list rule: flts.induct)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   865
        apply(auto)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   866
  by (metis UnCI bnullable_correctness erase_fuse imageI)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   867
  
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   868
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   869
lemma qs3:
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   870
  assumes "\<exists>r \<in> set rs. bnullable r"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   871
  shows "bmkeps (AALTs bs rs) = bmkeps (AALTs bs (flts rs))"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   872
  using assms
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   873
  apply(induct rs arbitrary: bs taking: size rule: measure_induct)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   874
  apply(case_tac x)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   875
  apply(simp)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   876
  apply(simp)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   877
  apply(case_tac a)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   878
       apply(simp)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   879
       apply (simp add: r1)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   880
      apply(simp)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   881
      apply (simp add: bnullable_Hdbmkeps_Hd)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   882
     apply(simp)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   883
     apply(case_tac "flts list")
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   884
      apply(simp)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   885
  apply (metis L_erase_AALTs L_erase_flts L_flat_Prf1 L_flat_Prf2 Prf_elims(1) bnullable_correctness erase.simps(4) mkeps_nullable r2)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   886
     apply(simp)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   887
     apply (simp add: r1)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   888
    prefer 3
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   889
    apply(simp)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   890
    apply (simp add: bnullable_Hdbmkeps_Hd)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   891
   prefer 2
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   892
   apply(simp)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   893
  apply(case_tac "\<exists>x\<in>set x52. bnullable x")
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   894
  apply(case_tac "list")
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   895
    apply(simp)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   896
    apply (metis b2 fuse.simps(4) q3a r2)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   897
   apply(erule disjE)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   898
    apply(subst qq1)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   899
     apply(auto)[1]
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   900
     apply (metis bnullable_correctness erase_fuse)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   901
    apply(simp)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   902
     apply (metis b2 fuse.simps(4) q3a r2)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   903
    apply(simp)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   904
    apply(auto)[1]
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   905
     apply(subst qq1)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   906
      apply (metis bnullable_correctness erase_fuse image_eqI set_map)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   907
     apply (metis b2 fuse.simps(4) q3a r2)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   908
  apply(subst qq1)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   909
      apply (metis bnullable_correctness erase_fuse image_eqI set_map)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   910
    apply (metis b2 fuse.simps(4) q3a r2)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   911
   apply(simp)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   912
   apply(subst qq2)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   913
     apply (metis bnullable_correctness erase_fuse imageE set_map)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   914
  prefer 2
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   915
  apply(case_tac "list")
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   916
     apply(simp)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   917
    apply(simp)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   918
   apply (simp add: qq4)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   919
  apply(simp)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   920
  apply(auto)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   921
   apply(case_tac list)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   922
    apply(simp)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   923
   apply(simp)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   924
   apply (simp add: bnullable_Hdbmkeps_Hd)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   925
  apply(case_tac "bnullable (ASEQ x41 x42 x43)")
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   926
   apply(case_tac list)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   927
    apply(simp)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   928
   apply(simp)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   929
   apply (simp add: bnullable_Hdbmkeps_Hd)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   930
  apply(simp)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   931
  using qq4 r1 r2 by auto
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   932
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   933
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   934
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   935
  
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   936
lemma bder_fuse:
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   937
  shows "bder c (fuse bs a) = fuse bs  (bder c a)"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   938
  apply(induct a arbitrary: bs c)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   939
       apply(simp_all)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   940
  done
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   941
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   942
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   943
fun flts2 :: "char \<Rightarrow> arexp list \<Rightarrow> arexp list"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   944
  where 
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   945
  "flts2 _ [] = []"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   946
| "flts2 c (AZERO # rs) = flts2 c rs"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   947
| "flts2 c (AONE _ # rs) = flts2 c rs"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   948
| "flts2 c (ACHAR bs d # rs) = (if c = d then (ACHAR bs d # flts2 c rs) else flts2 c rs)"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   949
| "flts2 c ((AALTs bs rs1) # rs) = (map (fuse bs) rs1) @ flts2 c rs"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   950
| "flts2 c (ASEQ bs r1 r2 # rs) = (if (bnullable(r1) \<and> r2 = AZERO) then 
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   951
    flts2 c rs
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   952
    else ASEQ bs r1 r2 # flts2 c rs)"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   953
| "flts2 c (r1 # rs) = r1 # flts2 c rs"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   954
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   955
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   956
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   957
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   958
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   959
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   960
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   961
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   962
 
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   963
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   964
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   965
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   966
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   967
lemma WQ1:
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   968
  assumes "s \<in> L (der c r)"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   969
  shows "s \<in> der c r \<rightarrow> mkeps (ders s (der c r))"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   970
  using assms
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   971
  oops
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   972
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   973
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   974
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   975
lemma bder_bsimp_AALTs:
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   976
  shows "bder c (bsimp_AALTs bs rs) = bsimp_AALTs bs (map (bder c) rs)"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   977
  apply(induct bs rs rule: bsimp_AALTs.induct)  
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   978
    apply(simp)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   979
   apply(simp)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   980
   apply (simp add: bder_fuse)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   981
  apply(simp)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   982
  done
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   983
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   984
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   985
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   986
lemma
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   987
  assumes "asize (bsimp a) = asize a"  "a = AALTs bs [AALTs bs2 [], AZERO, AONE bs3]"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   988
  shows "bsimp a = a"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   989
  using assms
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   990
  apply(simp)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   991
  oops
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   992
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   993
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   994
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   995
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   996
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   997
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   998
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   999
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1000
inductive rrewrite:: "arexp \<Rightarrow> arexp \<Rightarrow> bool" ("_ \<leadsto> _" [99, 99] 99)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1001
  where
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1002
  "ASEQ bs AZERO r2 \<leadsto> AZERO"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1003
| "ASEQ bs r1 AZERO \<leadsto> AZERO"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1004
| "ASEQ bs (AONE bs1) r \<leadsto> fuse (bs@bs1) r"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1005
| "r1 \<leadsto> r2 \<Longrightarrow> ASEQ bs r1 r3 \<leadsto> ASEQ bs r2 r3"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1006
| "r3 \<leadsto> r4 \<Longrightarrow> ASEQ bs r1 r3 \<leadsto> ASEQ bs r1 r4"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1007
| "r \<leadsto> r' \<Longrightarrow> (AALTs bs (rs1 @ [r] @ rs2)) \<leadsto> (AALTs bs (rs1 @ [r'] @ rs2))"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1008
(*context rule for eliminating 0, alts--corresponds to the recursive call flts r::rs = r::(flts rs)*)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1009
| "AALTs bs (rsa@AZERO # rsb) \<leadsto> AALTs bs (rsa@rsb)"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1010
| "AALTs bs (rsa@(AALTs bs1 rs1)# rsb) \<leadsto> AALTs bs (rsa@(map (fuse bs1) rs1)@rsb)"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1011
(*the below rule for extracting common prefixes between a list of rexp's bitcodes*)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1012
| "AALTs bs (map (fuse bs1) rs) \<leadsto> AALTs (bs@bs1) rs"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1013
(*opposite direction also allowed, which means bits  are free to be moved around
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1014
as long as they are on the right path*)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1015
| "AALTs (bs@bs1) rs \<leadsto> AALTs bs (map (fuse bs1) rs)"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1016
| "AALTs bs [] \<leadsto> AZERO"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1017
| "AALTs bs [r] \<leadsto> fuse bs r"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1018
| "erase a1 = erase a2 \<Longrightarrow> AALTs bs (rsa@[a1]@rsb@[a2]@rsc) \<leadsto> AALTs bs (rsa@[a1]@rsb@rsc)"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1019
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1020
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1021
inductive rrewrites:: "arexp \<Rightarrow> arexp \<Rightarrow> bool" ("_ \<leadsto>* _" [100, 100] 100)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1022
  where 
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1023
rs1[intro, simp]:"r \<leadsto>* r"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1024
| rs2[intro]: "\<lbrakk>r1 \<leadsto>* r2; r2 \<leadsto> r3\<rbrakk> \<Longrightarrow> r1 \<leadsto>* r3"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1025
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1026
inductive srewrites:: "arexp list \<Rightarrow> arexp list \<Rightarrow> bool" (" _ s\<leadsto>* _" [100, 100] 100)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1027
  where
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1028
ss1: "[] s\<leadsto>* []"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1029
|ss2: "\<lbrakk>r \<leadsto>* r'; rs s\<leadsto>* rs'\<rbrakk> \<Longrightarrow> (r#rs) s\<leadsto>* (r'#rs')"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1030
(*rs1 = [r1, r2, ..., rn] rs2 = [r1', r2', ..., rn']
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1031
[r1, r2, ..., rn] \<leadsto>* [r1', r2, ..., rn] \<leadsto>* [...r2',...] \<leadsto>* [r1', r2',... rn']
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1032
*)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1033
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1034
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1035
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1036
lemma r_in_rstar : "r1 \<leadsto> r2 \<Longrightarrow> r1 \<leadsto>* r2"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1037
  using rrewrites.intros(1) rrewrites.intros(2) by blast
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1038
 
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1039
lemma real_trans: 
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1040
  assumes a1: "r1 \<leadsto>* r2"  and a2: "r2 \<leadsto>* r3"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1041
  shows "r1 \<leadsto>* r3"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1042
  using a2 a1
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1043
  apply(induct r2 r3 arbitrary: r1 rule: rrewrites.induct) 
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1044
   apply(auto)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1045
  done
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1046
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1047
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1048
lemma  many_steps_later: "\<lbrakk>r1 \<leadsto> r2; r2 \<leadsto>* r3 \<rbrakk> \<Longrightarrow> r1 \<leadsto>* r3"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1049
  by (meson r_in_rstar real_trans)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1050
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1051
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1052
lemma contextrewrites1: "r \<leadsto>* r' \<Longrightarrow> (AALTs bs (r#rs)) \<leadsto>* (AALTs bs (r'#rs))"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1053
  apply(induct r r' rule: rrewrites.induct)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1054
   apply simp
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1055
  by (metis append_Cons append_Nil rrewrite.intros(6) rs2)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1056
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1057
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1058
lemma contextrewrites2: "r \<leadsto>* r' \<Longrightarrow> (AALTs bs (rs1@[r]@rs)) \<leadsto>* (AALTs bs (rs1@[r']@rs))"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1059
  apply(induct r r' rule: rrewrites.induct)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1060
   apply simp
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1061
  using rrewrite.intros(6) by blast
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1062
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1063
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1064
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1065
lemma srewrites_alt: "rs1 s\<leadsto>* rs2 \<Longrightarrow> (AALTs bs (rs@rs1)) \<leadsto>* (AALTs bs (rs@rs2))"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1066
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1067
  apply(induct rs1 rs2 arbitrary: bs rs rule: srewrites.induct)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1068
   apply(rule rs1)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1069
  apply(drule_tac x = "bs" in meta_spec)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1070
  apply(drule_tac x = "rsa@[r']" in meta_spec)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1071
  apply simp
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1072
  apply(rule real_trans)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1073
   prefer 2
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1074
   apply(assumption)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1075
  apply(drule contextrewrites2)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1076
  apply auto
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1077
  done
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1078
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1079
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1080
corollary srewrites_alt1: "rs1 s\<leadsto>* rs2 \<Longrightarrow> AALTs bs rs1 \<leadsto>* AALTs bs rs2"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1081
  by (metis append.left_neutral srewrites_alt)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1082
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1083
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1084
lemma star_seq:  "r1 \<leadsto>* r2 \<Longrightarrow> ASEQ bs r1 r3 \<leadsto>* ASEQ bs r2 r3"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1085
  apply(induct r1 r2 arbitrary: r3 rule: rrewrites.induct)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1086
   apply(rule rs1)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1087
  apply(erule rrewrites.cases)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1088
   apply(simp)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1089
   apply(rule r_in_rstar)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1090
   apply(rule rrewrite.intros(4))
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1091
   apply simp
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1092
  apply(rule rs2)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1093
   apply(assumption)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1094
  apply(rule rrewrite.intros(4))
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1095
  by assumption
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1096
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1097
lemma star_seq2:  "r3 \<leadsto>* r4 \<Longrightarrow> ASEQ bs r1 r3 \<leadsto>* ASEQ bs r1 r4"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1098
  apply(induct r3 r4 arbitrary: r1 rule: rrewrites.induct)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1099
   apply auto
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1100
  using rrewrite.intros(5) by blast
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1101
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1102
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1103
lemma continuous_rewrite: "\<lbrakk>r1 \<leadsto>* AZERO\<rbrakk> \<Longrightarrow> ASEQ bs1 r1 r2 \<leadsto>* AZERO"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1104
  apply(induction ra\<equiv>"r1" rb\<equiv>"AZERO" arbitrary: bs1 r1 r2 rule: rrewrites.induct)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1105
   apply (simp add: r_in_rstar rrewrite.intros(1))
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1106
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1107
  by (meson rrewrite.intros(1) rrewrites.intros(2) star_seq)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1108
  
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1109
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1110
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1111
lemma bsimp_aalts_simpcases: "AONE bs \<leadsto>* (bsimp (AONE bs))"  "AZERO \<leadsto>* bsimp AZERO" "ACHAR bs c \<leadsto>* (bsimp (ACHAR bs c))"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1112
  apply (simp add: rrewrites.intros(1))
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1113
  apply (simp add: rrewrites.intros(1))
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1114
  by (simp add: rrewrites.intros(1))
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1115
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1116
lemma trivialbsimpsrewrites: "\<lbrakk>\<And>x. x \<in> set rs \<Longrightarrow> x \<leadsto>* f x \<rbrakk> \<Longrightarrow> rs s\<leadsto>* (map f rs)"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1117
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1118
  apply(induction rs)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1119
   apply simp
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1120
   apply(rule ss1)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1121
  by (metis insert_iff list.simps(15) list.simps(9) srewrites.simps)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1122
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1123
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1124
lemma bsimp_AALTsrewrites: "AALTs bs1 rs \<leadsto>* bsimp_AALTs bs1 rs"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1125
  apply(induction rs)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1126
  apply simp
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1127
   apply(rule r_in_rstar)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1128
   apply(simp add:  rrewrite.intros(11))
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1129
  apply(case_tac "rs = Nil")
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1130
   apply(simp)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1131
  using rrewrite.intros(12) apply auto[1]
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1132
  apply(subgoal_tac "length (a#rs) > 1")
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1133
   apply(simp add: bsimp_AALTs_qq)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1134
  apply(simp)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1135
  done 
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1136
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1137
inductive frewrites:: "arexp list \<Rightarrow> arexp list \<Rightarrow> bool" (" _ f\<leadsto>* _" [100, 100] 100)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1138
  where
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1139
fs1: "[] f\<leadsto>* []"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1140
|fs2: "\<lbrakk>rs f\<leadsto>* rs'\<rbrakk> \<Longrightarrow> (AZERO#rs) f\<leadsto>* rs'"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1141
|fs3: "\<lbrakk>rs f\<leadsto>* rs'\<rbrakk> \<Longrightarrow> ((AALTs bs rs1) # rs) f\<leadsto>* ((map (fuse bs) rs1) @ rs')"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1142
|fs4: "\<lbrakk>rs f\<leadsto>* rs';nonalt r; nonazero r\<rbrakk> \<Longrightarrow> (r#rs) f\<leadsto>* (r#rs')"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1143
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1144
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1145
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1146
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1147
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1148
lemma flts_prepend: "\<lbrakk>nonalt a; nonazero a\<rbrakk> \<Longrightarrow> flts (a#rs) = a # (flts rs)"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1149
  by (metis append_Cons append_Nil flts_single1 k00)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1150
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1151
lemma fltsfrewrites: "rs f\<leadsto>* (flts rs)"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1152
  apply(induction rs)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1153
  apply simp
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1154
   apply(rule fs1)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1155
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1156
  apply(case_tac "a = AZERO")
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1157
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1158
   
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1159
  using fs2 apply auto[1]
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1160
  apply(case_tac "\<exists>bs rs. a = AALTs bs rs")
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1161
   apply(erule exE)+
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1162
   
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1163
   apply (simp add: fs3)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1164
  apply(subst flts_prepend)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1165
    apply(rule nonalt.elims(2))
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1166
  prefer 2
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1167
  thm nonalt.elims
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1168
   
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1169
         apply blast
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1170
   
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1171
  using bbbbs1 apply blast
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1172
       apply(simp add: nonalt.simps)+
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1173
   
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1174
   apply (meson nonazero.elims(3))
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1175
   
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1176
  by (meson fs4 nonalt.elims(3) nonazero.elims(3))
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1177
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1178
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1179
lemma rrewrite0away: "AALTs bs ( AZERO # rsb) \<leadsto> AALTs bs rsb"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1180
  by (metis append_Nil rrewrite.intros(7))
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1181
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1182
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1183
lemma frewritesaalts:"rs f\<leadsto>* rs' \<Longrightarrow> (AALTs bs (rs1@rs)) \<leadsto>* (AALTs bs (rs1@rs'))"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1184
  apply(induct rs rs' arbitrary: bs rs1 rule:frewrites.induct)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1185
    apply(rule rs1)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1186
    apply(drule_tac x = "bs" in meta_spec)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1187
  apply(drule_tac x = "rs1 @ [AZERO]" in meta_spec)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1188
    apply(rule real_trans)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1189
     apply simp
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1190
  using r_in_rstar rrewrite.intros(7) apply presburger
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1191
    apply(drule_tac x = "bsa" in meta_spec)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1192
  apply(drule_tac x = "rs1a @ [AALTs bs rs1]" in meta_spec)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1193
   apply(rule real_trans)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1194
    apply simp
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1195
  using r_in_rstar rrewrite.intros(8) apply presburger
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1196
    apply(drule_tac x = "bs" in meta_spec)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1197
  apply(drule_tac x = "rs1@[r]" in meta_spec)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1198
    apply(rule real_trans)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1199
   apply simp
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1200
  apply auto
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1201
  done
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1202
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1203
lemma fltsrewrites: "  AALTs bs1 rs \<leadsto>* AALTs bs1 (flts rs)"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1204
  apply(induction rs)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1205
   apply simp
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1206
  apply(case_tac "a = AZERO")
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1207
  apply (metis append_Nil flts.simps(2) many_steps_later rrewrite.intros(7))
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1208
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1209
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1210
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1211
  apply(case_tac "\<exists>bs2 rs2. a = AALTs bs2 rs2")
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1212
   apply(erule exE)+
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1213
   apply(simp add: flts.simps)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1214
   prefer 2
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1215
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1216
  apply(subst flts_prepend)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1217
   
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1218
     apply (meson nonalt.elims(3))
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1219
   
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1220
    apply (meson nonazero.elims(3))
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1221
   apply(subgoal_tac "(a#rs) f\<leadsto>* (a#flts rs)")
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1222
  apply (metis append_Nil frewritesaalts)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1223
  apply (meson fltsfrewrites fs4 nonalt.elims(3) nonazero.elims(3))
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1224
  by (metis append_Cons append_Nil fltsfrewrites frewritesaalts k00 k0a)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1225
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1226
lemma alts_simpalts: "\<And>bs1 rs. (\<And>x. x \<in> set rs \<Longrightarrow> x \<leadsto>* bsimp x) \<Longrightarrow> 
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1227
AALTs bs1 rs \<leadsto>* AALTs bs1 (map bsimp rs)"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1228
  apply(subgoal_tac " rs s\<leadsto>*  (map bsimp rs)")
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1229
   prefer 2
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1230
  using trivialbsimpsrewrites apply auto[1]
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1231
  using srewrites_alt1 by auto
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1232
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1233
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1234
lemma threelistsappend: "rsa@a#rsb = (rsa@[a])@rsb"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1235
  apply auto
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1236
  done
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1237
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1238
fun distinctByAcc :: "'a list \<Rightarrow> ('a \<Rightarrow> 'b) \<Rightarrow> 'b set \<Rightarrow> 'b set"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1239
  where
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1240
  "distinctByAcc [] f acc = acc"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1241
| "distinctByAcc (x#xs) f acc = 
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1242
     (if (f x) \<in> acc then distinctByAcc xs f acc 
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1243
      else  (distinctByAcc xs f ({f x} \<union> acc)))"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1244
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1245
lemma dB_single_step: "distinctBy (a#rs) f {} = a # distinctBy rs f {f a}"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1246
  apply simp
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1247
  done
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1248
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1249
lemma somewhereInside: "r \<in> set rs \<Longrightarrow> \<exists>rs1 rs2. rs = rs1@[r]@rs2"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1250
  using split_list by fastforce
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1251
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1252
lemma somewhereMapInside: "f r \<in> f ` set rs \<Longrightarrow> \<exists>rs1 rs2 a. rs = rs1@[a]@rs2 \<and> f a = f r"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1253
  apply auto
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1254
  by (metis split_list)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1255
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1256
lemma alts_dBrewrites_withFront: " AALTs bs (rsa @ rs) \<leadsto>* AALTs bs (rsa @ distinctBy rs erase (erase ` set rsa))"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1257
  apply(induction rs arbitrary: rsa)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1258
   apply simp
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1259
  apply(drule_tac x = "rsa@[a]" in meta_spec)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1260
  apply(subst threelistsappend)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1261
  apply(rule real_trans)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1262
  apply simp
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1263
  apply(case_tac "a \<in> set rsa")
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1264
   apply simp
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1265
   apply(drule somewhereInside)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1266
   apply(erule exE)+
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1267
   apply simp
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1268
  apply(subgoal_tac " AALTs bs
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1269
            (rs1 @
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1270
             a #
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1271
             rs2 @
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1272
             a #
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1273
             distinctBy rs erase
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1274
              (insert (erase a)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1275
                (erase `
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1276
                 (set rs1 \<union> set rs2)))) \<leadsto> AALTs bs (rs1@ a # rs2 @  distinctBy rs erase
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1277
              (insert (erase a)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1278
                (erase `
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1279
                 (set rs1 \<union> set rs2)))) ")
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1280
  prefer 2
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1281
  using rrewrite.intros(13) apply force
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1282
  using r_in_rstar apply force
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1283
  apply(subgoal_tac "erase ` set (rsa @ [a]) = insert (erase a) (erase ` set rsa)")
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1284
  prefer 2
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1285
    
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1286
   apply auto[1]
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1287
  apply(case_tac "erase a \<in> erase `set rsa")
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1288
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1289
   apply simp
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1290
  apply(subgoal_tac "AALTs bs (rsa @ a # distinctBy rs erase (insert (erase a) (erase ` set rsa))) \<leadsto>
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1291
                     AALTs bs (rsa @ distinctBy rs erase (insert (erase a) (erase ` set rsa)))")
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1292
  apply force
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1293
  apply (smt (verit, ccfv_threshold) append_Cons append_assoc append_self_conv2 r_in_rstar rrewrite.intros(13) same_append_eq somewhereMapInside)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1294
  by force
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1295
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1296
 
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1297
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1298
lemma alts_dBrewrites: "AALTs bs rs \<leadsto>* AALTs bs (distinctBy rs erase {})"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1299
  apply(induction rs)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1300
   apply simp
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1301
  apply simp
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1302
  using alts_dBrewrites_withFront
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1303
  by (metis append_Nil dB_single_step empty_set image_empty)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1304
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1305
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1306
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1307
  
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1308
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1309
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1310
lemma bsimp_rewrite: " (rrewrites r ( bsimp r))"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1311
  apply(induction r rule: bsimp.induct)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1312
       apply simp
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1313
       apply(case_tac "bsimp r1 = AZERO")
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1314
        apply simp
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1315
  using continuous_rewrite apply blast
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1316
       apply(case_tac "\<exists>bs. bsimp r1 = AONE bs")
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1317
        apply(erule exE)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1318
        apply simp
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1319
        apply(subst bsimp_ASEQ2)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1320
        apply (meson real_trans rrewrite.intros(3) rrewrites.intros(2) star_seq star_seq2)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1321
       apply (smt (verit, best) bsimp_ASEQ0 bsimp_ASEQ1 real_trans rrewrite.intros(2) rs2 star_seq star_seq2)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1322
      defer
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1323
  using bsimp_aalts_simpcases(2) apply blast
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1324
  apply simp
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1325
  apply simp
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1326
  apply simp
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1327
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1328
  apply auto
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1329
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1330
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1331
  apply(subgoal_tac "AALTs bs1 rs \<leadsto>* AALTs bs1 (map bsimp rs)")
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1332
   apply(subgoal_tac "AALTs bs1 (map bsimp rs) \<leadsto>* AALTs bs1 (flts (map bsimp rs))")
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1333
  apply(subgoal_tac "AALTs bs1 (flts (map bsimp rs)) \<leadsto>* AALTs bs1 (distinctBy (flts (map bsimp rs)) erase {})")
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1334
    apply(subgoal_tac "AALTs bs1 (distinctBy (flts (map bsimp rs)) erase {}) \<leadsto>* bsimp_AALTs bs1 (distinctBy (flts (map bsimp rs)) erase {} )")
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1335
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1336
  
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1337
      apply (meson real_trans)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1338
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1339
   apply (meson bsimp_AALTsrewrites)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1340
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1341
  apply (meson alts_dBrewrites)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1342
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1343
  using fltsrewrites apply auto[1]
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1344
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1345
  using alts_simpalts by force
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1346
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1347
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1348
lemma rewritenullable: "\<lbrakk>r1 \<leadsto> r2; bnullable r1 \<rbrakk> \<Longrightarrow> bnullable r2"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1349
  apply(induction r1 r2 rule: rrewrite.induct)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1350
             apply(simp)+
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1351
  apply (metis bnullable_correctness erase_fuse)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1352
          apply simp
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1353
         apply simp
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1354
        apply auto[1]
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1355
       apply auto[1]
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1356
      apply auto[4]
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1357
     apply (metis UnCI bnullable_correctness erase_fuse imageI)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1358
    apply (metis bnullable_correctness erase_fuse)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1359
    apply (metis bnullable_correctness erase_fuse)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1360
  
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1361
   apply (metis bnullable_correctness erase.simps(5) erase_fuse)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1362
  
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1363
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1364
  by (smt (z3) Un_iff bnullable_correctness insert_iff list.set(2) qq3 set_append)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1365
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1366
lemma rewrite_non_nullable: "\<lbrakk>r1 \<leadsto> r2; \<not>bnullable r1 \<rbrakk> \<Longrightarrow> \<not>bnullable r2"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1367
  apply(induction r1 r2 rule: rrewrite.induct)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1368
             apply auto 
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1369
      apply (metis bnullable_correctness erase_fuse)+
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1370
  done
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1371
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1372
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1373
lemma rewritesnullable: "\<lbrakk> r1 \<leadsto>* r2; bnullable r1 \<rbrakk> \<Longrightarrow> bnullable r2"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1374
  apply(induction r1 r2 rule: rrewrites.induct)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1375
   apply simp
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1376
  apply(rule rewritenullable)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1377
   apply simp
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1378
  apply simp
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1379
  done
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1380
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1381
lemma nonbnullable_lists_concat: " \<lbrakk> \<not> (\<exists>r0\<in>set rs1. bnullable r0); \<not> bnullable r; \<not> (\<exists>r0\<in>set rs2. bnullable r0)\<rbrakk> \<Longrightarrow> 
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1382
\<not>(\<exists>r0 \<in> (set (rs1@[r]@rs2)). bnullable r0 ) "
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1383
  apply simp
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1384
  apply blast
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1385
  done
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1386
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1387
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1388
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1389
lemma nomember_bnullable: "\<lbrakk> \<not> (\<exists>r0\<in>set rs1. bnullable r0); \<not> bnullable r; \<not> (\<exists>r0\<in>set rs2. bnullable r0)\<rbrakk>
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1390
 \<Longrightarrow> \<not>bnullable (AALTs bs (rs1 @ [r] @ rs2))"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1391
  using nonbnullable_lists_concat qq3 by presburger
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1392
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1393
lemma bnullable_segment: " bnullable (AALTs bs (rs1@[r]@rs2)) \<Longrightarrow> bnullable (AALTs bs rs1) \<or> bnullable (AALTs bs rs2) \<or> bnullable r"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1394
  apply(case_tac "\<exists>r0\<in>set rs1.  bnullable r0")
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1395
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1396
  using qq3 apply blast
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1397
  apply(case_tac "bnullable r")
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1398
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1399
  apply blast
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1400
  apply(case_tac "\<exists>r0\<in>set rs2.  bnullable r0")
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1401
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1402
  using bnullable.simps(4) apply presburger
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1403
  apply(subgoal_tac "False")
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1404
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1405
  apply blast
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1406
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1407
  using nomember_bnullable by blast
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1408
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1409
  
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1410
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1411
lemma bnullablewhichbmkeps: "\<lbrakk>bnullable  (AALTs bs (rs1@[r]@rs2)); \<not> bnullable (AALTs bs rs1); bnullable r \<rbrakk>
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1412
 \<Longrightarrow> bmkeps (AALTs bs (rs1@[r]@rs2)) = bs @ (bmkeps r)"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1413
  using qq2 bnullable_Hdbmkeps_Hd by force
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1414
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1415
lemma rrewrite_nbnullable: "\<lbrakk> r1 \<leadsto> r2 ; \<not> bnullable r1 \<rbrakk> \<Longrightarrow> \<not>bnullable r2"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1416
  apply(induction rule: rrewrite.induct)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1417
             apply auto[1]
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1418
            apply auto[1]
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1419
           apply auto[1]
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1420
           apply (metis bnullable_correctness erase_fuse)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1421
          apply auto[1]
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1422
         apply auto[1]
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1423
        apply auto[1]
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1424
       apply auto[1]
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1425
      apply auto[1]
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1426
      apply (metis bnullable_correctness erase_fuse)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1427
     apply auto[1]
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1428
     apply (metis bnullable_correctness erase_fuse)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1429
    apply auto[1]
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1430
    apply (metis bnullable_correctness erase_fuse)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1431
   apply auto[1]
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1432
   apply auto[1]
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1433
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1434
  apply (metis bnullable_correctness erase_fuse)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1435
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1436
  by (meson rewrite_non_nullable rrewrite.intros(13))
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1437
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1438
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1439
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1440
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1441
lemma spillbmkepslistr: "bnullable (AALTs bs1 rs1)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1442
    \<Longrightarrow> bmkeps (AALTs bs (AALTs bs1 rs1 # rsb)) = bmkeps (AALTs bs ( map (fuse bs1) rs1 @ rsb))"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1443
  apply(subst bnullable_Hdbmkeps_Hd)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1444
  
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1445
   apply simp
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1446
  by (metis bmkeps.simps(3) k0a list.set_intros(1) qq1 qq4 qs3)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1447
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1448
lemma third_segment_bnullable: "\<lbrakk>bnullable (AALTs bs (rs1@rs2@rs3)); \<not>bnullable (AALTs bs rs1); \<not>bnullable (AALTs bs rs2)\<rbrakk> \<Longrightarrow> 
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1449
bnullable (AALTs bs rs3)"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1450
  
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1451
  by (metis append.left_neutral append_Cons bnullable.simps(1) bnullable_segment rrewrite.intros(7) rrewrite_nbnullable)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1452
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1453
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1454
lemma third_segment_bmkeps:  "\<lbrakk>bnullable (AALTs bs (rs1@rs2@rs3)); \<not>bnullable (AALTs bs rs1); \<not>bnullable (AALTs bs rs2)\<rbrakk> \<Longrightarrow> 
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1455
bmkeps (AALTs bs (rs1@rs2@rs3) ) = bmkeps (AALTs bs rs3)"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1456
  apply(subgoal_tac "bnullable (AALTs bs rs3)")
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1457
   apply(subgoal_tac "\<forall>r \<in> set (rs1@rs2). \<not>bnullable r")
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1458
  apply(subgoal_tac "bmkeps (AALTs bs (rs1@rs2@rs3)) = bmkeps (AALTs bs ((rs1@rs2)@rs3) )")
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1459
  apply (metis qq2 qq3)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1460
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1461
  apply (metis append.assoc)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1462
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1463
  apply (metis append.assoc in_set_conv_decomp r2 third_segment_bnullable)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1464
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1465
  using third_segment_bnullable by blast
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1466
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1467
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1468
lemma rewrite_bmkepsalt: " \<lbrakk>bnullable (AALTs bs (rsa @ AALTs bs1 rs1 # rsb)); bnullable (AALTs bs (rsa @ map (fuse bs1) rs1 @ rsb))\<rbrakk>
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1469
       \<Longrightarrow> bmkeps (AALTs bs (rsa @ AALTs bs1 rs1 # rsb)) = bmkeps (AALTs bs (rsa @ map (fuse bs1) rs1 @ rsb))"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1470
  apply(case_tac "bnullable (AALTs bs rsa)")
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1471
  
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1472
  using qq1 apply force
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1473
  apply(case_tac "bnullable (AALTs bs1 rs1)")
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1474
  apply(subst qq2)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1475
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1476
  
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1477
  using r2 apply blast
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1478
  
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1479
    apply (metis list.set_intros(1))
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1480
  apply (smt (verit, ccfv_threshold) append_eq_append_conv2 list.set_intros(1) qq2 qq3 rewritenullable rrewrite.intros(8) self_append_conv2 spillbmkepslistr)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1481
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1482
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1483
  thm qq1
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1484
  apply(subgoal_tac "bmkeps  (AALTs bs (rsa @ AALTs bs1 rs1 # rsb)) = bmkeps (AALTs bs rsb) ")
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1485
   prefer 2
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1486
  
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1487
  apply (metis append_Cons append_Nil bnullable.simps(1) bnullable_segment rewritenullable rrewrite.intros(11) third_segment_bmkeps)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1488
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1489
  by (metis bnullable.simps(4) rewrite_non_nullable rrewrite.intros(10) third_segment_bmkeps)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1490
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1491
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1492
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1493
lemma rewrite_bmkeps: "\<lbrakk> r1 \<leadsto> r2; (bnullable r1)\<rbrakk> \<Longrightarrow> bmkeps r1 = bmkeps r2"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1494
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1495
  apply(frule rewritenullable)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1496
  apply simp
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1497
  apply(induction r1 r2 rule: rrewrite.induct)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1498
             apply simp
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1499
  using bnullable.simps(1) bnullable.simps(5) apply blast
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1500
         apply (simp add: b2)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1501
        apply simp
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1502
         apply simp
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1503
  apply(frule bnullable_segment)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1504
        apply(case_tac "bnullable (AALTs bs rs1)")
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1505
  using qq1 apply force
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1506
        apply(case_tac "bnullable r")
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1507
  using bnullablewhichbmkeps rewritenullable apply presburger
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1508
        apply(subgoal_tac "bnullable (AALTs bs rs2)")
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1509
  apply(subgoal_tac "\<not> bnullable r'")
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1510
  apply (simp add: qq2 r1)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1511
  
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1512
  using rrewrite_nbnullable apply blast
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1513
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1514
        apply blast
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1515
       apply (simp add: flts_append qs3)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1516
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1517
  apply (meson rewrite_bmkepsalt)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1518
  
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1519
  using bnullable.simps(4) q3a apply blast
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1520
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1521
  apply (simp add: q3a)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1522
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1523
  using bnullable.simps(1) apply blast
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1524
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1525
  apply (simp add: b2)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1526
 
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1527
  by (smt (z3) Un_iff bnullable_correctness erase.simps(5) qq1 qq2 qq3 set_append)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1528
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1529
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1530
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1531
lemma rewrites_bmkeps: "\<lbrakk> (r1 \<leadsto>* r2); (bnullable r1)\<rbrakk> \<Longrightarrow> bmkeps r1 = bmkeps r2"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1532
  apply(induction r1 r2 rule: rrewrites.induct)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1533
   apply simp
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1534
  apply(subgoal_tac "bnullable r2")
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1535
  prefer 2
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1536
   apply(metis rewritesnullable)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1537
  apply(subgoal_tac "bmkeps r1 = bmkeps r2")
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1538
   prefer 2
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1539
   apply fastforce
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1540
  using rewrite_bmkeps by presburger
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1541
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1542
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1543
thm rrewrite.intros(12)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1544
lemma alts_rewrite_front: "r \<leadsto> r' \<Longrightarrow> AALTs bs (r # rs) \<leadsto> AALTs bs (r' # rs)"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1545
  by (metis append_Cons append_Nil rrewrite.intros(6))
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1546
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1547
lemma alt_rewrite_front: "r \<leadsto> r' \<Longrightarrow> AALT bs r r2 \<leadsto> AALT bs r' r2"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1548
  using alts_rewrite_front by blast
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1549
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1550
lemma to_zero_in_alt: " AALT bs (ASEQ [] AZERO r) r2 \<leadsto>  AALT bs AZERO r2"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1551
  by (simp add: alts_rewrite_front rrewrite.intros(1))
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1552
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1553
lemma alt_remove0_front: " AALT bs AZERO r \<leadsto> AALTs bs [r]"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1554
  by (simp add: rrewrite0away)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1555
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1556
lemma alt_rewrites_back: "r2 \<leadsto>* r2' \<Longrightarrow>AALT bs r1 r2 \<leadsto>* AALT bs r1 r2'"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1557
  apply(induction r2 r2' arbitrary: bs rule: rrewrites.induct)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1558
   apply simp
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1559
  by (meson rs1 rs2 srewrites_alt1 ss1 ss2)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1560
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1561
lemma rewrite_fuse: " r2 \<leadsto> r3 \<Longrightarrow> fuse bs r2 \<leadsto>* fuse bs r3"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1562
  apply(induction r2 r3 arbitrary: bs rule: rrewrite.induct)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1563
             apply auto
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1564
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1565
           apply (simp add: continuous_rewrite)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1566
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1567
          apply (simp add: r_in_rstar rrewrite.intros(2))
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1568
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1569
         apply (metis fuse_append r_in_rstar rrewrite.intros(3))
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1570
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1571
  using r_in_rstar star_seq apply blast
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1572
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1573
  using r_in_rstar star_seq2 apply blast
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1574
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1575
  using contextrewrites2 r_in_rstar apply auto[1]
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1576
  
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1577
       apply (simp add: r_in_rstar rrewrite.intros(7))
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1578
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1579
  using rrewrite.intros(8) apply auto[1]
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1580
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1581
   apply (metis append_assoc r_in_rstar rrewrite.intros(9))
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1582
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1583
  apply (metis append_assoc r_in_rstar rrewrite.intros(10))
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1584
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1585
  apply (simp add: r_in_rstar rrewrite.intros(11))
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1586
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1587
  apply (metis fuse_append r_in_rstar rrewrite.intros(12))
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1588
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1589
  using rrewrite.intros(13) by auto
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1590
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1591
  
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1592
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1593
lemma rewrites_fuse:  "r2 \<leadsto>* r2' \<Longrightarrow>  (fuse bs1 r2) \<leadsto>*  (fuse bs1 r2')"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1594
  apply(induction r2 r2' arbitrary: bs1 rule: rrewrites.induct)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1595
   apply simp
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1596
  by (meson real_trans rewrite_fuse)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1597
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1598
lemma  bder_fuse_list: " map (bder c \<circ> fuse bs1) rs1 = map (fuse bs1 \<circ> bder c) rs1"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1599
  apply(induction rs1)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1600
  apply simp
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1601
  by (simp add: bder_fuse)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1602
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1603
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1604
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1605
lemma rewrite_der_altmiddle: "bder c (AALTs bs (rsa @ AALTs bs1 rs1 # rsb)) \<leadsto>* bder c (AALTs bs (rsa @ map (fuse bs1) rs1 @ rsb))"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1606
   apply simp
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1607
   apply(simp add: bder_fuse_list)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1608
  apply(rule many_steps_later)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1609
   apply(subst rrewrite.intros(8))
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1610
   apply simp
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1611
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1612
  by fastforce
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1613
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1614
lemma lock_step_der_removal: 
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1615
  shows " erase a1 = erase a2 \<Longrightarrow> 
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1616
                                  bder c (AALTs bs (rsa @ [a1] @ rsb @ [a2] @ rsc)) \<leadsto>* 
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1617
                                  bder c (AALTs bs (rsa @ [a1] @ rsb @ rsc))"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1618
  apply(simp)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1619
  
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1620
  using rrewrite.intros(13) by auto
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1621
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1622
lemma rewrite_after_der: "r1 \<leadsto> r2 \<Longrightarrow> (bder c r1) \<leadsto>* (bder c r2)"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1623
  apply(induction r1 r2 arbitrary: c rule: rrewrite.induct)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1624
  
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1625
              apply (simp add: r_in_rstar rrewrite.intros(1))
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1626
  apply simp
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1627
  
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1628
  apply (meson contextrewrites1 r_in_rstar rrewrite.intros(11) rrewrite.intros(2) rrewrite0away rs2)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1629
           apply(simp)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1630
           apply(rule many_steps_later)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1631
            apply(rule to_zero_in_alt)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1632
           apply(rule many_steps_later)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1633
  apply(rule alt_remove0_front)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1634
           apply(rule many_steps_later)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1635
            apply(rule rrewrite.intros(12))
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1636
  using bder_fuse fuse_append rs1 apply presburger
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1637
          apply(case_tac "bnullable r1")
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1638
  prefer 2
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1639
           apply(subgoal_tac "\<not>bnullable r2")
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1640
            prefer 2
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1641
  using rewrite_non_nullable apply presburger
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1642
           apply simp+
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1643
  
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1644
  using star_seq apply auto[1]
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1645
          apply(subgoal_tac "bnullable r2")
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1646
           apply simp+
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1647
  apply(subgoal_tac "bmkeps r1 = bmkeps r2")
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1648
  prefer 2
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1649
  using rewrite_bmkeps apply auto[1]
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1650
  using contextrewrites1 star_seq apply auto[1]
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1651
  using rewritenullable apply auto[1]
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1652
         apply(case_tac "bnullable r1")
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1653
          apply simp
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1654
          apply(subgoal_tac "ASEQ [] (bder c r1) r3 \<leadsto> ASEQ [] (bder c r1) r4") 
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1655
           prefer 2
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1656
  using rrewrite.intros(5) apply blast
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1657
          apply(rule many_steps_later)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1658
           apply(rule alt_rewrite_front)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1659
           apply assumption
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1660
  apply (meson alt_rewrites_back rewrites_fuse) 
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1661
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1662
       apply (simp add: r_in_rstar rrewrite.intros(5))
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1663
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1664
  using contextrewrites2 apply force
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1665
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1666
  using rrewrite.intros(7) apply force
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1667
  
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1668
  using rewrite_der_altmiddle apply auto[1]
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1669
  
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1670
  apply (metis bder.simps(4) bder_fuse_list map_map r_in_rstar rrewrite.intros(9))
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1671
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1672
  apply (metis List.map.compositionality bder.simps(4) bder_fuse_list r_in_rstar rrewrite.intros(10))
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1673
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1674
  apply (simp add: r_in_rstar rrewrite.intros(11))
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1675
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1676
   apply (metis bder.simps(4) bder_bsimp_AALTs bsimp_AALTs.simps(2) bsimp_AALTsrewrites)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1677
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1678
  
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1679
  using lock_step_der_removal by auto
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1680
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1681
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1682
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1683
lemma rewrites_after_der: "  r1 \<leadsto>* r2  \<Longrightarrow>  (bder c r1) \<leadsto>* (bder c r2)"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1684
  apply(induction r1 r2 rule: rrewrites.induct)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1685
   apply(rule rs1)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1686
  by (meson real_trans rewrite_after_der)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1687
  
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1688
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1689
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1690
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1691
lemma central: " (bders r s) \<leadsto>*  (bders_simp r s)" 
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1692
  apply(induct s arbitrary: r rule: rev_induct)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1693
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1694
   apply simp
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1695
  apply(subst bders_append)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1696
  apply(subst bders_simp_append)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1697
  by (metis bders.simps(1) bders.simps(2) bders_simp.simps(1) bders_simp.simps(2) bsimp_rewrite real_trans rewrites_after_der)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1698
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1699
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1700
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1701
thm arexp.induct
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1702
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1703
lemma quasi_main: "bnullable (bders r s) \<Longrightarrow> bmkeps (bders r s) = bmkeps (bders_simp r s)"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1704
  using central rewrites_bmkeps by blast
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1705
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1706
theorem main_main: "blexer r s = blexer_simp r s"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1707
  by (simp add: b4 blexer_def blexer_simp_def quasi_main)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1708
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1709
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1710
theorem blexersimp_correctness: "blexer_simp r s= lexer r s"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1711
  using blexer_correctness main_main by auto
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1712
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1713
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1714
unused_thms
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1715
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1716
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1717
end