thys2/SizeBound2.thy
author Chengsong
Fri, 30 Dec 2022 23:41:44 +0000
changeset 640 bd1354127574
parent 393 3954579ebdaf
permissions -rw-r--r--
more proofreading done, last version before submission
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
365
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
     1
392
8194086c2a8a simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents: 385
diff changeset
     2
theory SizeBound2
365
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
fun fuse :: "bit list \<Rightarrow> arexp \<Rightarrow> arexp" where
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   122
  "fuse bs AZERO = AZERO"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   123
| "fuse bs (AONE cs) = AONE (bs @ cs)" 
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   124
| "fuse bs (ACHAR cs c) = ACHAR (bs @ cs) c"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   125
| "fuse bs (AALTs cs rs) = AALTs (bs @ cs) rs"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   126
| "fuse bs (ASEQ cs r1 r2) = ASEQ (bs @ cs) r1 r2"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   127
| "fuse bs (ASTAR cs r) = ASTAR (bs @ cs) r"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   128
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   129
lemma fuse_append:
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   130
  shows "fuse (bs1 @ bs2) r = fuse bs1 (fuse bs2 r)"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   131
  apply(induct r)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   132
  apply(auto)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   133
  done
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   134
385
c80720289645 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 381
diff changeset
   135
lemma fuse_Nil:
c80720289645 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 381
diff changeset
   136
  shows "fuse [] r = r"
c80720289645 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 381
diff changeset
   137
  by (induct r)(simp_all)
c80720289645 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 381
diff changeset
   138
c80720289645 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 381
diff changeset
   139
lemma map_fuse_Nil:
c80720289645 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 381
diff changeset
   140
  shows "map (fuse []) rs = rs"
c80720289645 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 381
diff changeset
   141
  by (induct rs)(simp_all add: fuse_Nil)
c80720289645 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 381
diff changeset
   142
365
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   143
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   144
fun intern :: "rexp \<Rightarrow> arexp" where
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   145
  "intern ZERO = AZERO"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   146
| "intern ONE = AONE []"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   147
| "intern (CH c) = ACHAR [] c"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   148
| "intern (ALT r1 r2) = AALT [] (fuse [Z] (intern r1)) 
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   149
                                (fuse [S]  (intern r2))"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   150
| "intern (SEQ r1 r2) = ASEQ [] (intern r1) (intern r2)"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   151
| "intern (STAR r) = ASTAR [] (intern r)"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   152
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   153
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   154
fun retrieve :: "arexp \<Rightarrow> val \<Rightarrow> bit list" where
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   155
  "retrieve (AONE bs) Void = bs"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   156
| "retrieve (ACHAR bs c) (Char d) = bs"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   157
| "retrieve (AALTs bs [r]) v = bs @ retrieve r v" 
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   158
| "retrieve (AALTs bs (r#rs)) (Left v) = bs @ retrieve r v"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   159
| "retrieve (AALTs bs (r#rs)) (Right v) = bs @ retrieve (AALTs [] rs) v"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   160
| "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
   161
| "retrieve (ASTAR bs r) (Stars []) = bs @ [S]"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   162
| "retrieve (ASTAR bs r) (Stars (v#vs)) = 
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   163
     bs @ [Z] @ retrieve r v @ retrieve (ASTAR [] r) (Stars vs)"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   164
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   165
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   166
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   167
fun
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   168
 bnullable :: "arexp \<Rightarrow> bool"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   169
where
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   170
  "bnullable (AZERO) = False"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   171
| "bnullable (AONE bs) = True"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   172
| "bnullable (ACHAR bs c) = False"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   173
| "bnullable (AALTs bs rs) = (\<exists>r \<in> set rs. bnullable r)"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   174
| "bnullable (ASEQ bs r1 r2) = (bnullable r1 \<and> bnullable r2)"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   175
| "bnullable (ASTAR bs r) = True"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   176
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   177
fun 
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   178
  bmkeps :: "arexp \<Rightarrow> bit list"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   179
where
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   180
  "bmkeps(AONE bs) = bs"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   181
| "bmkeps(ASEQ bs r1 r2) = bs @ (bmkeps r1) @ (bmkeps r2)"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   182
| "bmkeps(AALTs bs [r]) = bs @ (bmkeps r)"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   183
| "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
   184
| "bmkeps(ASTAR bs r) = bs @ [S]"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   185
393
3954579ebdaf polished
Christian Urban <christian.urban@kcl.ac.uk>
parents: 392
diff changeset
   186
fun 
3954579ebdaf polished
Christian Urban <christian.urban@kcl.ac.uk>
parents: 392
diff changeset
   187
  bmkepss :: "arexp list \<Rightarrow> bit list"
3954579ebdaf polished
Christian Urban <christian.urban@kcl.ac.uk>
parents: 392
diff changeset
   188
where
3954579ebdaf polished
Christian Urban <christian.urban@kcl.ac.uk>
parents: 392
diff changeset
   189
  "bmkepss [] = []"
3954579ebdaf polished
Christian Urban <christian.urban@kcl.ac.uk>
parents: 392
diff changeset
   190
| "bmkepss (r # rs) = (if bnullable(r) then (bmkeps r) else (bmkepss rs))"
365
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   191
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   192
fun
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   193
 bder :: "char \<Rightarrow> arexp \<Rightarrow> arexp"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   194
where
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   195
  "bder c (AZERO) = AZERO"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   196
| "bder c (AONE bs) = AZERO"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   197
| "bder c (ACHAR bs d) = (if c = d then AONE bs else AZERO)"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   198
| "bder c (AALTs bs rs) = AALTs bs (map (bder c) rs)"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   199
| "bder c (ASEQ bs r1 r2) = 
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   200
     (if bnullable r1
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   201
      then AALT bs (ASEQ [] (bder c r1) r2) (fuse (bmkeps r1) (bder c r2))
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   202
      else ASEQ bs (bder c r1) r2)"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   203
| "bder c (ASTAR bs r) = ASEQ bs (fuse [Z] (bder c r)) (ASTAR [] r)"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   204
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   205
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   206
fun 
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   207
  bders :: "arexp \<Rightarrow> string \<Rightarrow> arexp"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   208
where
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   209
  "bders r [] = r"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   210
| "bders r (c#s) = bders (bder c r) s"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   211
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   212
lemma bders_append:
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   213
  "bders r (s1 @ s2) = bders (bders r s1) s2"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   214
  apply(induct s1 arbitrary: r s2)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   215
  apply(simp_all)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   216
  done
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   217
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   218
lemma bnullable_correctness:
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   219
  shows "nullable (erase r) = bnullable r"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   220
  apply(induct r rule: erase.induct)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   221
  apply(simp_all)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   222
  done
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   223
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   224
lemma erase_fuse:
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   225
  shows "erase (fuse bs r) = erase r"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   226
  apply(induct r rule: erase.induct)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   227
  apply(simp_all)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   228
  done
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   229
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   230
lemma erase_intern [simp]:
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   231
  shows "erase (intern r) = r"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   232
  apply(induct r)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   233
  apply(simp_all add: erase_fuse)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   234
  done
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   235
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   236
lemma erase_bder [simp]:
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   237
  shows "erase (bder a r) = der a (erase r)"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   238
  apply(induct r rule: erase.induct)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   239
  apply(simp_all add: erase_fuse bnullable_correctness)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   240
  done
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   241
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   242
lemma erase_bders [simp]:
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   243
  shows "erase (bders r s) = ders s (erase r)"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   244
  apply(induct s arbitrary: r )
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   245
  apply(simp_all)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   246
  done
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   247
381
0c666a0c57d7 isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents: 379
diff changeset
   248
lemma bnullable_fuse:
0c666a0c57d7 isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents: 379
diff changeset
   249
  shows "bnullable (fuse bs r) = bnullable r"
0c666a0c57d7 isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents: 379
diff changeset
   250
  apply(induct r arbitrary: bs)
0c666a0c57d7 isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents: 379
diff changeset
   251
  apply(auto)
0c666a0c57d7 isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents: 379
diff changeset
   252
  done
0c666a0c57d7 isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents: 379
diff changeset
   253
365
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   254
lemma retrieve_encode_STARS:
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   255
  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
   256
  shows "code (Stars vs) = retrieve (ASTAR [] (intern r)) (Stars vs)"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   257
  using assms
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   258
  apply(induct vs)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   259
  apply(simp_all)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   260
  done
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   261
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   262
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   263
lemma retrieve_fuse2:
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   264
  assumes "\<Turnstile> v : (erase r)"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   265
  shows "retrieve (fuse bs r) v = bs @ retrieve r v"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   266
  using assms
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   267
  apply(induct r arbitrary: v bs)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   268
         apply(auto elim: Prf_elims)[4]
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   269
   defer
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   270
  using retrieve_encode_STARS
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   271
   apply(auto elim!: Prf_elims)[1]
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   272
   apply(case_tac vs)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   273
    apply(simp)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   274
   apply(simp)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   275
  (* AALTs  case *)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   276
  apply(simp)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   277
  apply(case_tac x2a)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   278
   apply(simp)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   279
   apply(auto elim!: Prf_elims)[1]
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(case_tac list)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   282
   apply(simp)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   283
  apply(auto)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   284
  apply(auto elim!: Prf_elims)[1]
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   285
  done
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   286
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   287
lemma retrieve_fuse:
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   288
  assumes "\<Turnstile> v : r"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   289
  shows "retrieve (fuse bs (intern r)) v = bs @ retrieve (intern r) v"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   290
  using assms 
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   291
  by (simp_all add: retrieve_fuse2)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   292
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   293
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   294
lemma retrieve_code:
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 "code v = 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
  apply(induct v r )
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   299
  apply(simp_all add: retrieve_fuse retrieve_encode_STARS)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   300
  done
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   301
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   302
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   303
lemma bnullable_Hdbmkeps_Hd:
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   304
  assumes "bnullable a" 
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   305
  shows  "bmkeps (AALTs bs (a # rs)) = bs @ (bmkeps a)"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   306
  using assms
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   307
  by (metis bmkeps.simps(3) bmkeps.simps(4) list.exhaust)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   308
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   309
lemma r1:
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   310
  assumes "\<not> bnullable a" "bnullable (AALTs bs rs)"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   311
  shows  "bmkeps (AALTs bs (a # rs)) = bmkeps (AALTs bs rs)"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   312
  using assms
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   313
  apply(induct rs)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   314
   apply(auto)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   315
  done
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   316
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   317
lemma r2:
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   318
  assumes "x \<in> set rs" "bnullable x"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   319
  shows "bnullable (AALTs bs rs)"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   320
  using assms
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   321
  apply(induct rs)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   322
   apply(auto)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   323
  done
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   324
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   325
lemma  r3:
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   326
  assumes "\<not> bnullable r" 
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   327
          " \<exists> x \<in> set rs. bnullable x"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   328
  shows "retrieve (AALTs bs rs) (mkeps (erase (AALTs bs rs))) =
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   329
         retrieve (AALTs bs (r # rs)) (mkeps (erase (AALTs bs (r # rs))))"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   330
  using assms
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   331
  apply(induct rs arbitrary: r bs)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   332
   apply(auto)[1]
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   333
  apply(auto)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   334
  using bnullable_correctness apply blast
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   335
    apply(auto simp add: bnullable_correctness mkeps_nullable retrieve_fuse2)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   336
   apply(subst retrieve_fuse2[symmetric])
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   337
  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
   338
   apply(simp)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   339
  apply(case_tac "bnullable a")
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   340
  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
   341
  apply(drule_tac x="a" in meta_spec)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   342
  apply(drule_tac x="bs" in meta_spec)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   343
  apply(drule meta_mp)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   344
   apply(simp)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   345
  apply(drule meta_mp)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   346
   apply(auto)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   347
  apply(subst retrieve_fuse2[symmetric])
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   348
  apply(case_tac rs)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   349
    apply(simp)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   350
   apply(auto)[1]
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   351
      apply (simp add: bnullable_correctness)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   352
  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
   353
    apply (simp add: bnullable_correctness)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   354
  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
   355
  apply(simp)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   356
  done
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   357
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   358
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   359
lemma t: 
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   360
  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
   361
          "nullable (erase (AALTs bs rs))"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   362
  shows " bmkeps (AALTs bs rs) = retrieve (AALTs bs rs) (mkeps (erase (AALTs bs rs)))"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   363
  using assms
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   364
  apply(induct rs arbitrary: bs)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   365
   apply(simp)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   366
  apply(auto simp add: bnullable_correctness)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   367
   apply(case_tac rs)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   368
     apply(auto simp add: bnullable_correctness)[2]
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   369
   apply(subst r1)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   370
     apply(simp)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   371
    apply(rule r2)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   372
     apply(assumption)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   373
    apply(simp)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   374
   apply(drule_tac x="bs" in meta_spec)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   375
   apply(drule meta_mp)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   376
    apply(auto)[1]
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   377
   prefer 2
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   378
  apply(case_tac "bnullable a")
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   379
    apply(subst bnullable_Hdbmkeps_Hd)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   380
     apply blast
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   381
    apply(subgoal_tac "nullable (erase a)")
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   382
  prefer 2
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   383
  using bnullable_correctness apply blast
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   384
  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
   385
  apply(subst r1)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   386
     apply(simp)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   387
  using r2 apply blast
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   388
  apply(drule_tac x="bs" in meta_spec)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   389
   apply(drule meta_mp)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   390
    apply(auto)[1]
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   391
   apply(simp)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   392
  using r3 apply blast
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   393
  apply(auto)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   394
  using r3 by blast
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   395
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   396
lemma bmkeps_retrieve:
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   397
  assumes "nullable (erase r)"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   398
  shows "bmkeps r = retrieve r (mkeps (erase r))"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   399
  using assms
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   400
  apply(induct r)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   401
         apply(simp)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   402
        apply(simp)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   403
       apply(simp)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   404
    apply(simp)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   405
   defer
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   406
   apply(simp)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   407
  apply(rule t)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   408
   apply(auto)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   409
  done
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   410
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   411
lemma bder_retrieve:
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   412
  assumes "\<Turnstile> v : der c (erase r)"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   413
  shows "retrieve (bder c r) v = retrieve r (injval (erase r) c v)"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   414
  using assms
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   415
  apply(induct r arbitrary: v rule: erase.induct)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   416
         apply(simp)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   417
         apply(erule Prf_elims)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   418
        apply(simp)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   419
        apply(erule Prf_elims) 
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   420
        apply(simp)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   421
      apply(case_tac "c = ca")
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   422
       apply(simp)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   423
       apply(erule Prf_elims)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   424
       apply(simp)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   425
      apply(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(erule Prf_elims)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   429
     apply(simp)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   430
    apply(simp)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   431
  apply(rename_tac "r\<^sub>1" "r\<^sub>2" rs v)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   432
    apply(erule Prf_elims)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   433
     apply(simp)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   434
    apply(simp)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   435
    apply(case_tac rs)
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 (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
   439
   apply(simp)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   440
   apply(case_tac "nullable (erase r1)")
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(erule Prf_elims)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   443
     apply(subgoal_tac "bnullable r1")
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   444
  prefer 2
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   445
  using bnullable_correctness apply blast
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(erule Prf_elims)
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(subgoal_tac "bnullable r1")
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   450
  prefer 2
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   451
  using bnullable_correctness apply blast
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   452
    apply(simp)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   453
    apply(simp add: retrieve_fuse2)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   454
    apply(simp add: bmkeps_retrieve)
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(erule Prf_elims)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   457
   apply(simp)
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(rename_tac bs r v)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   460
  apply(simp)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   461
  apply(erule Prf_elims)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   462
     apply(clarify)
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(clarify)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   465
  apply(subst injval.simps)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   466
  apply(simp del: retrieve.simps)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   467
  apply(subst retrieve.simps)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   468
  apply(subst retrieve.simps)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   469
  apply(simp)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   470
  apply(simp add: retrieve_fuse2)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   471
  done
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   472
  
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   473
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   474
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   475
lemma MAIN_decode:
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   476
  assumes "\<Turnstile> v : ders s r"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   477
  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
   478
  using assms
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   479
proof (induct s arbitrary: v rule: rev_induct)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   480
  case Nil
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   481
  have "\<Turnstile> v : ders [] r" by fact
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   482
  then have "\<Turnstile> v : r" by simp
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   483
  then have "Some v = decode (retrieve (intern r) v) r"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   484
    using decode_code retrieve_code by auto
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   485
  then show "Some (flex r id [] v) = decode (retrieve (bders (intern r) []) v) r"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   486
    by simp
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   487
next
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   488
  case (snoc c s v)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   489
  have IH: "\<And>v. \<Turnstile> v : ders s r \<Longrightarrow> 
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   490
     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
   491
  have asm: "\<Turnstile> v : ders (s @ [c]) r" by fact
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   492
  then have asm2: "\<Turnstile> injval (ders s r) c v : ders s r" 
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   493
    by (simp add: Prf_injval ders_append)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   494
  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
   495
    by (simp add: flex_append)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   496
  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
   497
    using asm2 IH by simp
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   498
  also have "... = decode (retrieve (bder c (bders (intern r) s)) v) r"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   499
    using asm by (simp_all add: bder_retrieve ders_append)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   500
  finally show "Some (flex r id (s @ [c]) v) = 
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   501
                 decode (retrieve (bders (intern r) (s @ [c])) v) r" by (simp add: bders_append)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   502
qed
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   503
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   504
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   505
definition blex where
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   506
 "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
   507
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   508
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   509
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   510
definition blexer where
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   511
 "blexer r s \<equiv> if bnullable (bders (intern r) s) then 
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   512
                decode (bmkeps (bders (intern r) s)) r else None"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   513
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   514
lemma blexer_correctness:
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   515
  shows "blexer r s = lexer r s"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   516
proof -
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   517
  { define bds where "bds \<equiv> bders (intern r) s"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   518
    define ds  where "ds \<equiv> ders s r"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   519
    assume asm: "nullable ds"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   520
    have era: "erase bds = ds" 
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   521
      unfolding ds_def bds_def by simp
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   522
    have mke: "\<Turnstile> mkeps ds : ds"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   523
      using asm by (simp add: mkeps_nullable)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   524
    have "decode (bmkeps bds) r = decode (retrieve bds (mkeps ds)) r"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   525
      using bmkeps_retrieve
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   526
      using asm era by (simp add: bmkeps_retrieve)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   527
    also have "... =  Some (flex r id s (mkeps ds))"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   528
      using mke by (simp_all add: MAIN_decode ds_def bds_def)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   529
    finally have "decode (bmkeps bds) r = Some (flex r id s (mkeps ds))" 
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   530
      unfolding bds_def ds_def .
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   531
  }
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   532
  then show "blexer r s = lexer r s"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   533
    unfolding blexer_def lexer_flex
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   534
    apply(subst bnullable_correctness[symmetric])
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   535
    apply(simp)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   536
    done
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   537
qed
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   538
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   539
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   540
fun distinctBy :: "'a list \<Rightarrow> ('a \<Rightarrow> 'b) \<Rightarrow> 'b set \<Rightarrow> 'a list"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   541
  where
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   542
  "distinctBy [] f acc = []"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   543
| "distinctBy (x#xs) f acc = 
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   544
     (if (f x) \<in> acc then distinctBy xs f acc 
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   545
      else x # (distinctBy xs f ({f x} \<union> acc)))"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   546
393
3954579ebdaf polished
Christian Urban <christian.urban@kcl.ac.uk>
parents: 392
diff changeset
   547
 
365
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   548
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   549
fun flts :: "arexp list \<Rightarrow> arexp list"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   550
  where 
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   551
  "flts [] = []"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   552
| "flts (AZERO # rs) = flts rs"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   553
| "flts ((AALTs bs  rs1) # rs) = (map (fuse bs) rs1) @ flts rs"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   554
| "flts (r1 # rs) = r1 # flts rs"
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
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   558
fun bsimp_ASEQ :: "bit list \<Rightarrow> arexp \<Rightarrow> arexp \<Rightarrow> arexp"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   559
  where
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   560
  "bsimp_ASEQ _ AZERO _ = AZERO"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   561
| "bsimp_ASEQ _ _ AZERO = AZERO"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   562
| "bsimp_ASEQ bs1 (AONE bs2) r2 = fuse (bs1 @ bs2) r2"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   563
| "bsimp_ASEQ bs1 r1 r2 = ASEQ  bs1 r1 r2"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   564
393
3954579ebdaf polished
Christian Urban <christian.urban@kcl.ac.uk>
parents: 392
diff changeset
   565
lemma bsimp_ASEQ0[simp]:
3954579ebdaf polished
Christian Urban <christian.urban@kcl.ac.uk>
parents: 392
diff changeset
   566
  shows "bsimp_ASEQ bs r1 AZERO = AZERO"
3954579ebdaf polished
Christian Urban <christian.urban@kcl.ac.uk>
parents: 392
diff changeset
   567
  by (case_tac r1)(simp_all)
3954579ebdaf polished
Christian Urban <christian.urban@kcl.ac.uk>
parents: 392
diff changeset
   568
3954579ebdaf polished
Christian Urban <christian.urban@kcl.ac.uk>
parents: 392
diff changeset
   569
lemma bsimp_ASEQ1:
3954579ebdaf polished
Christian Urban <christian.urban@kcl.ac.uk>
parents: 392
diff changeset
   570
  assumes "r1 \<noteq> AZERO" "r2 \<noteq> AZERO" "\<nexists>bs. r1 = AONE bs"
3954579ebdaf polished
Christian Urban <christian.urban@kcl.ac.uk>
parents: 392
diff changeset
   571
  shows "bsimp_ASEQ bs r1 r2 = ASEQ bs r1 r2"
3954579ebdaf polished
Christian Urban <christian.urban@kcl.ac.uk>
parents: 392
diff changeset
   572
  using assms
3954579ebdaf polished
Christian Urban <christian.urban@kcl.ac.uk>
parents: 392
diff changeset
   573
  apply(induct bs r1 r2 rule: bsimp_ASEQ.induct)
3954579ebdaf polished
Christian Urban <christian.urban@kcl.ac.uk>
parents: 392
diff changeset
   574
  apply(auto)
3954579ebdaf polished
Christian Urban <christian.urban@kcl.ac.uk>
parents: 392
diff changeset
   575
  done
3954579ebdaf polished
Christian Urban <christian.urban@kcl.ac.uk>
parents: 392
diff changeset
   576
3954579ebdaf polished
Christian Urban <christian.urban@kcl.ac.uk>
parents: 392
diff changeset
   577
lemma bsimp_ASEQ2[simp]:
3954579ebdaf polished
Christian Urban <christian.urban@kcl.ac.uk>
parents: 392
diff changeset
   578
  shows "bsimp_ASEQ bs1 (AONE bs2) r2 = fuse (bs1 @ bs2) r2"
3954579ebdaf polished
Christian Urban <christian.urban@kcl.ac.uk>
parents: 392
diff changeset
   579
  by (case_tac r2) (simp_all)
3954579ebdaf polished
Christian Urban <christian.urban@kcl.ac.uk>
parents: 392
diff changeset
   580
365
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   581
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   582
fun bsimp_AALTs :: "bit list \<Rightarrow> arexp list \<Rightarrow> arexp"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   583
  where
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   584
  "bsimp_AALTs _ [] = AZERO"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   585
| "bsimp_AALTs bs1 [r] = fuse bs1 r"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   586
| "bsimp_AALTs bs1 rs = AALTs bs1 rs"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   587
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   588
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   589
fun bsimp :: "arexp \<Rightarrow> arexp" 
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   590
  where
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   591
  "bsimp (ASEQ bs1 r1 r2) = bsimp_ASEQ bs1 (bsimp r1) (bsimp r2)"
374
98362002c818 slightly more
Christian Urban <christian.urban@kcl.ac.uk>
parents: 373
diff changeset
   592
| "bsimp (AALTs bs1 rs) = bsimp_AALTs bs1 (distinctBy (flts (map bsimp rs)) erase {}) "
365
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   593
| "bsimp r = r"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   594
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   595
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   596
fun 
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   597
  bders_simp :: "arexp \<Rightarrow> string \<Rightarrow> arexp"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   598
where
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   599
  "bders_simp r [] = r"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   600
| "bders_simp r (c # s) = bders_simp (bsimp (bder c r)) s"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   601
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   602
definition blexer_simp where
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   603
 "blexer_simp r s \<equiv> if bnullable (bders_simp (intern r) s) then 
374
98362002c818 slightly more
Christian Urban <christian.urban@kcl.ac.uk>
parents: 373
diff changeset
   604
                    decode (bmkeps (bders_simp (intern r) s)) r else None"
365
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   605
393
3954579ebdaf polished
Christian Urban <christian.urban@kcl.ac.uk>
parents: 392
diff changeset
   606
(*export_code bders_simp in Scala module_name Example*)
365
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   607
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   608
lemma bders_simp_append:
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   609
  shows "bders_simp r (s1 @ s2) = bders_simp (bders_simp r s1) s2"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   610
  apply(induct s1 arbitrary: r s2)
374
98362002c818 slightly more
Christian Urban <christian.urban@kcl.ac.uk>
parents: 373
diff changeset
   611
  apply(simp_all)
365
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   612
  done
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   613
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   614
lemma L_bsimp_ASEQ:
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   615
  "L (SEQ (erase r1) (erase r2)) = L (erase (bsimp_ASEQ bs r1 r2))"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   616
  apply(induct bs r1 r2 rule: bsimp_ASEQ.induct)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   617
  apply(simp_all)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   618
  by (metis erase_fuse fuse.simps(4))
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   619
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   620
lemma L_bsimp_AALTs:
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   621
  "L (erase (AALTs bs rs)) = L (erase (bsimp_AALTs bs rs))"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   622
  apply(induct bs rs rule: bsimp_AALTs.induct)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   623
  apply(simp_all add: erase_fuse)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   624
  done
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   625
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   626
lemma L_erase_AALTs:
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   627
  shows "L (erase (AALTs bs rs)) = \<Union> (L ` erase ` (set rs))"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   628
  apply(induct rs)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   629
   apply(simp)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   630
  apply(simp)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   631
  apply(case_tac rs)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   632
   apply(simp)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   633
  apply(simp)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   634
  done
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   635
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   636
lemma L_erase_flts:
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   637
  shows "\<Union> (L ` erase ` (set (flts rs))) = \<Union> (L ` erase ` (set rs))"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   638
  apply(induct rs rule: flts.induct)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   639
        apply(simp_all)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   640
  apply(auto)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   641
  using L_erase_AALTs erase_fuse apply auto[1]
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   642
  by (simp add: L_erase_AALTs erase_fuse)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   643
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   644
lemma L_erase_dB_acc:
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   645
  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
   646
  apply(induction rs arbitrary: acc)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   647
   apply simp
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   648
  apply simp
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   649
  by (smt (z3) SUP_absorb UN_insert sup_assoc sup_commute)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   650
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   651
lemma L_erase_dB:
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   652
  shows " ( \<Union> (L ` erase ` (set (distinctBy rs erase {}) ) ) ) = \<Union> (L ` erase ` (set rs))"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   653
  by (metis L_erase_dB_acc Un_commute Union_image_empty)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   654
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   655
lemma L_bsimp_erase:
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   656
  shows "L (erase r) = L (erase (bsimp r))"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   657
  apply(induct r)
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
  apply(simp)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   661
  apply(auto simp add: Sequ_def)[1]
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   662
  apply(subst L_bsimp_ASEQ[symmetric])
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   663
  apply(auto simp add: Sequ_def)[1]
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   664
  apply(subst (asm)  L_bsimp_ASEQ[symmetric])
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   665
  apply(auto simp add: Sequ_def)[1]
374
98362002c818 slightly more
Christian Urban <christian.urban@kcl.ac.uk>
parents: 373
diff changeset
   666
  apply(simp)
98362002c818 slightly more
Christian Urban <christian.urban@kcl.ac.uk>
parents: 373
diff changeset
   667
  apply(subst L_bsimp_AALTs[symmetric])
98362002c818 slightly more
Christian Urban <christian.urban@kcl.ac.uk>
parents: 373
diff changeset
   668
  defer
98362002c818 slightly more
Christian Urban <christian.urban@kcl.ac.uk>
parents: 373
diff changeset
   669
  apply(simp)
365
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   670
  apply(subst (2)L_erase_AALTs)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   671
  apply(subst L_erase_dB)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   672
  apply(subst L_erase_flts)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   673
  apply(auto)
374
98362002c818 slightly more
Christian Urban <christian.urban@kcl.ac.uk>
parents: 373
diff changeset
   674
  apply (simp add: L_erase_AALTs)
365
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   675
  using L_erase_AALTs by blast
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   676
374
98362002c818 slightly more
Christian Urban <christian.urban@kcl.ac.uk>
parents: 373
diff changeset
   677
98362002c818 slightly more
Christian Urban <christian.urban@kcl.ac.uk>
parents: 373
diff changeset
   678
365
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   679
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   680
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   681
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   682
lemma L_bders_simp:
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   683
  shows "L (erase (bders_simp r s)) = L (erase (bders r s))"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   684
  apply(induct s arbitrary: r rule: rev_induct)
374
98362002c818 slightly more
Christian Urban <christian.urban@kcl.ac.uk>
parents: 373
diff changeset
   685
  apply(simp)
365
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   686
  apply(simp)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   687
  apply(simp add: ders_append)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   688
  apply(simp add: bders_simp_append)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   689
  apply(simp add: L_bsimp_erase[symmetric])
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   690
  by (simp add: der_correctness)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   691
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   692
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   693
lemma b2:
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   694
  assumes "bnullable r"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   695
  shows "bmkeps (fuse bs r) = bs @ bmkeps r"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   696
  by (simp add: assms bmkeps_retrieve bnullable_correctness erase_fuse mkeps_nullable retrieve_fuse2)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   697
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   698
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   699
lemma b4:
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   700
  shows "bnullable (bders_simp r s) = bnullable (bders r s)"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   701
  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
   702
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   703
lemma qq1:
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   704
  assumes "\<exists>r \<in> set rs. bnullable r"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   705
  shows "bmkeps (AALTs bs (rs @ rs1)) = bmkeps (AALTs bs rs)"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   706
  using assms
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   707
  apply(induct rs arbitrary: rs1 bs)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   708
  apply(simp)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   709
  apply(simp)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   710
  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
   711
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   712
lemma qq2:
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   713
  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
   714
  shows "bmkeps (AALTs bs (rs @ rs1)) = bmkeps (AALTs bs rs1)"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   715
  using assms
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   716
  apply(induct rs arbitrary: rs1 bs)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   717
  apply(simp)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   718
  apply(simp)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   719
  by (metis append_assoc in_set_conv_decomp r1 r2)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   720
  
381
0c666a0c57d7 isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents: 379
diff changeset
   721
lemma qq3:
0c666a0c57d7 isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents: 379
diff changeset
   722
  assumes "bnullable (AALTs bs (rs @ rs1))"
0c666a0c57d7 isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents: 379
diff changeset
   723
          "bnullable (AALTs bs (rs @ rs2))"
0c666a0c57d7 isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents: 379
diff changeset
   724
          "\<lbrakk>bnullable (AALTs bs rs1); bnullable (AALTs bs rs2); \<forall>r\<in>set rs. \<not>bnullable r\<rbrakk> \<Longrightarrow> 
0c666a0c57d7 isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents: 379
diff changeset
   725
               bmkeps (AALTs bs rs1) = bmkeps (AALTs bs rs2)"
0c666a0c57d7 isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents: 379
diff changeset
   726
  shows "bmkeps (AALTs bs (rs @ rs1)) = bmkeps (AALTs bs (rs @ rs2))"
0c666a0c57d7 isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents: 379
diff changeset
   727
  using assms
0c666a0c57d7 isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents: 379
diff changeset
   728
  apply(case_tac "\<exists>r \<in> set rs. bnullable r")
0c666a0c57d7 isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents: 379
diff changeset
   729
  using qq1 apply auto[1]
0c666a0c57d7 isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents: 379
diff changeset
   730
  by (metis UnE bnullable.simps(4) qq2 set_append)
365
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 q3a:
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 (map (fuse bs1) rs)) = bmkeps (AALTs (bs@bs1) 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: bs bs1)
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
  apply(auto)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   741
   apply (metis append_assoc b2 bnullable_correctness erase_fuse bnullable_Hdbmkeps_Hd)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   742
  apply(case_tac "bnullable a")
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   743
   apply (metis append.assoc b2 bnullable_correctness erase_fuse bnullable_Hdbmkeps_Hd)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   744
  apply(case_tac rs)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   745
  apply(simp)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   746
  apply(simp)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   747
  apply(auto)[1]
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   748
   apply (metis bnullable_correctness erase_fuse)+
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   749
  done
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   750
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   751
lemma qq4:
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   752
  assumes "\<exists>x\<in>set list. bnullable x"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   753
  shows "\<exists>x\<in>set (flts list). bnullable x"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   754
  using assms
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   755
  apply(induct list rule: flts.induct)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   756
        apply(auto)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   757
  by (metis UnCI bnullable_correctness erase_fuse imageI)
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
lemma qs3:
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   761
  assumes "\<exists>r \<in> set rs. bnullable r"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   762
  shows "bmkeps (AALTs bs rs) = bmkeps (AALTs bs (flts rs))"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   763
  using assms
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   764
  apply(induct rs arbitrary: bs taking: size rule: measure_induct)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   765
  apply(case_tac x)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   766
  apply(simp)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   767
  apply(simp)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   768
  apply(case_tac a)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   769
       apply(simp)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   770
       apply (simp add: r1)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   771
      apply(simp)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   772
      apply (simp add: bnullable_Hdbmkeps_Hd)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   773
     apply(simp)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   774
     apply(case_tac "flts list")
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   775
      apply(simp)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   776
  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
   777
     apply(simp)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   778
     apply (simp add: r1)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   779
    prefer 3
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   780
    apply(simp)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   781
    apply (simp add: bnullable_Hdbmkeps_Hd)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   782
   prefer 2
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   783
   apply(simp)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   784
  apply(case_tac "\<exists>x\<in>set x52. bnullable x")
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   785
  apply(case_tac "list")
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   786
    apply(simp)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   787
    apply (metis b2 fuse.simps(4) q3a r2)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   788
   apply(erule disjE)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   789
    apply(subst qq1)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   790
     apply(auto)[1]
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   791
     apply (metis bnullable_correctness erase_fuse)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   792
    apply(simp)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   793
     apply (metis b2 fuse.simps(4) q3a r2)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   794
    apply(simp)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   795
    apply(auto)[1]
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   796
     apply(subst qq1)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   797
      apply (metis bnullable_correctness erase_fuse image_eqI set_map)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   798
     apply (metis b2 fuse.simps(4) q3a r2)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   799
  apply(subst qq1)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   800
      apply (metis bnullable_correctness erase_fuse image_eqI set_map)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   801
    apply (metis b2 fuse.simps(4) q3a r2)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   802
   apply(simp)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   803
   apply(subst qq2)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   804
     apply (metis bnullable_correctness erase_fuse imageE set_map)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   805
  prefer 2
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   806
  apply(case_tac "list")
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   807
     apply(simp)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   808
    apply(simp)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   809
   apply (simp add: qq4)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   810
  apply(simp)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   811
  apply(auto)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   812
   apply(case_tac list)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   813
    apply(simp)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   814
   apply(simp)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   815
   apply (simp add: bnullable_Hdbmkeps_Hd)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   816
  apply(case_tac "bnullable (ASEQ x41 x42 x43)")
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   817
   apply(case_tac list)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   818
    apply(simp)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   819
   apply(simp)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   820
   apply (simp add: bnullable_Hdbmkeps_Hd)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   821
  apply(simp)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   822
  using qq4 r1 r2 by auto
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   823
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   824
lemma bder_fuse:
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   825
  shows "bder c (fuse bs a) = fuse bs  (bder c a)"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   826
  apply(induct a arbitrary: bs c)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   827
       apply(simp_all)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   828
  done
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   829
385
c80720289645 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 381
diff changeset
   830
c80720289645 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 381
diff changeset
   831
c80720289645 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 381
diff changeset
   832
381
0c666a0c57d7 isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents: 379
diff changeset
   833
inductive 
0c666a0c57d7 isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents: 379
diff changeset
   834
  rrewrite:: "arexp \<Rightarrow> arexp \<Rightarrow> bool" ("_ \<leadsto> _" [99, 99] 99)
392
8194086c2a8a simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents: 385
diff changeset
   835
and 
8194086c2a8a simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents: 385
diff changeset
   836
  srewrite:: "arexp list \<Rightarrow> arexp list \<Rightarrow> bool" (" _ s\<leadsto> _" [100, 100] 100)
381
0c666a0c57d7 isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents: 379
diff changeset
   837
where
392
8194086c2a8a simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents: 385
diff changeset
   838
  bs1: "ASEQ bs AZERO r2 \<leadsto> AZERO"
8194086c2a8a simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents: 385
diff changeset
   839
| bs2: "ASEQ bs r1 AZERO \<leadsto> AZERO"
8194086c2a8a simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents: 385
diff changeset
   840
| bs3: "ASEQ bs1 (AONE bs2) r \<leadsto> fuse (bs1@bs2) r"
8194086c2a8a simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents: 385
diff changeset
   841
| bs4: "r1 \<leadsto> r2 \<Longrightarrow> ASEQ bs r1 r3 \<leadsto> ASEQ bs r2 r3"
8194086c2a8a simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents: 385
diff changeset
   842
| bs5: "r3 \<leadsto> r4 \<Longrightarrow> ASEQ bs r1 r3 \<leadsto> ASEQ bs r1 r4"
8194086c2a8a simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents: 385
diff changeset
   843
| bs6: "AALTs bs [] \<leadsto> AZERO"
8194086c2a8a simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents: 385
diff changeset
   844
| bs7: "AALTs bs [r] \<leadsto> fuse bs r"
8194086c2a8a simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents: 385
diff changeset
   845
| bs10: "rs1 s\<leadsto> rs2 \<Longrightarrow> AALTs bs rs1 \<leadsto> AALTs bs rs2"
8194086c2a8a simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents: 385
diff changeset
   846
| ss1:  "[] s\<leadsto> []"
8194086c2a8a simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents: 385
diff changeset
   847
| ss2:  "rs1 s\<leadsto> rs2 \<Longrightarrow> (r # rs1) s\<leadsto> (r # rs2)"
8194086c2a8a simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents: 385
diff changeset
   848
| ss3:  "r1 \<leadsto> r2 \<Longrightarrow> (r1 # rs) s\<leadsto> (r2 # rs)"
8194086c2a8a simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents: 385
diff changeset
   849
| ss4:  "(AZERO # rs) s\<leadsto> rs"
8194086c2a8a simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents: 385
diff changeset
   850
| ss5:  "(AALTs bs1 rs1 # rsb) s\<leadsto> ((map (fuse bs1) rs1) @ rsb)"
8194086c2a8a simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents: 385
diff changeset
   851
| ss6:  "erase a1 = erase a2 \<Longrightarrow> (rsa@[a1]@rsb@[a2]@rsc) s\<leadsto> (rsa@[a1]@rsb@rsc)"
365
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   852
393
3954579ebdaf polished
Christian Urban <christian.urban@kcl.ac.uk>
parents: 392
diff changeset
   853
381
0c666a0c57d7 isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents: 379
diff changeset
   854
inductive 
0c666a0c57d7 isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents: 379
diff changeset
   855
  rrewrites:: "arexp \<Rightarrow> arexp \<Rightarrow> bool" ("_ \<leadsto>* _" [100, 100] 100)
0c666a0c57d7 isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents: 379
diff changeset
   856
where 
0c666a0c57d7 isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents: 379
diff changeset
   857
  rs1[intro, simp]:"r \<leadsto>* r"
365
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   858
| rs2[intro]: "\<lbrakk>r1 \<leadsto>* r2; r2 \<leadsto> r3\<rbrakk> \<Longrightarrow> r1 \<leadsto>* r3"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   859
381
0c666a0c57d7 isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents: 379
diff changeset
   860
inductive 
392
8194086c2a8a simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents: 385
diff changeset
   861
  srewrites:: "arexp list \<Rightarrow> arexp list \<Rightarrow> bool" ("_ s\<leadsto>* _" [100, 100] 100)
8194086c2a8a simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents: 385
diff changeset
   862
where 
8194086c2a8a simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents: 385
diff changeset
   863
  sss1[intro, simp]:"rs s\<leadsto>* rs"
8194086c2a8a simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents: 385
diff changeset
   864
| sss2[intro]: "\<lbrakk>rs1 s\<leadsto> rs2; rs2 s\<leadsto>* rs3\<rbrakk> \<Longrightarrow> rs1 s\<leadsto>* rs3"
365
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   865
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   866
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   867
lemma r_in_rstar : "r1 \<leadsto> r2 \<Longrightarrow> r1 \<leadsto>* r2"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   868
  using rrewrites.intros(1) rrewrites.intros(2) by blast
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   869
 
392
8194086c2a8a simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents: 385
diff changeset
   870
lemma rrewrites_trans[trans]: 
365
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   871
  assumes a1: "r1 \<leadsto>* r2"  and a2: "r2 \<leadsto>* r3"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   872
  shows "r1 \<leadsto>* r3"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   873
  using a2 a1
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   874
  apply(induct r2 r3 arbitrary: r1 rule: rrewrites.induct) 
381
0c666a0c57d7 isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents: 379
diff changeset
   875
  apply(auto)
365
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   876
  done
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   877
392
8194086c2a8a simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents: 385
diff changeset
   878
lemma srewrites_trans[trans]: 
8194086c2a8a simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents: 385
diff changeset
   879
  assumes a1: "r1 s\<leadsto>* r2"  and a2: "r2 s\<leadsto>* r3"
8194086c2a8a simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents: 385
diff changeset
   880
  shows "r1 s\<leadsto>* r3"
8194086c2a8a simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents: 385
diff changeset
   881
  using a1 a2
8194086c2a8a simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents: 385
diff changeset
   882
  apply(induct r1 r2 arbitrary: r3 rule: srewrites.induct) 
8194086c2a8a simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents: 385
diff changeset
   883
   apply(auto)
8194086c2a8a simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents: 385
diff changeset
   884
  done
365
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   885
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   886
392
8194086c2a8a simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents: 385
diff changeset
   887
8194086c2a8a simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents: 385
diff changeset
   888
lemma contextrewrites0: 
8194086c2a8a simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents: 385
diff changeset
   889
  "rs1 s\<leadsto>* rs2 \<Longrightarrow> AALTs bs rs1 \<leadsto>* AALTs bs rs2"
8194086c2a8a simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents: 385
diff changeset
   890
  apply(induct rs1 rs2 rule: srewrites.inducts)
8194086c2a8a simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents: 385
diff changeset
   891
   apply simp
8194086c2a8a simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents: 385
diff changeset
   892
  using bs10 r_in_rstar rrewrites_trans by blast
8194086c2a8a simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents: 385
diff changeset
   893
8194086c2a8a simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents: 385
diff changeset
   894
lemma contextrewrites1: 
8194086c2a8a simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents: 385
diff changeset
   895
  "r \<leadsto>* r' \<Longrightarrow> AALTs bs (r#rs) \<leadsto>* AALTs bs (r'#rs)"
8194086c2a8a simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents: 385
diff changeset
   896
  apply(induct r r' rule: rrewrites.induct)
8194086c2a8a simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents: 385
diff changeset
   897
   apply simp
8194086c2a8a simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents: 385
diff changeset
   898
  using bs10 ss3 by blast
8194086c2a8a simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents: 385
diff changeset
   899
8194086c2a8a simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents: 385
diff changeset
   900
lemma srewrite1: 
8194086c2a8a simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents: 385
diff changeset
   901
  shows "rs1 s\<leadsto> rs2 \<Longrightarrow> (rs @ rs1) s\<leadsto> (rs @ rs2)"
8194086c2a8a simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents: 385
diff changeset
   902
  apply(induct rs)
8194086c2a8a simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents: 385
diff changeset
   903
   apply(auto)
8194086c2a8a simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents: 385
diff changeset
   904
  using ss2 by auto
8194086c2a8a simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents: 385
diff changeset
   905
8194086c2a8a simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents: 385
diff changeset
   906
lemma srewrites1: 
8194086c2a8a simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents: 385
diff changeset
   907
  shows "rs1 s\<leadsto>* rs2 \<Longrightarrow> (rs @ rs1) s\<leadsto>* (rs @ rs2)"
8194086c2a8a simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents: 385
diff changeset
   908
  apply(induct rs1 rs2 rule: srewrites.induct)
8194086c2a8a simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents: 385
diff changeset
   909
   apply(auto)
8194086c2a8a simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents: 385
diff changeset
   910
  using srewrite1 by blast
365
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   911
392
8194086c2a8a simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents: 385
diff changeset
   912
lemma srewrite2: 
8194086c2a8a simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents: 385
diff changeset
   913
  shows  "r1 \<leadsto> r2 \<Longrightarrow> True"
8194086c2a8a simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents: 385
diff changeset
   914
  and "rs1 s\<leadsto> rs2 \<Longrightarrow> (rs1 @ rs) s\<leadsto>* (rs2 @ rs)"
8194086c2a8a simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents: 385
diff changeset
   915
  apply(induct rule: rrewrite_srewrite.inducts)
8194086c2a8a simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents: 385
diff changeset
   916
               apply(auto)
8194086c2a8a simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents: 385
diff changeset
   917
     apply (metis append_Cons append_Nil srewrites1)
8194086c2a8a simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents: 385
diff changeset
   918
    apply(meson srewrites.simps ss3)
8194086c2a8a simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents: 385
diff changeset
   919
  apply (meson srewrites.simps ss4)
8194086c2a8a simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents: 385
diff changeset
   920
  apply (meson srewrites.simps ss5)
8194086c2a8a simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents: 385
diff changeset
   921
  by (metis append_Cons append_Nil srewrites.simps ss6)
8194086c2a8a simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents: 385
diff changeset
   922
  
8194086c2a8a simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents: 385
diff changeset
   923
8194086c2a8a simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents: 385
diff changeset
   924
lemma srewrites3: 
8194086c2a8a simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents: 385
diff changeset
   925
  shows "rs1 s\<leadsto>* rs2 \<Longrightarrow> (rs1 @ rs) s\<leadsto>* (rs2 @ rs)"
8194086c2a8a simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents: 385
diff changeset
   926
  apply(induct rs1 rs2 arbitrary: rs rule: srewrites.induct)
8194086c2a8a simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents: 385
diff changeset
   927
   apply(auto)
8194086c2a8a simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents: 385
diff changeset
   928
  by (meson srewrite2(2) srewrites_trans)
365
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   929
392
8194086c2a8a simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents: 385
diff changeset
   930
(*
8194086c2a8a simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents: 385
diff changeset
   931
lemma srewrites4:
8194086c2a8a simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents: 385
diff changeset
   932
  assumes "rs3 s\<leadsto>* rs4" "rs1 s\<leadsto>* rs2" 
8194086c2a8a simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents: 385
diff changeset
   933
  shows "(rs1 @ rs3) s\<leadsto>* (rs2 @ rs4)"
8194086c2a8a simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents: 385
diff changeset
   934
  using assms
8194086c2a8a simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents: 385
diff changeset
   935
  apply(induct rs3 rs4 arbitrary: rs1 rs2 rule: srewrites.induct)
8194086c2a8a simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents: 385
diff changeset
   936
  apply (simp add: srewrites3)
8194086c2a8a simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents: 385
diff changeset
   937
  using srewrite1 by blast
8194086c2a8a simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents: 385
diff changeset
   938
*)
8194086c2a8a simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents: 385
diff changeset
   939
8194086c2a8a simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents: 385
diff changeset
   940
lemma srewrites6:
8194086c2a8a simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents: 385
diff changeset
   941
  assumes "r1 \<leadsto>* r2" 
8194086c2a8a simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents: 385
diff changeset
   942
  shows "[r1] s\<leadsto>* [r2]"
8194086c2a8a simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents: 385
diff changeset
   943
  using assms
8194086c2a8a simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents: 385
diff changeset
   944
  apply(induct r1 r2 rule: rrewrites.induct)
8194086c2a8a simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents: 385
diff changeset
   945
   apply(auto)
8194086c2a8a simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents: 385
diff changeset
   946
  by (meson srewrites.simps srewrites_trans ss3)
8194086c2a8a simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents: 385
diff changeset
   947
8194086c2a8a simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents: 385
diff changeset
   948
lemma srewrites7:
8194086c2a8a simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents: 385
diff changeset
   949
  assumes "rs3 s\<leadsto>* rs4" "r1 \<leadsto>* r2" 
8194086c2a8a simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents: 385
diff changeset
   950
  shows "(r1 # rs3) s\<leadsto>* (r2 # rs4)"
8194086c2a8a simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents: 385
diff changeset
   951
  using assms
8194086c2a8a simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents: 385
diff changeset
   952
  by (smt (verit, best) append_Cons append_Nil srewrites1 srewrites3 srewrites6 srewrites_trans)
8194086c2a8a simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents: 385
diff changeset
   953
393
3954579ebdaf polished
Christian Urban <christian.urban@kcl.ac.uk>
parents: 392
diff changeset
   954
lemma ss6_stronger_aux:
3954579ebdaf polished
Christian Urban <christian.urban@kcl.ac.uk>
parents: 392
diff changeset
   955
  shows "(rs1 @ rs2) s\<leadsto>* (rs1 @ distinctBy rs2 erase (set (map erase rs1)))"
3954579ebdaf polished
Christian Urban <christian.urban@kcl.ac.uk>
parents: 392
diff changeset
   956
  apply(induct rs2 arbitrary: rs1)
3954579ebdaf polished
Christian Urban <christian.urban@kcl.ac.uk>
parents: 392
diff changeset
   957
   apply(auto)
3954579ebdaf polished
Christian Urban <christian.urban@kcl.ac.uk>
parents: 392
diff changeset
   958
  apply (smt (verit, best) append.assoc append.right_neutral append_Cons append_Nil split_list srewrite2(2) srewrites_trans ss6)
3954579ebdaf polished
Christian Urban <christian.urban@kcl.ac.uk>
parents: 392
diff changeset
   959
  apply(drule_tac x="rs1 @ [a]" in meta_spec)
3954579ebdaf polished
Christian Urban <christian.urban@kcl.ac.uk>
parents: 392
diff changeset
   960
  apply(simp)
3954579ebdaf polished
Christian Urban <christian.urban@kcl.ac.uk>
parents: 392
diff changeset
   961
  done
3954579ebdaf polished
Christian Urban <christian.urban@kcl.ac.uk>
parents: 392
diff changeset
   962
3954579ebdaf polished
Christian Urban <christian.urban@kcl.ac.uk>
parents: 392
diff changeset
   963
lemma ss6_stronger:
3954579ebdaf polished
Christian Urban <christian.urban@kcl.ac.uk>
parents: 392
diff changeset
   964
  shows "rs1 s\<leadsto>* distinctBy rs1 erase {}"
3954579ebdaf polished
Christian Urban <christian.urban@kcl.ac.uk>
parents: 392
diff changeset
   965
  using ss6_stronger_aux[of "[]" _] by auto
3954579ebdaf polished
Christian Urban <christian.urban@kcl.ac.uk>
parents: 392
diff changeset
   966
3954579ebdaf polished
Christian Urban <christian.urban@kcl.ac.uk>
parents: 392
diff changeset
   967
3954579ebdaf polished
Christian Urban <christian.urban@kcl.ac.uk>
parents: 392
diff changeset
   968
lemma rewrite_preserves_fuse: 
3954579ebdaf polished
Christian Urban <christian.urban@kcl.ac.uk>
parents: 392
diff changeset
   969
  shows "r2 \<leadsto> r3 \<Longrightarrow> fuse bs r2 \<leadsto> fuse bs r3"
3954579ebdaf polished
Christian Urban <christian.urban@kcl.ac.uk>
parents: 392
diff changeset
   970
  and   "rs2 s\<leadsto> rs3 \<Longrightarrow> map (fuse bs) rs2 s\<leadsto>* map (fuse bs) rs3"
3954579ebdaf polished
Christian Urban <christian.urban@kcl.ac.uk>
parents: 392
diff changeset
   971
proof(induct rule: rrewrite_srewrite.inducts)
3954579ebdaf polished
Christian Urban <christian.urban@kcl.ac.uk>
parents: 392
diff changeset
   972
  case (bs3 bs1 bs2 r)
3954579ebdaf polished
Christian Urban <christian.urban@kcl.ac.uk>
parents: 392
diff changeset
   973
  then show ?case
3954579ebdaf polished
Christian Urban <christian.urban@kcl.ac.uk>
parents: 392
diff changeset
   974
    by (metis fuse.simps(5) fuse_append rrewrite_srewrite.bs3) 
3954579ebdaf polished
Christian Urban <christian.urban@kcl.ac.uk>
parents: 392
diff changeset
   975
next
3954579ebdaf polished
Christian Urban <christian.urban@kcl.ac.uk>
parents: 392
diff changeset
   976
  case (bs7 bs r)
3954579ebdaf polished
Christian Urban <christian.urban@kcl.ac.uk>
parents: 392
diff changeset
   977
  then show ?case
3954579ebdaf polished
Christian Urban <christian.urban@kcl.ac.uk>
parents: 392
diff changeset
   978
    by (metis fuse.simps(4) fuse_append rrewrite_srewrite.bs7) 
3954579ebdaf polished
Christian Urban <christian.urban@kcl.ac.uk>
parents: 392
diff changeset
   979
next
3954579ebdaf polished
Christian Urban <christian.urban@kcl.ac.uk>
parents: 392
diff changeset
   980
  case (ss2 rs1 rs2 r)
3954579ebdaf polished
Christian Urban <christian.urban@kcl.ac.uk>
parents: 392
diff changeset
   981
  then show ?case
3954579ebdaf polished
Christian Urban <christian.urban@kcl.ac.uk>
parents: 392
diff changeset
   982
    using srewrites7 by force 
3954579ebdaf polished
Christian Urban <christian.urban@kcl.ac.uk>
parents: 392
diff changeset
   983
next
3954579ebdaf polished
Christian Urban <christian.urban@kcl.ac.uk>
parents: 392
diff changeset
   984
  case (ss3 r1 r2 rs)
3954579ebdaf polished
Christian Urban <christian.urban@kcl.ac.uk>
parents: 392
diff changeset
   985
  then show ?case by (simp add: r_in_rstar srewrites7)
3954579ebdaf polished
Christian Urban <christian.urban@kcl.ac.uk>
parents: 392
diff changeset
   986
next
3954579ebdaf polished
Christian Urban <christian.urban@kcl.ac.uk>
parents: 392
diff changeset
   987
  case (ss5 bs1 rs1 rsb)
3954579ebdaf polished
Christian Urban <christian.urban@kcl.ac.uk>
parents: 392
diff changeset
   988
  then show ?case 
3954579ebdaf polished
Christian Urban <christian.urban@kcl.ac.uk>
parents: 392
diff changeset
   989
    apply(simp)
3954579ebdaf polished
Christian Urban <christian.urban@kcl.ac.uk>
parents: 392
diff changeset
   990
    by (metis (mono_tags, lifting) comp_def fuse_append map_eq_conv rrewrite_srewrite.ss5 srewrites.simps)
3954579ebdaf polished
Christian Urban <christian.urban@kcl.ac.uk>
parents: 392
diff changeset
   991
next
3954579ebdaf polished
Christian Urban <christian.urban@kcl.ac.uk>
parents: 392
diff changeset
   992
  case (ss6 a1 a2 rsa rsb rsc)
3954579ebdaf polished
Christian Urban <christian.urban@kcl.ac.uk>
parents: 392
diff changeset
   993
  then show ?case 
3954579ebdaf polished
Christian Urban <christian.urban@kcl.ac.uk>
parents: 392
diff changeset
   994
    apply(simp only: map_append)
3954579ebdaf polished
Christian Urban <christian.urban@kcl.ac.uk>
parents: 392
diff changeset
   995
    by (smt (verit, ccfv_threshold) erase_fuse list.simps(8) list.simps(9) rrewrite_srewrite.ss6 srewrites.simps)  
3954579ebdaf polished
Christian Urban <christian.urban@kcl.ac.uk>
parents: 392
diff changeset
   996
qed (auto intro: rrewrite_srewrite.intros)
3954579ebdaf polished
Christian Urban <christian.urban@kcl.ac.uk>
parents: 392
diff changeset
   997
3954579ebdaf polished
Christian Urban <christian.urban@kcl.ac.uk>
parents: 392
diff changeset
   998
3954579ebdaf polished
Christian Urban <christian.urban@kcl.ac.uk>
parents: 392
diff changeset
   999
lemma rewrites_fuse:  
3954579ebdaf polished
Christian Urban <christian.urban@kcl.ac.uk>
parents: 392
diff changeset
  1000
  assumes "r1 \<leadsto>* r2"
3954579ebdaf polished
Christian Urban <christian.urban@kcl.ac.uk>
parents: 392
diff changeset
  1001
  shows "fuse bs r1 \<leadsto>* fuse bs r2"
3954579ebdaf polished
Christian Urban <christian.urban@kcl.ac.uk>
parents: 392
diff changeset
  1002
using assms
3954579ebdaf polished
Christian Urban <christian.urban@kcl.ac.uk>
parents: 392
diff changeset
  1003
apply(induction r1 r2 arbitrary: bs rule: rrewrites.induct)
3954579ebdaf polished
Christian Urban <christian.urban@kcl.ac.uk>
parents: 392
diff changeset
  1004
apply(auto intro: rewrite_preserves_fuse rrewrites_trans)
3954579ebdaf polished
Christian Urban <christian.urban@kcl.ac.uk>
parents: 392
diff changeset
  1005
done
365
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1006
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1007
374
98362002c818 slightly more
Christian Urban <christian.urban@kcl.ac.uk>
parents: 373
diff changeset
  1008
lemma star_seq:  
98362002c818 slightly more
Christian Urban <christian.urban@kcl.ac.uk>
parents: 373
diff changeset
  1009
  assumes "r1 \<leadsto>* r2"
98362002c818 slightly more
Christian Urban <christian.urban@kcl.ac.uk>
parents: 373
diff changeset
  1010
  shows "ASEQ bs r1 r3 \<leadsto>* ASEQ bs r2 r3"
98362002c818 slightly more
Christian Urban <christian.urban@kcl.ac.uk>
parents: 373
diff changeset
  1011
using assms
98362002c818 slightly more
Christian Urban <christian.urban@kcl.ac.uk>
parents: 373
diff changeset
  1012
apply(induct r1 r2 arbitrary: r3 rule: rrewrites.induct)
392
8194086c2a8a simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents: 385
diff changeset
  1013
apply(auto intro: rrewrite_srewrite.intros)
374
98362002c818 slightly more
Christian Urban <christian.urban@kcl.ac.uk>
parents: 373
diff changeset
  1014
done
365
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1015
374
98362002c818 slightly more
Christian Urban <christian.urban@kcl.ac.uk>
parents: 373
diff changeset
  1016
lemma star_seq2:  
98362002c818 slightly more
Christian Urban <christian.urban@kcl.ac.uk>
parents: 373
diff changeset
  1017
  assumes "r3 \<leadsto>* r4"
98362002c818 slightly more
Christian Urban <christian.urban@kcl.ac.uk>
parents: 373
diff changeset
  1018
  shows "ASEQ bs r1 r3 \<leadsto>* ASEQ bs r1 r4"
392
8194086c2a8a simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents: 385
diff changeset
  1019
  using assms
374
98362002c818 slightly more
Christian Urban <christian.urban@kcl.ac.uk>
parents: 373
diff changeset
  1020
apply(induct r3 r4 arbitrary: r1 rule: rrewrites.induct)
392
8194086c2a8a simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents: 385
diff changeset
  1021
apply(auto intro: rrewrite_srewrite.intros)
374
98362002c818 slightly more
Christian Urban <christian.urban@kcl.ac.uk>
parents: 373
diff changeset
  1022
done
365
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1023
374
98362002c818 slightly more
Christian Urban <christian.urban@kcl.ac.uk>
parents: 373
diff changeset
  1024
lemma continuous_rewrite: 
98362002c818 slightly more
Christian Urban <christian.urban@kcl.ac.uk>
parents: 373
diff changeset
  1025
  assumes "r1 \<leadsto>* AZERO"
98362002c818 slightly more
Christian Urban <christian.urban@kcl.ac.uk>
parents: 373
diff changeset
  1026
  shows "ASEQ bs1 r1 r2 \<leadsto>* AZERO"
392
8194086c2a8a simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents: 385
diff changeset
  1027
using assms bs1 star_seq by blast
365
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1028
393
3954579ebdaf polished
Christian Urban <christian.urban@kcl.ac.uk>
parents: 392
diff changeset
  1029
(*
3954579ebdaf polished
Christian Urban <christian.urban@kcl.ac.uk>
parents: 392
diff changeset
  1030
lemma continuous_rewrite2: 
3954579ebdaf polished
Christian Urban <christian.urban@kcl.ac.uk>
parents: 392
diff changeset
  1031
  assumes "r1 \<leadsto>* AONE bs"
3954579ebdaf polished
Christian Urban <christian.urban@kcl.ac.uk>
parents: 392
diff changeset
  1032
  shows "ASEQ bs1 r1 r2 \<leadsto>* (fuse (bs1 @ bs) r2)"
3954579ebdaf polished
Christian Urban <christian.urban@kcl.ac.uk>
parents: 392
diff changeset
  1033
  using assms  by (meson bs3 rrewrites.simps star_seq)
3954579ebdaf polished
Christian Urban <christian.urban@kcl.ac.uk>
parents: 392
diff changeset
  1034
*)
365
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1035
374
98362002c818 slightly more
Christian Urban <christian.urban@kcl.ac.uk>
parents: 373
diff changeset
  1036
lemma bsimp_aalts_simpcases: 
98362002c818 slightly more
Christian Urban <christian.urban@kcl.ac.uk>
parents: 373
diff changeset
  1037
  shows "AONE bs \<leadsto>* bsimp (AONE bs)"  
98362002c818 slightly more
Christian Urban <christian.urban@kcl.ac.uk>
parents: 373
diff changeset
  1038
  and   "AZERO \<leadsto>* bsimp AZERO" 
98362002c818 slightly more
Christian Urban <christian.urban@kcl.ac.uk>
parents: 373
diff changeset
  1039
  and   "ACHAR bs c \<leadsto>* bsimp (ACHAR bs c)"
98362002c818 slightly more
Christian Urban <christian.urban@kcl.ac.uk>
parents: 373
diff changeset
  1040
  by (simp_all)
365
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1041
393
3954579ebdaf polished
Christian Urban <christian.urban@kcl.ac.uk>
parents: 392
diff changeset
  1042
lemma bsimp_AALTs_rewrites: 
3954579ebdaf polished
Christian Urban <christian.urban@kcl.ac.uk>
parents: 392
diff changeset
  1043
  shows "AALTs bs1 rs \<leadsto>* bsimp_AALTs bs1 rs"
3954579ebdaf polished
Christian Urban <christian.urban@kcl.ac.uk>
parents: 392
diff changeset
  1044
  by (smt (verit) bs6 bs7 bsimp_AALTs.elims rrewrites.simps)
385
c80720289645 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 381
diff changeset
  1045
c80720289645 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 381
diff changeset
  1046
lemma trivialbsimp_srewrites: 
381
0c666a0c57d7 isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents: 379
diff changeset
  1047
  "\<lbrakk>\<And>x. x \<in> set rs \<Longrightarrow> x \<leadsto>* f x \<rbrakk> \<Longrightarrow> rs s\<leadsto>* (map f rs)"
365
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1048
  apply(induction rs)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1049
   apply simp
392
8194086c2a8a simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents: 385
diff changeset
  1050
  apply(simp)
8194086c2a8a simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents: 385
diff changeset
  1051
  using srewrites7 by auto
365
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1052
392
8194086c2a8a simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents: 385
diff changeset
  1053
8194086c2a8a simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents: 385
diff changeset
  1054
393
3954579ebdaf polished
Christian Urban <christian.urban@kcl.ac.uk>
parents: 392
diff changeset
  1055
lemma fltsfrewrites: "rs s\<leadsto>* (flts rs)"
3954579ebdaf polished
Christian Urban <christian.urban@kcl.ac.uk>
parents: 392
diff changeset
  1056
  apply(induction rs rule: flts.induct)
3954579ebdaf polished
Christian Urban <christian.urban@kcl.ac.uk>
parents: 392
diff changeset
  1057
  apply(auto intro: rrewrite_srewrite.intros)
3954579ebdaf polished
Christian Urban <christian.urban@kcl.ac.uk>
parents: 392
diff changeset
  1058
  apply (meson srewrites.simps srewrites1 ss5)
3954579ebdaf polished
Christian Urban <christian.urban@kcl.ac.uk>
parents: 392
diff changeset
  1059
  using rs1 srewrites7 apply presburger
3954579ebdaf polished
Christian Urban <christian.urban@kcl.ac.uk>
parents: 392
diff changeset
  1060
  using srewrites7 apply force
3954579ebdaf polished
Christian Urban <christian.urban@kcl.ac.uk>
parents: 392
diff changeset
  1061
  apply (simp add: srewrites7)
3954579ebdaf polished
Christian Urban <christian.urban@kcl.ac.uk>
parents: 392
diff changeset
  1062
  by (simp add: srewrites7)
365
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1063
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1064
392
8194086c2a8a simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents: 385
diff changeset
  1065
lemma bnullable1:
8194086c2a8a simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents: 385
diff changeset
  1066
shows "r1 \<leadsto> r2 \<Longrightarrow> (bnullable r1 \<Longrightarrow> bnullable r2)" 
8194086c2a8a simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents: 385
diff changeset
  1067
  and "rs1 s\<leadsto> rs2 \<Longrightarrow>  ((\<exists>x \<in> set rs1. bnullable x) \<Longrightarrow> \<exists>x\<in>set rs2. bnullable x)" 
8194086c2a8a simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents: 385
diff changeset
  1068
apply(induct rule: rrewrite_srewrite.inducts)
8194086c2a8a simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents: 385
diff changeset
  1069
               apply(auto)
8194086c2a8a simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents: 385
diff changeset
  1070
  using bnullable_fuse apply blast
8194086c2a8a simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents: 385
diff changeset
  1071
    apply (simp add: bnullable_fuse)
8194086c2a8a simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents: 385
diff changeset
  1072
  apply (meson UnCI bnullable_fuse imageI)
8194086c2a8a simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents: 385
diff changeset
  1073
  by (metis bnullable_correctness)
8194086c2a8a simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents: 385
diff changeset
  1074
8194086c2a8a simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents: 385
diff changeset
  1075
lemma bnullable2:
8194086c2a8a simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents: 385
diff changeset
  1076
shows "r1 \<leadsto> r2 \<Longrightarrow> (bnullable r2 \<Longrightarrow> bnullable r1)" 
8194086c2a8a simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents: 385
diff changeset
  1077
  and "rs1 s\<leadsto> rs2 \<Longrightarrow>  ((\<exists>x \<in> set rs2. bnullable x) \<Longrightarrow> \<exists>x\<in>set rs1. bnullable x)" 
8194086c2a8a simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents: 385
diff changeset
  1078
apply(induct rule: rrewrite_srewrite.inducts)
8194086c2a8a simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents: 385
diff changeset
  1079
               apply(auto)
8194086c2a8a simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents: 385
diff changeset
  1080
  using bnullable_fuse apply blast
8194086c2a8a simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents: 385
diff changeset
  1081
   apply (simp add: bnullable_fuse)
8194086c2a8a simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents: 385
diff changeset
  1082
  using bnullable_fuse by blast
8194086c2a8a simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents: 385
diff changeset
  1083
373
320f923c77b9 slightly
Christian Urban <christian.urban@kcl.ac.uk>
parents: 365
diff changeset
  1084
lemma rewrite_non_nullable_strong: 
320f923c77b9 slightly
Christian Urban <christian.urban@kcl.ac.uk>
parents: 365
diff changeset
  1085
  assumes "r1 \<leadsto> r2"
320f923c77b9 slightly
Christian Urban <christian.urban@kcl.ac.uk>
parents: 365
diff changeset
  1086
  shows "bnullable r1 = bnullable r2"
320f923c77b9 slightly
Christian Urban <christian.urban@kcl.ac.uk>
parents: 365
diff changeset
  1087
using assms
392
8194086c2a8a simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents: 385
diff changeset
  1088
apply(induction r1 r2 rule: rrewrite_srewrite.inducts(1))
373
320f923c77b9 slightly
Christian Urban <christian.urban@kcl.ac.uk>
parents: 365
diff changeset
  1089
apply(auto)
392
8194086c2a8a simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents: 385
diff changeset
  1090
      apply(metis bnullable_correctness erase_fuse)+
8194086c2a8a simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents: 385
diff changeset
  1091
  using bnullable1(2) apply blast
8194086c2a8a simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents: 385
diff changeset
  1092
  using bnullable2(2) apply blast
373
320f923c77b9 slightly
Christian Urban <christian.urban@kcl.ac.uk>
parents: 365
diff changeset
  1093
done
365
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1094
373
320f923c77b9 slightly
Christian Urban <christian.urban@kcl.ac.uk>
parents: 365
diff changeset
  1095
320f923c77b9 slightly
Christian Urban <christian.urban@kcl.ac.uk>
parents: 365
diff changeset
  1096
lemma rewritesnullable: 
320f923c77b9 slightly
Christian Urban <christian.urban@kcl.ac.uk>
parents: 365
diff changeset
  1097
  assumes "r1 \<leadsto>* r2" "bnullable r1"
320f923c77b9 slightly
Christian Urban <christian.urban@kcl.ac.uk>
parents: 365
diff changeset
  1098
  shows "bnullable r2"
393
3954579ebdaf polished
Christian Urban <christian.urban@kcl.ac.uk>
parents: 392
diff changeset
  1099
using assms 
365
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1100
  apply(induction r1 r2 rule: rrewrites.induct)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1101
  apply simp
373
320f923c77b9 slightly
Christian Urban <christian.urban@kcl.ac.uk>
parents: 365
diff changeset
  1102
  using rewrite_non_nullable_strong by blast
365
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1103
381
0c666a0c57d7 isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents: 379
diff changeset
  1104
lemma rewrite_bmkeps_aux: 
392
8194086c2a8a simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents: 385
diff changeset
  1105
  shows "r1 \<leadsto> r2 \<Longrightarrow> (bnullable r1 \<and> bnullable r2 \<Longrightarrow> bmkeps r1 = bmkeps r2)"
8194086c2a8a simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents: 385
diff changeset
  1106
  and   "rs1 s\<leadsto> rs2 \<Longrightarrow> (\<And>bs. (bnullable (AALTs bs rs1) \<and> bnullable (AALTs bs rs2) \<Longrightarrow> 
8194086c2a8a simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents: 385
diff changeset
  1107
           bmkeps (AALTs bs rs1) = bmkeps (AALTs bs rs2)))" 
8194086c2a8a simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents: 385
diff changeset
  1108
proof (induct rule: rrewrite_srewrite.inducts)
8194086c2a8a simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents: 385
diff changeset
  1109
  case (bs1 bs r2)
8194086c2a8a simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents: 385
diff changeset
  1110
  then show ?case by fastforce 
8194086c2a8a simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents: 385
diff changeset
  1111
next
8194086c2a8a simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents: 385
diff changeset
  1112
  case (bs2 bs r1)
8194086c2a8a simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents: 385
diff changeset
  1113
  then show ?case by fastforce 
8194086c2a8a simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents: 385
diff changeset
  1114
next
8194086c2a8a simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents: 385
diff changeset
  1115
  case (bs3 bs1 bs2 r)
8194086c2a8a simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents: 385
diff changeset
  1116
  then show ?case by (simp add: b2) 
8194086c2a8a simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents: 385
diff changeset
  1117
next
8194086c2a8a simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents: 385
diff changeset
  1118
  case (bs4 r1 r2 bs r3)
8194086c2a8a simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents: 385
diff changeset
  1119
  then show ?case by simp 
8194086c2a8a simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents: 385
diff changeset
  1120
next
8194086c2a8a simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents: 385
diff changeset
  1121
  case (bs5 r3 r4 bs r1)
381
0c666a0c57d7 isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents: 379
diff changeset
  1122
  then show ?case by simp 
0c666a0c57d7 isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents: 379
diff changeset
  1123
next
392
8194086c2a8a simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents: 385
diff changeset
  1124
  case (bs6 bs)
8194086c2a8a simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents: 385
diff changeset
  1125
  then show ?case by fastforce 
381
0c666a0c57d7 isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents: 379
diff changeset
  1126
next
392
8194086c2a8a simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents: 385
diff changeset
  1127
  case (bs7 bs r)
381
0c666a0c57d7 isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents: 379
diff changeset
  1128
  then show ?case by (simp add: b2) 
0c666a0c57d7 isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents: 379
diff changeset
  1129
next
392
8194086c2a8a simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents: 385
diff changeset
  1130
  case (bs10 rs1 rs2 bs)
8194086c2a8a simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents: 385
diff changeset
  1131
  then show ?case
8194086c2a8a simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents: 385
diff changeset
  1132
    by blast 
381
0c666a0c57d7 isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents: 379
diff changeset
  1133
next
392
8194086c2a8a simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents: 385
diff changeset
  1134
  case ss1
381
0c666a0c57d7 isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents: 379
diff changeset
  1135
  then show ?case by simp
0c666a0c57d7 isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents: 379
diff changeset
  1136
next
392
8194086c2a8a simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents: 385
diff changeset
  1137
  case (ss2 rs1 rs2 r)
8194086c2a8a simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents: 385
diff changeset
  1138
  then show ?case 
8194086c2a8a simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents: 385
diff changeset
  1139
    apply(simp)
8194086c2a8a simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents: 385
diff changeset
  1140
    by (metis bnullable_Hdbmkeps_Hd r1 r2)
381
0c666a0c57d7 isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents: 379
diff changeset
  1141
next
392
8194086c2a8a simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents: 385
diff changeset
  1142
  case (ss3 r1 r2 rs)
381
0c666a0c57d7 isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents: 379
diff changeset
  1143
  then show ?case
392
8194086c2a8a simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents: 385
diff changeset
  1144
    by (metis bnullable.simps(4) bnullable_Hdbmkeps_Hd r1 rewrite_non_nullable_strong set_ConsD) 
381
0c666a0c57d7 isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents: 379
diff changeset
  1145
next
392
8194086c2a8a simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents: 385
diff changeset
  1146
  case (ss4 rs)
8194086c2a8a simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents: 385
diff changeset
  1147
  then show ?case apply(simp_all)
8194086c2a8a simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents: 385
diff changeset
  1148
    using bnullable.simps(1) local.ss4 r1 by blast
381
0c666a0c57d7 isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents: 379
diff changeset
  1149
next
392
8194086c2a8a simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents: 385
diff changeset
  1150
  case (ss5 bs1 rs1 rsb)
8194086c2a8a simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents: 385
diff changeset
  1151
  then show ?case 
8194086c2a8a simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents: 385
diff changeset
  1152
    apply(simp)
8194086c2a8a simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents: 385
diff changeset
  1153
    by (metis bnullable.simps(4) flts.simps(3) local.ss5 qq3 qq4 qs3)
381
0c666a0c57d7 isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents: 379
diff changeset
  1154
next
392
8194086c2a8a simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents: 385
diff changeset
  1155
  case (ss6 a1 a2 bs rsa rsb rsc)
8194086c2a8a simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents: 385
diff changeset
  1156
  then show ?case 
381
0c666a0c57d7 isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents: 379
diff changeset
  1157
    by (smt (verit, ccfv_threshold) append_Cons append_eq_appendI append_self_conv2 bnullable_correctness list.set_intros(1) qq3 r1)
0c666a0c57d7 isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents: 379
diff changeset
  1158
qed
365
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1159
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1160
381
0c666a0c57d7 isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents: 379
diff changeset
  1161
lemma rewrite_bmkeps: 
0c666a0c57d7 isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents: 379
diff changeset
  1162
  assumes "r1 \<leadsto> r2" "bnullable r1"
0c666a0c57d7 isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents: 379
diff changeset
  1163
  shows "bmkeps r1 = bmkeps r2"
392
8194086c2a8a simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents: 385
diff changeset
  1164
  using assms
8194086c2a8a simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents: 385
diff changeset
  1165
  by (simp add: rewrite_bmkeps_aux(1) rewrite_non_nullable_strong) 
365
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1166
373
320f923c77b9 slightly
Christian Urban <christian.urban@kcl.ac.uk>
parents: 365
diff changeset
  1167
lemma rewrites_bmkeps: 
320f923c77b9 slightly
Christian Urban <christian.urban@kcl.ac.uk>
parents: 365
diff changeset
  1168
  assumes "r1 \<leadsto>* r2" "bnullable r1" 
320f923c77b9 slightly
Christian Urban <christian.urban@kcl.ac.uk>
parents: 365
diff changeset
  1169
  shows "bmkeps r1 = bmkeps r2"
320f923c77b9 slightly
Christian Urban <christian.urban@kcl.ac.uk>
parents: 365
diff changeset
  1170
  using assms
320f923c77b9 slightly
Christian Urban <christian.urban@kcl.ac.uk>
parents: 365
diff changeset
  1171
proof(induction r1 r2 rule: rrewrites.induct)
320f923c77b9 slightly
Christian Urban <christian.urban@kcl.ac.uk>
parents: 365
diff changeset
  1172
  case (rs1 r)
320f923c77b9 slightly
Christian Urban <christian.urban@kcl.ac.uk>
parents: 365
diff changeset
  1173
  then show "bmkeps r = bmkeps r" by simp
320f923c77b9 slightly
Christian Urban <christian.urban@kcl.ac.uk>
parents: 365
diff changeset
  1174
next
320f923c77b9 slightly
Christian Urban <christian.urban@kcl.ac.uk>
parents: 365
diff changeset
  1175
  case (rs2 r1 r2 r3)
320f923c77b9 slightly
Christian Urban <christian.urban@kcl.ac.uk>
parents: 365
diff changeset
  1176
  then have IH: "bmkeps r1 = bmkeps r2" by simp
320f923c77b9 slightly
Christian Urban <christian.urban@kcl.ac.uk>
parents: 365
diff changeset
  1177
  have a1: "bnullable r1" by fact
320f923c77b9 slightly
Christian Urban <christian.urban@kcl.ac.uk>
parents: 365
diff changeset
  1178
  have a2: "r1 \<leadsto>* r2" by fact
320f923c77b9 slightly
Christian Urban <christian.urban@kcl.ac.uk>
parents: 365
diff changeset
  1179
  have a3: "r2 \<leadsto> r3" by fact
320f923c77b9 slightly
Christian Urban <christian.urban@kcl.ac.uk>
parents: 365
diff changeset
  1180
  have a4: "bnullable r2" using a1 a2 by (simp add: rewritesnullable) 
320f923c77b9 slightly
Christian Urban <christian.urban@kcl.ac.uk>
parents: 365
diff changeset
  1181
  then have "bmkeps r2 = bmkeps r3" using rewrite_bmkeps a3 a4 by simp
320f923c77b9 slightly
Christian Urban <christian.urban@kcl.ac.uk>
parents: 365
diff changeset
  1182
  then show "bmkeps r1 = bmkeps r3" using IH by simp
320f923c77b9 slightly
Christian Urban <christian.urban@kcl.ac.uk>
parents: 365
diff changeset
  1183
qed
365
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1184
393
3954579ebdaf polished
Christian Urban <christian.urban@kcl.ac.uk>
parents: 392
diff changeset
  1185
3954579ebdaf polished
Christian Urban <christian.urban@kcl.ac.uk>
parents: 392
diff changeset
  1186
lemma rewrites_to_bsimp: 
3954579ebdaf polished
Christian Urban <christian.urban@kcl.ac.uk>
parents: 392
diff changeset
  1187
  shows "r \<leadsto>* bsimp r"
3954579ebdaf polished
Christian Urban <christian.urban@kcl.ac.uk>
parents: 392
diff changeset
  1188
proof (induction r rule: bsimp.induct)
3954579ebdaf polished
Christian Urban <christian.urban@kcl.ac.uk>
parents: 392
diff changeset
  1189
  case (1 bs1 r1 r2)
3954579ebdaf polished
Christian Urban <christian.urban@kcl.ac.uk>
parents: 392
diff changeset
  1190
  have IH1: "r1 \<leadsto>* bsimp r1" by fact
3954579ebdaf polished
Christian Urban <christian.urban@kcl.ac.uk>
parents: 392
diff changeset
  1191
  have IH2: "r2 \<leadsto>* bsimp r2" by fact
3954579ebdaf polished
Christian Urban <christian.urban@kcl.ac.uk>
parents: 392
diff changeset
  1192
  { assume as: "bsimp r1 = AZERO \<or> bsimp r2 = AZERO"
3954579ebdaf polished
Christian Urban <christian.urban@kcl.ac.uk>
parents: 392
diff changeset
  1193
    with IH1 IH2 have "r1 \<leadsto>* AZERO \<or> r2 \<leadsto>* AZERO" by auto
3954579ebdaf polished
Christian Urban <christian.urban@kcl.ac.uk>
parents: 392
diff changeset
  1194
    then have "ASEQ bs1 r1 r2 \<leadsto>* AZERO"
3954579ebdaf polished
Christian Urban <christian.urban@kcl.ac.uk>
parents: 392
diff changeset
  1195
      by (metis bs2 continuous_rewrite rrewrites.simps star_seq2)  
3954579ebdaf polished
Christian Urban <christian.urban@kcl.ac.uk>
parents: 392
diff changeset
  1196
    then have "ASEQ bs1 r1 r2 \<leadsto>* bsimp (ASEQ bs1 r1 r2)" using as by auto
3954579ebdaf polished
Christian Urban <christian.urban@kcl.ac.uk>
parents: 392
diff changeset
  1197
  }
3954579ebdaf polished
Christian Urban <christian.urban@kcl.ac.uk>
parents: 392
diff changeset
  1198
  moreover
3954579ebdaf polished
Christian Urban <christian.urban@kcl.ac.uk>
parents: 392
diff changeset
  1199
  { assume "\<exists>bs. bsimp r1 = AONE bs"
3954579ebdaf polished
Christian Urban <christian.urban@kcl.ac.uk>
parents: 392
diff changeset
  1200
    then obtain bs where as: "bsimp r1 = AONE bs" by blast
3954579ebdaf polished
Christian Urban <christian.urban@kcl.ac.uk>
parents: 392
diff changeset
  1201
    with IH1 have "r1 \<leadsto>* AONE bs" by simp
3954579ebdaf polished
Christian Urban <christian.urban@kcl.ac.uk>
parents: 392
diff changeset
  1202
    then have "ASEQ bs1 r1 r2 \<leadsto>* fuse (bs1 @ bs) r2" using bs3 star_seq by blast
3954579ebdaf polished
Christian Urban <christian.urban@kcl.ac.uk>
parents: 392
diff changeset
  1203
    with IH2 have "ASEQ bs1 r1 r2 \<leadsto>* fuse (bs1 @ bs) (bsimp r2)"
3954579ebdaf polished
Christian Urban <christian.urban@kcl.ac.uk>
parents: 392
diff changeset
  1204
      using rewrites_fuse by (meson rrewrites_trans) 
3954579ebdaf polished
Christian Urban <christian.urban@kcl.ac.uk>
parents: 392
diff changeset
  1205
    then have "ASEQ bs1 r1 r2 \<leadsto>* bsimp (ASEQ bs1 (AONE bs) r2)" by simp
3954579ebdaf polished
Christian Urban <christian.urban@kcl.ac.uk>
parents: 392
diff changeset
  1206
    then have "ASEQ bs1 r1 r2 \<leadsto>* bsimp (ASEQ bs1 r1 r2)" by (simp add: as) 
3954579ebdaf polished
Christian Urban <christian.urban@kcl.ac.uk>
parents: 392
diff changeset
  1207
  } 
3954579ebdaf polished
Christian Urban <christian.urban@kcl.ac.uk>
parents: 392
diff changeset
  1208
  moreover
3954579ebdaf polished
Christian Urban <christian.urban@kcl.ac.uk>
parents: 392
diff changeset
  1209
  { assume as1: "bsimp r1 \<noteq> AZERO" "bsimp r2 \<noteq> AZERO" and as2: "(\<nexists>bs. bsimp r1 = AONE bs)" 
3954579ebdaf polished
Christian Urban <christian.urban@kcl.ac.uk>
parents: 392
diff changeset
  1210
    then have "bsimp_ASEQ bs1 (bsimp r1) (bsimp r2) = ASEQ bs1 (bsimp r1) (bsimp r2)" 
3954579ebdaf polished
Christian Urban <christian.urban@kcl.ac.uk>
parents: 392
diff changeset
  1211
      by (simp add: bsimp_ASEQ1) 
3954579ebdaf polished
Christian Urban <christian.urban@kcl.ac.uk>
parents: 392
diff changeset
  1212
    then have "ASEQ bs1 r1 r2 \<leadsto>* bsimp_ASEQ bs1 (bsimp r1) (bsimp r2)" using as1 as2 IH1 IH2
3954579ebdaf polished
Christian Urban <christian.urban@kcl.ac.uk>
parents: 392
diff changeset
  1213
      by (metis rrewrites_trans star_seq star_seq2) 
3954579ebdaf polished
Christian Urban <christian.urban@kcl.ac.uk>
parents: 392
diff changeset
  1214
    then have "ASEQ bs1 r1 r2 \<leadsto>* bsimp (ASEQ bs1 r1 r2)" by simp
3954579ebdaf polished
Christian Urban <christian.urban@kcl.ac.uk>
parents: 392
diff changeset
  1215
  } 
3954579ebdaf polished
Christian Urban <christian.urban@kcl.ac.uk>
parents: 392
diff changeset
  1216
  ultimately show "ASEQ bs1 r1 r2 \<leadsto>* bsimp (ASEQ bs1 r1 r2)" by blast
3954579ebdaf polished
Christian Urban <christian.urban@kcl.ac.uk>
parents: 392
diff changeset
  1217
next
3954579ebdaf polished
Christian Urban <christian.urban@kcl.ac.uk>
parents: 392
diff changeset
  1218
  case (2 bs1 rs)
3954579ebdaf polished
Christian Urban <christian.urban@kcl.ac.uk>
parents: 392
diff changeset
  1219
  have IH: "\<And>x. x \<in> set rs \<Longrightarrow> x \<leadsto>* bsimp x" by fact
3954579ebdaf polished
Christian Urban <christian.urban@kcl.ac.uk>
parents: 392
diff changeset
  1220
  then have "rs s\<leadsto>* (map bsimp rs)" by (simp add: trivialbsimp_srewrites)
3954579ebdaf polished
Christian Urban <christian.urban@kcl.ac.uk>
parents: 392
diff changeset
  1221
  also have "... s\<leadsto>* flts (map bsimp rs)" by (simp add: fltsfrewrites) 
3954579ebdaf polished
Christian Urban <christian.urban@kcl.ac.uk>
parents: 392
diff changeset
  1222
  also have "... s\<leadsto>* distinctBy (flts (map bsimp rs)) erase {}" by (simp add: ss6_stronger) 
3954579ebdaf polished
Christian Urban <christian.urban@kcl.ac.uk>
parents: 392
diff changeset
  1223
  finally have "AALTs bs1 rs \<leadsto>* AALTs bs1 (distinctBy (flts (map bsimp rs)) erase {})"
3954579ebdaf polished
Christian Urban <christian.urban@kcl.ac.uk>
parents: 392
diff changeset
  1224
    using contextrewrites0 by blast
3954579ebdaf polished
Christian Urban <christian.urban@kcl.ac.uk>
parents: 392
diff changeset
  1225
  also have "... \<leadsto>* bsimp_AALTs  bs1 (distinctBy (flts (map bsimp rs)) erase {})"
3954579ebdaf polished
Christian Urban <christian.urban@kcl.ac.uk>
parents: 392
diff changeset
  1226
    by (simp add: bsimp_AALTs_rewrites)     
3954579ebdaf polished
Christian Urban <christian.urban@kcl.ac.uk>
parents: 392
diff changeset
  1227
  finally show "AALTs bs1 rs \<leadsto>* bsimp (AALTs bs1 rs)" by simp
3954579ebdaf polished
Christian Urban <christian.urban@kcl.ac.uk>
parents: 392
diff changeset
  1228
next
3954579ebdaf polished
Christian Urban <christian.urban@kcl.ac.uk>
parents: 392
diff changeset
  1229
  case "3_1"
3954579ebdaf polished
Christian Urban <christian.urban@kcl.ac.uk>
parents: 392
diff changeset
  1230
  then show "AZERO \<leadsto>* bsimp AZERO" by simp
3954579ebdaf polished
Christian Urban <christian.urban@kcl.ac.uk>
parents: 392
diff changeset
  1231
next
3954579ebdaf polished
Christian Urban <christian.urban@kcl.ac.uk>
parents: 392
diff changeset
  1232
  case ("3_2" v)
3954579ebdaf polished
Christian Urban <christian.urban@kcl.ac.uk>
parents: 392
diff changeset
  1233
  then show "AONE v \<leadsto>* bsimp (AONE v)" by simp
3954579ebdaf polished
Christian Urban <christian.urban@kcl.ac.uk>
parents: 392
diff changeset
  1234
next
3954579ebdaf polished
Christian Urban <christian.urban@kcl.ac.uk>
parents: 392
diff changeset
  1235
  case ("3_3" v va)
3954579ebdaf polished
Christian Urban <christian.urban@kcl.ac.uk>
parents: 392
diff changeset
  1236
  then show "ACHAR v va \<leadsto>* bsimp (ACHAR v va)" by simp
3954579ebdaf polished
Christian Urban <christian.urban@kcl.ac.uk>
parents: 392
diff changeset
  1237
next
3954579ebdaf polished
Christian Urban <christian.urban@kcl.ac.uk>
parents: 392
diff changeset
  1238
  case ("3_4" v va)
3954579ebdaf polished
Christian Urban <christian.urban@kcl.ac.uk>
parents: 392
diff changeset
  1239
  then show "ASTAR v va \<leadsto>* bsimp (ASTAR v va)" by simp
3954579ebdaf polished
Christian Urban <christian.urban@kcl.ac.uk>
parents: 392
diff changeset
  1240
qed
3954579ebdaf polished
Christian Urban <christian.urban@kcl.ac.uk>
parents: 392
diff changeset
  1241
3954579ebdaf polished
Christian Urban <christian.urban@kcl.ac.uk>
parents: 392
diff changeset
  1242
3954579ebdaf polished
Christian Urban <christian.urban@kcl.ac.uk>
parents: 392
diff changeset
  1243
392
8194086c2a8a simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents: 385
diff changeset
  1244
lemma to_zero_in_alt: 
393
3954579ebdaf polished
Christian Urban <christian.urban@kcl.ac.uk>
parents: 392
diff changeset
  1245
  shows "AALT bs (ASEQ [] AZERO r) r2 \<leadsto> AALT bs AZERO r2"
392
8194086c2a8a simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents: 385
diff changeset
  1246
  by (simp add: bs1 bs10 ss3)
365
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1247
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1248
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1249
374
98362002c818 slightly more
Christian Urban <christian.urban@kcl.ac.uk>
parents: 373
diff changeset
  1250
lemma  bder_fuse_list: 
98362002c818 slightly more
Christian Urban <christian.urban@kcl.ac.uk>
parents: 373
diff changeset
  1251
  shows "map (bder c \<circ> fuse bs1) rs1 = map (fuse bs1 \<circ> bder c) rs1"
392
8194086c2a8a simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents: 385
diff changeset
  1252
  apply(induction rs1)
8194086c2a8a simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents: 385
diff changeset
  1253
  apply(simp_all add: bder_fuse)
8194086c2a8a simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents: 385
diff changeset
  1254
  done
365
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1255
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1256
393
3954579ebdaf polished
Christian Urban <christian.urban@kcl.ac.uk>
parents: 392
diff changeset
  1257
lemma rewrite_preserves_bder: 
392
8194086c2a8a simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents: 385
diff changeset
  1258
  shows "r1 \<leadsto> r2 \<Longrightarrow> (bder c r1) \<leadsto>* (bder c r2)"
8194086c2a8a simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents: 385
diff changeset
  1259
  and   "rs1 s\<leadsto> rs2 \<Longrightarrow> map (bder c) rs1 s\<leadsto>* map (bder c) rs2"
8194086c2a8a simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents: 385
diff changeset
  1260
proof(induction rule: rrewrite_srewrite.inducts)
8194086c2a8a simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents: 385
diff changeset
  1261
  case (bs1 bs r2)
8194086c2a8a simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents: 385
diff changeset
  1262
  then show ?case
381
0c666a0c57d7 isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents: 379
diff changeset
  1263
    by (simp add: continuous_rewrite) 
0c666a0c57d7 isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents: 379
diff changeset
  1264
next
392
8194086c2a8a simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents: 385
diff changeset
  1265
  case (bs2 bs r1)
8194086c2a8a simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents: 385
diff changeset
  1266
  then show ?case 
8194086c2a8a simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents: 385
diff changeset
  1267
    apply(auto)
8194086c2a8a simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents: 385
diff changeset
  1268
    apply (meson bs6 contextrewrites0 rrewrite_srewrite.bs2 rs2 ss3 ss4 sss1 sss2)
8194086c2a8a simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents: 385
diff changeset
  1269
    by (simp add: r_in_rstar rrewrite_srewrite.bs2)
381
0c666a0c57d7 isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents: 379
diff changeset
  1270
next
392
8194086c2a8a simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents: 385
diff changeset
  1271
  case (bs3 bs1 bs2 r)
8194086c2a8a simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents: 385
diff changeset
  1272
  then show ?case 
381
0c666a0c57d7 isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents: 379
diff changeset
  1273
    apply(simp)
393
3954579ebdaf polished
Christian Urban <christian.urban@kcl.ac.uk>
parents: 392
diff changeset
  1274
    
392
8194086c2a8a simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents: 385
diff changeset
  1275
    by (metis (no_types, lifting) bder_fuse bs10 bs7 fuse_append rrewrites.simps ss4 to_zero_in_alt)
381
0c666a0c57d7 isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents: 379
diff changeset
  1276
next
392
8194086c2a8a simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents: 385
diff changeset
  1277
  case (bs4 r1 r2 bs r3)
381
0c666a0c57d7 isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents: 379
diff changeset
  1278
  have as: "r1 \<leadsto> r2" by fact
0c666a0c57d7 isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents: 379
diff changeset
  1279
  have IH: "bder c r1 \<leadsto>* bder c r2" by fact
0c666a0c57d7 isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents: 379
diff changeset
  1280
  from as IH show "bder c (ASEQ bs r1 r3) \<leadsto>* bder c (ASEQ bs r2 r3)"
0c666a0c57d7 isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents: 379
diff changeset
  1281
    by (simp add: contextrewrites1 rewrite_bmkeps rewrite_non_nullable_strong star_seq) 
0c666a0c57d7 isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents: 379
diff changeset
  1282
next
392
8194086c2a8a simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents: 385
diff changeset
  1283
  case (bs5 r3 r4 bs r1)
381
0c666a0c57d7 isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents: 379
diff changeset
  1284
  have as: "r3 \<leadsto> r4" by fact 
0c666a0c57d7 isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents: 379
diff changeset
  1285
  have IH: "bder c r3 \<leadsto>* bder c r4" by fact 
385
c80720289645 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 381
diff changeset
  1286
  from as IH show "bder c (ASEQ bs r1 r3) \<leadsto>* bder c (ASEQ bs r1 r4)"
392
8194086c2a8a simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents: 385
diff changeset
  1287
    apply(simp)
8194086c2a8a simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents: 385
diff changeset
  1288
    apply(auto)
8194086c2a8a simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents: 385
diff changeset
  1289
    using contextrewrites0 r_in_rstar rewrites_fuse srewrites6 srewrites7 star_seq2 apply presburger
8194086c2a8a simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents: 385
diff changeset
  1290
    using star_seq2 by blast
8194086c2a8a simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents: 385
diff changeset
  1291
next
8194086c2a8a simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents: 385
diff changeset
  1292
  case (bs6 bs)
8194086c2a8a simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents: 385
diff changeset
  1293
  then show ?case
8194086c2a8a simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents: 385
diff changeset
  1294
    using rrewrite_srewrite.bs6 by force 
381
0c666a0c57d7 isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents: 379
diff changeset
  1295
next
392
8194086c2a8a simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents: 385
diff changeset
  1296
  case (bs7 bs r)
8194086c2a8a simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents: 385
diff changeset
  1297
  then show ?case
8194086c2a8a simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents: 385
diff changeset
  1298
    by (simp add: bder_fuse r_in_rstar rrewrite_srewrite.bs7) 
381
0c666a0c57d7 isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents: 379
diff changeset
  1299
next
392
8194086c2a8a simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents: 385
diff changeset
  1300
  case (bs10 rs1 rs2 bs)
8194086c2a8a simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents: 385
diff changeset
  1301
  then show ?case
8194086c2a8a simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents: 385
diff changeset
  1302
    using contextrewrites0 by force    
8194086c2a8a simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents: 385
diff changeset
  1303
next
8194086c2a8a simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents: 385
diff changeset
  1304
  case ss1
8194086c2a8a simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents: 385
diff changeset
  1305
  then show ?case by simp
381
0c666a0c57d7 isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents: 379
diff changeset
  1306
next
392
8194086c2a8a simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents: 385
diff changeset
  1307
  case (ss2 rs1 rs2 r)
8194086c2a8a simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents: 385
diff changeset
  1308
  then show ?case
8194086c2a8a simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents: 385
diff changeset
  1309
    by (simp add: srewrites7) 
381
0c666a0c57d7 isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents: 379
diff changeset
  1310
next
392
8194086c2a8a simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents: 385
diff changeset
  1311
  case (ss3 r1 r2 rs)
8194086c2a8a simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents: 385
diff changeset
  1312
  then show ?case
8194086c2a8a simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents: 385
diff changeset
  1313
    by (simp add: srewrites7) 
381
0c666a0c57d7 isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents: 379
diff changeset
  1314
next
392
8194086c2a8a simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents: 385
diff changeset
  1315
  case (ss4 rs)
8194086c2a8a simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents: 385
diff changeset
  1316
  then show ?case
8194086c2a8a simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents: 385
diff changeset
  1317
    using rrewrite_srewrite.ss4 by fastforce 
381
0c666a0c57d7 isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents: 379
diff changeset
  1318
next
392
8194086c2a8a simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents: 385
diff changeset
  1319
  case (ss5 bs1 rs1 rsb)
8194086c2a8a simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents: 385
diff changeset
  1320
  then show ?case 
8194086c2a8a simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents: 385
diff changeset
  1321
    apply(simp)
8194086c2a8a simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents: 385
diff changeset
  1322
    using bder_fuse_list map_map rrewrite_srewrite.ss5 srewrites.simps by blast
8194086c2a8a simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents: 385
diff changeset
  1323
next
8194086c2a8a simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents: 385
diff changeset
  1324
  case (ss6 a1 a2 bs rsa rsb)
8194086c2a8a simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents: 385
diff changeset
  1325
  then show ?case
8194086c2a8a simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents: 385
diff changeset
  1326
    apply(simp only: map_append)
8194086c2a8a simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents: 385
diff changeset
  1327
    by (smt (verit, best) erase_bder list.simps(8) list.simps(9) local.ss6 rrewrite_srewrite.ss6 srewrites.simps)
381
0c666a0c57d7 isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents: 379
diff changeset
  1328
qed
365
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1329
393
3954579ebdaf polished
Christian Urban <christian.urban@kcl.ac.uk>
parents: 392
diff changeset
  1330
lemma rewrites_preserves_bder: 
373
320f923c77b9 slightly
Christian Urban <christian.urban@kcl.ac.uk>
parents: 365
diff changeset
  1331
  assumes "r1 \<leadsto>* r2"
320f923c77b9 slightly
Christian Urban <christian.urban@kcl.ac.uk>
parents: 365
diff changeset
  1332
  shows "bder c r1 \<leadsto>* bder c r2"
320f923c77b9 slightly
Christian Urban <christian.urban@kcl.ac.uk>
parents: 365
diff changeset
  1333
using assms  
320f923c77b9 slightly
Christian Urban <christian.urban@kcl.ac.uk>
parents: 365
diff changeset
  1334
apply(induction r1 r2 rule: rrewrites.induct)
393
3954579ebdaf polished
Christian Urban <christian.urban@kcl.ac.uk>
parents: 392
diff changeset
  1335
apply(simp_all add: rewrite_preserves_bder rrewrites_trans)
373
320f923c77b9 slightly
Christian Urban <christian.urban@kcl.ac.uk>
parents: 365
diff changeset
  1336
done
365
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1337
381
0c666a0c57d7 isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents: 379
diff changeset
  1338
373
320f923c77b9 slightly
Christian Urban <christian.urban@kcl.ac.uk>
parents: 365
diff changeset
  1339
lemma central:  
320f923c77b9 slightly
Christian Urban <christian.urban@kcl.ac.uk>
parents: 365
diff changeset
  1340
  shows "bders r s \<leadsto>* bders_simp r s"
320f923c77b9 slightly
Christian Urban <christian.urban@kcl.ac.uk>
parents: 365
diff changeset
  1341
proof(induct s arbitrary: r rule: rev_induct)
320f923c77b9 slightly
Christian Urban <christian.urban@kcl.ac.uk>
parents: 365
diff changeset
  1342
  case Nil
320f923c77b9 slightly
Christian Urban <christian.urban@kcl.ac.uk>
parents: 365
diff changeset
  1343
  then show "bders r [] \<leadsto>* bders_simp r []" by simp
320f923c77b9 slightly
Christian Urban <christian.urban@kcl.ac.uk>
parents: 365
diff changeset
  1344
next
320f923c77b9 slightly
Christian Urban <christian.urban@kcl.ac.uk>
parents: 365
diff changeset
  1345
  case (snoc x xs)
320f923c77b9 slightly
Christian Urban <christian.urban@kcl.ac.uk>
parents: 365
diff changeset
  1346
  have IH: "\<And>r. bders r xs \<leadsto>* bders_simp r xs" by fact
320f923c77b9 slightly
Christian Urban <christian.urban@kcl.ac.uk>
parents: 365
diff changeset
  1347
  have "bders r (xs @ [x]) = bders (bders r xs) [x]" by (simp add: bders_append)
320f923c77b9 slightly
Christian Urban <christian.urban@kcl.ac.uk>
parents: 365
diff changeset
  1348
  also have "... \<leadsto>* bders (bders_simp r xs) [x]" using IH
393
3954579ebdaf polished
Christian Urban <christian.urban@kcl.ac.uk>
parents: 392
diff changeset
  1349
    by (simp add: rewrites_preserves_bder)
373
320f923c77b9 slightly
Christian Urban <christian.urban@kcl.ac.uk>
parents: 365
diff changeset
  1350
  also have "... \<leadsto>* bders_simp (bders_simp r xs) [x]" using IH
393
3954579ebdaf polished
Christian Urban <christian.urban@kcl.ac.uk>
parents: 392
diff changeset
  1351
    by (simp add: rewrites_to_bsimp)
373
320f923c77b9 slightly
Christian Urban <christian.urban@kcl.ac.uk>
parents: 365
diff changeset
  1352
  finally show "bders r (xs @ [x]) \<leadsto>* bders_simp r (xs @ [x])" 
320f923c77b9 slightly
Christian Urban <christian.urban@kcl.ac.uk>
parents: 365
diff changeset
  1353
    by (simp add: bders_simp_append)
320f923c77b9 slightly
Christian Urban <christian.urban@kcl.ac.uk>
parents: 365
diff changeset
  1354
qed
365
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1355
393
3954579ebdaf polished
Christian Urban <christian.urban@kcl.ac.uk>
parents: 392
diff changeset
  1356
lemma main_aux: 
373
320f923c77b9 slightly
Christian Urban <christian.urban@kcl.ac.uk>
parents: 365
diff changeset
  1357
  assumes "bnullable (bders r s)"
320f923c77b9 slightly
Christian Urban <christian.urban@kcl.ac.uk>
parents: 365
diff changeset
  1358
  shows "bmkeps (bders r s) = bmkeps (bders_simp r s)"
381
0c666a0c57d7 isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents: 379
diff changeset
  1359
proof -
0c666a0c57d7 isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents: 379
diff changeset
  1360
  have "bders r s \<leadsto>* bders_simp r s" by (rule central)
0c666a0c57d7 isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents: 379
diff changeset
  1361
  then 
0c666a0c57d7 isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents: 379
diff changeset
  1362
  show "bmkeps (bders r s) = bmkeps (bders_simp r s)" using assms
0c666a0c57d7 isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents: 379
diff changeset
  1363
    by (rule rewrites_bmkeps)
0c666a0c57d7 isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents: 379
diff changeset
  1364
qed  
0c666a0c57d7 isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents: 379
diff changeset
  1365
365
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1366
385
c80720289645 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 381
diff changeset
  1367
c80720289645 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 381
diff changeset
  1368
393
3954579ebdaf polished
Christian Urban <christian.urban@kcl.ac.uk>
parents: 392
diff changeset
  1369
theorem main_blexer_simp: 
373
320f923c77b9 slightly
Christian Urban <christian.urban@kcl.ac.uk>
parents: 365
diff changeset
  1370
  shows "blexer r s = blexer_simp r s"
381
0c666a0c57d7 isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents: 379
diff changeset
  1371
  unfolding blexer_def blexer_simp_def
393
3954579ebdaf polished
Christian Urban <christian.urban@kcl.ac.uk>
parents: 392
diff changeset
  1372
  using b4 main_aux by simp
365
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1373
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1374
373
320f923c77b9 slightly
Christian Urban <christian.urban@kcl.ac.uk>
parents: 365
diff changeset
  1375
theorem blexersimp_correctness: 
320f923c77b9 slightly
Christian Urban <christian.urban@kcl.ac.uk>
parents: 365
diff changeset
  1376
  shows "lexer r s = blexer_simp r s"
393
3954579ebdaf polished
Christian Urban <christian.urban@kcl.ac.uk>
parents: 392
diff changeset
  1377
  using blexer_correctness main_blexer_simp by simp
365
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1378
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1379
378
Chengsong
parents: 375
diff changeset
  1380
Chengsong
parents: 375
diff changeset
  1381
export_code blexer_simp blexer lexer bders bders_simp in Scala module_name VerifiedLexers
Chengsong
parents: 375
diff changeset
  1382
Chengsong
parents: 375
diff changeset
  1383
365
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1384
unused_thms
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1385
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1386
378
Chengsong
parents: 375
diff changeset
  1387
inductive aggressive:: "arexp \<Rightarrow> arexp \<Rightarrow> bool" ("_ \<leadsto>? _" [99, 99] 99)
Chengsong
parents: 375
diff changeset
  1388
  where
Chengsong
parents: 375
diff changeset
  1389
 "ASEQ bs (AALTs bs1 rs) r \<leadsto>? AALTs (bs@bs1) (map (\<lambda>r'. ASEQ [] r' r) rs) "
Chengsong
parents: 375
diff changeset
  1390
Chengsong
parents: 375
diff changeset
  1391
Chengsong
parents: 375
diff changeset
  1392
365
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1393
end