thys2/SizeBound4.thy
author Chengsong
Wed, 02 Mar 2022 23:13:59 +0000
changeset 438 a73b2e553804
parent 425 14c558ae0b09
child 436 222333d2bdc2
permissions -rw-r--r--
templateforPhd
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
365
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
     1
393
3954579ebdaf polished
Christian Urban <christian.urban@kcl.ac.uk>
parents: 392
diff changeset
     2
theory SizeBound4
405
3cfea5bb5e23 updated some of the text and cardinality proof
Christian Urban <christian.urban@kcl.ac.uk>
parents: 402
diff changeset
     3
  imports "Lexer" "PDerivs"
365
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
     4
begin
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
     5
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
     6
section \<open>Bit-Encodings\<close>
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
     7
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
     8
datatype bit = Z | S
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
     9
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    10
fun code :: "val \<Rightarrow> bit list"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    11
where
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    12
  "code Void = []"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    13
| "code (Char c) = []"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    14
| "code (Left v) = Z # (code v)"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    15
| "code (Right v) = S # (code v)"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    16
| "code (Seq v1 v2) = (code v1) @ (code v2)"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    17
| "code (Stars []) = [S]"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    18
| "code (Stars (v # vs)) =  (Z # code v) @ code (Stars vs)"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    19
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    20
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    21
fun 
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    22
  Stars_add :: "val \<Rightarrow> val \<Rightarrow> val"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    23
where
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    24
  "Stars_add v (Stars vs) = Stars (v # vs)"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    25
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    26
function
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    27
  decode' :: "bit list \<Rightarrow> rexp \<Rightarrow> (val * bit list)"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    28
where
405
3cfea5bb5e23 updated some of the text and cardinality proof
Christian Urban <christian.urban@kcl.ac.uk>
parents: 402
diff changeset
    29
  "decode' bs ZERO = (undefined, bs)"
3cfea5bb5e23 updated some of the text and cardinality proof
Christian Urban <christian.urban@kcl.ac.uk>
parents: 402
diff changeset
    30
| "decode' bs ONE = (Void, bs)"
3cfea5bb5e23 updated some of the text and cardinality proof
Christian Urban <christian.urban@kcl.ac.uk>
parents: 402
diff changeset
    31
| "decode' bs (CH d) = (Char d, bs)"
365
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    32
| "decode' [] (ALT r1 r2) = (Void, [])"
405
3cfea5bb5e23 updated some of the text and cardinality proof
Christian Urban <christian.urban@kcl.ac.uk>
parents: 402
diff changeset
    33
| "decode' (Z # bs) (ALT r1 r2) = (let (v, bs') = decode' bs r1 in (Left v, bs'))"
3cfea5bb5e23 updated some of the text and cardinality proof
Christian Urban <christian.urban@kcl.ac.uk>
parents: 402
diff changeset
    34
| "decode' (S # bs) (ALT r1 r2) = (let (v, bs') = decode' bs r2 in (Right v, bs'))"
3cfea5bb5e23 updated some of the text and cardinality proof
Christian Urban <christian.urban@kcl.ac.uk>
parents: 402
diff changeset
    35
| "decode' bs (SEQ r1 r2) = (let (v1, bs') = decode' bs r1 in
3cfea5bb5e23 updated some of the text and cardinality proof
Christian Urban <christian.urban@kcl.ac.uk>
parents: 402
diff changeset
    36
                             let (v2, bs'') = decode' bs' r2 in (Seq v1 v2, bs''))"
365
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    37
| "decode' [] (STAR r) = (Void, [])"
405
3cfea5bb5e23 updated some of the text and cardinality proof
Christian Urban <christian.urban@kcl.ac.uk>
parents: 402
diff changeset
    38
| "decode' (S # bs) (STAR r) = (Stars [], bs)"
3cfea5bb5e23 updated some of the text and cardinality proof
Christian Urban <christian.urban@kcl.ac.uk>
parents: 402
diff changeset
    39
| "decode' (Z # bs) (STAR r) = (let (v, bs') = decode' bs r in
3cfea5bb5e23 updated some of the text and cardinality proof
Christian Urban <christian.urban@kcl.ac.uk>
parents: 402
diff changeset
    40
                                    let (vs, bs'') = decode' bs' (STAR r) 
3cfea5bb5e23 updated some of the text and cardinality proof
Christian Urban <christian.urban@kcl.ac.uk>
parents: 402
diff changeset
    41
                                    in (Stars_add v vs, bs''))"
365
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:
405
3cfea5bb5e23 updated some of the text and cardinality proof
Christian Urban <christian.urban@kcl.ac.uk>
parents: 402
diff changeset
    45
  assumes "decode'_dom (bs, r)"
3cfea5bb5e23 updated some of the text and cardinality proof
Christian Urban <christian.urban@kcl.ac.uk>
parents: 402
diff changeset
    46
  shows "length (snd (decode' bs r)) \<le> length bs"
365
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
    47
using assms
405
3cfea5bb5e23 updated some of the text and cardinality proof
Christian Urban <christian.urban@kcl.ac.uk>
parents: 402
diff changeset
    48
apply(induct bs r)
365
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
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   135
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   136
fun intern :: "rexp \<Rightarrow> arexp" where
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   137
  "intern ZERO = AZERO"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   138
| "intern ONE = AONE []"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   139
| "intern (CH c) = ACHAR [] c"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   140
| "intern (ALT r1 r2) = AALT [] (fuse [Z] (intern r1)) 
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   141
                                (fuse [S]  (intern r2))"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   142
| "intern (SEQ r1 r2) = ASEQ [] (intern r1) (intern r2)"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   143
| "intern (STAR r) = ASTAR [] (intern r)"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   144
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   145
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   146
fun retrieve :: "arexp \<Rightarrow> val \<Rightarrow> bit list" where
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   147
  "retrieve (AONE bs) Void = bs"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   148
| "retrieve (ACHAR bs c) (Char d) = bs"
402
1612f2a77bf6 more definitions in the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents: 400
diff changeset
   149
| "retrieve (AALTs bs [r]) v = bs @ retrieve r v"
365
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   150
| "retrieve (AALTs bs (r#rs)) (Left v) = bs @ retrieve r v"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   151
| "retrieve (AALTs bs (r#rs)) (Right v) = bs @ retrieve (AALTs [] rs) v"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   152
| "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
   153
| "retrieve (ASTAR bs r) (Stars []) = bs @ [S]"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   154
| "retrieve (ASTAR bs r) (Stars (v#vs)) = 
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   155
     bs @ [Z] @ retrieve r v @ retrieve (ASTAR [] r) (Stars vs)"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   156
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   157
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   158
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   159
fun
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   160
 bnullable :: "arexp \<Rightarrow> bool"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   161
where
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   162
  "bnullable (AZERO) = False"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   163
| "bnullable (AONE bs) = True"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   164
| "bnullable (ACHAR bs c) = False"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   165
| "bnullable (AALTs bs rs) = (\<exists>r \<in> set rs. bnullable r)"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   166
| "bnullable (ASEQ bs r1 r2) = (bnullable r1 \<and> bnullable r2)"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   167
| "bnullable (ASTAR bs r) = True"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   168
393
3954579ebdaf polished
Christian Urban <christian.urban@kcl.ac.uk>
parents: 392
diff changeset
   169
abbreviation
3954579ebdaf polished
Christian Urban <christian.urban@kcl.ac.uk>
parents: 392
diff changeset
   170
  bnullables :: "arexp list \<Rightarrow> bool"
3954579ebdaf polished
Christian Urban <christian.urban@kcl.ac.uk>
parents: 392
diff changeset
   171
where
3954579ebdaf polished
Christian Urban <christian.urban@kcl.ac.uk>
parents: 392
diff changeset
   172
  "bnullables rs \<equiv> (\<exists>r \<in> set rs. bnullable r)"
3954579ebdaf polished
Christian Urban <christian.urban@kcl.ac.uk>
parents: 392
diff changeset
   173
365
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   174
fun 
393
3954579ebdaf polished
Christian Urban <christian.urban@kcl.ac.uk>
parents: 392
diff changeset
   175
  bmkeps :: "arexp \<Rightarrow> bit list" and
3954579ebdaf polished
Christian Urban <christian.urban@kcl.ac.uk>
parents: 392
diff changeset
   176
  bmkepss :: "arexp list \<Rightarrow> bit list"
365
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   177
where
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   178
  "bmkeps(AONE bs) = bs"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   179
| "bmkeps(ASEQ bs r1 r2) = bs @ (bmkeps r1) @ (bmkeps r2)"
393
3954579ebdaf polished
Christian Urban <christian.urban@kcl.ac.uk>
parents: 392
diff changeset
   180
| "bmkeps(AALTs bs rs) = bs @ (bmkepss rs)"
365
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   181
| "bmkeps(ASTAR bs r) = bs @ [S]"
418
41a2a3b63853 more of the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents: 416
diff changeset
   182
(*| "bmkepss [] = []"*)
393
3954579ebdaf polished
Christian Urban <christian.urban@kcl.ac.uk>
parents: 392
diff changeset
   183
| "bmkepss (r # rs) = (if bnullable(r) then (bmkeps r) else (bmkepss rs))"
3954579ebdaf polished
Christian Urban <christian.urban@kcl.ac.uk>
parents: 392
diff changeset
   184
3954579ebdaf polished
Christian Urban <christian.urban@kcl.ac.uk>
parents: 392
diff changeset
   185
lemma bmkepss1:
3954579ebdaf polished
Christian Urban <christian.urban@kcl.ac.uk>
parents: 392
diff changeset
   186
  assumes "\<not> bnullables rs1"
3954579ebdaf polished
Christian Urban <christian.urban@kcl.ac.uk>
parents: 392
diff changeset
   187
  shows "bmkepss (rs1 @ rs2) = bmkepss rs2"
3954579ebdaf polished
Christian Urban <christian.urban@kcl.ac.uk>
parents: 392
diff changeset
   188
  using assms
3954579ebdaf polished
Christian Urban <christian.urban@kcl.ac.uk>
parents: 392
diff changeset
   189
  by (induct rs1) (auto)
3954579ebdaf polished
Christian Urban <christian.urban@kcl.ac.uk>
parents: 392
diff changeset
   190
3954579ebdaf polished
Christian Urban <christian.urban@kcl.ac.uk>
parents: 392
diff changeset
   191
lemma bmkepss2:
3954579ebdaf polished
Christian Urban <christian.urban@kcl.ac.uk>
parents: 392
diff changeset
   192
  assumes "bnullables rs1"
3954579ebdaf polished
Christian Urban <christian.urban@kcl.ac.uk>
parents: 392
diff changeset
   193
  shows "bmkepss (rs1 @ rs2) = bmkepss rs1"
3954579ebdaf polished
Christian Urban <christian.urban@kcl.ac.uk>
parents: 392
diff changeset
   194
  using assms
3954579ebdaf polished
Christian Urban <christian.urban@kcl.ac.uk>
parents: 392
diff changeset
   195
  by (induct rs1) (auto)
365
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   196
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   197
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   198
fun
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   199
 bder :: "char \<Rightarrow> arexp \<Rightarrow> arexp"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   200
where
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   201
  "bder c (AZERO) = AZERO"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   202
| "bder c (AONE bs) = AZERO"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   203
| "bder c (ACHAR bs d) = (if c = d then AONE bs else AZERO)"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   204
| "bder c (AALTs bs rs) = AALTs bs (map (bder c) rs)"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   205
| "bder c (ASEQ bs r1 r2) = 
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   206
     (if bnullable r1
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   207
      then AALT bs (ASEQ [] (bder c r1) r2) (fuse (bmkeps r1) (bder c r2))
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   208
      else ASEQ bs (bder c r1) r2)"
416
57182b36ec01 more with the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents: 411
diff changeset
   209
| "bder c (ASTAR bs r) = ASEQ (bs @ [Z]) (bder c r) (ASTAR [] r)"
365
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   210
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   211
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   212
fun 
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   213
  bders :: "arexp \<Rightarrow> string \<Rightarrow> arexp"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   214
where
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   215
  "bders r [] = r"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   216
| "bders r (c#s) = bders (bder c r) s"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   217
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   218
lemma bders_append:
398
dac6d27c99c6 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 397
diff changeset
   219
  "bders c (s1 @ s2) = bders (bders c s1) s2"
dac6d27c99c6 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 397
diff changeset
   220
  apply(induct s1 arbitrary: c s2)
365
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 bnullable_correctness:
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   225
  shows "nullable (erase r) = bnullable 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_fuse:
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   231
  shows "erase (fuse bs r) = erase r"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   232
  apply(induct r rule: erase.induct)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   233
  apply(simp_all)
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_intern [simp]:
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   237
  shows "erase (intern r) = r"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   238
  apply(induct r)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   239
  apply(simp_all add: erase_fuse)
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_bder [simp]:
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   243
  shows "erase (bder a r) = der a (erase r)"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   244
  apply(induct r rule: erase.induct)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   245
  apply(simp_all add: erase_fuse bnullable_correctness)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   246
  done
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   247
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   248
lemma erase_bders [simp]:
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   249
  shows "erase (bders r s) = ders s (erase r)"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   250
  apply(induct s arbitrary: r )
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   251
  apply(simp_all)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   252
  done
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   253
381
0c666a0c57d7 isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents: 379
diff changeset
   254
lemma bnullable_fuse:
0c666a0c57d7 isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents: 379
diff changeset
   255
  shows "bnullable (fuse bs r) = bnullable r"
0c666a0c57d7 isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents: 379
diff changeset
   256
  apply(induct r arbitrary: bs)
0c666a0c57d7 isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents: 379
diff changeset
   257
  apply(auto)
0c666a0c57d7 isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents: 379
diff changeset
   258
  done
0c666a0c57d7 isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents: 379
diff changeset
   259
365
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   260
lemma retrieve_encode_STARS:
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   261
  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
   262
  shows "code (Stars vs) = retrieve (ASTAR [] (intern r)) (Stars vs)"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   263
  using assms
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   264
  apply(induct vs)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   265
  apply(simp_all)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   266
  done
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   267
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   268
lemma retrieve_fuse2:
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   269
  assumes "\<Turnstile> v : (erase r)"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   270
  shows "retrieve (fuse bs r) v = bs @ retrieve r v"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   271
  using assms
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   272
  apply(induct r arbitrary: v bs)
397
e1b74d618f1b updated Sizebound4
Christian Urban <christian.urban@kcl.ac.uk>
parents: 396
diff changeset
   273
  apply(auto elim: Prf_elims)[4]
e1b74d618f1b updated Sizebound4
Christian Urban <christian.urban@kcl.ac.uk>
parents: 396
diff changeset
   274
  apply(case_tac x2a)
e1b74d618f1b updated Sizebound4
Christian Urban <christian.urban@kcl.ac.uk>
parents: 396
diff changeset
   275
  apply(simp)
e1b74d618f1b updated Sizebound4
Christian Urban <christian.urban@kcl.ac.uk>
parents: 396
diff changeset
   276
  using Prf_elims(1) apply blast
e1b74d618f1b updated Sizebound4
Christian Urban <christian.urban@kcl.ac.uk>
parents: 396
diff changeset
   277
  apply(case_tac x2a)
e1b74d618f1b updated Sizebound4
Christian Urban <christian.urban@kcl.ac.uk>
parents: 396
diff changeset
   278
  apply(simp)
e1b74d618f1b updated Sizebound4
Christian Urban <christian.urban@kcl.ac.uk>
parents: 396
diff changeset
   279
  apply(simp)
e1b74d618f1b updated Sizebound4
Christian Urban <christian.urban@kcl.ac.uk>
parents: 396
diff changeset
   280
  apply(case_tac list)
365
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   281
  apply(simp)
397
e1b74d618f1b updated Sizebound4
Christian Urban <christian.urban@kcl.ac.uk>
parents: 396
diff changeset
   282
  apply(simp)
e1b74d618f1b updated Sizebound4
Christian Urban <christian.urban@kcl.ac.uk>
parents: 396
diff changeset
   283
  apply (smt (verit, best) Prf_elims(3) append_assoc retrieve.simps(4) retrieve.simps(5))
365
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   284
  apply(simp)
397
e1b74d618f1b updated Sizebound4
Christian Urban <christian.urban@kcl.ac.uk>
parents: 396
diff changeset
   285
  using retrieve_encode_STARS
365
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   286
  apply(auto elim!: Prf_elims)[1]
397
e1b74d618f1b updated Sizebound4
Christian Urban <christian.urban@kcl.ac.uk>
parents: 396
diff changeset
   287
  apply(case_tac vs)
e1b74d618f1b updated Sizebound4
Christian Urban <christian.urban@kcl.ac.uk>
parents: 396
diff changeset
   288
  apply(simp)
e1b74d618f1b updated Sizebound4
Christian Urban <christian.urban@kcl.ac.uk>
parents: 396
diff changeset
   289
  apply(simp)
365
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   290
  done
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   291
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   292
lemma retrieve_fuse:
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   293
  assumes "\<Turnstile> v : r"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   294
  shows "retrieve (fuse bs (intern r)) v = bs @ retrieve (intern r) v"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   295
  using assms 
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   296
  by (simp_all add: retrieve_fuse2)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   297
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   298
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   299
lemma retrieve_code:
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   300
  assumes "\<Turnstile> v : r"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   301
  shows "code v = retrieve (intern r) v"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   302
  using assms
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   303
  apply(induct v r )
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   304
  apply(simp_all add: retrieve_fuse retrieve_encode_STARS)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   305
  done
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   306
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   307
397
e1b74d618f1b updated Sizebound4
Christian Urban <christian.urban@kcl.ac.uk>
parents: 396
diff changeset
   308
lemma retrieve_AALTs_bnullable1:
e1b74d618f1b updated Sizebound4
Christian Urban <christian.urban@kcl.ac.uk>
parents: 396
diff changeset
   309
  assumes "bnullable r"
e1b74d618f1b updated Sizebound4
Christian Urban <christian.urban@kcl.ac.uk>
parents: 396
diff changeset
   310
  shows "retrieve (AALTs bs (r # rs)) (mkeps (erase (AALTs bs (r # rs))))
e1b74d618f1b updated Sizebound4
Christian Urban <christian.urban@kcl.ac.uk>
parents: 396
diff changeset
   311
         = bs @ retrieve r (mkeps (erase r))"
365
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   312
  using assms
397
e1b74d618f1b updated Sizebound4
Christian Urban <christian.urban@kcl.ac.uk>
parents: 396
diff changeset
   313
  apply(case_tac rs)
e1b74d618f1b updated Sizebound4
Christian Urban <christian.urban@kcl.ac.uk>
parents: 396
diff changeset
   314
  apply(auto simp add: bnullable_correctness)
365
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   315
  done
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   316
397
e1b74d618f1b updated Sizebound4
Christian Urban <christian.urban@kcl.ac.uk>
parents: 396
diff changeset
   317
lemma retrieve_AALTs_bnullable2:
e1b74d618f1b updated Sizebound4
Christian Urban <christian.urban@kcl.ac.uk>
parents: 396
diff changeset
   318
  assumes "\<not>bnullable r" "bnullables rs"
e1b74d618f1b updated Sizebound4
Christian Urban <christian.urban@kcl.ac.uk>
parents: 396
diff changeset
   319
  shows "retrieve (AALTs bs (r # rs)) (mkeps (erase (AALTs bs (r # rs))))
e1b74d618f1b updated Sizebound4
Christian Urban <christian.urban@kcl.ac.uk>
parents: 396
diff changeset
   320
         = retrieve (AALTs bs rs) (mkeps (erase (AALTs bs rs)))"
365
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   321
  using assms
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   322
  apply(induct rs arbitrary: r bs)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   323
  apply(auto)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   324
  using bnullable_correctness apply blast
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   325
  apply(case_tac rs)
397
e1b74d618f1b updated Sizebound4
Christian Urban <christian.urban@kcl.ac.uk>
parents: 396
diff changeset
   326
  apply(auto)
e1b74d618f1b updated Sizebound4
Christian Urban <christian.urban@kcl.ac.uk>
parents: 396
diff changeset
   327
  using bnullable_correctness apply blast
e1b74d618f1b updated Sizebound4
Christian Urban <christian.urban@kcl.ac.uk>
parents: 396
diff changeset
   328
  apply(case_tac rs)
e1b74d618f1b updated Sizebound4
Christian Urban <christian.urban@kcl.ac.uk>
parents: 396
diff changeset
   329
  apply(auto)
365
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   330
  done
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   331
397
e1b74d618f1b updated Sizebound4
Christian Urban <christian.urban@kcl.ac.uk>
parents: 396
diff changeset
   332
lemma bmkeps_retrieve_AALTs: 
393
3954579ebdaf polished
Christian Urban <christian.urban@kcl.ac.uk>
parents: 392
diff changeset
   333
  assumes "\<forall>r \<in> set rs. bnullable r \<longrightarrow> bmkeps r = retrieve r (mkeps (erase r))" 
3954579ebdaf polished
Christian Urban <christian.urban@kcl.ac.uk>
parents: 392
diff changeset
   334
          "bnullables rs"
3954579ebdaf polished
Christian Urban <christian.urban@kcl.ac.uk>
parents: 392
diff changeset
   335
  shows "bs @ bmkepss rs = retrieve (AALTs bs rs) (mkeps (erase (AALTs bs rs)))"
3954579ebdaf polished
Christian Urban <christian.urban@kcl.ac.uk>
parents: 392
diff changeset
   336
 using assms
365
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   337
  apply(induct rs arbitrary: bs)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   338
  apply(auto)
397
e1b74d618f1b updated Sizebound4
Christian Urban <christian.urban@kcl.ac.uk>
parents: 396
diff changeset
   339
  using retrieve_AALTs_bnullable1 apply presburger
e1b74d618f1b updated Sizebound4
Christian Urban <christian.urban@kcl.ac.uk>
parents: 396
diff changeset
   340
  apply (metis retrieve_AALTs_bnullable2)
e1b74d618f1b updated Sizebound4
Christian Urban <christian.urban@kcl.ac.uk>
parents: 396
diff changeset
   341
  apply (simp add: retrieve_AALTs_bnullable1)
e1b74d618f1b updated Sizebound4
Christian Urban <christian.urban@kcl.ac.uk>
parents: 396
diff changeset
   342
  by (metis retrieve_AALTs_bnullable2)
e1b74d618f1b updated Sizebound4
Christian Urban <christian.urban@kcl.ac.uk>
parents: 396
diff changeset
   343
e1b74d618f1b updated Sizebound4
Christian Urban <christian.urban@kcl.ac.uk>
parents: 396
diff changeset
   344
    
365
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   345
lemma bmkeps_retrieve:
393
3954579ebdaf polished
Christian Urban <christian.urban@kcl.ac.uk>
parents: 392
diff changeset
   346
  assumes "bnullable r"
365
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   347
  shows "bmkeps r = retrieve r (mkeps (erase r))"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   348
  using assms
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   349
  apply(induct r)
397
e1b74d618f1b updated Sizebound4
Christian Urban <christian.urban@kcl.ac.uk>
parents: 396
diff changeset
   350
  apply(auto)  
e1b74d618f1b updated Sizebound4
Christian Urban <christian.urban@kcl.ac.uk>
parents: 396
diff changeset
   351
  using bmkeps_retrieve_AALTs by auto
365
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   352
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   353
lemma bder_retrieve:
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   354
  assumes "\<Turnstile> v : der c (erase r)"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   355
  shows "retrieve (bder c r) v = retrieve r (injval (erase r) c v)"
393
3954579ebdaf polished
Christian Urban <christian.urban@kcl.ac.uk>
parents: 392
diff changeset
   356
  using assms  
365
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   357
  apply(induct r arbitrary: v rule: erase.induct)
397
e1b74d618f1b updated Sizebound4
Christian Urban <christian.urban@kcl.ac.uk>
parents: 396
diff changeset
   358
  using Prf_elims(1) apply auto[1]
e1b74d618f1b updated Sizebound4
Christian Urban <christian.urban@kcl.ac.uk>
parents: 396
diff changeset
   359
  using Prf_elims(1) apply auto[1]
e1b74d618f1b updated Sizebound4
Christian Urban <christian.urban@kcl.ac.uk>
parents: 396
diff changeset
   360
  apply(auto)[1]
e1b74d618f1b updated Sizebound4
Christian Urban <christian.urban@kcl.ac.uk>
parents: 396
diff changeset
   361
  apply (metis Prf_elims(4) injval.simps(1) retrieve.simps(1) retrieve.simps(2))
e1b74d618f1b updated Sizebound4
Christian Urban <christian.urban@kcl.ac.uk>
parents: 396
diff changeset
   362
  using Prf_elims(1) apply blast
e1b74d618f1b updated Sizebound4
Christian Urban <christian.urban@kcl.ac.uk>
parents: 396
diff changeset
   363
  (* AALTs case *)
365
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   364
  apply(simp)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   365
  apply(erule Prf_elims)
397
e1b74d618f1b updated Sizebound4
Christian Urban <christian.urban@kcl.ac.uk>
parents: 396
diff changeset
   366
  apply(simp)
e1b74d618f1b updated Sizebound4
Christian Urban <christian.urban@kcl.ac.uk>
parents: 396
diff changeset
   367
  apply(simp)
e1b74d618f1b updated Sizebound4
Christian Urban <christian.urban@kcl.ac.uk>
parents: 396
diff changeset
   368
  apply(rename_tac "r\<^sub>1" "r\<^sub>2" rs v)
e1b74d618f1b updated Sizebound4
Christian Urban <christian.urban@kcl.ac.uk>
parents: 396
diff changeset
   369
  apply(erule Prf_elims)
e1b74d618f1b updated Sizebound4
Christian Urban <christian.urban@kcl.ac.uk>
parents: 396
diff changeset
   370
  apply(simp)
e1b74d618f1b updated Sizebound4
Christian Urban <christian.urban@kcl.ac.uk>
parents: 396
diff changeset
   371
  apply(simp)
e1b74d618f1b updated Sizebound4
Christian Urban <christian.urban@kcl.ac.uk>
parents: 396
diff changeset
   372
  apply(case_tac rs)
e1b74d618f1b updated Sizebound4
Christian Urban <christian.urban@kcl.ac.uk>
parents: 396
diff changeset
   373
  apply(simp)
e1b74d618f1b updated Sizebound4
Christian Urban <christian.urban@kcl.ac.uk>
parents: 396
diff changeset
   374
  apply(simp)
e1b74d618f1b updated Sizebound4
Christian Urban <christian.urban@kcl.ac.uk>
parents: 396
diff changeset
   375
  using Prf_elims(3) apply fastforce
e1b74d618f1b updated Sizebound4
Christian Urban <christian.urban@kcl.ac.uk>
parents: 396
diff changeset
   376
  (* ASEQ case *) 
e1b74d618f1b updated Sizebound4
Christian Urban <christian.urban@kcl.ac.uk>
parents: 396
diff changeset
   377
  apply(simp)
e1b74d618f1b updated Sizebound4
Christian Urban <christian.urban@kcl.ac.uk>
parents: 396
diff changeset
   378
  apply(case_tac "nullable (erase r1)")
e1b74d618f1b updated Sizebound4
Christian Urban <christian.urban@kcl.ac.uk>
parents: 396
diff changeset
   379
  apply(simp)
e1b74d618f1b updated Sizebound4
Christian Urban <christian.urban@kcl.ac.uk>
parents: 396
diff changeset
   380
  apply(erule Prf_elims)
e1b74d618f1b updated Sizebound4
Christian Urban <christian.urban@kcl.ac.uk>
parents: 396
diff changeset
   381
  using Prf_elims(2) bnullable_correctness apply force
e1b74d618f1b updated Sizebound4
Christian Urban <christian.urban@kcl.ac.uk>
parents: 396
diff changeset
   382
  apply (simp add: bmkeps_retrieve bnullable_correctness retrieve_fuse2)
e1b74d618f1b updated Sizebound4
Christian Urban <christian.urban@kcl.ac.uk>
parents: 396
diff changeset
   383
  apply (simp add: bmkeps_retrieve bnullable_correctness retrieve_fuse2)
e1b74d618f1b updated Sizebound4
Christian Urban <christian.urban@kcl.ac.uk>
parents: 396
diff changeset
   384
  using Prf_elims(2) apply force
e1b74d618f1b updated Sizebound4
Christian Urban <christian.urban@kcl.ac.uk>
parents: 396
diff changeset
   385
  (* ASTAR case *)  
e1b74d618f1b updated Sizebound4
Christian Urban <christian.urban@kcl.ac.uk>
parents: 396
diff changeset
   386
  apply(rename_tac bs r v)
e1b74d618f1b updated Sizebound4
Christian Urban <christian.urban@kcl.ac.uk>
parents: 396
diff changeset
   387
  apply(simp)  
365
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   388
  apply(erule Prf_elims)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   389
  apply(clarify)
397
e1b74d618f1b updated Sizebound4
Christian Urban <christian.urban@kcl.ac.uk>
parents: 396
diff changeset
   390
  apply(erule Prf_elims)
e1b74d618f1b updated Sizebound4
Christian Urban <christian.urban@kcl.ac.uk>
parents: 396
diff changeset
   391
  apply(clarify)
e1b74d618f1b updated Sizebound4
Christian Urban <christian.urban@kcl.ac.uk>
parents: 396
diff changeset
   392
  by (simp add: retrieve_fuse2)
365
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   393
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   394
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   395
lemma MAIN_decode:
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   396
  assumes "\<Turnstile> v : ders s r"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   397
  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
   398
  using assms
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   399
proof (induct s arbitrary: v rule: rev_induct)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   400
  case Nil
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   401
  have "\<Turnstile> v : ders [] r" by fact
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   402
  then have "\<Turnstile> v : r" by simp
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   403
  then have "Some v = decode (retrieve (intern r) v) r"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   404
    using decode_code retrieve_code by auto
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   405
  then show "Some (flex r id [] v) = decode (retrieve (bders (intern r) []) v) r"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   406
    by simp
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   407
next
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   408
  case (snoc c s v)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   409
  have IH: "\<And>v. \<Turnstile> v : ders s r \<Longrightarrow> 
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   410
     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
   411
  have asm: "\<Turnstile> v : ders (s @ [c]) r" by fact
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   412
  then have asm2: "\<Turnstile> injval (ders s r) c v : ders s r" 
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   413
    by (simp add: Prf_injval ders_append)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   414
  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
   415
    by (simp add: flex_append)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   416
  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
   417
    using asm2 IH by simp
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   418
  also have "... = decode (retrieve (bder c (bders (intern r) s)) v) r"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   419
    using asm by (simp_all add: bder_retrieve ders_append)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   420
  finally show "Some (flex r id (s @ [c]) v) = 
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   421
                 decode (retrieve (bders (intern r) (s @ [c])) v) r" by (simp add: bders_append)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   422
qed
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   423
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   424
definition blexer where
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   425
 "blexer r s \<equiv> if bnullable (bders (intern r) s) then 
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   426
                decode (bmkeps (bders (intern r) s)) r else None"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   427
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   428
lemma blexer_correctness:
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   429
  shows "blexer r s = lexer r s"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   430
proof -
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   431
  { define bds where "bds \<equiv> bders (intern r) s"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   432
    define ds  where "ds \<equiv> ders s r"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   433
    assume asm: "nullable ds"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   434
    have era: "erase bds = ds" 
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   435
      unfolding ds_def bds_def by simp
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   436
    have mke: "\<Turnstile> mkeps ds : ds"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   437
      using asm by (simp add: mkeps_nullable)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   438
    have "decode (bmkeps bds) r = decode (retrieve bds (mkeps ds)) r"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   439
      using bmkeps_retrieve
393
3954579ebdaf polished
Christian Urban <christian.urban@kcl.ac.uk>
parents: 392
diff changeset
   440
      using asm era
3954579ebdaf polished
Christian Urban <christian.urban@kcl.ac.uk>
parents: 392
diff changeset
   441
      using bnullable_correctness by force 
365
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   442
    also have "... =  Some (flex r id s (mkeps ds))"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   443
      using mke by (simp_all add: MAIN_decode ds_def bds_def)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   444
    finally have "decode (bmkeps bds) r = Some (flex r id s (mkeps ds))" 
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   445
      unfolding bds_def ds_def .
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   446
  }
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   447
  then show "blexer r s = lexer r s"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   448
    unfolding blexer_def lexer_flex
393
3954579ebdaf polished
Christian Urban <christian.urban@kcl.ac.uk>
parents: 392
diff changeset
   449
    by (auto simp add: bnullable_correctness[symmetric])
365
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   450
qed
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   451
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   452
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   453
fun distinctBy :: "'a list \<Rightarrow> ('a \<Rightarrow> 'b) \<Rightarrow> 'b set \<Rightarrow> 'a list"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   454
  where
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   455
  "distinctBy [] f acc = []"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   456
| "distinctBy (x#xs) f acc = 
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   457
     (if (f x) \<in> acc then distinctBy xs f acc 
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   458
      else x # (distinctBy xs f ({f x} \<union> acc)))"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   459
402
1612f2a77bf6 more definitions in the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents: 400
diff changeset
   460
  
365
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   461
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   462
fun flts :: "arexp list \<Rightarrow> arexp list"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   463
  where 
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   464
  "flts [] = []"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   465
| "flts (AZERO # rs) = flts rs"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   466
| "flts ((AALTs bs  rs1) # rs) = (map (fuse bs) rs1) @ flts rs"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   467
| "flts (r1 # rs) = r1 # flts rs"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   468
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   469
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   470
fun bsimp_ASEQ :: "bit list \<Rightarrow> arexp \<Rightarrow> arexp \<Rightarrow> arexp"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   471
  where
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   472
  "bsimp_ASEQ _ AZERO _ = AZERO"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   473
| "bsimp_ASEQ _ _ AZERO = AZERO"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   474
| "bsimp_ASEQ bs1 (AONE bs2) r2 = fuse (bs1 @ bs2) r2"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   475
| "bsimp_ASEQ bs1 r1 r2 = ASEQ  bs1 r1 r2"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   476
393
3954579ebdaf polished
Christian Urban <christian.urban@kcl.ac.uk>
parents: 392
diff changeset
   477
lemma bsimp_ASEQ0[simp]:
3954579ebdaf polished
Christian Urban <christian.urban@kcl.ac.uk>
parents: 392
diff changeset
   478
  shows "bsimp_ASEQ bs r1 AZERO = AZERO"
3954579ebdaf polished
Christian Urban <christian.urban@kcl.ac.uk>
parents: 392
diff changeset
   479
  by (case_tac r1)(simp_all)
3954579ebdaf polished
Christian Urban <christian.urban@kcl.ac.uk>
parents: 392
diff changeset
   480
3954579ebdaf polished
Christian Urban <christian.urban@kcl.ac.uk>
parents: 392
diff changeset
   481
lemma bsimp_ASEQ1:
3954579ebdaf polished
Christian Urban <christian.urban@kcl.ac.uk>
parents: 392
diff changeset
   482
  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
   483
  shows "bsimp_ASEQ bs r1 r2 = ASEQ bs r1 r2"
3954579ebdaf polished
Christian Urban <christian.urban@kcl.ac.uk>
parents: 392
diff changeset
   484
  using assms
3954579ebdaf polished
Christian Urban <christian.urban@kcl.ac.uk>
parents: 392
diff changeset
   485
  apply(induct bs r1 r2 rule: bsimp_ASEQ.induct)
3954579ebdaf polished
Christian Urban <christian.urban@kcl.ac.uk>
parents: 392
diff changeset
   486
  apply(auto)
3954579ebdaf polished
Christian Urban <christian.urban@kcl.ac.uk>
parents: 392
diff changeset
   487
  done
3954579ebdaf polished
Christian Urban <christian.urban@kcl.ac.uk>
parents: 392
diff changeset
   488
3954579ebdaf polished
Christian Urban <christian.urban@kcl.ac.uk>
parents: 392
diff changeset
   489
lemma bsimp_ASEQ2[simp]:
3954579ebdaf polished
Christian Urban <christian.urban@kcl.ac.uk>
parents: 392
diff changeset
   490
  shows "bsimp_ASEQ bs1 (AONE bs2) r2 = fuse (bs1 @ bs2) r2"
3954579ebdaf polished
Christian Urban <christian.urban@kcl.ac.uk>
parents: 392
diff changeset
   491
  by (case_tac r2) (simp_all)
3954579ebdaf polished
Christian Urban <christian.urban@kcl.ac.uk>
parents: 392
diff changeset
   492
365
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   493
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   494
fun bsimp_AALTs :: "bit list \<Rightarrow> arexp list \<Rightarrow> arexp"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   495
  where
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   496
  "bsimp_AALTs _ [] = AZERO"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   497
| "bsimp_AALTs bs1 [r] = fuse bs1 r"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   498
| "bsimp_AALTs bs1 rs = AALTs bs1 rs"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   499
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   500
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   501
fun bsimp :: "arexp \<Rightarrow> arexp" 
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   502
  where
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   503
  "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
   504
| "bsimp (AALTs bs1 rs) = bsimp_AALTs bs1 (distinctBy (flts (map bsimp rs)) erase {}) "
365
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   505
| "bsimp r = r"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   506
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   507
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   508
fun 
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   509
  bders_simp :: "arexp \<Rightarrow> string \<Rightarrow> arexp"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   510
where
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   511
  "bders_simp r [] = r"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   512
| "bders_simp r (c # s) = bders_simp (bsimp (bder c r)) s"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   513
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   514
definition blexer_simp where
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   515
 "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
   516
                    decode (bmkeps (bders_simp (intern r) s)) r else None"
365
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   517
393
3954579ebdaf polished
Christian Urban <christian.urban@kcl.ac.uk>
parents: 392
diff changeset
   518
365
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   519
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   520
lemma bders_simp_append:
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   521
  shows "bders_simp r (s1 @ s2) = bders_simp (bders_simp r s1) s2"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   522
  apply(induct s1 arbitrary: r s2)
374
98362002c818 slightly more
Christian Urban <christian.urban@kcl.ac.uk>
parents: 373
diff changeset
   523
  apply(simp_all)
365
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   524
  done
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   525
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   526
393
3954579ebdaf polished
Christian Urban <christian.urban@kcl.ac.uk>
parents: 392
diff changeset
   527
lemma bmkeps_fuse:
365
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   528
  assumes "bnullable r"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   529
  shows "bmkeps (fuse bs r) = bs @ bmkeps r"
398
dac6d27c99c6 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 397
diff changeset
   530
  using assms
dac6d27c99c6 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 397
diff changeset
   531
  by (metis bmkeps_retrieve bnullable_correctness erase_fuse mkeps_nullable retrieve_fuse2)
393
3954579ebdaf polished
Christian Urban <christian.urban@kcl.ac.uk>
parents: 392
diff changeset
   532
3954579ebdaf polished
Christian Urban <christian.urban@kcl.ac.uk>
parents: 392
diff changeset
   533
lemma bmkepss_fuse: 
3954579ebdaf polished
Christian Urban <christian.urban@kcl.ac.uk>
parents: 392
diff changeset
   534
  assumes "bnullables rs"
3954579ebdaf polished
Christian Urban <christian.urban@kcl.ac.uk>
parents: 392
diff changeset
   535
  shows "bmkepss (map (fuse bs) rs) = bs @ bmkepss rs"
3954579ebdaf polished
Christian Urban <christian.urban@kcl.ac.uk>
parents: 392
diff changeset
   536
  using assms
3954579ebdaf polished
Christian Urban <christian.urban@kcl.ac.uk>
parents: 392
diff changeset
   537
  apply(induct rs arbitrary: bs)
3954579ebdaf polished
Christian Urban <christian.urban@kcl.ac.uk>
parents: 392
diff changeset
   538
  apply(auto simp add: bmkeps_fuse bnullable_fuse)
3954579ebdaf polished
Christian Urban <christian.urban@kcl.ac.uk>
parents: 392
diff changeset
   539
  done
365
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   540
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   541
lemma bder_fuse:
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   542
  shows "bder c (fuse bs a) = fuse bs  (bder c a)"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   543
  apply(induct a arbitrary: bs c)
398
dac6d27c99c6 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 397
diff changeset
   544
  apply(simp_all)
365
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   545
  done
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   546
385
c80720289645 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 381
diff changeset
   547
c80720289645 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 381
diff changeset
   548
c80720289645 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 381
diff changeset
   549
381
0c666a0c57d7 isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents: 379
diff changeset
   550
inductive 
0c666a0c57d7 isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents: 379
diff changeset
   551
  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
   552
and 
8194086c2a8a simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents: 385
diff changeset
   553
  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
   554
where
392
8194086c2a8a simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents: 385
diff changeset
   555
  bs1: "ASEQ bs AZERO r2 \<leadsto> AZERO"
8194086c2a8a simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents: 385
diff changeset
   556
| bs2: "ASEQ bs r1 AZERO \<leadsto> AZERO"
8194086c2a8a simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents: 385
diff changeset
   557
| 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
   558
| 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
   559
| 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
   560
| bs6: "AALTs bs [] \<leadsto> AZERO"
8194086c2a8a simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents: 385
diff changeset
   561
| bs7: "AALTs bs [r] \<leadsto> fuse bs r"
398
dac6d27c99c6 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 397
diff changeset
   562
| bs8: "rs1 s\<leadsto> rs2 \<Longrightarrow> AALTs bs rs1 \<leadsto> AALTs bs rs2"
407
d73b722efe0e updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 405
diff changeset
   563
(*| ss1:  "[] s\<leadsto> []"*)
392
8194086c2a8a simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents: 385
diff changeset
   564
| 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
   565
| 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
   566
| ss4:  "(AZERO # rs) s\<leadsto> rs"
8194086c2a8a simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents: 385
diff changeset
   567
| ss5:  "(AALTs bs1 rs1 # rsb) s\<leadsto> ((map (fuse bs1) rs1) @ rsb)"
416
57182b36ec01 more with the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents: 411
diff changeset
   568
| ss6:  "L(erase a2) \<subseteq> L(erase a1) \<Longrightarrow> (rsa@[a1]@rsb@[a2]@rsc) s\<leadsto> (rsa@[a1]@rsb@rsc)"
57182b36ec01 more with the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents: 411
diff changeset
   569
(*| extra: "bnullable r1 \<Longrightarrow> ASEQ bs0 (ASEQ bs1 r1 r2) r3 \<leadsto>
57182b36ec01 more with the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents: 411
diff changeset
   570
            ASEQ (bs0 @ bs1) r1 (ASEQ [] r2 r3)"
57182b36ec01 more with the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents: 411
diff changeset
   571
*)
393
3954579ebdaf polished
Christian Urban <christian.urban@kcl.ac.uk>
parents: 392
diff changeset
   572
381
0c666a0c57d7 isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents: 379
diff changeset
   573
inductive 
0c666a0c57d7 isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents: 379
diff changeset
   574
  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
   575
where 
0c666a0c57d7 isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents: 379
diff changeset
   576
  rs1[intro, simp]:"r \<leadsto>* r"
365
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   577
| rs2[intro]: "\<lbrakk>r1 \<leadsto>* r2; r2 \<leadsto> r3\<rbrakk> \<Longrightarrow> r1 \<leadsto>* r3"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   578
381
0c666a0c57d7 isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents: 379
diff changeset
   579
inductive 
392
8194086c2a8a simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents: 385
diff changeset
   580
  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
   581
where 
8194086c2a8a simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents: 385
diff changeset
   582
  sss1[intro, simp]:"rs s\<leadsto>* rs"
8194086c2a8a simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents: 385
diff changeset
   583
| 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
   584
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   585
393
3954579ebdaf polished
Christian Urban <christian.urban@kcl.ac.uk>
parents: 392
diff changeset
   586
lemma r_in_rstar: 
3954579ebdaf polished
Christian Urban <christian.urban@kcl.ac.uk>
parents: 392
diff changeset
   587
  shows "r1 \<leadsto> r2 \<Longrightarrow> r1 \<leadsto>* r2"
3954579ebdaf polished
Christian Urban <christian.urban@kcl.ac.uk>
parents: 392
diff changeset
   588
  using rrewrites.intros(1) rrewrites.intros(2) by blast
3954579ebdaf polished
Christian Urban <christian.urban@kcl.ac.uk>
parents: 392
diff changeset
   589
416
57182b36ec01 more with the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents: 411
diff changeset
   590
lemma rs_in_rstar: 
57182b36ec01 more with the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents: 411
diff changeset
   591
  shows "r1 s\<leadsto> r2 \<Longrightarrow> r1 s\<leadsto>* r2"
57182b36ec01 more with the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents: 411
diff changeset
   592
  using rrewrites.intros(1) rrewrites.intros(2) by blast
57182b36ec01 more with the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents: 411
diff changeset
   593
392
8194086c2a8a simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents: 385
diff changeset
   594
lemma rrewrites_trans[trans]: 
365
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   595
  assumes a1: "r1 \<leadsto>* r2"  and a2: "r2 \<leadsto>* r3"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   596
  shows "r1 \<leadsto>* r3"
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   597
  using a2 a1
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   598
  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
   599
  apply(auto)
365
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   600
  done
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   601
392
8194086c2a8a simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents: 385
diff changeset
   602
lemma srewrites_trans[trans]: 
8194086c2a8a simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents: 385
diff changeset
   603
  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
   604
  shows "r1 s\<leadsto>* r3"
8194086c2a8a simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents: 385
diff changeset
   605
  using a1 a2
8194086c2a8a simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents: 385
diff changeset
   606
  apply(induct r1 r2 arbitrary: r3 rule: srewrites.induct) 
8194086c2a8a simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents: 385
diff changeset
   607
   apply(auto)
8194086c2a8a simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents: 385
diff changeset
   608
  done
365
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   609
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   610
392
8194086c2a8a simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents: 385
diff changeset
   611
8194086c2a8a simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents: 385
diff changeset
   612
lemma contextrewrites0: 
8194086c2a8a simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents: 385
diff changeset
   613
  "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
   614
  apply(induct rs1 rs2 rule: srewrites.inducts)
8194086c2a8a simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents: 385
diff changeset
   615
   apply simp
398
dac6d27c99c6 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 397
diff changeset
   616
  using bs8 r_in_rstar rrewrites_trans by blast
392
8194086c2a8a simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents: 385
diff changeset
   617
8194086c2a8a simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents: 385
diff changeset
   618
lemma contextrewrites1: 
393
3954579ebdaf polished
Christian Urban <christian.urban@kcl.ac.uk>
parents: 392
diff changeset
   619
  "r \<leadsto>* r' \<Longrightarrow> AALTs bs (r # rs) \<leadsto>* AALTs bs (r' # rs)"
392
8194086c2a8a simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents: 385
diff changeset
   620
  apply(induct r r' rule: rrewrites.induct)
8194086c2a8a simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents: 385
diff changeset
   621
   apply simp
398
dac6d27c99c6 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 397
diff changeset
   622
  using bs8 ss3 by blast
392
8194086c2a8a simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents: 385
diff changeset
   623
8194086c2a8a simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents: 385
diff changeset
   624
lemma srewrite1: 
8194086c2a8a simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents: 385
diff changeset
   625
  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
   626
  apply(induct rs)
8194086c2a8a simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents: 385
diff changeset
   627
   apply(auto)
8194086c2a8a simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents: 385
diff changeset
   628
  using ss2 by auto
8194086c2a8a simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents: 385
diff changeset
   629
8194086c2a8a simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents: 385
diff changeset
   630
lemma srewrites1: 
8194086c2a8a simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents: 385
diff changeset
   631
  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
   632
  apply(induct rs1 rs2 rule: srewrites.induct)
8194086c2a8a simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents: 385
diff changeset
   633
   apply(auto)
8194086c2a8a simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents: 385
diff changeset
   634
  using srewrite1 by blast
365
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   635
392
8194086c2a8a simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents: 385
diff changeset
   636
lemma srewrite2: 
8194086c2a8a simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents: 385
diff changeset
   637
  shows  "r1 \<leadsto> r2 \<Longrightarrow> True"
8194086c2a8a simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents: 385
diff changeset
   638
  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
   639
  apply(induct rule: rrewrite_srewrite.inducts)
398
dac6d27c99c6 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 397
diff changeset
   640
  apply(auto)
dac6d27c99c6 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 397
diff changeset
   641
  apply (metis append_Cons append_Nil srewrites1)
dac6d27c99c6 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 397
diff changeset
   642
  apply(meson srewrites.simps ss3)
392
8194086c2a8a simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents: 385
diff changeset
   643
  apply (meson srewrites.simps ss4)
8194086c2a8a simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents: 385
diff changeset
   644
  apply (meson srewrites.simps ss5)
8194086c2a8a simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents: 385
diff changeset
   645
  by (metis append_Cons append_Nil srewrites.simps ss6)
8194086c2a8a simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents: 385
diff changeset
   646
  
8194086c2a8a simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents: 385
diff changeset
   647
8194086c2a8a simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents: 385
diff changeset
   648
lemma srewrites3: 
8194086c2a8a simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents: 385
diff changeset
   649
  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
   650
  apply(induct rs1 rs2 arbitrary: rs rule: srewrites.induct)
8194086c2a8a simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents: 385
diff changeset
   651
   apply(auto)
8194086c2a8a simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents: 385
diff changeset
   652
  by (meson srewrite2(2) srewrites_trans)
365
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   653
392
8194086c2a8a simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents: 385
diff changeset
   654
(*
8194086c2a8a simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents: 385
diff changeset
   655
lemma srewrites4:
8194086c2a8a simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents: 385
diff changeset
   656
  assumes "rs3 s\<leadsto>* rs4" "rs1 s\<leadsto>* rs2" 
8194086c2a8a simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents: 385
diff changeset
   657
  shows "(rs1 @ rs3) s\<leadsto>* (rs2 @ rs4)"
8194086c2a8a simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents: 385
diff changeset
   658
  using assms
8194086c2a8a simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents: 385
diff changeset
   659
  apply(induct rs3 rs4 arbitrary: rs1 rs2 rule: srewrites.induct)
8194086c2a8a simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents: 385
diff changeset
   660
  apply (simp add: srewrites3)
8194086c2a8a simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents: 385
diff changeset
   661
  using srewrite1 by blast
8194086c2a8a simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents: 385
diff changeset
   662
*)
8194086c2a8a simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents: 385
diff changeset
   663
8194086c2a8a simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents: 385
diff changeset
   664
lemma srewrites6:
8194086c2a8a simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents: 385
diff changeset
   665
  assumes "r1 \<leadsto>* r2" 
8194086c2a8a simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents: 385
diff changeset
   666
  shows "[r1] s\<leadsto>* [r2]"
8194086c2a8a simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents: 385
diff changeset
   667
  using assms
8194086c2a8a simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents: 385
diff changeset
   668
  apply(induct r1 r2 rule: rrewrites.induct)
398
dac6d27c99c6 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 397
diff changeset
   669
  apply(auto)
392
8194086c2a8a simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents: 385
diff changeset
   670
  by (meson srewrites.simps srewrites_trans ss3)
8194086c2a8a simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents: 385
diff changeset
   671
8194086c2a8a simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents: 385
diff changeset
   672
lemma srewrites7:
8194086c2a8a simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents: 385
diff changeset
   673
  assumes "rs3 s\<leadsto>* rs4" "r1 \<leadsto>* r2" 
8194086c2a8a simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents: 385
diff changeset
   674
  shows "(r1 # rs3) s\<leadsto>* (r2 # rs4)"
8194086c2a8a simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents: 385
diff changeset
   675
  using assms
398
dac6d27c99c6 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 397
diff changeset
   676
  by (smt (verit, del_insts) append.simps srewrites1 srewrites3 srewrites6 srewrites_trans)
dac6d27c99c6 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 397
diff changeset
   677
  
393
3954579ebdaf polished
Christian Urban <christian.urban@kcl.ac.uk>
parents: 392
diff changeset
   678
lemma ss6_stronger_aux:
3954579ebdaf polished
Christian Urban <christian.urban@kcl.ac.uk>
parents: 392
diff changeset
   679
  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
   680
  apply(induct rs2 arbitrary: rs1)
3954579ebdaf polished
Christian Urban <christian.urban@kcl.ac.uk>
parents: 392
diff changeset
   681
   apply(auto)
416
57182b36ec01 more with the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents: 411
diff changeset
   682
  prefer 2
393
3954579ebdaf polished
Christian Urban <christian.urban@kcl.ac.uk>
parents: 392
diff changeset
   683
  apply(drule_tac x="rs1 @ [a]" in meta_spec)
416
57182b36ec01 more with the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents: 411
diff changeset
   684
   apply(simp)
57182b36ec01 more with the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents: 411
diff changeset
   685
  apply(drule_tac x="rs1" in meta_spec)
57182b36ec01 more with the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents: 411
diff changeset
   686
  apply(subgoal_tac "(rs1 @ a # rs2) s\<leadsto>* (rs1 @ rs2)")
57182b36ec01 more with the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents: 411
diff changeset
   687
  using srewrites_trans apply blast
57182b36ec01 more with the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents: 411
diff changeset
   688
   apply(subgoal_tac "\<exists>rs1a rs1b. rs1 = rs1a @ [x] @ rs1b")
57182b36ec01 more with the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents: 411
diff changeset
   689
    prefer 2
57182b36ec01 more with the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents: 411
diff changeset
   690
  apply (simp add: split_list)
57182b36ec01 more with the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents: 411
diff changeset
   691
  apply(erule exE)+
393
3954579ebdaf polished
Christian Urban <christian.urban@kcl.ac.uk>
parents: 392
diff changeset
   692
  apply(simp)
416
57182b36ec01 more with the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents: 411
diff changeset
   693
  using ss6[simplified]
57182b36ec01 more with the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents: 411
diff changeset
   694
  using rs_in_rstar by force
393
3954579ebdaf polished
Christian Urban <christian.urban@kcl.ac.uk>
parents: 392
diff changeset
   695
3954579ebdaf polished
Christian Urban <christian.urban@kcl.ac.uk>
parents: 392
diff changeset
   696
lemma ss6_stronger:
425
14c558ae0b09 updated paper
Christian Urban <christian.urban@kcl.ac.uk>
parents: 420
diff changeset
   697
  shows "rs s\<leadsto>* distinctBy rs erase {}"
393
3954579ebdaf polished
Christian Urban <christian.urban@kcl.ac.uk>
parents: 392
diff changeset
   698
  using ss6_stronger_aux[of "[]" _] by auto
3954579ebdaf polished
Christian Urban <christian.urban@kcl.ac.uk>
parents: 392
diff changeset
   699
3954579ebdaf polished
Christian Urban <christian.urban@kcl.ac.uk>
parents: 392
diff changeset
   700
lemma rewrite_preserves_fuse: 
3954579ebdaf polished
Christian Urban <christian.urban@kcl.ac.uk>
parents: 392
diff changeset
   701
  shows "r2 \<leadsto> r3 \<Longrightarrow> fuse bs r2 \<leadsto> fuse bs r3"
398
dac6d27c99c6 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 397
diff changeset
   702
  and   "rs2 s\<leadsto> rs3 \<Longrightarrow> map (fuse bs) rs2 s\<leadsto> map (fuse bs) rs3"
393
3954579ebdaf polished
Christian Urban <christian.urban@kcl.ac.uk>
parents: 392
diff changeset
   703
proof(induct rule: rrewrite_srewrite.inducts)
3954579ebdaf polished
Christian Urban <christian.urban@kcl.ac.uk>
parents: 392
diff changeset
   704
  case (bs3 bs1 bs2 r)
398
dac6d27c99c6 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 397
diff changeset
   705
  then show "fuse bs (ASEQ bs1 (AONE bs2) r) \<leadsto> fuse bs (fuse (bs1 @ bs2) r)"
393
3954579ebdaf polished
Christian Urban <christian.urban@kcl.ac.uk>
parents: 392
diff changeset
   706
    by (metis fuse.simps(5) fuse_append rrewrite_srewrite.bs3) 
3954579ebdaf polished
Christian Urban <christian.urban@kcl.ac.uk>
parents: 392
diff changeset
   707
next
398
dac6d27c99c6 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 397
diff changeset
   708
  case (bs7 bs1 r)
dac6d27c99c6 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 397
diff changeset
   709
  then show "fuse bs (AALTs bs1 [r]) \<leadsto> fuse bs (fuse bs1 r)"
393
3954579ebdaf polished
Christian Urban <christian.urban@kcl.ac.uk>
parents: 392
diff changeset
   710
    by (metis fuse.simps(4) fuse_append rrewrite_srewrite.bs7) 
3954579ebdaf polished
Christian Urban <christian.urban@kcl.ac.uk>
parents: 392
diff changeset
   711
next
3954579ebdaf polished
Christian Urban <christian.urban@kcl.ac.uk>
parents: 392
diff changeset
   712
  case (ss2 rs1 rs2 r)
398
dac6d27c99c6 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 397
diff changeset
   713
  then show "map (fuse bs) (r # rs1) s\<leadsto> map (fuse bs) (r # rs2)"
dac6d27c99c6 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 397
diff changeset
   714
    by (simp add: rrewrite_srewrite.ss2)
393
3954579ebdaf polished
Christian Urban <christian.urban@kcl.ac.uk>
parents: 392
diff changeset
   715
next
3954579ebdaf polished
Christian Urban <christian.urban@kcl.ac.uk>
parents: 392
diff changeset
   716
  case (ss3 r1 r2 rs)
398
dac6d27c99c6 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 397
diff changeset
   717
  then show "map (fuse bs) (r1 # rs) s\<leadsto> map (fuse bs) (r2 # rs)"
dac6d27c99c6 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 397
diff changeset
   718
    by (simp add: rrewrite_srewrite.ss3)
393
3954579ebdaf polished
Christian Urban <christian.urban@kcl.ac.uk>
parents: 392
diff changeset
   719
next
3954579ebdaf polished
Christian Urban <christian.urban@kcl.ac.uk>
parents: 392
diff changeset
   720
  case (ss5 bs1 rs1 rsb)
398
dac6d27c99c6 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 397
diff changeset
   721
  have "map (fuse bs) (AALTs bs1 rs1 # rsb) = AALTs (bs @ bs1) rs1 # (map (fuse bs) rsb)" by simp
dac6d27c99c6 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 397
diff changeset
   722
  also have "... s\<leadsto> ((map (fuse (bs @ bs1)) rs1) @ (map (fuse bs) rsb))"
dac6d27c99c6 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 397
diff changeset
   723
    by (simp add: rrewrite_srewrite.ss5)  
dac6d27c99c6 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 397
diff changeset
   724
  finally show "map (fuse bs) (AALTs bs1 rs1 # rsb) s\<leadsto> map (fuse bs) (map (fuse bs1) rs1 @ rsb)"
dac6d27c99c6 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 397
diff changeset
   725
    by (simp add: comp_def fuse_append)
393
3954579ebdaf polished
Christian Urban <christian.urban@kcl.ac.uk>
parents: 392
diff changeset
   726
next
416
57182b36ec01 more with the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents: 411
diff changeset
   727
  case (ss6 a2 a1 rsa rsb rsc)
57182b36ec01 more with the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents: 411
diff changeset
   728
  have "L (erase a2) \<subseteq> L (erase a1)" by fact
398
dac6d27c99c6 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 397
diff changeset
   729
  then show "map (fuse bs) (rsa @ [a1] @ rsb @ [a2] @ rsc) s\<leadsto> map (fuse bs) (rsa @ [a1] @ rsb @ rsc)"
393
3954579ebdaf polished
Christian Urban <christian.urban@kcl.ac.uk>
parents: 392
diff changeset
   730
    apply(simp)
3954579ebdaf polished
Christian Urban <christian.urban@kcl.ac.uk>
parents: 392
diff changeset
   731
    apply(rule rrewrite_srewrite.ss6[simplified])
3954579ebdaf polished
Christian Urban <christian.urban@kcl.ac.uk>
parents: 392
diff changeset
   732
    apply(simp add: erase_fuse)
3954579ebdaf polished
Christian Urban <christian.urban@kcl.ac.uk>
parents: 392
diff changeset
   733
    done
416
57182b36ec01 more with the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents: 411
diff changeset
   734
(*next 
57182b36ec01 more with the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents: 411
diff changeset
   735
  case (extra bs0 bs1 r1 r2 r3)
57182b36ec01 more with the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents: 411
diff changeset
   736
  then show ?case
57182b36ec01 more with the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents: 411
diff changeset
   737
    by (metis append_assoc fuse.simps(5) rrewrite_srewrite.extra)*)
397
e1b74d618f1b updated Sizebound4
Christian Urban <christian.urban@kcl.ac.uk>
parents: 396
diff changeset
   738
qed (auto intro: rrewrite_srewrite.intros)
393
3954579ebdaf polished
Christian Urban <christian.urban@kcl.ac.uk>
parents: 392
diff changeset
   739
3954579ebdaf polished
Christian Urban <christian.urban@kcl.ac.uk>
parents: 392
diff changeset
   740
lemma rewrites_fuse:  
3954579ebdaf polished
Christian Urban <christian.urban@kcl.ac.uk>
parents: 392
diff changeset
   741
  assumes "r1 \<leadsto>* r2"
3954579ebdaf polished
Christian Urban <christian.urban@kcl.ac.uk>
parents: 392
diff changeset
   742
  shows "fuse bs r1 \<leadsto>* fuse bs r2"
3954579ebdaf polished
Christian Urban <christian.urban@kcl.ac.uk>
parents: 392
diff changeset
   743
using assms
3954579ebdaf polished
Christian Urban <christian.urban@kcl.ac.uk>
parents: 392
diff changeset
   744
apply(induction r1 r2 arbitrary: bs rule: rrewrites.induct)
398
dac6d27c99c6 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 397
diff changeset
   745
apply(auto intro: rewrite_preserves_fuse)
393
3954579ebdaf polished
Christian Urban <christian.urban@kcl.ac.uk>
parents: 392
diff changeset
   746
done
365
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   747
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   748
374
98362002c818 slightly more
Christian Urban <christian.urban@kcl.ac.uk>
parents: 373
diff changeset
   749
lemma star_seq:  
98362002c818 slightly more
Christian Urban <christian.urban@kcl.ac.uk>
parents: 373
diff changeset
   750
  assumes "r1 \<leadsto>* r2"
98362002c818 slightly more
Christian Urban <christian.urban@kcl.ac.uk>
parents: 373
diff changeset
   751
  shows "ASEQ bs r1 r3 \<leadsto>* ASEQ bs r2 r3"
98362002c818 slightly more
Christian Urban <christian.urban@kcl.ac.uk>
parents: 373
diff changeset
   752
using assms
98362002c818 slightly more
Christian Urban <christian.urban@kcl.ac.uk>
parents: 373
diff changeset
   753
apply(induct r1 r2 arbitrary: r3 rule: rrewrites.induct)
392
8194086c2a8a simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents: 385
diff changeset
   754
apply(auto intro: rrewrite_srewrite.intros)
374
98362002c818 slightly more
Christian Urban <christian.urban@kcl.ac.uk>
parents: 373
diff changeset
   755
done
365
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   756
374
98362002c818 slightly more
Christian Urban <christian.urban@kcl.ac.uk>
parents: 373
diff changeset
   757
lemma star_seq2:  
98362002c818 slightly more
Christian Urban <christian.urban@kcl.ac.uk>
parents: 373
diff changeset
   758
  assumes "r3 \<leadsto>* r4"
98362002c818 slightly more
Christian Urban <christian.urban@kcl.ac.uk>
parents: 373
diff changeset
   759
  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
   760
  using assms
374
98362002c818 slightly more
Christian Urban <christian.urban@kcl.ac.uk>
parents: 373
diff changeset
   761
apply(induct r3 r4 arbitrary: r1 rule: rrewrites.induct)
392
8194086c2a8a simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents: 385
diff changeset
   762
apply(auto intro: rrewrite_srewrite.intros)
374
98362002c818 slightly more
Christian Urban <christian.urban@kcl.ac.uk>
parents: 373
diff changeset
   763
done
365
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   764
374
98362002c818 slightly more
Christian Urban <christian.urban@kcl.ac.uk>
parents: 373
diff changeset
   765
lemma continuous_rewrite: 
98362002c818 slightly more
Christian Urban <christian.urban@kcl.ac.uk>
parents: 373
diff changeset
   766
  assumes "r1 \<leadsto>* AZERO"
98362002c818 slightly more
Christian Urban <christian.urban@kcl.ac.uk>
parents: 373
diff changeset
   767
  shows "ASEQ bs1 r1 r2 \<leadsto>* AZERO"
392
8194086c2a8a simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents: 385
diff changeset
   768
using assms bs1 star_seq by blast
365
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   769
393
3954579ebdaf polished
Christian Urban <christian.urban@kcl.ac.uk>
parents: 392
diff changeset
   770
(*
3954579ebdaf polished
Christian Urban <christian.urban@kcl.ac.uk>
parents: 392
diff changeset
   771
lemma continuous_rewrite2: 
3954579ebdaf polished
Christian Urban <christian.urban@kcl.ac.uk>
parents: 392
diff changeset
   772
  assumes "r1 \<leadsto>* AONE bs"
3954579ebdaf polished
Christian Urban <christian.urban@kcl.ac.uk>
parents: 392
diff changeset
   773
  shows "ASEQ bs1 r1 r2 \<leadsto>* (fuse (bs1 @ bs) r2)"
3954579ebdaf polished
Christian Urban <christian.urban@kcl.ac.uk>
parents: 392
diff changeset
   774
  using assms  by (meson bs3 rrewrites.simps star_seq)
3954579ebdaf polished
Christian Urban <christian.urban@kcl.ac.uk>
parents: 392
diff changeset
   775
*)
365
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   776
374
98362002c818 slightly more
Christian Urban <christian.urban@kcl.ac.uk>
parents: 373
diff changeset
   777
lemma bsimp_aalts_simpcases: 
98362002c818 slightly more
Christian Urban <christian.urban@kcl.ac.uk>
parents: 373
diff changeset
   778
  shows "AONE bs \<leadsto>* bsimp (AONE bs)"  
98362002c818 slightly more
Christian Urban <christian.urban@kcl.ac.uk>
parents: 373
diff changeset
   779
  and   "AZERO \<leadsto>* bsimp AZERO" 
98362002c818 slightly more
Christian Urban <christian.urban@kcl.ac.uk>
parents: 373
diff changeset
   780
  and   "ACHAR bs c \<leadsto>* bsimp (ACHAR bs c)"
98362002c818 slightly more
Christian Urban <christian.urban@kcl.ac.uk>
parents: 373
diff changeset
   781
  by (simp_all)
365
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   782
393
3954579ebdaf polished
Christian Urban <christian.urban@kcl.ac.uk>
parents: 392
diff changeset
   783
lemma bsimp_AALTs_rewrites: 
3954579ebdaf polished
Christian Urban <christian.urban@kcl.ac.uk>
parents: 392
diff changeset
   784
  shows "AALTs bs1 rs \<leadsto>* bsimp_AALTs bs1 rs"
3954579ebdaf polished
Christian Urban <christian.urban@kcl.ac.uk>
parents: 392
diff changeset
   785
  by (smt (verit) bs6 bs7 bsimp_AALTs.elims rrewrites.simps)
385
c80720289645 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 381
diff changeset
   786
c80720289645 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 381
diff changeset
   787
lemma trivialbsimp_srewrites: 
398
dac6d27c99c6 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 397
diff changeset
   788
  assumes "\<And>x. x \<in> set rs \<Longrightarrow> x \<leadsto>* f x"
dac6d27c99c6 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 397
diff changeset
   789
  shows "rs s\<leadsto>* (map f rs)"
dac6d27c99c6 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 397
diff changeset
   790
using assms
365
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   791
  apply(induction rs)
398
dac6d27c99c6 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 397
diff changeset
   792
  apply(simp_all add: srewrites7)
dac6d27c99c6 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 397
diff changeset
   793
  done
392
8194086c2a8a simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents: 385
diff changeset
   794
393
3954579ebdaf polished
Christian Urban <christian.urban@kcl.ac.uk>
parents: 392
diff changeset
   795
lemma fltsfrewrites: "rs s\<leadsto>* flts rs"
3954579ebdaf polished
Christian Urban <christian.urban@kcl.ac.uk>
parents: 392
diff changeset
   796
  apply(induction rs rule: flts.induct)
3954579ebdaf polished
Christian Urban <christian.urban@kcl.ac.uk>
parents: 392
diff changeset
   797
  apply(auto intro: rrewrite_srewrite.intros)
3954579ebdaf polished
Christian Urban <christian.urban@kcl.ac.uk>
parents: 392
diff changeset
   798
  apply (meson srewrites.simps srewrites1 ss5)
3954579ebdaf polished
Christian Urban <christian.urban@kcl.ac.uk>
parents: 392
diff changeset
   799
  using rs1 srewrites7 apply presburger
3954579ebdaf polished
Christian Urban <christian.urban@kcl.ac.uk>
parents: 392
diff changeset
   800
  using srewrites7 apply force
3954579ebdaf polished
Christian Urban <christian.urban@kcl.ac.uk>
parents: 392
diff changeset
   801
  apply (simp add: srewrites7)
3954579ebdaf polished
Christian Urban <christian.urban@kcl.ac.uk>
parents: 392
diff changeset
   802
  by (simp add: srewrites7)
365
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   803
393
3954579ebdaf polished
Christian Urban <christian.urban@kcl.ac.uk>
parents: 392
diff changeset
   804
lemma bnullable0:
3954579ebdaf polished
Christian Urban <christian.urban@kcl.ac.uk>
parents: 392
diff changeset
   805
shows "r1 \<leadsto> r2 \<Longrightarrow> bnullable r1 = bnullable r2" 
3954579ebdaf polished
Christian Urban <christian.urban@kcl.ac.uk>
parents: 392
diff changeset
   806
  and "rs1 s\<leadsto> rs2 \<Longrightarrow> bnullables rs1 = bnullables rs2" 
3954579ebdaf polished
Christian Urban <christian.urban@kcl.ac.uk>
parents: 392
diff changeset
   807
  apply(induct rule: rrewrite_srewrite.inducts)
3954579ebdaf polished
Christian Urban <christian.urban@kcl.ac.uk>
parents: 392
diff changeset
   808
  apply(auto simp add:  bnullable_fuse)
416
57182b36ec01 more with the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents: 411
diff changeset
   809
   apply (meson UnCI bnullable_fuse imageI)
57182b36ec01 more with the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents: 411
diff changeset
   810
  
57182b36ec01 more with the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents: 411
diff changeset
   811
  using bnullable_correctness nullable_correctness by blast
392
8194086c2a8a simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents: 385
diff changeset
   812
373
320f923c77b9 slightly
Christian Urban <christian.urban@kcl.ac.uk>
parents: 365
diff changeset
   813
396
cc8e231529fb added ITP paper
Christian Urban <christian.urban@kcl.ac.uk>
parents: 393
diff changeset
   814
lemma rewrites_bnullable_eq: 
393
3954579ebdaf polished
Christian Urban <christian.urban@kcl.ac.uk>
parents: 392
diff changeset
   815
  assumes "r1 \<leadsto>* r2" 
3954579ebdaf polished
Christian Urban <christian.urban@kcl.ac.uk>
parents: 392
diff changeset
   816
  shows "bnullable r1 = bnullable r2"
3954579ebdaf polished
Christian Urban <christian.urban@kcl.ac.uk>
parents: 392
diff changeset
   817
using assms 
365
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   818
  apply(induction r1 r2 rule: rrewrites.induct)
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   819
  apply simp
393
3954579ebdaf polished
Christian Urban <christian.urban@kcl.ac.uk>
parents: 392
diff changeset
   820
  using bnullable0(1) by auto
365
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   821
381
0c666a0c57d7 isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents: 379
diff changeset
   822
lemma rewrite_bmkeps_aux: 
396
cc8e231529fb added ITP paper
Christian Urban <christian.urban@kcl.ac.uk>
parents: 393
diff changeset
   823
  shows "r1 \<leadsto> r2 \<Longrightarrow> bnullable r1 \<Longrightarrow> bmkeps r1 = bmkeps r2"
cc8e231529fb added ITP paper
Christian Urban <christian.urban@kcl.ac.uk>
parents: 393
diff changeset
   824
  and   "rs1 s\<leadsto> rs2 \<Longrightarrow> bnullables rs1 \<Longrightarrow> bmkepss rs1 = bmkepss rs2" 
392
8194086c2a8a simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents: 385
diff changeset
   825
proof (induct rule: rrewrite_srewrite.inducts)
8194086c2a8a simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents: 385
diff changeset
   826
  case (bs3 bs1 bs2 r)
396
cc8e231529fb added ITP paper
Christian Urban <christian.urban@kcl.ac.uk>
parents: 393
diff changeset
   827
  have IH2: "bnullable (ASEQ bs1 (AONE bs2) r)" by fact
cc8e231529fb added ITP paper
Christian Urban <christian.urban@kcl.ac.uk>
parents: 393
diff changeset
   828
  then show "bmkeps (ASEQ bs1 (AONE bs2) r) = bmkeps (fuse (bs1 @ bs2) r)"
cc8e231529fb added ITP paper
Christian Urban <christian.urban@kcl.ac.uk>
parents: 393
diff changeset
   829
    by (simp add: bmkeps_fuse)
381
0c666a0c57d7 isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents: 379
diff changeset
   830
next
392
8194086c2a8a simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents: 385
diff changeset
   831
  case (bs7 bs r)
396
cc8e231529fb added ITP paper
Christian Urban <christian.urban@kcl.ac.uk>
parents: 393
diff changeset
   832
  have IH2: "bnullable (AALTs bs [r])" by fact
cc8e231529fb added ITP paper
Christian Urban <christian.urban@kcl.ac.uk>
parents: 393
diff changeset
   833
  then show "bmkeps (AALTs bs [r]) = bmkeps (fuse bs r)" 
cc8e231529fb added ITP paper
Christian Urban <christian.urban@kcl.ac.uk>
parents: 393
diff changeset
   834
    by (simp add: bmkeps_fuse)
381
0c666a0c57d7 isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents: 379
diff changeset
   835
next
392
8194086c2a8a simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents: 385
diff changeset
   836
  case (ss3 r1 r2 rs)
396
cc8e231529fb added ITP paper
Christian Urban <christian.urban@kcl.ac.uk>
parents: 393
diff changeset
   837
  have IH1: "bnullable r1 \<Longrightarrow> bmkeps r1 = bmkeps r2" by fact
cc8e231529fb added ITP paper
Christian Urban <christian.urban@kcl.ac.uk>
parents: 393
diff changeset
   838
  have as: "r1 \<leadsto> r2" by fact
cc8e231529fb added ITP paper
Christian Urban <christian.urban@kcl.ac.uk>
parents: 393
diff changeset
   839
  from IH1 as show "bmkepss (r1 # rs) = bmkepss (r2 # rs)"
cc8e231529fb added ITP paper
Christian Urban <christian.urban@kcl.ac.uk>
parents: 393
diff changeset
   840
    by (simp add: bnullable0)
381
0c666a0c57d7 isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents: 379
diff changeset
   841
next
392
8194086c2a8a simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents: 385
diff changeset
   842
  case (ss5 bs1 rs1 rsb)
396
cc8e231529fb added ITP paper
Christian Urban <christian.urban@kcl.ac.uk>
parents: 393
diff changeset
   843
  have "bnullables (AALTs bs1 rs1 # rsb)" by fact
cc8e231529fb added ITP paper
Christian Urban <christian.urban@kcl.ac.uk>
parents: 393
diff changeset
   844
  then show "bmkepss (AALTs bs1 rs1 # rsb) = bmkepss (map (fuse bs1) rs1 @ rsb)"
393
3954579ebdaf polished
Christian Urban <christian.urban@kcl.ac.uk>
parents: 392
diff changeset
   845
    by (simp add: bmkepss1 bmkepss2 bmkepss_fuse bnullable_fuse)
381
0c666a0c57d7 isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents: 379
diff changeset
   846
next
416
57182b36ec01 more with the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents: 411
diff changeset
   847
  case (ss6 a2 a1 rsa rsb rsc)
57182b36ec01 more with the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents: 411
diff changeset
   848
  have as1: "L(erase a2) \<subseteq> L(erase a1)" by fact
396
cc8e231529fb added ITP paper
Christian Urban <christian.urban@kcl.ac.uk>
parents: 393
diff changeset
   849
  have as3: "bnullables (rsa @ [a1] @ rsb @ [a2] @ rsc)" by fact
cc8e231529fb added ITP paper
Christian Urban <christian.urban@kcl.ac.uk>
parents: 393
diff changeset
   850
  show "bmkepss (rsa @ [a1] @ rsb @ [a2] @ rsc) = bmkepss (rsa @ [a1] @ rsb @ rsc)" using as1 as3
418
41a2a3b63853 more of the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents: 416
diff changeset
   851
    by (smt (verit, ccfv_SIG) append_Cons bmkepss.simps(1) bmkepss1 bmkepss2 bnullable_correctness nullable_correctness subset_eq)
416
57182b36ec01 more with the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents: 411
diff changeset
   852
(*next 
57182b36ec01 more with the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents: 411
diff changeset
   853
  case (extra bs0 bs1 r1 bs2 r2 bs4 bs3)
57182b36ec01 more with the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents: 411
diff changeset
   854
  then show ?case 
57182b36ec01 more with the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents: 411
diff changeset
   855
    apply(subst bmkeps.simps)
57182b36ec01 more with the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents: 411
diff changeset
   856
    apply(subst bmkeps.simps)
57182b36ec01 more with the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents: 411
diff changeset
   857
    apply(subst bmkeps.simps)
57182b36ec01 more with the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents: 411
diff changeset
   858
    apply(subst bmkeps.simps)
57182b36ec01 more with the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents: 411
diff changeset
   859
    apply(subst bmkeps.simps)
57182b36ec01 more with the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents: 411
diff changeset
   860
    apply(subst bmkeps.simps)
57182b36ec01 more with the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents: 411
diff changeset
   861
    apply(simp)
57182b36ec01 more with the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents: 411
diff changeset
   862
    done*)
393
3954579ebdaf polished
Christian Urban <christian.urban@kcl.ac.uk>
parents: 392
diff changeset
   863
qed (auto)
365
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   864
373
320f923c77b9 slightly
Christian Urban <christian.urban@kcl.ac.uk>
parents: 365
diff changeset
   865
lemma rewrites_bmkeps: 
320f923c77b9 slightly
Christian Urban <christian.urban@kcl.ac.uk>
parents: 365
diff changeset
   866
  assumes "r1 \<leadsto>* r2" "bnullable r1" 
320f923c77b9 slightly
Christian Urban <christian.urban@kcl.ac.uk>
parents: 365
diff changeset
   867
  shows "bmkeps r1 = bmkeps r2"
320f923c77b9 slightly
Christian Urban <christian.urban@kcl.ac.uk>
parents: 365
diff changeset
   868
  using assms
320f923c77b9 slightly
Christian Urban <christian.urban@kcl.ac.uk>
parents: 365
diff changeset
   869
proof(induction r1 r2 rule: rrewrites.induct)
320f923c77b9 slightly
Christian Urban <christian.urban@kcl.ac.uk>
parents: 365
diff changeset
   870
  case (rs1 r)
320f923c77b9 slightly
Christian Urban <christian.urban@kcl.ac.uk>
parents: 365
diff changeset
   871
  then show "bmkeps r = bmkeps r" by simp
320f923c77b9 slightly
Christian Urban <christian.urban@kcl.ac.uk>
parents: 365
diff changeset
   872
next
320f923c77b9 slightly
Christian Urban <christian.urban@kcl.ac.uk>
parents: 365
diff changeset
   873
  case (rs2 r1 r2 r3)
320f923c77b9 slightly
Christian Urban <christian.urban@kcl.ac.uk>
parents: 365
diff changeset
   874
  then have IH: "bmkeps r1 = bmkeps r2" by simp
320f923c77b9 slightly
Christian Urban <christian.urban@kcl.ac.uk>
parents: 365
diff changeset
   875
  have a1: "bnullable r1" by fact
320f923c77b9 slightly
Christian Urban <christian.urban@kcl.ac.uk>
parents: 365
diff changeset
   876
  have a2: "r1 \<leadsto>* r2" by fact
320f923c77b9 slightly
Christian Urban <christian.urban@kcl.ac.uk>
parents: 365
diff changeset
   877
  have a3: "r2 \<leadsto> r3" by fact
396
cc8e231529fb added ITP paper
Christian Urban <christian.urban@kcl.ac.uk>
parents: 393
diff changeset
   878
  have a4: "bnullable r2" using a1 a2 by (simp add: rewrites_bnullable_eq) 
393
3954579ebdaf polished
Christian Urban <christian.urban@kcl.ac.uk>
parents: 392
diff changeset
   879
  then have "bmkeps r2 = bmkeps r3"
3954579ebdaf polished
Christian Urban <christian.urban@kcl.ac.uk>
parents: 392
diff changeset
   880
    using a3 bnullable0(1) rewrite_bmkeps_aux(1) by blast 
373
320f923c77b9 slightly
Christian Urban <christian.urban@kcl.ac.uk>
parents: 365
diff changeset
   881
  then show "bmkeps r1 = bmkeps r3" using IH by simp
320f923c77b9 slightly
Christian Urban <christian.urban@kcl.ac.uk>
parents: 365
diff changeset
   882
qed
365
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   883
393
3954579ebdaf polished
Christian Urban <christian.urban@kcl.ac.uk>
parents: 392
diff changeset
   884
3954579ebdaf polished
Christian Urban <christian.urban@kcl.ac.uk>
parents: 392
diff changeset
   885
lemma rewrites_to_bsimp: 
3954579ebdaf polished
Christian Urban <christian.urban@kcl.ac.uk>
parents: 392
diff changeset
   886
  shows "r \<leadsto>* bsimp r"
3954579ebdaf polished
Christian Urban <christian.urban@kcl.ac.uk>
parents: 392
diff changeset
   887
proof (induction r rule: bsimp.induct)
3954579ebdaf polished
Christian Urban <christian.urban@kcl.ac.uk>
parents: 392
diff changeset
   888
  case (1 bs1 r1 r2)
3954579ebdaf polished
Christian Urban <christian.urban@kcl.ac.uk>
parents: 392
diff changeset
   889
  have IH1: "r1 \<leadsto>* bsimp r1" by fact
3954579ebdaf polished
Christian Urban <christian.urban@kcl.ac.uk>
parents: 392
diff changeset
   890
  have IH2: "r2 \<leadsto>* bsimp r2" by fact
3954579ebdaf polished
Christian Urban <christian.urban@kcl.ac.uk>
parents: 392
diff changeset
   891
  { assume as: "bsimp r1 = AZERO \<or> bsimp r2 = AZERO"
3954579ebdaf polished
Christian Urban <christian.urban@kcl.ac.uk>
parents: 392
diff changeset
   892
    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
   893
    then have "ASEQ bs1 r1 r2 \<leadsto>* AZERO"
3954579ebdaf polished
Christian Urban <christian.urban@kcl.ac.uk>
parents: 392
diff changeset
   894
      by (metis bs2 continuous_rewrite rrewrites.simps star_seq2)  
3954579ebdaf polished
Christian Urban <christian.urban@kcl.ac.uk>
parents: 392
diff changeset
   895
    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
   896
  }
3954579ebdaf polished
Christian Urban <christian.urban@kcl.ac.uk>
parents: 392
diff changeset
   897
  moreover
3954579ebdaf polished
Christian Urban <christian.urban@kcl.ac.uk>
parents: 392
diff changeset
   898
  { assume "\<exists>bs. bsimp r1 = AONE bs"
3954579ebdaf polished
Christian Urban <christian.urban@kcl.ac.uk>
parents: 392
diff changeset
   899
    then obtain bs where as: "bsimp r1 = AONE bs" by blast
3954579ebdaf polished
Christian Urban <christian.urban@kcl.ac.uk>
parents: 392
diff changeset
   900
    with IH1 have "r1 \<leadsto>* AONE bs" by simp
3954579ebdaf polished
Christian Urban <christian.urban@kcl.ac.uk>
parents: 392
diff changeset
   901
    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
   902
    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
   903
      using rewrites_fuse by (meson rrewrites_trans) 
3954579ebdaf polished
Christian Urban <christian.urban@kcl.ac.uk>
parents: 392
diff changeset
   904
    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
   905
    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
   906
  } 
3954579ebdaf polished
Christian Urban <christian.urban@kcl.ac.uk>
parents: 392
diff changeset
   907
  moreover
3954579ebdaf polished
Christian Urban <christian.urban@kcl.ac.uk>
parents: 392
diff changeset
   908
  { 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
   909
    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
   910
      by (simp add: bsimp_ASEQ1) 
3954579ebdaf polished
Christian Urban <christian.urban@kcl.ac.uk>
parents: 392
diff changeset
   911
    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
   912
      by (metis rrewrites_trans star_seq star_seq2) 
3954579ebdaf polished
Christian Urban <christian.urban@kcl.ac.uk>
parents: 392
diff changeset
   913
    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
   914
  } 
3954579ebdaf polished
Christian Urban <christian.urban@kcl.ac.uk>
parents: 392
diff changeset
   915
  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
   916
next
3954579ebdaf polished
Christian Urban <christian.urban@kcl.ac.uk>
parents: 392
diff changeset
   917
  case (2 bs1 rs)
3954579ebdaf polished
Christian Urban <christian.urban@kcl.ac.uk>
parents: 392
diff changeset
   918
  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
   919
  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
   920
  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
   921
  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
   922
  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
   923
    using contextrewrites0 by blast
3954579ebdaf polished
Christian Urban <christian.urban@kcl.ac.uk>
parents: 392
diff changeset
   924
  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
   925
    by (simp add: bsimp_AALTs_rewrites)     
3954579ebdaf polished
Christian Urban <christian.urban@kcl.ac.uk>
parents: 392
diff changeset
   926
  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
   927
qed (simp_all)
3954579ebdaf polished
Christian Urban <christian.urban@kcl.ac.uk>
parents: 392
diff changeset
   928
3954579ebdaf polished
Christian Urban <christian.urban@kcl.ac.uk>
parents: 392
diff changeset
   929
392
8194086c2a8a simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents: 385
diff changeset
   930
lemma to_zero_in_alt: 
393
3954579ebdaf polished
Christian Urban <christian.urban@kcl.ac.uk>
parents: 392
diff changeset
   931
  shows "AALT bs (ASEQ [] AZERO r) r2 \<leadsto> AALT bs AZERO r2"
398
dac6d27c99c6 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 397
diff changeset
   932
  by (simp add: bs1 bs8 ss3)
365
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   933
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   934
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   935
374
98362002c818 slightly more
Christian Urban <christian.urban@kcl.ac.uk>
parents: 373
diff changeset
   936
lemma  bder_fuse_list: 
98362002c818 slightly more
Christian Urban <christian.urban@kcl.ac.uk>
parents: 373
diff changeset
   937
  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
   938
  apply(induction rs1)
8194086c2a8a simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents: 385
diff changeset
   939
  apply(simp_all add: bder_fuse)
8194086c2a8a simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents: 385
diff changeset
   940
  done
365
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
   941
416
57182b36ec01 more with the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents: 411
diff changeset
   942
lemma map_single:
57182b36ec01 more with the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents: 411
diff changeset
   943
  shows "map f [x] = [f x]"
57182b36ec01 more with the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents: 411
diff changeset
   944
  by simp
57182b36ec01 more with the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents: 411
diff changeset
   945
57182b36ec01 more with the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents: 411
diff changeset
   946
393
3954579ebdaf polished
Christian Urban <christian.urban@kcl.ac.uk>
parents: 392
diff changeset
   947
lemma rewrite_preserves_bder: 
396
cc8e231529fb added ITP paper
Christian Urban <christian.urban@kcl.ac.uk>
parents: 393
diff changeset
   948
  shows "r1 \<leadsto> r2 \<Longrightarrow> bder c r1 \<leadsto>* bder c r2"
392
8194086c2a8a simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents: 385
diff changeset
   949
  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
   950
proof(induction rule: rrewrite_srewrite.inducts)
8194086c2a8a simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents: 385
diff changeset
   951
  case (bs1 bs r2)
396
cc8e231529fb added ITP paper
Christian Urban <christian.urban@kcl.ac.uk>
parents: 393
diff changeset
   952
  show "bder c (ASEQ bs AZERO r2) \<leadsto>* bder c AZERO"
381
0c666a0c57d7 isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents: 379
diff changeset
   953
    by (simp add: continuous_rewrite) 
0c666a0c57d7 isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents: 379
diff changeset
   954
next
392
8194086c2a8a simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents: 385
diff changeset
   955
  case (bs2 bs r1)
396
cc8e231529fb added ITP paper
Christian Urban <christian.urban@kcl.ac.uk>
parents: 393
diff changeset
   956
  show "bder c (ASEQ bs r1 AZERO) \<leadsto>* bder c AZERO"
392
8194086c2a8a simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents: 385
diff changeset
   957
    apply(auto)
8194086c2a8a simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents: 385
diff changeset
   958
    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
   959
    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
   960
next
392
8194086c2a8a simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents: 385
diff changeset
   961
  case (bs3 bs1 bs2 r)
396
cc8e231529fb added ITP paper
Christian Urban <christian.urban@kcl.ac.uk>
parents: 393
diff changeset
   962
  show "bder c (ASEQ bs1 (AONE bs2) r) \<leadsto>* bder c (fuse (bs1 @ bs2) r)"
381
0c666a0c57d7 isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents: 379
diff changeset
   963
    apply(simp)
398
dac6d27c99c6 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 397
diff changeset
   964
    by (metis (no_types, lifting) bder_fuse bs8 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
   965
next
392
8194086c2a8a simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents: 385
diff changeset
   966
  case (bs4 r1 r2 bs r3)
381
0c666a0c57d7 isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents: 379
diff changeset
   967
  have as: "r1 \<leadsto> r2" by fact
0c666a0c57d7 isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents: 379
diff changeset
   968
  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
   969
  from as IH show "bder c (ASEQ bs r1 r3) \<leadsto>* bder c (ASEQ bs r2 r3)"
393
3954579ebdaf polished
Christian Urban <christian.urban@kcl.ac.uk>
parents: 392
diff changeset
   970
    by (metis bder.simps(5) bnullable0(1) contextrewrites1 rewrite_bmkeps_aux(1) star_seq)
381
0c666a0c57d7 isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents: 379
diff changeset
   971
next
392
8194086c2a8a simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents: 385
diff changeset
   972
  case (bs5 r3 r4 bs r1)
381
0c666a0c57d7 isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents: 379
diff changeset
   973
  have as: "r3 \<leadsto> r4" by fact 
0c666a0c57d7 isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents: 379
diff changeset
   974
  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
   975
  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
   976
    apply(simp)
8194086c2a8a simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents: 385
diff changeset
   977
    apply(auto)
8194086c2a8a simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents: 385
diff changeset
   978
    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
   979
    using star_seq2 by blast
8194086c2a8a simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents: 385
diff changeset
   980
next
8194086c2a8a simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents: 385
diff changeset
   981
  case (bs6 bs)
396
cc8e231529fb added ITP paper
Christian Urban <christian.urban@kcl.ac.uk>
parents: 393
diff changeset
   982
  show "bder c (AALTs bs []) \<leadsto>* bder c AZERO"
392
8194086c2a8a simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents: 385
diff changeset
   983
    using rrewrite_srewrite.bs6 by force 
381
0c666a0c57d7 isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents: 379
diff changeset
   984
next
392
8194086c2a8a simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents: 385
diff changeset
   985
  case (bs7 bs r)
396
cc8e231529fb added ITP paper
Christian Urban <christian.urban@kcl.ac.uk>
parents: 393
diff changeset
   986
  show "bder c (AALTs bs [r]) \<leadsto>* bder c (fuse bs r)"
392
8194086c2a8a simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents: 385
diff changeset
   987
    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
   988
next
398
dac6d27c99c6 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 397
diff changeset
   989
  case (bs8 rs1 rs2 bs)
396
cc8e231529fb added ITP paper
Christian Urban <christian.urban@kcl.ac.uk>
parents: 393
diff changeset
   990
  have IH1: "map (bder c) rs1 s\<leadsto>* map (bder c) rs2" by fact
cc8e231529fb added ITP paper
Christian Urban <christian.urban@kcl.ac.uk>
parents: 393
diff changeset
   991
  then show "bder c (AALTs bs rs1) \<leadsto>* bder c (AALTs bs rs2)" 
392
8194086c2a8a simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents: 385
diff changeset
   992
    using contextrewrites0 by force    
407
d73b722efe0e updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 405
diff changeset
   993
(*next
392
8194086c2a8a simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents: 385
diff changeset
   994
  case ss1
407
d73b722efe0e updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 405
diff changeset
   995
  show "map (bder c) [] s\<leadsto>* map (bder c) []" by simp*)
381
0c666a0c57d7 isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents: 379
diff changeset
   996
next
392
8194086c2a8a simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents: 385
diff changeset
   997
  case (ss2 rs1 rs2 r)
396
cc8e231529fb added ITP paper
Christian Urban <christian.urban@kcl.ac.uk>
parents: 393
diff changeset
   998
  have IH1: "map (bder c) rs1 s\<leadsto>* map (bder c) rs2" by fact
cc8e231529fb added ITP paper
Christian Urban <christian.urban@kcl.ac.uk>
parents: 393
diff changeset
   999
  then show "map (bder c) (r # rs1) s\<leadsto>* map (bder c) (r # rs2)"
392
8194086c2a8a simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents: 385
diff changeset
  1000
    by (simp add: srewrites7) 
381
0c666a0c57d7 isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents: 379
diff changeset
  1001
next
392
8194086c2a8a simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents: 385
diff changeset
  1002
  case (ss3 r1 r2 rs)
396
cc8e231529fb added ITP paper
Christian Urban <christian.urban@kcl.ac.uk>
parents: 393
diff changeset
  1003
  have IH: "bder c r1 \<leadsto>* bder c r2" by fact
cc8e231529fb added ITP paper
Christian Urban <christian.urban@kcl.ac.uk>
parents: 393
diff changeset
  1004
  then show "map (bder c) (r1 # rs) s\<leadsto>* map (bder c) (r2 # rs)"
392
8194086c2a8a simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents: 385
diff changeset
  1005
    by (simp add: srewrites7) 
381
0c666a0c57d7 isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents: 379
diff changeset
  1006
next
392
8194086c2a8a simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents: 385
diff changeset
  1007
  case (ss4 rs)
396
cc8e231529fb added ITP paper
Christian Urban <christian.urban@kcl.ac.uk>
parents: 393
diff changeset
  1008
  show "map (bder c) (AZERO # rs) s\<leadsto>* map (bder c) rs"
392
8194086c2a8a simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents: 385
diff changeset
  1009
    using rrewrite_srewrite.ss4 by fastforce 
381
0c666a0c57d7 isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents: 379
diff changeset
  1010
next
392
8194086c2a8a simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents: 385
diff changeset
  1011
  case (ss5 bs1 rs1 rsb)
396
cc8e231529fb added ITP paper
Christian Urban <christian.urban@kcl.ac.uk>
parents: 393
diff changeset
  1012
  show "map (bder c) (AALTs bs1 rs1 # rsb) s\<leadsto>* map (bder c) (map (fuse bs1) rs1 @ rsb)"
392
8194086c2a8a simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents: 385
diff changeset
  1013
    apply(simp)
8194086c2a8a simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents: 385
diff changeset
  1014
    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
  1015
next
416
57182b36ec01 more with the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents: 411
diff changeset
  1016
  case (ss6 a2 a1 bs rsa rsb)
57182b36ec01 more with the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents: 411
diff changeset
  1017
  have as: "L(erase a2) \<subseteq> L(erase a1)" by fact
396
cc8e231529fb added ITP paper
Christian Urban <christian.urban@kcl.ac.uk>
parents: 393
diff changeset
  1018
  show "map (bder c) (bs @ [a1] @ rsa @ [a2] @ rsb) s\<leadsto>* map (bder c) (bs @ [a1] @ rsa @ rsb)"
392
8194086c2a8a simplified version
Christian Urban <christian.urban@kcl.ac.uk>
parents: 385
diff changeset
  1019
    apply(simp only: map_append)
416
57182b36ec01 more with the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents: 411
diff changeset
  1020
    apply(simp only: map_single)
57182b36ec01 more with the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents: 411
diff changeset
  1021
    apply(rule rs_in_rstar)
57182b36ec01 more with the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents: 411
diff changeset
  1022
    thm rrewrite_srewrite.intros
57182b36ec01 more with the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents: 411
diff changeset
  1023
    apply(rule rrewrite_srewrite.ss6)
57182b36ec01 more with the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents: 411
diff changeset
  1024
    using as
57182b36ec01 more with the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents: 411
diff changeset
  1025
    apply(auto simp add: der_correctness Der_def)
57182b36ec01 more with the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents: 411
diff changeset
  1026
    done 
57182b36ec01 more with the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents: 411
diff changeset
  1027
(*next 
57182b36ec01 more with the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents: 411
diff changeset
  1028
  case (extra bs0 bs1 r1 r2 r3)
57182b36ec01 more with the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents: 411
diff changeset
  1029
  then show ?case
57182b36ec01 more with the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents: 411
diff changeset
  1030
    apply(auto simp add: comp_def)
57182b36ec01 more with the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents: 411
diff changeset
  1031
    
57182b36ec01 more with the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents: 411
diff changeset
  1032
       defer
57182b36ec01 more with the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents: 411
diff changeset
  1033
    using r_in_rstar rrewrite_srewrite.extra apply presburger
57182b36ec01 more with the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents: 411
diff changeset
  1034
      prefer 2
57182b36ec01 more with the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents: 411
diff changeset
  1035
    using r_in_rstar rrewrite_srewrite.extra apply presburger
57182b36ec01 more with the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents: 411
diff changeset
  1036
     prefer 2
57182b36ec01 more with the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents: 411
diff changeset
  1037
    sorry*)
381
0c666a0c57d7 isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents: 379
diff changeset
  1038
qed
365
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1039
416
57182b36ec01 more with the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents: 411
diff changeset
  1040
57182b36ec01 more with the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents: 411
diff changeset
  1041
393
3954579ebdaf polished
Christian Urban <christian.urban@kcl.ac.uk>
parents: 392
diff changeset
  1042
lemma rewrites_preserves_bder: 
373
320f923c77b9 slightly
Christian Urban <christian.urban@kcl.ac.uk>
parents: 365
diff changeset
  1043
  assumes "r1 \<leadsto>* r2"
320f923c77b9 slightly
Christian Urban <christian.urban@kcl.ac.uk>
parents: 365
diff changeset
  1044
  shows "bder c r1 \<leadsto>* bder c r2"
320f923c77b9 slightly
Christian Urban <christian.urban@kcl.ac.uk>
parents: 365
diff changeset
  1045
using assms  
320f923c77b9 slightly
Christian Urban <christian.urban@kcl.ac.uk>
parents: 365
diff changeset
  1046
apply(induction r1 r2 rule: rrewrites.induct)
393
3954579ebdaf polished
Christian Urban <christian.urban@kcl.ac.uk>
parents: 392
diff changeset
  1047
apply(simp_all add: rewrite_preserves_bder rrewrites_trans)
416
57182b36ec01 more with the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents: 411
diff changeset
  1048
  done
365
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1049
381
0c666a0c57d7 isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents: 379
diff changeset
  1050
373
320f923c77b9 slightly
Christian Urban <christian.urban@kcl.ac.uk>
parents: 365
diff changeset
  1051
lemma central:  
320f923c77b9 slightly
Christian Urban <christian.urban@kcl.ac.uk>
parents: 365
diff changeset
  1052
  shows "bders r s \<leadsto>* bders_simp r s"
320f923c77b9 slightly
Christian Urban <christian.urban@kcl.ac.uk>
parents: 365
diff changeset
  1053
proof(induct s arbitrary: r rule: rev_induct)
320f923c77b9 slightly
Christian Urban <christian.urban@kcl.ac.uk>
parents: 365
diff changeset
  1054
  case Nil
320f923c77b9 slightly
Christian Urban <christian.urban@kcl.ac.uk>
parents: 365
diff changeset
  1055
  then show "bders r [] \<leadsto>* bders_simp r []" by simp
320f923c77b9 slightly
Christian Urban <christian.urban@kcl.ac.uk>
parents: 365
diff changeset
  1056
next
320f923c77b9 slightly
Christian Urban <christian.urban@kcl.ac.uk>
parents: 365
diff changeset
  1057
  case (snoc x xs)
320f923c77b9 slightly
Christian Urban <christian.urban@kcl.ac.uk>
parents: 365
diff changeset
  1058
  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
  1059
  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
  1060
  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
  1061
    by (simp add: rewrites_preserves_bder)
373
320f923c77b9 slightly
Christian Urban <christian.urban@kcl.ac.uk>
parents: 365
diff changeset
  1062
  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
  1063
    by (simp add: rewrites_to_bsimp)
373
320f923c77b9 slightly
Christian Urban <christian.urban@kcl.ac.uk>
parents: 365
diff changeset
  1064
  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
  1065
    by (simp add: bders_simp_append)
320f923c77b9 slightly
Christian Urban <christian.urban@kcl.ac.uk>
parents: 365
diff changeset
  1066
qed
365
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1067
393
3954579ebdaf polished
Christian Urban <christian.urban@kcl.ac.uk>
parents: 392
diff changeset
  1068
lemma main_aux: 
373
320f923c77b9 slightly
Christian Urban <christian.urban@kcl.ac.uk>
parents: 365
diff changeset
  1069
  assumes "bnullable (bders r s)"
320f923c77b9 slightly
Christian Urban <christian.urban@kcl.ac.uk>
parents: 365
diff changeset
  1070
  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
  1071
proof -
0c666a0c57d7 isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents: 379
diff changeset
  1072
  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
  1073
  then 
0c666a0c57d7 isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents: 379
diff changeset
  1074
  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
  1075
    by (rule rewrites_bmkeps)
0c666a0c57d7 isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents: 379
diff changeset
  1076
qed  
0c666a0c57d7 isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents: 379
diff changeset
  1077
365
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1078
393
3954579ebdaf polished
Christian Urban <christian.urban@kcl.ac.uk>
parents: 392
diff changeset
  1079
theorem main_blexer_simp: 
373
320f923c77b9 slightly
Christian Urban <christian.urban@kcl.ac.uk>
parents: 365
diff changeset
  1080
  shows "blexer r s = blexer_simp r s"
381
0c666a0c57d7 isarfied some proofs
Christian Urban <christian.urban@kcl.ac.uk>
parents: 379
diff changeset
  1081
  unfolding blexer_def blexer_simp_def
397
e1b74d618f1b updated Sizebound4
Christian Urban <christian.urban@kcl.ac.uk>
parents: 396
diff changeset
  1082
  by (metis central main_aux rewrites_bnullable_eq)
365
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1083
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1084
373
320f923c77b9 slightly
Christian Urban <christian.urban@kcl.ac.uk>
parents: 365
diff changeset
  1085
theorem blexersimp_correctness: 
320f923c77b9 slightly
Christian Urban <christian.urban@kcl.ac.uk>
parents: 365
diff changeset
  1086
  shows "lexer r s = blexer_simp r s"
393
3954579ebdaf polished
Christian Urban <christian.urban@kcl.ac.uk>
parents: 392
diff changeset
  1087
  using blexer_correctness main_blexer_simp by simp
365
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1088
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1089
405
3cfea5bb5e23 updated some of the text and cardinality proof
Christian Urban <christian.urban@kcl.ac.uk>
parents: 402
diff changeset
  1090
(* some tests *)
3cfea5bb5e23 updated some of the text and cardinality proof
Christian Urban <christian.urban@kcl.ac.uk>
parents: 402
diff changeset
  1091
416
57182b36ec01 more with the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents: 411
diff changeset
  1092
definition
57182b36ec01 more with the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents: 411
diff changeset
  1093
  bders_simp_Set :: "string set \<Rightarrow> arexp \<Rightarrow> arexp set"
57182b36ec01 more with the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents: 411
diff changeset
  1094
where
57182b36ec01 more with the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents: 411
diff changeset
  1095
  "bders_simp_Set A r \<equiv> bders_simp r ` A"
57182b36ec01 more with the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents: 411
diff changeset
  1096
57182b36ec01 more with the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents: 411
diff changeset
  1097
lemma pders_Set_union:
57182b36ec01 more with the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents: 411
diff changeset
  1098
  shows "bders_simp_Set (A \<union> B) r = (bders_simp_Set A r \<union> bders_simp_Set B r)"
57182b36ec01 more with the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents: 411
diff changeset
  1099
  apply (simp add: bders_simp_Set_def)
57182b36ec01 more with the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents: 411
diff changeset
  1100
  by (simp add: image_Un)
57182b36ec01 more with the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents: 411
diff changeset
  1101
  
57182b36ec01 more with the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents: 411
diff changeset
  1102
lemma pders_Set_subset:
57182b36ec01 more with the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents: 411
diff changeset
  1103
  shows "A \<subseteq> B \<Longrightarrow> bders_simp_Set A r \<subseteq> bders_simp_Set B r"
57182b36ec01 more with the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents: 411
diff changeset
  1104
  apply (auto simp add: bders_simp_Set_def)
57182b36ec01 more with the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents: 411
diff changeset
  1105
  done
57182b36ec01 more with the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents: 411
diff changeset
  1106
57182b36ec01 more with the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents: 411
diff changeset
  1107
57182b36ec01 more with the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents: 411
diff changeset
  1108
lemma AZERO_r:
57182b36ec01 more with the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents: 411
diff changeset
  1109
  "bders_simp AZERO s = AZERO"
57182b36ec01 more with the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents: 411
diff changeset
  1110
  apply(induct s)
57182b36ec01 more with the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents: 411
diff changeset
  1111
   apply(auto)
57182b36ec01 more with the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents: 411
diff changeset
  1112
  done
57182b36ec01 more with the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents: 411
diff changeset
  1113
57182b36ec01 more with the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents: 411
diff changeset
  1114
lemma bders_simp_Set_ZERO [simp]:
57182b36ec01 more with the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents: 411
diff changeset
  1115
  shows "bders_simp_Set UNIV1 AZERO \<subseteq> {AZERO}"
57182b36ec01 more with the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents: 411
diff changeset
  1116
  unfolding UNIV1_def bders_simp_Set_def 
57182b36ec01 more with the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents: 411
diff changeset
  1117
  apply(auto)
57182b36ec01 more with the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents: 411
diff changeset
  1118
  using AZERO_r by blast
57182b36ec01 more with the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents: 411
diff changeset
  1119
57182b36ec01 more with the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents: 411
diff changeset
  1120
lemma AONE_r:
57182b36ec01 more with the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents: 411
diff changeset
  1121
  shows "bders_simp (AONE bs) s = AZERO \<or> bders_simp (AONE bs) s = AONE bs"
57182b36ec01 more with the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents: 411
diff changeset
  1122
  apply(induct s)
57182b36ec01 more with the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents: 411
diff changeset
  1123
   apply(auto)
57182b36ec01 more with the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents: 411
diff changeset
  1124
  using AZERO_r apply blast
57182b36ec01 more with the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents: 411
diff changeset
  1125
  using AZERO_r by blast
57182b36ec01 more with the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents: 411
diff changeset
  1126
57182b36ec01 more with the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents: 411
diff changeset
  1127
lemma bders_simp_Set_ONE [simp]:
57182b36ec01 more with the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents: 411
diff changeset
  1128
  shows "bders_simp_Set UNIV1 (AONE bs) \<subseteq> {AZERO, AONE bs}"
57182b36ec01 more with the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents: 411
diff changeset
  1129
  unfolding UNIV1_def bders_simp_Set_def 
57182b36ec01 more with the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents: 411
diff changeset
  1130
  apply(auto split: if_splits)
57182b36ec01 more with the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents: 411
diff changeset
  1131
  using AONE_r by blast
57182b36ec01 more with the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents: 411
diff changeset
  1132
57182b36ec01 more with the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents: 411
diff changeset
  1133
lemma ACHAR_r:
57182b36ec01 more with the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents: 411
diff changeset
  1134
  shows "bders_simp (ACHAR bs c) s = AZERO \<or> 
57182b36ec01 more with the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents: 411
diff changeset
  1135
         bders_simp (ACHAR bs c) s = AONE bs \<or>
57182b36ec01 more with the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents: 411
diff changeset
  1136
         bders_simp (ACHAR bs c) s = ACHAR bs c"
57182b36ec01 more with the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents: 411
diff changeset
  1137
  apply(induct s)
57182b36ec01 more with the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents: 411
diff changeset
  1138
   apply(auto)
57182b36ec01 more with the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents: 411
diff changeset
  1139
  using AONE_r apply blast
57182b36ec01 more with the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents: 411
diff changeset
  1140
  using AZERO_r apply force
57182b36ec01 more with the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents: 411
diff changeset
  1141
  using AONE_r apply blast
57182b36ec01 more with the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents: 411
diff changeset
  1142
  using AZERO_r apply blast
57182b36ec01 more with the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents: 411
diff changeset
  1143
  using AONE_r apply blast
57182b36ec01 more with the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents: 411
diff changeset
  1144
  using AZERO_r by blast
57182b36ec01 more with the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents: 411
diff changeset
  1145
57182b36ec01 more with the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents: 411
diff changeset
  1146
lemma bders_simp_Set_CHAR [simp]:
57182b36ec01 more with the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents: 411
diff changeset
  1147
  shows "bders_simp_Set UNIV1 (ACHAR bs c) \<subseteq> {AZERO, AONE bs, ACHAR bs c}"
57182b36ec01 more with the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents: 411
diff changeset
  1148
unfolding UNIV1_def bders_simp_Set_def
57182b36ec01 more with the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents: 411
diff changeset
  1149
  apply(auto)
57182b36ec01 more with the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents: 411
diff changeset
  1150
  using ACHAR_r by blast
57182b36ec01 more with the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents: 411
diff changeset
  1151
  
57182b36ec01 more with the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents: 411
diff changeset
  1152
lemma bders_simp_Set_ALT [simp]:
57182b36ec01 more with the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents: 411
diff changeset
  1153
  shows "bders_simp_Set UNIV1 (AALT bs r1 r2) = bders_simp_Set UNIV1 r1 \<union> bders_simp_Set UNIV1 r2"
57182b36ec01 more with the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents: 411
diff changeset
  1154
  unfolding UNIV1_def bders_simp_Set_def
57182b36ec01 more with the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents: 411
diff changeset
  1155
  apply(auto)
57182b36ec01 more with the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents: 411
diff changeset
  1156
  oops
57182b36ec01 more with the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents: 411
diff changeset
  1157
57182b36ec01 more with the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents: 411
diff changeset
  1158
57182b36ec01 more with the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents: 411
diff changeset
  1159
(*
407
d73b722efe0e updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 405
diff changeset
  1160
lemma asize_fuse:
d73b722efe0e updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 405
diff changeset
  1161
  shows "asize (fuse bs r) = asize r"
d73b722efe0e updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 405
diff changeset
  1162
  apply(induct r arbitrary: bs)
d73b722efe0e updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 405
diff changeset
  1163
  apply(auto)
d73b722efe0e updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 405
diff changeset
  1164
  done
d73b722efe0e updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 405
diff changeset
  1165
d73b722efe0e updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 405
diff changeset
  1166
lemma asize_rewrite2:
d73b722efe0e updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 405
diff changeset
  1167
  shows "r1 \<leadsto> r2 \<Longrightarrow> asize r1 \<ge> asize r2"
d73b722efe0e updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 405
diff changeset
  1168
  and   "rs1 s\<leadsto> rs2 \<Longrightarrow> (sum_list (map asize rs1)) \<ge> (sum_list (map asize rs2))"
d73b722efe0e updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 405
diff changeset
  1169
   apply(induct rule: rrewrite_srewrite.inducts)
d73b722efe0e updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 405
diff changeset
  1170
   apply(auto simp add: asize_fuse comp_def)
d73b722efe0e updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 405
diff changeset
  1171
  done
d73b722efe0e updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 405
diff changeset
  1172
d73b722efe0e updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 405
diff changeset
  1173
lemma asize_rrewrites:
d73b722efe0e updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 405
diff changeset
  1174
  assumes "r1 \<leadsto>* r2"
d73b722efe0e updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 405
diff changeset
  1175
  shows "asize r1 \<ge> asize r2"
d73b722efe0e updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 405
diff changeset
  1176
  using assms
d73b722efe0e updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 405
diff changeset
  1177
  apply(induct rule: rrewrites.induct)
d73b722efe0e updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 405
diff changeset
  1178
   apply(auto)
d73b722efe0e updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 405
diff changeset
  1179
  using asize_rewrite2(1) le_trans by blast
d73b722efe0e updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 405
diff changeset
  1180
  
d73b722efe0e updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 405
diff changeset
  1181
d73b722efe0e updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 405
diff changeset
  1182
d73b722efe0e updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 405
diff changeset
  1183
fun asize2 :: "arexp \<Rightarrow> nat" where
d73b722efe0e updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 405
diff changeset
  1184
  "asize2 AZERO = 1"
d73b722efe0e updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 405
diff changeset
  1185
| "asize2 (AONE cs) = 1" 
d73b722efe0e updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 405
diff changeset
  1186
| "asize2 (ACHAR cs c) = 1"
d73b722efe0e updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 405
diff changeset
  1187
| "asize2 (AALTs cs rs) = Suc (Suc (sum_list (map asize2 rs)))"
d73b722efe0e updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 405
diff changeset
  1188
| "asize2 (ASEQ cs r1 r2) = Suc (asize2 r1 + asize2 r2)"
d73b722efe0e updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 405
diff changeset
  1189
| "asize2 (ASTAR cs r) = Suc (asize2 r)"
d73b722efe0e updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 405
diff changeset
  1190
d73b722efe0e updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 405
diff changeset
  1191
410
9261d980225d updated papers
Christian Urban <christian.urban@kcl.ac.uk>
parents: 407
diff changeset
  1192
407
d73b722efe0e updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 405
diff changeset
  1193
lemma asize2_fuse:
d73b722efe0e updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 405
diff changeset
  1194
  shows "asize2 (fuse bs r) = asize2 r"
d73b722efe0e updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 405
diff changeset
  1195
  apply(induct r arbitrary: bs)
d73b722efe0e updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 405
diff changeset
  1196
  apply(auto)
d73b722efe0e updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 405
diff changeset
  1197
  done
d73b722efe0e updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 405
diff changeset
  1198
d73b722efe0e updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 405
diff changeset
  1199
lemma asize2_not_zero:
d73b722efe0e updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 405
diff changeset
  1200
  shows "0 < asize2 r"
d73b722efe0e updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 405
diff changeset
  1201
  apply(induct r)
d73b722efe0e updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 405
diff changeset
  1202
  apply(auto)
d73b722efe0e updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 405
diff changeset
  1203
  done
d73b722efe0e updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 405
diff changeset
  1204
d73b722efe0e updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 405
diff changeset
  1205
lemma asize_rewrite:
d73b722efe0e updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 405
diff changeset
  1206
  shows "r1 \<leadsto> r2 \<Longrightarrow> asize2 r1 > asize2 r2"
d73b722efe0e updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 405
diff changeset
  1207
  and   "rs1 s\<leadsto> rs2 \<Longrightarrow> (sum_list (map asize2 rs1)) > (sum_list (map asize2 rs2))"
d73b722efe0e updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 405
diff changeset
  1208
   apply(induct rule: rrewrite_srewrite.inducts)
d73b722efe0e updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 405
diff changeset
  1209
   apply(auto simp add: asize2_fuse comp_def)
d73b722efe0e updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 405
diff changeset
  1210
  apply(simp add: asize2_not_zero) 
d73b722efe0e updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 405
diff changeset
  1211
  done
d73b722efe0e updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 405
diff changeset
  1212
d73b722efe0e updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 405
diff changeset
  1213
lemma asize2_bsimp_ASEQ:
d73b722efe0e updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 405
diff changeset
  1214
  shows "asize2 (bsimp_ASEQ bs r1 r2) \<le> Suc (asize2 r1 + asize2 r2)"
d73b722efe0e updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 405
diff changeset
  1215
  apply(induct bs r1 r2 rule: bsimp_ASEQ.induct)
d73b722efe0e updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 405
diff changeset
  1216
  apply(auto)
d73b722efe0e updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 405
diff changeset
  1217
  done
d73b722efe0e updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 405
diff changeset
  1218
d73b722efe0e updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 405
diff changeset
  1219
lemma asize2_bsimp_AALTs:
d73b722efe0e updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 405
diff changeset
  1220
  shows "asize2 (bsimp_AALTs bs rs) \<le> Suc (Suc (sum_list (map asize2 rs)))"
d73b722efe0e updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 405
diff changeset
  1221
  apply(induct bs rs rule: bsimp_AALTs.induct)
d73b722efe0e updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 405
diff changeset
  1222
  apply(auto simp add: asize2_fuse)
d73b722efe0e updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 405
diff changeset
  1223
  done
d73b722efe0e updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 405
diff changeset
  1224
d73b722efe0e updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 405
diff changeset
  1225
lemma distinctBy_asize2:
d73b722efe0e updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 405
diff changeset
  1226
  shows "sum_list (map asize2 (distinctBy rs f acc)) \<le> sum_list (map asize2 rs)"
d73b722efe0e updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 405
diff changeset
  1227
  apply(induct rs f acc rule: distinctBy.induct)
d73b722efe0e updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 405
diff changeset
  1228
  apply(auto)
d73b722efe0e updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 405
diff changeset
  1229
  done
d73b722efe0e updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 405
diff changeset
  1230
d73b722efe0e updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 405
diff changeset
  1231
lemma flts_asize2:
d73b722efe0e updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 405
diff changeset
  1232
  shows "sum_list (map asize2 (flts rs)) \<le> sum_list (map asize2 rs)"
d73b722efe0e updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 405
diff changeset
  1233
  apply(induct rs rule: flts.induct)
d73b722efe0e updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 405
diff changeset
  1234
  apply(auto simp add: comp_def asize2_fuse)
d73b722efe0e updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 405
diff changeset
  1235
  done
d73b722efe0e updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 405
diff changeset
  1236
d73b722efe0e updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 405
diff changeset
  1237
lemma sumlist_asize2:
d73b722efe0e updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 405
diff changeset
  1238
  assumes "\<And>x. x \<in> set rs \<Longrightarrow> asize2 (f x) \<le> asize2 x"
d73b722efe0e updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 405
diff changeset
  1239
  shows "sum_list (map asize2 (map f rs)) \<le> sum_list (map asize2 rs)"
d73b722efe0e updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 405
diff changeset
  1240
  using assms
d73b722efe0e updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 405
diff changeset
  1241
  apply(induct rs)
d73b722efe0e updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 405
diff changeset
  1242
   apply(auto simp add: comp_def)
d73b722efe0e updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 405
diff changeset
  1243
  by (simp add: add_le_mono)
d73b722efe0e updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 405
diff changeset
  1244
d73b722efe0e updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 405
diff changeset
  1245
lemma test0:
d73b722efe0e updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 405
diff changeset
  1246
  assumes "r1 \<leadsto>* r2"
d73b722efe0e updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 405
diff changeset
  1247
  shows "r1 = r2 \<or> (\<exists>r3. r1 \<leadsto> r3 \<and> r3 \<leadsto>* r2)"
d73b722efe0e updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 405
diff changeset
  1248
  using assms
d73b722efe0e updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 405
diff changeset
  1249
  apply(induct r1 r2 rule: rrewrites.induct)
d73b722efe0e updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 405
diff changeset
  1250
   apply(auto)
d73b722efe0e updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 405
diff changeset
  1251
  done
d73b722efe0e updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 405
diff changeset
  1252
d73b722efe0e updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 405
diff changeset
  1253
lemma test2:
d73b722efe0e updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 405
diff changeset
  1254
  assumes "r1 \<leadsto>* r2"
d73b722efe0e updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 405
diff changeset
  1255
  shows "asize2 r1 \<ge> asize2 r2"
d73b722efe0e updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 405
diff changeset
  1256
using assms
d73b722efe0e updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 405
diff changeset
  1257
  apply(induct r1 r2 rule: rrewrites.induct)
d73b722efe0e updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 405
diff changeset
  1258
  apply(auto)
d73b722efe0e updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 405
diff changeset
  1259
  using asize_rewrite(1) by fastforce
d73b722efe0e updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 405
diff changeset
  1260
  
d73b722efe0e updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 405
diff changeset
  1261
d73b722efe0e updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 405
diff changeset
  1262
lemma test3:
d73b722efe0e updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 405
diff changeset
  1263
  shows "r = bsimp r \<or> (asize2 (bsimp r) < asize2 r)"
d73b722efe0e updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 405
diff changeset
  1264
proof -
d73b722efe0e updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 405
diff changeset
  1265
  have "r \<leadsto>* bsimp r"
d73b722efe0e updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 405
diff changeset
  1266
    by (simp add: rewrites_to_bsimp)
d73b722efe0e updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 405
diff changeset
  1267
  then have "r = bsimp r \<or> (\<exists>r3. r \<leadsto> r3 \<and> r3 \<leadsto>* bsimp r)"
d73b722efe0e updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 405
diff changeset
  1268
    using test0 by blast
d73b722efe0e updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 405
diff changeset
  1269
  then show ?thesis
d73b722efe0e updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 405
diff changeset
  1270
    by (meson asize_rewrite(1) dual_order.strict_trans2 test2)
d73b722efe0e updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 405
diff changeset
  1271
qed
d73b722efe0e updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 405
diff changeset
  1272
d73b722efe0e updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 405
diff changeset
  1273
lemma test3Q:
d73b722efe0e updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 405
diff changeset
  1274
  shows "r = bsimp r \<or> (asize (bsimp r) \<le> asize r)"
d73b722efe0e updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 405
diff changeset
  1275
proof -
d73b722efe0e updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 405
diff changeset
  1276
  have "r \<leadsto>* bsimp r"
d73b722efe0e updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 405
diff changeset
  1277
    by (simp add: rewrites_to_bsimp)
d73b722efe0e updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 405
diff changeset
  1278
  then have "r = bsimp r \<or> (\<exists>r3. r \<leadsto> r3 \<and> r3 \<leadsto>* bsimp r)"
d73b722efe0e updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 405
diff changeset
  1279
    using test0 by blast
d73b722efe0e updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 405
diff changeset
  1280
  then show ?thesis
d73b722efe0e updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 405
diff changeset
  1281
    using asize_rewrite2(1) asize_rrewrites le_trans by blast
d73b722efe0e updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 405
diff changeset
  1282
qed
d73b722efe0e updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 405
diff changeset
  1283
d73b722efe0e updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 405
diff changeset
  1284
lemma test4:
d73b722efe0e updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 405
diff changeset
  1285
  shows "asize2 (bsimp (bsimp r)) \<le> asize2 (bsimp r)"
d73b722efe0e updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 405
diff changeset
  1286
  apply(induct r rule: bsimp.induct)
d73b722efe0e updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 405
diff changeset
  1287
       apply(auto)
d73b722efe0e updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 405
diff changeset
  1288
  using rewrites_to_bsimp test2 apply fastforce
d73b722efe0e updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 405
diff changeset
  1289
  using rewrites_to_bsimp test2 by presburger
d73b722efe0e updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 405
diff changeset
  1290
d73b722efe0e updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 405
diff changeset
  1291
lemma test4Q:
d73b722efe0e updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 405
diff changeset
  1292
  shows "asize (bsimp (bsimp r)) \<le> asize (bsimp r)"
d73b722efe0e updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 405
diff changeset
  1293
  apply(induct r rule: bsimp.induct)
d73b722efe0e updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 405
diff changeset
  1294
       apply(auto)
d73b722efe0e updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 405
diff changeset
  1295
  apply (metis order_refl test3Q)
d73b722efe0e updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 405
diff changeset
  1296
  by (metis le_refl test3Q)
d73b722efe0e updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 405
diff changeset
  1297
d73b722efe0e updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 405
diff changeset
  1298
d73b722efe0e updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 405
diff changeset
  1299
d73b722efe0e updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 405
diff changeset
  1300
lemma testb0:
d73b722efe0e updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 405
diff changeset
  1301
  shows "fuse bs1 (bsimp_ASEQ bs r1 r2) =  bsimp_ASEQ (bs1 @ bs) r1 r2"
d73b722efe0e updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 405
diff changeset
  1302
  apply(induct bs r1 r2 arbitrary: bs1 rule: bsimp_ASEQ.induct)
d73b722efe0e updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 405
diff changeset
  1303
  apply(auto)
d73b722efe0e updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 405
diff changeset
  1304
  done
d73b722efe0e updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 405
diff changeset
  1305
d73b722efe0e updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 405
diff changeset
  1306
lemma testb1:
d73b722efe0e updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 405
diff changeset
  1307
  shows "fuse bs1 (bsimp_AALTs bs rs) =  bsimp_AALTs (bs1 @ bs) rs"
d73b722efe0e updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 405
diff changeset
  1308
  apply(induct bs rs arbitrary: bs1 rule: bsimp_AALTs.induct)
d73b722efe0e updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 405
diff changeset
  1309
  apply(auto simp add: fuse_append)
d73b722efe0e updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 405
diff changeset
  1310
  done
d73b722efe0e updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 405
diff changeset
  1311
d73b722efe0e updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 405
diff changeset
  1312
lemma testb2:
d73b722efe0e updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 405
diff changeset
  1313
  shows "bsimp (bsimp_ASEQ bs r1 r2) =  bsimp_ASEQ bs (bsimp r1) (bsimp r2)"
d73b722efe0e updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 405
diff changeset
  1314
  apply(induct bs r1 r2 rule: bsimp_ASEQ.induct)
d73b722efe0e updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 405
diff changeset
  1315
  apply(auto simp add: testb0 testb1)
d73b722efe0e updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 405
diff changeset
  1316
  done  
d73b722efe0e updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 405
diff changeset
  1317
d73b722efe0e updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 405
diff changeset
  1318
lemma testb3:
d73b722efe0e updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 405
diff changeset
  1319
  shows "\<nexists>r'. (bsimp r \<leadsto> r') \<and> asize2 (bsimp r) > asize2 r'"
d73b722efe0e updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 405
diff changeset
  1320
apply(induct r rule: bsimp.induct)
d73b722efe0e updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 405
diff changeset
  1321
       apply(auto)
d73b722efe0e updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 405
diff changeset
  1322
       defer
d73b722efe0e updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 405
diff changeset
  1323
       defer
d73b722efe0e updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 405
diff changeset
  1324
  using rrewrite.cases apply blast
d73b722efe0e updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 405
diff changeset
  1325
  using rrewrite.cases apply blast
d73b722efe0e updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 405
diff changeset
  1326
  using rrewrite.cases apply blast
d73b722efe0e updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 405
diff changeset
  1327
  using rrewrite.cases apply blast
d73b722efe0e updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 405
diff changeset
  1328
  oops
d73b722efe0e updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 405
diff changeset
  1329
d73b722efe0e updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 405
diff changeset
  1330
lemma testb4:
d73b722efe0e updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 405
diff changeset
  1331
  assumes "sum_list (map asize rs1) \<le> sum_list (map asize rs2)"
d73b722efe0e updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 405
diff changeset
  1332
  shows "asize (bsimp_AALTs bs1 rs1) \<le> Suc (asize (bsimp_AALTs bs1 rs2))"
d73b722efe0e updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 405
diff changeset
  1333
  using assms 
d73b722efe0e updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 405
diff changeset
  1334
apply(induct bs1 rs2 arbitrary: rs1 rule: bsimp_AALTs.induct)
d73b722efe0e updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 405
diff changeset
  1335
    apply(auto)
d73b722efe0e updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 405
diff changeset
  1336
    apply(case_tac rs1)
d73b722efe0e updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 405
diff changeset
  1337
     apply(auto)
d73b722efe0e updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 405
diff changeset
  1338
  using asize2.elims apply auto[1]
d73b722efe0e updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 405
diff changeset
  1339
  apply (metis One_nat_def Zero_not_Suc asize.elims)
d73b722efe0e updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 405
diff changeset
  1340
      apply(case_tac rs1)
d73b722efe0e updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 405
diff changeset
  1341
    apply(auto)
d73b722efe0e updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 405
diff changeset
  1342
   apply(case_tac list)
d73b722efe0e updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 405
diff changeset
  1343
    apply(auto)
d73b722efe0e updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 405
diff changeset
  1344
  using asize_fuse apply force
d73b722efe0e updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 405
diff changeset
  1345
  apply (simp add: asize_fuse)
d73b722efe0e updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 405
diff changeset
  1346
  by (smt (verit, ccfv_threshold) One_nat_def add.right_neutral asize.simps(1) asize.simps(4) asize_fuse bsimp_AALTs.elims le_Suc_eq list.map(1) list.map(2) not_less_eq_eq sum_list_simps(1) sum_list_simps(2))
d73b722efe0e updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 405
diff changeset
  1347
d73b722efe0e updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 405
diff changeset
  1348
lemma flts_asize:
d73b722efe0e updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 405
diff changeset
  1349
  shows "sum_list (map asize (flts rs)) \<le> sum_list (map asize rs)"
d73b722efe0e updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 405
diff changeset
  1350
  apply(induct rs rule: flts.induct)
d73b722efe0e updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 405
diff changeset
  1351
  apply(auto simp add: comp_def asize_fuse)
d73b722efe0e updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 405
diff changeset
  1352
  done
d73b722efe0e updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 405
diff changeset
  1353
d73b722efe0e updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 405
diff changeset
  1354
d73b722efe0e updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 405
diff changeset
  1355
lemma test5:
d73b722efe0e updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 405
diff changeset
  1356
  shows "asize2 r \<ge> asize2 (bsimp r)"
d73b722efe0e updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 405
diff changeset
  1357
  apply(induct r rule: bsimp.induct)
d73b722efe0e updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 405
diff changeset
  1358
       apply(auto)
d73b722efe0e updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 405
diff changeset
  1359
  apply (meson Suc_le_mono add_le_mono asize2_bsimp_ASEQ order_trans)
d73b722efe0e updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 405
diff changeset
  1360
  apply(rule order_trans)
d73b722efe0e updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 405
diff changeset
  1361
   apply(rule asize2_bsimp_AALTs)
d73b722efe0e updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 405
diff changeset
  1362
  apply(simp)
d73b722efe0e updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 405
diff changeset
  1363
  apply(rule order_trans)
d73b722efe0e updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 405
diff changeset
  1364
   apply(rule distinctBy_asize2)
d73b722efe0e updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 405
diff changeset
  1365
  apply(rule order_trans)
d73b722efe0e updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 405
diff changeset
  1366
   apply(rule flts_asize2)
d73b722efe0e updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 405
diff changeset
  1367
  using sumlist_asize2 by force
d73b722efe0e updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 405
diff changeset
  1368
  
d73b722efe0e updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 405
diff changeset
  1369
405
3cfea5bb5e23 updated some of the text and cardinality proof
Christian Urban <christian.urban@kcl.ac.uk>
parents: 402
diff changeset
  1370
fun awidth :: "arexp \<Rightarrow> nat" where
3cfea5bb5e23 updated some of the text and cardinality proof
Christian Urban <christian.urban@kcl.ac.uk>
parents: 402
diff changeset
  1371
  "awidth AZERO = 1"
3cfea5bb5e23 updated some of the text and cardinality proof
Christian Urban <christian.urban@kcl.ac.uk>
parents: 402
diff changeset
  1372
| "awidth (AONE cs) = 1" 
3cfea5bb5e23 updated some of the text and cardinality proof
Christian Urban <christian.urban@kcl.ac.uk>
parents: 402
diff changeset
  1373
| "awidth (ACHAR cs c) = 1"
3cfea5bb5e23 updated some of the text and cardinality proof
Christian Urban <christian.urban@kcl.ac.uk>
parents: 402
diff changeset
  1374
| "awidth (AALTs cs rs) = (sum_list (map awidth rs))"
3cfea5bb5e23 updated some of the text and cardinality proof
Christian Urban <christian.urban@kcl.ac.uk>
parents: 402
diff changeset
  1375
| "awidth (ASEQ cs r1 r2) = (awidth r1 + awidth r2)"
3cfea5bb5e23 updated some of the text and cardinality proof
Christian Urban <christian.urban@kcl.ac.uk>
parents: 402
diff changeset
  1376
| "awidth (ASTAR cs r) = (awidth r)"
3cfea5bb5e23 updated some of the text and cardinality proof
Christian Urban <christian.urban@kcl.ac.uk>
parents: 402
diff changeset
  1377
3cfea5bb5e23 updated some of the text and cardinality proof
Christian Urban <christian.urban@kcl.ac.uk>
parents: 402
diff changeset
  1378
3cfea5bb5e23 updated some of the text and cardinality proof
Christian Urban <christian.urban@kcl.ac.uk>
parents: 402
diff changeset
  1379
3cfea5bb5e23 updated some of the text and cardinality proof
Christian Urban <christian.urban@kcl.ac.uk>
parents: 402
diff changeset
  1380
lemma 
3cfea5bb5e23 updated some of the text and cardinality proof
Christian Urban <christian.urban@kcl.ac.uk>
parents: 402
diff changeset
  1381
  shows "s \<notin> L r \<Longrightarrow> blexer_simp r s = None"
3cfea5bb5e23 updated some of the text and cardinality proof
Christian Urban <christian.urban@kcl.ac.uk>
parents: 402
diff changeset
  1382
  by (simp add: blexersimp_correctness lexer_correct_None)
3cfea5bb5e23 updated some of the text and cardinality proof
Christian Urban <christian.urban@kcl.ac.uk>
parents: 402
diff changeset
  1383
3cfea5bb5e23 updated some of the text and cardinality proof
Christian Urban <christian.urban@kcl.ac.uk>
parents: 402
diff changeset
  1384
lemma g1:
3cfea5bb5e23 updated some of the text and cardinality proof
Christian Urban <christian.urban@kcl.ac.uk>
parents: 402
diff changeset
  1385
  "bders_simp AZERO s = AZERO"
3cfea5bb5e23 updated some of the text and cardinality proof
Christian Urban <christian.urban@kcl.ac.uk>
parents: 402
diff changeset
  1386
 apply(induct s)
3cfea5bb5e23 updated some of the text and cardinality proof
Christian Urban <christian.urban@kcl.ac.uk>
parents: 402
diff changeset
  1387
 apply(simp)
3cfea5bb5e23 updated some of the text and cardinality proof
Christian Urban <christian.urban@kcl.ac.uk>
parents: 402
diff changeset
  1388
 apply(simp)
3cfea5bb5e23 updated some of the text and cardinality proof
Christian Urban <christian.urban@kcl.ac.uk>
parents: 402
diff changeset
  1389
  done
3cfea5bb5e23 updated some of the text and cardinality proof
Christian Urban <christian.urban@kcl.ac.uk>
parents: 402
diff changeset
  1390
3cfea5bb5e23 updated some of the text and cardinality proof
Christian Urban <christian.urban@kcl.ac.uk>
parents: 402
diff changeset
  1391
lemma g2:
3cfea5bb5e23 updated some of the text and cardinality proof
Christian Urban <christian.urban@kcl.ac.uk>
parents: 402
diff changeset
  1392
  "s \<noteq> Nil \<Longrightarrow> bders_simp (AONE bs) s = AZERO"
3cfea5bb5e23 updated some of the text and cardinality proof
Christian Urban <christian.urban@kcl.ac.uk>
parents: 402
diff changeset
  1393
 apply(induct s)
3cfea5bb5e23 updated some of the text and cardinality proof
Christian Urban <christian.urban@kcl.ac.uk>
parents: 402
diff changeset
  1394
 apply(simp)
3cfea5bb5e23 updated some of the text and cardinality proof
Christian Urban <christian.urban@kcl.ac.uk>
parents: 402
diff changeset
  1395
  apply(simp)
3cfea5bb5e23 updated some of the text and cardinality proof
Christian Urban <christian.urban@kcl.ac.uk>
parents: 402
diff changeset
  1396
  apply(case_tac s)
3cfea5bb5e23 updated some of the text and cardinality proof
Christian Urban <christian.urban@kcl.ac.uk>
parents: 402
diff changeset
  1397
  apply(simp)
3cfea5bb5e23 updated some of the text and cardinality proof
Christian Urban <christian.urban@kcl.ac.uk>
parents: 402
diff changeset
  1398
       apply(simp)
3cfea5bb5e23 updated some of the text and cardinality proof
Christian Urban <christian.urban@kcl.ac.uk>
parents: 402
diff changeset
  1399
  done
3cfea5bb5e23 updated some of the text and cardinality proof
Christian Urban <christian.urban@kcl.ac.uk>
parents: 402
diff changeset
  1400
3cfea5bb5e23 updated some of the text and cardinality proof
Christian Urban <christian.urban@kcl.ac.uk>
parents: 402
diff changeset
  1401
lemma finite_pder:
3cfea5bb5e23 updated some of the text and cardinality proof
Christian Urban <christian.urban@kcl.ac.uk>
parents: 402
diff changeset
  1402
  shows "finite (pder c r)"
3cfea5bb5e23 updated some of the text and cardinality proof
Christian Urban <christian.urban@kcl.ac.uk>
parents: 402
diff changeset
  1403
  apply(induct c r rule: pder.induct)
3cfea5bb5e23 updated some of the text and cardinality proof
Christian Urban <christian.urban@kcl.ac.uk>
parents: 402
diff changeset
  1404
  apply(auto)
3cfea5bb5e23 updated some of the text and cardinality proof
Christian Urban <christian.urban@kcl.ac.uk>
parents: 402
diff changeset
  1405
  done
3cfea5bb5e23 updated some of the text and cardinality proof
Christian Urban <christian.urban@kcl.ac.uk>
parents: 402
diff changeset
  1406
407
d73b722efe0e updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 405
diff changeset
  1407
405
3cfea5bb5e23 updated some of the text and cardinality proof
Christian Urban <christian.urban@kcl.ac.uk>
parents: 402
diff changeset
  1408
3cfea5bb5e23 updated some of the text and cardinality proof
Christian Urban <christian.urban@kcl.ac.uk>
parents: 402
diff changeset
  1409
lemma awidth_fuse:
3cfea5bb5e23 updated some of the text and cardinality proof
Christian Urban <christian.urban@kcl.ac.uk>
parents: 402
diff changeset
  1410
  shows "awidth (fuse bs r) = awidth r"
3cfea5bb5e23 updated some of the text and cardinality proof
Christian Urban <christian.urban@kcl.ac.uk>
parents: 402
diff changeset
  1411
  apply(induct r arbitrary: bs)
3cfea5bb5e23 updated some of the text and cardinality proof
Christian Urban <christian.urban@kcl.ac.uk>
parents: 402
diff changeset
  1412
  apply(auto)
3cfea5bb5e23 updated some of the text and cardinality proof
Christian Urban <christian.urban@kcl.ac.uk>
parents: 402
diff changeset
  1413
  done
3cfea5bb5e23 updated some of the text and cardinality proof
Christian Urban <christian.urban@kcl.ac.uk>
parents: 402
diff changeset
  1414
3cfea5bb5e23 updated some of the text and cardinality proof
Christian Urban <christian.urban@kcl.ac.uk>
parents: 402
diff changeset
  1415
lemma pders_SEQs:
3cfea5bb5e23 updated some of the text and cardinality proof
Christian Urban <christian.urban@kcl.ac.uk>
parents: 402
diff changeset
  1416
  assumes "finite A"
3cfea5bb5e23 updated some of the text and cardinality proof
Christian Urban <christian.urban@kcl.ac.uk>
parents: 402
diff changeset
  1417
  shows "card (SEQs A (STAR r)) \<le> card A"
3cfea5bb5e23 updated some of the text and cardinality proof
Christian Urban <christian.urban@kcl.ac.uk>
parents: 402
diff changeset
  1418
  using assms
3cfea5bb5e23 updated some of the text and cardinality proof
Christian Urban <christian.urban@kcl.ac.uk>
parents: 402
diff changeset
  1419
  by (simp add: SEQs_eq_image card_image_le)
3cfea5bb5e23 updated some of the text and cardinality proof
Christian Urban <christian.urban@kcl.ac.uk>
parents: 402
diff changeset
  1420
3cfea5bb5e23 updated some of the text and cardinality proof
Christian Urban <christian.urban@kcl.ac.uk>
parents: 402
diff changeset
  1421
lemma binullable_intern:
3cfea5bb5e23 updated some of the text and cardinality proof
Christian Urban <christian.urban@kcl.ac.uk>
parents: 402
diff changeset
  1422
  shows "bnullable (intern r) = nullable r"
3cfea5bb5e23 updated some of the text and cardinality proof
Christian Urban <christian.urban@kcl.ac.uk>
parents: 402
diff changeset
  1423
  apply(induct r)
3cfea5bb5e23 updated some of the text and cardinality proof
Christian Urban <christian.urban@kcl.ac.uk>
parents: 402
diff changeset
  1424
  apply(auto simp add: bnullable_fuse)
3cfea5bb5e23 updated some of the text and cardinality proof
Christian Urban <christian.urban@kcl.ac.uk>
parents: 402
diff changeset
  1425
  done
3cfea5bb5e23 updated some of the text and cardinality proof
Christian Urban <christian.urban@kcl.ac.uk>
parents: 402
diff changeset
  1426
3cfea5bb5e23 updated some of the text and cardinality proof
Christian Urban <christian.urban@kcl.ac.uk>
parents: 402
diff changeset
  1427
lemma
3cfea5bb5e23 updated some of the text and cardinality proof
Christian Urban <christian.urban@kcl.ac.uk>
parents: 402
diff changeset
  1428
  "card (pder c r) \<le> awidth (bder c (intern r))"
3cfea5bb5e23 updated some of the text and cardinality proof
Christian Urban <christian.urban@kcl.ac.uk>
parents: 402
diff changeset
  1429
  apply(induct c r rule: pder.induct)
3cfea5bb5e23 updated some of the text and cardinality proof
Christian Urban <christian.urban@kcl.ac.uk>
parents: 402
diff changeset
  1430
  apply(simp)
3cfea5bb5e23 updated some of the text and cardinality proof
Christian Urban <christian.urban@kcl.ac.uk>
parents: 402
diff changeset
  1431
      apply(simp)
3cfea5bb5e23 updated some of the text and cardinality proof
Christian Urban <christian.urban@kcl.ac.uk>
parents: 402
diff changeset
  1432
     apply(simp)
3cfea5bb5e23 updated some of the text and cardinality proof
Christian Urban <christian.urban@kcl.ac.uk>
parents: 402
diff changeset
  1433
    apply(simp)
3cfea5bb5e23 updated some of the text and cardinality proof
Christian Urban <christian.urban@kcl.ac.uk>
parents: 402
diff changeset
  1434
  apply(rule order_trans)
3cfea5bb5e23 updated some of the text and cardinality proof
Christian Urban <christian.urban@kcl.ac.uk>
parents: 402
diff changeset
  1435
     apply(rule card_Un_le)
3cfea5bb5e23 updated some of the text and cardinality proof
Christian Urban <christian.urban@kcl.ac.uk>
parents: 402
diff changeset
  1436
  apply (simp add: awidth_fuse bder_fuse)
3cfea5bb5e23 updated some of the text and cardinality proof
Christian Urban <christian.urban@kcl.ac.uk>
parents: 402
diff changeset
  1437
   defer
3cfea5bb5e23 updated some of the text and cardinality proof
Christian Urban <christian.urban@kcl.ac.uk>
parents: 402
diff changeset
  1438
   apply(simp)
3cfea5bb5e23 updated some of the text and cardinality proof
Christian Urban <christian.urban@kcl.ac.uk>
parents: 402
diff changeset
  1439
  apply(rule order_trans)
3cfea5bb5e23 updated some of the text and cardinality proof
Christian Urban <christian.urban@kcl.ac.uk>
parents: 402
diff changeset
  1440
    apply(rule pders_SEQs)
3cfea5bb5e23 updated some of the text and cardinality proof
Christian Urban <christian.urban@kcl.ac.uk>
parents: 402
diff changeset
  1441
  using finite_pder apply presburger
3cfea5bb5e23 updated some of the text and cardinality proof
Christian Urban <christian.urban@kcl.ac.uk>
parents: 402
diff changeset
  1442
  apply (simp add: awidth_fuse)
3cfea5bb5e23 updated some of the text and cardinality proof
Christian Urban <christian.urban@kcl.ac.uk>
parents: 402
diff changeset
  1443
  apply(auto)
3cfea5bb5e23 updated some of the text and cardinality proof
Christian Urban <christian.urban@kcl.ac.uk>
parents: 402
diff changeset
  1444
     apply(rule order_trans)
3cfea5bb5e23 updated some of the text and cardinality proof
Christian Urban <christian.urban@kcl.ac.uk>
parents: 402
diff changeset
  1445
      apply(rule card_Un_le)
3cfea5bb5e23 updated some of the text and cardinality proof
Christian Urban <christian.urban@kcl.ac.uk>
parents: 402
diff changeset
  1446
     apply(simp add: awidth_fuse)
3cfea5bb5e23 updated some of the text and cardinality proof
Christian Urban <christian.urban@kcl.ac.uk>
parents: 402
diff changeset
  1447
     defer
3cfea5bb5e23 updated some of the text and cardinality proof
Christian Urban <christian.urban@kcl.ac.uk>
parents: 402
diff changeset
  1448
  using binullable_intern apply blast
3cfea5bb5e23 updated some of the text and cardinality proof
Christian Urban <christian.urban@kcl.ac.uk>
parents: 402
diff changeset
  1449
  using binullable_intern apply blast
3cfea5bb5e23 updated some of the text and cardinality proof
Christian Urban <christian.urban@kcl.ac.uk>
parents: 402
diff changeset
  1450
  apply (smt (verit, best) SEQs_eq_image add.commute add_Suc_right card_image_le dual_order.trans finite_pder trans_le_add2)
3cfea5bb5e23 updated some of the text and cardinality proof
Christian Urban <christian.urban@kcl.ac.uk>
parents: 402
diff changeset
  1451
  apply(subgoal_tac "card (SEQs (pder c r1) r2) \<le> card (pder c r1)")
3cfea5bb5e23 updated some of the text and cardinality proof
Christian Urban <christian.urban@kcl.ac.uk>
parents: 402
diff changeset
  1452
  apply(linarith)
3cfea5bb5e23 updated some of the text and cardinality proof
Christian Urban <christian.urban@kcl.ac.uk>
parents: 402
diff changeset
  1453
    by (simp add: UNION_singleton_eq_range card_image_le finite_pder)
3cfea5bb5e23 updated some of the text and cardinality proof
Christian Urban <christian.urban@kcl.ac.uk>
parents: 402
diff changeset
  1454
  
3cfea5bb5e23 updated some of the text and cardinality proof
Christian Urban <christian.urban@kcl.ac.uk>
parents: 402
diff changeset
  1455
lemma
3cfea5bb5e23 updated some of the text and cardinality proof
Christian Urban <christian.urban@kcl.ac.uk>
parents: 402
diff changeset
  1456
  "card (pder c r) \<le> asize (bder c (intern r))"
3cfea5bb5e23 updated some of the text and cardinality proof
Christian Urban <christian.urban@kcl.ac.uk>
parents: 402
diff changeset
  1457
  apply(induct c r rule: pder.induct)
3cfea5bb5e23 updated some of the text and cardinality proof
Christian Urban <christian.urban@kcl.ac.uk>
parents: 402
diff changeset
  1458
       apply(simp)
3cfea5bb5e23 updated some of the text and cardinality proof
Christian Urban <christian.urban@kcl.ac.uk>
parents: 402
diff changeset
  1459
  apply(simp)
3cfea5bb5e23 updated some of the text and cardinality proof
Christian Urban <christian.urban@kcl.ac.uk>
parents: 402
diff changeset
  1460
     apply(simp)
3cfea5bb5e23 updated some of the text and cardinality proof
Christian Urban <christian.urban@kcl.ac.uk>
parents: 402
diff changeset
  1461
    apply(simp)
3cfea5bb5e23 updated some of the text and cardinality proof
Christian Urban <christian.urban@kcl.ac.uk>
parents: 402
diff changeset
  1462
  apply (metis add_mono_thms_linordered_semiring(1) asize_fuse bder_fuse card_Un_le le_Suc_eq order_trans)
3cfea5bb5e23 updated some of the text and cardinality proof
Christian Urban <christian.urban@kcl.ac.uk>
parents: 402
diff changeset
  1463
  defer 
3cfea5bb5e23 updated some of the text and cardinality proof
Christian Urban <christian.urban@kcl.ac.uk>
parents: 402
diff changeset
  1464
   apply(simp)
3cfea5bb5e23 updated some of the text and cardinality proof
Christian Urban <christian.urban@kcl.ac.uk>
parents: 402
diff changeset
  1465
   apply(rule order_trans)
3cfea5bb5e23 updated some of the text and cardinality proof
Christian Urban <christian.urban@kcl.ac.uk>
parents: 402
diff changeset
  1466
    apply(rule pders_SEQs)
3cfea5bb5e23 updated some of the text and cardinality proof
Christian Urban <christian.urban@kcl.ac.uk>
parents: 402
diff changeset
  1467
  using finite_pder apply presburger
3cfea5bb5e23 updated some of the text and cardinality proof
Christian Urban <christian.urban@kcl.ac.uk>
parents: 402
diff changeset
  1468
  apply (simp add: asize_fuse)
3cfea5bb5e23 updated some of the text and cardinality proof
Christian Urban <christian.urban@kcl.ac.uk>
parents: 402
diff changeset
  1469
  apply(simp)
3cfea5bb5e23 updated some of the text and cardinality proof
Christian Urban <christian.urban@kcl.ac.uk>
parents: 402
diff changeset
  1470
  apply(auto)
3cfea5bb5e23 updated some of the text and cardinality proof
Christian Urban <christian.urban@kcl.ac.uk>
parents: 402
diff changeset
  1471
  apply(rule order_trans)
3cfea5bb5e23 updated some of the text and cardinality proof
Christian Urban <christian.urban@kcl.ac.uk>
parents: 402
diff changeset
  1472
      apply(rule card_Un_le)
3cfea5bb5e23 updated some of the text and cardinality proof
Christian Urban <christian.urban@kcl.ac.uk>
parents: 402
diff changeset
  1473
  apply (smt (z3) SEQs_eq_image add.commute add_Suc_right add_mono_thms_linordered_semiring(1) asize_fuse card_image_le dual_order.trans finite_pder le_add1)
3cfea5bb5e23 updated some of the text and cardinality proof
Christian Urban <christian.urban@kcl.ac.uk>
parents: 402
diff changeset
  1474
    apply(rule order_trans)
3cfea5bb5e23 updated some of the text and cardinality proof
Christian Urban <christian.urban@kcl.ac.uk>
parents: 402
diff changeset
  1475
     apply(rule card_Un_le)
3cfea5bb5e23 updated some of the text and cardinality proof
Christian Urban <christian.urban@kcl.ac.uk>
parents: 402
diff changeset
  1476
  using binullable_intern apply blast
3cfea5bb5e23 updated some of the text and cardinality proof
Christian Urban <christian.urban@kcl.ac.uk>
parents: 402
diff changeset
  1477
  using binullable_intern apply blast
3cfea5bb5e23 updated some of the text and cardinality proof
Christian Urban <christian.urban@kcl.ac.uk>
parents: 402
diff changeset
  1478
  by (smt (verit, best) SEQs_eq_image add.commute add_Suc_right card_image_le dual_order.trans finite_pder trans_le_add2)
410
9261d980225d updated papers
Christian Urban <christian.urban@kcl.ac.uk>
parents: 407
diff changeset
  1479
9261d980225d updated papers
Christian Urban <christian.urban@kcl.ac.uk>
parents: 407
diff changeset
  1480
9261d980225d updated papers
Christian Urban <christian.urban@kcl.ac.uk>
parents: 407
diff changeset
  1481
405
3cfea5bb5e23 updated some of the text and cardinality proof
Christian Urban <christian.urban@kcl.ac.uk>
parents: 402
diff changeset
  1482
lemma
3cfea5bb5e23 updated some of the text and cardinality proof
Christian Urban <christian.urban@kcl.ac.uk>
parents: 402
diff changeset
  1483
  "card (pder c r) \<le> asize (bsimp (bder c (intern r)))"
3cfea5bb5e23 updated some of the text and cardinality proof
Christian Urban <christian.urban@kcl.ac.uk>
parents: 402
diff changeset
  1484
  apply(induct c r rule: pder.induct)
3cfea5bb5e23 updated some of the text and cardinality proof
Christian Urban <christian.urban@kcl.ac.uk>
parents: 402
diff changeset
  1485
       apply(simp)
3cfea5bb5e23 updated some of the text and cardinality proof
Christian Urban <christian.urban@kcl.ac.uk>
parents: 402
diff changeset
  1486
      apply(simp)
3cfea5bb5e23 updated some of the text and cardinality proof
Christian Urban <christian.urban@kcl.ac.uk>
parents: 402
diff changeset
  1487
     apply(simp)
3cfea5bb5e23 updated some of the text and cardinality proof
Christian Urban <christian.urban@kcl.ac.uk>
parents: 402
diff changeset
  1488
    apply(simp)
3cfea5bb5e23 updated some of the text and cardinality proof
Christian Urban <christian.urban@kcl.ac.uk>
parents: 402
diff changeset
  1489
  apply(rule order_trans)
3cfea5bb5e23 updated some of the text and cardinality proof
Christian Urban <christian.urban@kcl.ac.uk>
parents: 402
diff changeset
  1490
     apply(rule card_Un_le)
3cfea5bb5e23 updated some of the text and cardinality proof
Christian Urban <christian.urban@kcl.ac.uk>
parents: 402
diff changeset
  1491
    prefer 3
3cfea5bb5e23 updated some of the text and cardinality proof
Christian Urban <christian.urban@kcl.ac.uk>
parents: 402
diff changeset
  1492
    apply(simp)
3cfea5bb5e23 updated some of the text and cardinality proof
Christian Urban <christian.urban@kcl.ac.uk>
parents: 402
diff changeset
  1493
  apply(rule order_trans)
3cfea5bb5e23 updated some of the text and cardinality proof
Christian Urban <christian.urban@kcl.ac.uk>
parents: 402
diff changeset
  1494
     apply(rule pders_SEQs)
3cfea5bb5e23 updated some of the text and cardinality proof
Christian Urban <christian.urban@kcl.ac.uk>
parents: 402
diff changeset
  1495
  using finite_pder apply blast
3cfea5bb5e23 updated some of the text and cardinality proof
Christian Urban <christian.urban@kcl.ac.uk>
parents: 402
diff changeset
  1496
  oops
3cfea5bb5e23 updated some of the text and cardinality proof
Christian Urban <christian.urban@kcl.ac.uk>
parents: 402
diff changeset
  1497
  
416
57182b36ec01 more with the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents: 411
diff changeset
  1498
*)
410
9261d980225d updated papers
Christian Urban <christian.urban@kcl.ac.uk>
parents: 407
diff changeset
  1499
9261d980225d updated papers
Christian Urban <christian.urban@kcl.ac.uk>
parents: 407
diff changeset
  1500
400
46e5566ad4ba updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 398
diff changeset
  1501
(* below is the idempotency of bsimp *)
378
Chengsong
parents: 375
diff changeset
  1502
416
57182b36ec01 more with the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents: 411
diff changeset
  1503
(*
57182b36ec01 more with the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents: 411
diff changeset
  1504
400
46e5566ad4ba updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 398
diff changeset
  1505
lemma bsimp_ASEQ_fuse:
46e5566ad4ba updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 398
diff changeset
  1506
  shows "fuse bs1 (bsimp_ASEQ bs2 r1 r2) = bsimp_ASEQ (bs1 @ bs2) r1 r2"
46e5566ad4ba updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 398
diff changeset
  1507
  apply(induct r1 r2 arbitrary: bs1 bs2 rule: bsimp_ASEQ.induct)
46e5566ad4ba updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 398
diff changeset
  1508
  apply(auto)
46e5566ad4ba updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 398
diff changeset
  1509
  done
46e5566ad4ba updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 398
diff changeset
  1510
46e5566ad4ba updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 398
diff changeset
  1511
lemma bsimp_AALTs_fuse:
46e5566ad4ba updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 398
diff changeset
  1512
  assumes "\<forall>r \<in> set rs. fuse bs1 (fuse bs2 r) = fuse (bs1 @ bs2) r"
46e5566ad4ba updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 398
diff changeset
  1513
  shows "fuse bs1 (bsimp_AALTs bs2 rs) = bsimp_AALTs (bs1 @ bs2) rs"
46e5566ad4ba updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 398
diff changeset
  1514
  using assms
46e5566ad4ba updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 398
diff changeset
  1515
  apply(induct bs2 rs arbitrary: bs1 rule: bsimp_AALTs.induct)
46e5566ad4ba updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 398
diff changeset
  1516
  apply(auto)
46e5566ad4ba updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 398
diff changeset
  1517
  done
46e5566ad4ba updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 398
diff changeset
  1518
46e5566ad4ba updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 398
diff changeset
  1519
lemma bsimp_fuse:
46e5566ad4ba updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 398
diff changeset
  1520
  shows "fuse bs (bsimp r) = bsimp (fuse bs r)"
46e5566ad4ba updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 398
diff changeset
  1521
  apply(induct r arbitrary: bs)
46e5566ad4ba updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 398
diff changeset
  1522
  apply(simp_all add: bsimp_ASEQ_fuse bsimp_AALTs_fuse fuse_append)
46e5566ad4ba updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 398
diff changeset
  1523
  done
46e5566ad4ba updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 398
diff changeset
  1524
46e5566ad4ba updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 398
diff changeset
  1525
lemma bsimp_ASEQ_idem:
46e5566ad4ba updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 398
diff changeset
  1526
  assumes "bsimp (bsimp r1) = bsimp r1" "bsimp (bsimp r2) = bsimp r2"
46e5566ad4ba updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 398
diff changeset
  1527
  shows "bsimp (bsimp_ASEQ x1 (bsimp r1) (bsimp r2)) = bsimp_ASEQ x1 (bsimp r1) (bsimp r2)"
46e5566ad4ba updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 398
diff changeset
  1528
  using assms
46e5566ad4ba updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 398
diff changeset
  1529
  apply(case_tac "bsimp r1 = AZERO")
46e5566ad4ba updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 398
diff changeset
  1530
  apply(simp)
46e5566ad4ba updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 398
diff changeset
  1531
  apply(case_tac "bsimp r2 = AZERO")
46e5566ad4ba updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 398
diff changeset
  1532
  apply(simp)
46e5566ad4ba updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 398
diff changeset
  1533
  apply(case_tac "\<exists>bs. bsimp r1 = AONE bs")
46e5566ad4ba updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 398
diff changeset
  1534
  apply(auto)[1]
46e5566ad4ba updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 398
diff changeset
  1535
  apply (metis bsimp_fuse)
46e5566ad4ba updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 398
diff changeset
  1536
  apply(simp add: bsimp_ASEQ1)
46e5566ad4ba updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 398
diff changeset
  1537
  done  
46e5566ad4ba updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 398
diff changeset
  1538
46e5566ad4ba updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 398
diff changeset
  1539
lemma bsimp_AALTs_idem:
46e5566ad4ba updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 398
diff changeset
  1540
  assumes "\<forall>r \<in> set rs. bsimp (bsimp r) = bsimp r" 
46e5566ad4ba updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 398
diff changeset
  1541
  shows "bsimp (bsimp_AALTs bs rs) = bsimp_AALTs bs (map bsimp rs)" 
46e5566ad4ba updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 398
diff changeset
  1542
  using assms
46e5566ad4ba updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 398
diff changeset
  1543
  apply(induct bs rs rule: bsimp_AALTs.induct)
46e5566ad4ba updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 398
diff changeset
  1544
  apply(simp)
46e5566ad4ba updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 398
diff changeset
  1545
   apply(simp)
46e5566ad4ba updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 398
diff changeset
  1546
  using bsimp_fuse apply presburger
46e5566ad4ba updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 398
diff changeset
  1547
  oops   
46e5566ad4ba updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 398
diff changeset
  1548
  
46e5566ad4ba updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 398
diff changeset
  1549
lemma bsimp_idem_rev:
46e5566ad4ba updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 398
diff changeset
  1550
  shows "\<nexists>r2. bsimp r1 \<leadsto> r2"
46e5566ad4ba updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 398
diff changeset
  1551
  apply(induct r1 rule: bsimp.induct)
46e5566ad4ba updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 398
diff changeset
  1552
  apply(auto)
46e5566ad4ba updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 398
diff changeset
  1553
  defer
46e5566ad4ba updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 398
diff changeset
  1554
  defer
46e5566ad4ba updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 398
diff changeset
  1555
  using rrewrite.simps apply blast
46e5566ad4ba updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 398
diff changeset
  1556
  using rrewrite.cases apply blast
46e5566ad4ba updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 398
diff changeset
  1557
  using rrewrite.simps apply blast
46e5566ad4ba updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 398
diff changeset
  1558
  using rrewrite.cases apply blast
46e5566ad4ba updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 398
diff changeset
  1559
  apply(case_tac "bsimp r1 = AZERO")
46e5566ad4ba updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 398
diff changeset
  1560
  apply(simp)
46e5566ad4ba updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 398
diff changeset
  1561
  apply(case_tac "bsimp r2 = AZERO")
46e5566ad4ba updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 398
diff changeset
  1562
  apply(simp)
46e5566ad4ba updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 398
diff changeset
  1563
  apply(case_tac "\<exists>bs. bsimp r1 = AONE bs")
46e5566ad4ba updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 398
diff changeset
  1564
  apply(auto)[1]
46e5566ad4ba updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 398
diff changeset
  1565
  prefer 2
46e5566ad4ba updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 398
diff changeset
  1566
  apply (smt (verit, best) arexp.distinct(25) arexp.inject(3) bsimp_ASEQ1 rrewrite.simps)
46e5566ad4ba updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 398
diff changeset
  1567
  defer
46e5566ad4ba updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 398
diff changeset
  1568
  oops
46e5566ad4ba updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 398
diff changeset
  1569
46e5566ad4ba updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 398
diff changeset
  1570
lemma bsimp_idem:
46e5566ad4ba updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 398
diff changeset
  1571
  shows "bsimp (bsimp r) = bsimp r"
398
dac6d27c99c6 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 397
diff changeset
  1572
  apply(induct r rule: bsimp.induct)
dac6d27c99c6 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 397
diff changeset
  1573
  apply(auto)
400
46e5566ad4ba updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 398
diff changeset
  1574
  using bsimp_ASEQ_idem apply presburger
398
dac6d27c99c6 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 397
diff changeset
  1575
  oops
dac6d27c99c6 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 397
diff changeset
  1576
409
Chengsong
parents: 407
diff changeset
  1577
lemma neg:
Chengsong
parents: 407
diff changeset
  1578
  shows " \<not>(\<exists>r2. r1 \<leadsto> r2 \<and>  (r2 \<leadsto>* bsimp r1) )"
Chengsong
parents: 407
diff changeset
  1579
  apply(rule notI)
Chengsong
parents: 407
diff changeset
  1580
  apply(erule exE)
Chengsong
parents: 407
diff changeset
  1581
  apply(erule conjE)
Chengsong
parents: 407
diff changeset
  1582
  oops
Chengsong
parents: 407
diff changeset
  1583
Chengsong
parents: 407
diff changeset
  1584
Chengsong
parents: 407
diff changeset
  1585
Chengsong
parents: 407
diff changeset
  1586
Chengsong
parents: 407
diff changeset
  1587
lemma reduction_always_in_bsimp:
Chengsong
parents: 407
diff changeset
  1588
  shows " \<lbrakk> r1 \<leadsto> r2 ; \<not>(r2 \<leadsto>* bsimp r1)\<rbrakk> \<Longrightarrow> False"
Chengsong
parents: 407
diff changeset
  1589
  apply(erule rrewrite.cases)
Chengsong
parents: 407
diff changeset
  1590
         apply simp
Chengsong
parents: 407
diff changeset
  1591
        apply auto
Chengsong
parents: 407
diff changeset
  1592
Chengsong
parents: 407
diff changeset
  1593
  oops
416
57182b36ec01 more with the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents: 411
diff changeset
  1594
*)
57182b36ec01 more with the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents: 411
diff changeset
  1595
409
Chengsong
parents: 407
diff changeset
  1596
Chengsong
parents: 407
diff changeset
  1597
(*
Chengsong
parents: 407
diff changeset
  1598
AALTs [] [AZERO, AALTs(bs1, [a, b]) ] 
Chengsong
parents: 407
diff changeset
  1599
rewrite seq 1: \<leadsto> AALTs [] [ AALTs(bs1, [a, b]) ] \<leadsto>
Chengsong
parents: 407
diff changeset
  1600
fuse [] (AALTs bs1, [a, b])
Chengsong
parents: 407
diff changeset
  1601
rewrite seq 2: \<leadsto> AALTs [] [AZERO, (fuse bs1 a), (fuse bs1 b)]) ]
Chengsong
parents: 407
diff changeset
  1602
Chengsong
parents: 407
diff changeset
  1603
*)
Chengsong
parents: 407
diff changeset
  1604
Chengsong
parents: 407
diff changeset
  1605
Chengsong
parents: 407
diff changeset
  1606
  (*r' size bsimp r > size r' 
Chengsong
parents: 407
diff changeset
  1607
    r' \<leadsto>* bsimp bsimp r
Chengsong
parents: 407
diff changeset
  1608
size bsimp r > size r' \<ge> size bsimp bsimp r*)
Chengsong
parents: 407
diff changeset
  1609
378
Chengsong
parents: 375
diff changeset
  1610
365
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1611
unused_thms
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1612
416
57182b36ec01 more with the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents: 411
diff changeset
  1613
(*
378
Chengsong
parents: 375
diff changeset
  1614
inductive aggressive:: "arexp \<Rightarrow> arexp \<Rightarrow> bool" ("_ \<leadsto>? _" [99, 99] 99)
Chengsong
parents: 375
diff changeset
  1615
  where
Chengsong
parents: 375
diff changeset
  1616
 "ASEQ bs (AALTs bs1 rs) r \<leadsto>? AALTs (bs@bs1) (map (\<lambda>r'. ASEQ [] r' r) rs) "
416
57182b36ec01 more with the paper
Christian Urban <christian.urban@kcl.ac.uk>
parents: 411
diff changeset
  1617
*)
378
Chengsong
parents: 375
diff changeset
  1618
Chengsong
parents: 375
diff changeset
  1619
365
ec5e4fe4cc70 for new journal/conf paper!
Chengsong
parents:
diff changeset
  1620
end