thys2/SizeBound6CT.thy
author Chengsong
Wed, 02 Mar 2022 23:23:19 +0000
changeset 439 a5376206fd52
parent 438 a73b2e553804
parent 437 43b87bab0dac
child 441 426a93160f4a
permissions -rw-r--r--
merged
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
433
Chengsong
parents:
diff changeset
     1
Chengsong
parents:
diff changeset
     2
theory SizeBound6CT
Chengsong
parents:
diff changeset
     3
  imports "Lexer" "PDerivs" 
Chengsong
parents:
diff changeset
     4
begin
Chengsong
parents:
diff changeset
     5
Chengsong
parents:
diff changeset
     6
section \<open>Bit-Encodings\<close>
Chengsong
parents:
diff changeset
     7
Chengsong
parents:
diff changeset
     8
fun orderedSufAux :: "nat \<Rightarrow> char list \<Rightarrow> char list list"
Chengsong
parents:
diff changeset
     9
  where
Chengsong
parents:
diff changeset
    10
 "orderedSufAux (Suc i) ss = (drop i ss) # (orderedSufAux i ss)"
Chengsong
parents:
diff changeset
    11
|"orderedSufAux 0 ss = Nil"
Chengsong
parents:
diff changeset
    12
Chengsong
parents:
diff changeset
    13
fun 
Chengsong
parents:
diff changeset
    14
orderedSuf :: "char list \<Rightarrow> char list list"
Chengsong
parents:
diff changeset
    15
where
Chengsong
parents:
diff changeset
    16
"orderedSuf s = orderedSufAux (length s) s"
Chengsong
parents:
diff changeset
    17
Chengsong
parents:
diff changeset
    18
fun orderedPrefAux :: "nat \<Rightarrow> char list \<Rightarrow> char list list"
Chengsong
parents:
diff changeset
    19
  where
Chengsong
parents:
diff changeset
    20
"orderedPrefAux (Suc i) ss = (take i ss) # (orderedPrefAux i ss)"
Chengsong
parents:
diff changeset
    21
|"orderedPrefAux 0 ss = Nil"
Chengsong
parents:
diff changeset
    22
Chengsong
parents:
diff changeset
    23
438
a73b2e553804 templateforPhd
Chengsong
parents: 435
diff changeset
    24
fun ordsuf :: "char list \<Rightarrow> char list list"
a73b2e553804 templateforPhd
Chengsong
parents: 435
diff changeset
    25
  where
a73b2e553804 templateforPhd
Chengsong
parents: 435
diff changeset
    26
  "ordsuf [] = []"
a73b2e553804 templateforPhd
Chengsong
parents: 435
diff changeset
    27
| "ordsuf (x # xs) = (ordsuf xs) @ [(x # xs)]" 
a73b2e553804 templateforPhd
Chengsong
parents: 435
diff changeset
    28
a73b2e553804 templateforPhd
Chengsong
parents: 435
diff changeset
    29
433
Chengsong
parents:
diff changeset
    30
fun orderedPref :: "char list \<Rightarrow> char list list"
Chengsong
parents:
diff changeset
    31
  where
Chengsong
parents:
diff changeset
    32
"orderedPref s = orderedPrefAux (length s) s"
Chengsong
parents:
diff changeset
    33
Chengsong
parents:
diff changeset
    34
lemma shape_of_pref_1list:
Chengsong
parents:
diff changeset
    35
  shows "orderedPref [c] = [[]]"
Chengsong
parents:
diff changeset
    36
  apply auto
Chengsong
parents:
diff changeset
    37
  done
Chengsong
parents:
diff changeset
    38
Chengsong
parents:
diff changeset
    39
lemma shape_of_suf_1list:
Chengsong
parents:
diff changeset
    40
  shows "orderedSuf [c] = [[c]]"
Chengsong
parents:
diff changeset
    41
  by auto
Chengsong
parents:
diff changeset
    42
Chengsong
parents:
diff changeset
    43
lemma shape_of_suf_2list:
Chengsong
parents:
diff changeset
    44
  shows "orderedSuf [c2, c3] = [[c3], [c2,c3]]"
Chengsong
parents:
diff changeset
    45
  by auto
Chengsong
parents:
diff changeset
    46
Chengsong
parents:
diff changeset
    47
lemma shape_of_prf_2list:
Chengsong
parents:
diff changeset
    48
  shows "orderedPref [c1, c2] = [[c1], []]"
Chengsong
parents:
diff changeset
    49
  by auto
Chengsong
parents:
diff changeset
    50
Chengsong
parents:
diff changeset
    51
Chengsong
parents:
diff changeset
    52
lemma shape_of_suf_3list:
Chengsong
parents:
diff changeset
    53
  shows "orderedSuf [c1, c2, c3] = [[c3], [c2, c3], [c1, c2, c3]]"
Chengsong
parents:
diff changeset
    54
  by auto
Chengsong
parents:
diff changeset
    55
436
222333d2bdc2 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 434
diff changeset
    56
222333d2bdc2 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 434
diff changeset
    57
lemma ordsuf_last:
222333d2bdc2 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 434
diff changeset
    58
  shows "ordsuf (xs @ [x]) = [x] # (map (\<lambda>s. s @ [x]) (ordsuf xs))" 
222333d2bdc2 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 434
diff changeset
    59
  apply(induct xs)
222333d2bdc2 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 434
diff changeset
    60
  apply(auto)
222333d2bdc2 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 434
diff changeset
    61
  done
222333d2bdc2 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 434
diff changeset
    62
222333d2bdc2 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 434
diff changeset
    63
lemma ordsuf_append:
222333d2bdc2 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 434
diff changeset
    64
  shows "ordsuf (s1 @ s) = (ordsuf s) @ (map (\<lambda>s11. s11 @ s) (ordsuf s1))"
222333d2bdc2 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 434
diff changeset
    65
apply(induct s1 arbitrary: s rule: rev_induct)
222333d2bdc2 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 434
diff changeset
    66
  apply(simp)
222333d2bdc2 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 434
diff changeset
    67
  apply(drule_tac x="[x] @ s" in meta_spec)
222333d2bdc2 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 434
diff changeset
    68
  apply(simp)
222333d2bdc2 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 434
diff changeset
    69
  apply(subst ordsuf_last)
222333d2bdc2 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 434
diff changeset
    70
  apply(simp)
222333d2bdc2 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 434
diff changeset
    71
  done
222333d2bdc2 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 434
diff changeset
    72
222333d2bdc2 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 434
diff changeset
    73
222333d2bdc2 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 434
diff changeset
    74
222333d2bdc2 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 434
diff changeset
    75
(*
433
Chengsong
parents:
diff changeset
    76
lemma throwing_elem_around:
Chengsong
parents:
diff changeset
    77
  shows "orderedSuf (s1 @ [a] @ s) = (orderedSuf s) @ (map (\<lambda>s11. s11 @ s) (orderedSuf ( s1 @ [a]) ))"
Chengsong
parents:
diff changeset
    78
and "orderedSuf (s1 @ [a] @ s) = (orderedSuf ([a] @ s) @ (map (\<lambda>s11. s11 @ ([a] @ s))) (orderedSuf s1) )"
Chengsong
parents:
diff changeset
    79
  sorry
Chengsong
parents:
diff changeset
    80
Chengsong
parents:
diff changeset
    81
Chengsong
parents:
diff changeset
    82
lemma suf_cons:
Chengsong
parents:
diff changeset
    83
  shows "orderedSuf (s1 @ s) = (orderedSuf s) @ (map (\<lambda>s11. s11 @ s) (orderedSuf s1))"
Chengsong
parents:
diff changeset
    84
  apply(induct s arbitrary: s1)
Chengsong
parents:
diff changeset
    85
   apply simp
Chengsong
parents:
diff changeset
    86
  apply(subgoal_tac "s1 @ a # s = (s1 @ [a]) @ s")
Chengsong
parents:
diff changeset
    87
  prefer 2
Chengsong
parents:
diff changeset
    88
   apply simp
Chengsong
parents:
diff changeset
    89
  apply(subgoal_tac "orderedSuf (s1 @ a # s) = orderedSuf ((s1 @ [a]) @ s)")
Chengsong
parents:
diff changeset
    90
  prefer 2
Chengsong
parents:
diff changeset
    91
   apply presburger
Chengsong
parents:
diff changeset
    92
  apply(drule_tac x="s1 @ [a]" in meta_spec)
Chengsong
parents:
diff changeset
    93
  sorry
435
Chengsong
parents: 434
diff changeset
    94
*)
433
Chengsong
parents:
diff changeset
    95
Chengsong
parents:
diff changeset
    96
Chengsong
parents:
diff changeset
    97
lemma shape_of_prf_3list:
Chengsong
parents:
diff changeset
    98
  shows "orderedPref [c1, c2, c3] = [[c1, c2], [c1], []]"
Chengsong
parents:
diff changeset
    99
  by auto
Chengsong
parents:
diff changeset
   100
Chengsong
parents:
diff changeset
   101
fun zip_concat :: "char list list \<Rightarrow> char list list \<Rightarrow> char list list"
Chengsong
parents:
diff changeset
   102
  where 
Chengsong
parents:
diff changeset
   103
    "zip_concat (s1#ss1) (s2#ss2) = (s1@s2) # (zip_concat ss1 ss2)"
Chengsong
parents:
diff changeset
   104
  |   "zip_concat [] [] = []"
Chengsong
parents:
diff changeset
   105
  | "zip_concat [] (s2#ss2) = s2 # (zip_concat [] ss2)"
Chengsong
parents:
diff changeset
   106
  | "zip_concat (s1#ss1) [] = s1 # (zip_concat ss1 [])"
Chengsong
parents:
diff changeset
   107
Chengsong
parents:
diff changeset
   108
434
Chengsong
parents: 433
diff changeset
   109
(*
433
Chengsong
parents:
diff changeset
   110
lemma compliment_pref_suf:
Chengsong
parents:
diff changeset
   111
  shows "zip_concat (orderedPref s) (orderedSuf s) = replicate (length s) s "
Chengsong
parents:
diff changeset
   112
  apply(induct s)
Chengsong
parents:
diff changeset
   113
   apply auto[1]
Chengsong
parents:
diff changeset
   114
  sorry
Chengsong
parents:
diff changeset
   115
Chengsong
parents:
diff changeset
   116
434
Chengsong
parents: 433
diff changeset
   117
*)
433
Chengsong
parents:
diff changeset
   118
438
a73b2e553804 templateforPhd
Chengsong
parents: 435
diff changeset
   119
datatype cchar = 
a73b2e553804 templateforPhd
Chengsong
parents: 435
diff changeset
   120
Achar
a73b2e553804 templateforPhd
Chengsong
parents: 435
diff changeset
   121
|Bchar
a73b2e553804 templateforPhd
Chengsong
parents: 435
diff changeset
   122
|Cchar
a73b2e553804 templateforPhd
Chengsong
parents: 435
diff changeset
   123
|Dchar
a73b2e553804 templateforPhd
Chengsong
parents: 435
diff changeset
   124
433
Chengsong
parents:
diff changeset
   125
datatype rrexp = 
Chengsong
parents:
diff changeset
   126
  RZERO
Chengsong
parents:
diff changeset
   127
| RONE 
438
a73b2e553804 templateforPhd
Chengsong
parents: 435
diff changeset
   128
| RCHAR cchar
433
Chengsong
parents:
diff changeset
   129
| RSEQ rrexp rrexp
Chengsong
parents:
diff changeset
   130
| RALTS "rrexp list"
Chengsong
parents:
diff changeset
   131
| RSTAR rrexp
Chengsong
parents:
diff changeset
   132
Chengsong
parents:
diff changeset
   133
abbreviation
Chengsong
parents:
diff changeset
   134
  "RALT r1 r2 \<equiv> RALTS [r1, r2]"
Chengsong
parents:
diff changeset
   135
Chengsong
parents:
diff changeset
   136
Chengsong
parents:
diff changeset
   137
Chengsong
parents:
diff changeset
   138
fun
Chengsong
parents:
diff changeset
   139
 rnullable :: "rrexp \<Rightarrow> bool"
Chengsong
parents:
diff changeset
   140
where
Chengsong
parents:
diff changeset
   141
  "rnullable (RZERO) = False"
Chengsong
parents:
diff changeset
   142
| "rnullable (RONE  ) = True"
Chengsong
parents:
diff changeset
   143
| "rnullable (RCHAR   c) = False"
Chengsong
parents:
diff changeset
   144
| "rnullable (RALTS   rs) = (\<exists>r \<in> set rs. rnullable r)"
Chengsong
parents:
diff changeset
   145
| "rnullable (RSEQ  r1 r2) = (rnullable r1 \<and> rnullable r2)"
Chengsong
parents:
diff changeset
   146
| "rnullable (RSTAR   r) = True"
Chengsong
parents:
diff changeset
   147
438
a73b2e553804 templateforPhd
Chengsong
parents: 435
diff changeset
   148
fun convert_cchar_char :: "cchar \<Rightarrow> char"
a73b2e553804 templateforPhd
Chengsong
parents: 435
diff changeset
   149
  where
a73b2e553804 templateforPhd
Chengsong
parents: 435
diff changeset
   150
"convert_cchar_char Achar = (CHR 0x41) "
a73b2e553804 templateforPhd
Chengsong
parents: 435
diff changeset
   151
| "convert_cchar_char Bchar = (CHR 0x42) "
a73b2e553804 templateforPhd
Chengsong
parents: 435
diff changeset
   152
| "convert_cchar_char Cchar = (CHR 0x43) "
a73b2e553804 templateforPhd
Chengsong
parents: 435
diff changeset
   153
| "convert_cchar_char Dchar = (CHR 0x44) "
433
Chengsong
parents:
diff changeset
   154
Chengsong
parents:
diff changeset
   155
fun
Chengsong
parents:
diff changeset
   156
 rder :: "char \<Rightarrow> rrexp \<Rightarrow> rrexp"
Chengsong
parents:
diff changeset
   157
where
Chengsong
parents:
diff changeset
   158
  "rder c (RZERO) = RZERO"
Chengsong
parents:
diff changeset
   159
| "rder c (RONE) = RZERO"
438
a73b2e553804 templateforPhd
Chengsong
parents: 435
diff changeset
   160
| "rder c (RCHAR d) = (if c = (convert_cchar_char d) then RONE else RZERO)"
433
Chengsong
parents:
diff changeset
   161
| "rder c (RALTS rs) = RALTS (map (rder c) rs)"
Chengsong
parents:
diff changeset
   162
| "rder c (RSEQ r1 r2) = 
Chengsong
parents:
diff changeset
   163
     (if rnullable r1
Chengsong
parents:
diff changeset
   164
      then RALT   (RSEQ (rder c r1) r2) (rder c r2)
Chengsong
parents:
diff changeset
   165
      else RSEQ   (rder c r1) r2)"
Chengsong
parents:
diff changeset
   166
| "rder c (RSTAR r) = RSEQ  (rder c r) (RSTAR r)"
Chengsong
parents:
diff changeset
   167
Chengsong
parents:
diff changeset
   168
Chengsong
parents:
diff changeset
   169
fun 
Chengsong
parents:
diff changeset
   170
  rders :: "rrexp \<Rightarrow> string \<Rightarrow> rrexp"
Chengsong
parents:
diff changeset
   171
where
Chengsong
parents:
diff changeset
   172
  "rders r [] = r"
Chengsong
parents:
diff changeset
   173
| "rders r (c#s) = rders (rder c r) s"
Chengsong
parents:
diff changeset
   174
Chengsong
parents:
diff changeset
   175
fun rdistinct :: "'a list \<Rightarrow>'a set \<Rightarrow> 'a list"
Chengsong
parents:
diff changeset
   176
  where
Chengsong
parents:
diff changeset
   177
  "rdistinct [] acc = []"
Chengsong
parents:
diff changeset
   178
| "rdistinct (x#xs)  acc = 
Chengsong
parents:
diff changeset
   179
     (if x \<in> acc then rdistinct xs  acc 
Chengsong
parents:
diff changeset
   180
      else x # (rdistinct xs  ({x} \<union> acc)))"
Chengsong
parents:
diff changeset
   181
Chengsong
parents:
diff changeset
   182
Chengsong
parents:
diff changeset
   183
Chengsong
parents:
diff changeset
   184
Chengsong
parents:
diff changeset
   185
Chengsong
parents:
diff changeset
   186
fun rflts :: "rrexp list \<Rightarrow> rrexp list"
Chengsong
parents:
diff changeset
   187
  where 
Chengsong
parents:
diff changeset
   188
  "rflts [] = []"
Chengsong
parents:
diff changeset
   189
| "rflts (RZERO # rs) = rflts rs"
Chengsong
parents:
diff changeset
   190
| "rflts ((RALTS rs1) # rs) = rs1 @ rflts rs"
Chengsong
parents:
diff changeset
   191
| "rflts (r1 # rs) = r1 # rflts rs"
Chengsong
parents:
diff changeset
   192
Chengsong
parents:
diff changeset
   193
Chengsong
parents:
diff changeset
   194
fun rsimp_ALTs :: " rrexp list \<Rightarrow> rrexp"
Chengsong
parents:
diff changeset
   195
  where
Chengsong
parents:
diff changeset
   196
  "rsimp_ALTs  [] = RZERO"
Chengsong
parents:
diff changeset
   197
| "rsimp_ALTs [r] =  r"
Chengsong
parents:
diff changeset
   198
| "rsimp_ALTs rs = RALTS rs"
Chengsong
parents:
diff changeset
   199
Chengsong
parents:
diff changeset
   200
fun rsimp_SEQ :: " rrexp \<Rightarrow> rrexp \<Rightarrow> rrexp"
Chengsong
parents:
diff changeset
   201
  where
Chengsong
parents:
diff changeset
   202
  "rsimp_SEQ  RZERO _ = RZERO"
Chengsong
parents:
diff changeset
   203
| "rsimp_SEQ  _ RZERO = RZERO"
Chengsong
parents:
diff changeset
   204
| "rsimp_SEQ RONE r2 = r2"
Chengsong
parents:
diff changeset
   205
| "rsimp_SEQ r1 r2 = RSEQ r1 r2"
Chengsong
parents:
diff changeset
   206
Chengsong
parents:
diff changeset
   207
Chengsong
parents:
diff changeset
   208
fun rsimp :: "rrexp \<Rightarrow> rrexp" 
Chengsong
parents:
diff changeset
   209
  where
Chengsong
parents:
diff changeset
   210
  "rsimp (RSEQ r1 r2) = rsimp_SEQ  (rsimp r1) (rsimp r2)"
Chengsong
parents:
diff changeset
   211
| "rsimp (RALTS rs) = rsimp_ALTs  (rdistinct (rflts (map rsimp rs))  {}) "
Chengsong
parents:
diff changeset
   212
| "rsimp r = r"
Chengsong
parents:
diff changeset
   213
Chengsong
parents:
diff changeset
   214
Chengsong
parents:
diff changeset
   215
fun 
Chengsong
parents:
diff changeset
   216
  rders_simp :: "rrexp \<Rightarrow> string \<Rightarrow> rrexp"
Chengsong
parents:
diff changeset
   217
where
Chengsong
parents:
diff changeset
   218
  "rders_simp r [] = r"
Chengsong
parents:
diff changeset
   219
| "rders_simp r (c#s) = rders_simp (rsimp (rder c r)) s"
Chengsong
parents:
diff changeset
   220
Chengsong
parents:
diff changeset
   221
fun rsize :: "rrexp \<Rightarrow> nat" where
Chengsong
parents:
diff changeset
   222
  "rsize RZERO = 1"
Chengsong
parents:
diff changeset
   223
| "rsize (RONE) = 1" 
Chengsong
parents:
diff changeset
   224
| "rsize (RCHAR  c) = 1"
Chengsong
parents:
diff changeset
   225
| "rsize (RALTS  rs) = Suc (sum_list (map rsize rs))"
Chengsong
parents:
diff changeset
   226
| "rsize (RSEQ  r1 r2) = Suc (rsize r1 + rsize r2)"
Chengsong
parents:
diff changeset
   227
| "rsize (RSTAR  r) = Suc (rsize r)"
Chengsong
parents:
diff changeset
   228
Chengsong
parents:
diff changeset
   229
Chengsong
parents:
diff changeset
   230
fun rlist_size :: "rrexp list \<Rightarrow> nat" where
Chengsong
parents:
diff changeset
   231
"rlist_size (r # rs) = rsize r + rlist_size rs" 
Chengsong
parents:
diff changeset
   232
| "rlist_size [] = 0"
Chengsong
parents:
diff changeset
   233
Chengsong
parents:
diff changeset
   234
thm neq_Nil_conv
435
Chengsong
parents: 434
diff changeset
   235
lemma hand_made_def_rlist_size:
Chengsong
parents: 434
diff changeset
   236
  shows "rlist_size rs = sum_list (map rsize rs)"
Chengsong
parents: 434
diff changeset
   237
proof (induct rs)
Chengsong
parents: 434
diff changeset
   238
  case Nil show ?case by simp
Chengsong
parents: 434
diff changeset
   239
next
Chengsong
parents: 434
diff changeset
   240
  case (Cons a rs) thus ?case
Chengsong
parents: 434
diff changeset
   241
    by simp
Chengsong
parents: 434
diff changeset
   242
qed
433
Chengsong
parents:
diff changeset
   243
Chengsong
parents:
diff changeset
   244
lemma rsimp_aalts_smaller:
Chengsong
parents:
diff changeset
   245
  shows "rsize (rsimp_ALTs  rs) \<le> rsize (RALTS rs)"
Chengsong
parents:
diff changeset
   246
  apply(induct rs)
Chengsong
parents:
diff changeset
   247
   apply simp
Chengsong
parents:
diff changeset
   248
  apply simp
Chengsong
parents:
diff changeset
   249
  apply(case_tac "rs = []")
Chengsong
parents:
diff changeset
   250
   apply simp
Chengsong
parents:
diff changeset
   251
  apply(subgoal_tac "\<exists>rsp ap. rs = ap # rsp")
Chengsong
parents:
diff changeset
   252
   apply(erule exE)+
Chengsong
parents:
diff changeset
   253
   apply simp
Chengsong
parents:
diff changeset
   254
  apply simp
Chengsong
parents:
diff changeset
   255
  by(meson neq_Nil_conv)
Chengsong
parents:
diff changeset
   256
  
Chengsong
parents:
diff changeset
   257
Chengsong
parents:
diff changeset
   258
Chengsong
parents:
diff changeset
   259
Chengsong
parents:
diff changeset
   260
Chengsong
parents:
diff changeset
   261
Chengsong
parents:
diff changeset
   262
(*
Chengsong
parents:
diff changeset
   263
lemma rders_shape:
Chengsong
parents:
diff changeset
   264
  shows "s \<noteq> [] \<Longrightarrow> rders_simp (RSEQ r1 r2) s = 
Chengsong
parents:
diff changeset
   265
         rsimp (RALTS  ((RSEQ (rders r1 s) r2) #
Chengsong
parents:
diff changeset
   266
           (map (rders r2) (orderedSuf s))) )"
Chengsong
parents:
diff changeset
   267
  apply(induct s arbitrary: r1 r2 rule: rev_induct)
Chengsong
parents:
diff changeset
   268
   apply simp
Chengsong
parents:
diff changeset
   269
  apply simp
Chengsong
parents:
diff changeset
   270
Chengsong
parents:
diff changeset
   271
  sorry
Chengsong
parents:
diff changeset
   272
*)
Chengsong
parents:
diff changeset
   273
Chengsong
parents:
diff changeset
   274
Chengsong
parents:
diff changeset
   275
Chengsong
parents:
diff changeset
   276
fun rders_cond_list :: "rrexp \<Rightarrow> bool list \<Rightarrow> char list list \<Rightarrow> rrexp list"
Chengsong
parents:
diff changeset
   277
  where
Chengsong
parents:
diff changeset
   278
"rders_cond_list r2 (True # bs) (s # strs) = (rders_simp r2 s) # (rders_cond_list r2 bs strs)"
Chengsong
parents:
diff changeset
   279
| "rders_cond_list r2 (False # bs) (s # strs) = rders_cond_list r2 bs strs"
Chengsong
parents:
diff changeset
   280
| "rders_cond_list r2 [] s = []"
Chengsong
parents:
diff changeset
   281
| "rders_cond_list r2 bs [] = []"
Chengsong
parents:
diff changeset
   282
Chengsong
parents:
diff changeset
   283
fun nullable_bools :: "rrexp \<Rightarrow> char list list \<Rightarrow> bool list"
Chengsong
parents:
diff changeset
   284
  where
Chengsong
parents:
diff changeset
   285
"nullable_bools r (s#strs) = (rnullable (rders r s)) # (nullable_bools r strs) "
Chengsong
parents:
diff changeset
   286
|"nullable_bools r [] = []"
Chengsong
parents:
diff changeset
   287
Chengsong
parents:
diff changeset
   288
fun cond_list :: "rrexp \<Rightarrow> rrexp \<Rightarrow> char list \<Rightarrow> rrexp list"
Chengsong
parents:
diff changeset
   289
  where
Chengsong
parents:
diff changeset
   290
"cond_list r1 r2 s = rders_cond_list r2 (nullable_bools r1 (orderedPref s) ) (orderedSuf s)"
Chengsong
parents:
diff changeset
   291
435
Chengsong
parents: 434
diff changeset
   292
438
a73b2e553804 templateforPhd
Chengsong
parents: 435
diff changeset
   293
fun seq_update :: " char \<Rightarrow> rrexp \<Rightarrow> char list list \<Rightarrow> char list list"
a73b2e553804 templateforPhd
Chengsong
parents: 435
diff changeset
   294
  where
a73b2e553804 templateforPhd
Chengsong
parents: 435
diff changeset
   295
"seq_update c r Ss = (if (rnullable r) then ([c] # (map (\<lambda>s1. s1 @ [c]) Ss)) else (map (\<lambda>s1. s1 @ [c]) Ss))"
a73b2e553804 templateforPhd
Chengsong
parents: 435
diff changeset
   296
a73b2e553804 templateforPhd
Chengsong
parents: 435
diff changeset
   297
a73b2e553804 templateforPhd
Chengsong
parents: 435
diff changeset
   298
433
Chengsong
parents:
diff changeset
   299
lemma rSEQ_mono:
Chengsong
parents:
diff changeset
   300
  shows "rsize (rsimp_SEQ r1 r2) \<le>rsize ( RSEQ r1 r2)"
Chengsong
parents:
diff changeset
   301
  apply auto
Chengsong
parents:
diff changeset
   302
  apply(induct r1)
Chengsong
parents:
diff changeset
   303
       apply auto
Chengsong
parents:
diff changeset
   304
      apply(case_tac "r2")
Chengsong
parents:
diff changeset
   305
       apply simp_all
Chengsong
parents:
diff changeset
   306
     apply(case_tac r2)
Chengsong
parents:
diff changeset
   307
          apply simp_all
Chengsong
parents:
diff changeset
   308
     apply(case_tac r2)
Chengsong
parents:
diff changeset
   309
         apply simp_all
Chengsong
parents:
diff changeset
   310
     apply(case_tac r2)
Chengsong
parents:
diff changeset
   311
        apply simp_all
Chengsong
parents:
diff changeset
   312
     apply(case_tac r2)
Chengsong
parents:
diff changeset
   313
  apply simp_all
Chengsong
parents:
diff changeset
   314
  done
Chengsong
parents:
diff changeset
   315
435
Chengsong
parents: 434
diff changeset
   316
lemma ralts_cap_mono:
Chengsong
parents: 434
diff changeset
   317
  shows "rsize (RALTS rs) \<le> Suc ( sum_list (map rsize rs)) "
Chengsong
parents: 434
diff changeset
   318
  by simp
Chengsong
parents: 434
diff changeset
   319
Chengsong
parents: 434
diff changeset
   320
lemma rflts_def_idiot:
Chengsong
parents: 434
diff changeset
   321
  shows "\<lbrakk> a \<noteq> RZERO; \<nexists>rs1. a = RALTS rs1\<rbrakk>
Chengsong
parents: 434
diff changeset
   322
       \<Longrightarrow> rflts (a # rs) = a # rflts rs"
Chengsong
parents: 434
diff changeset
   323
  apply(case_tac a)
Chengsong
parents: 434
diff changeset
   324
       apply simp_all
Chengsong
parents: 434
diff changeset
   325
  done
Chengsong
parents: 434
diff changeset
   326
Chengsong
parents: 434
diff changeset
   327
Chengsong
parents: 434
diff changeset
   328
lemma rflts_mono:
Chengsong
parents: 434
diff changeset
   329
  shows "sum_list (map rsize (rflts rs))\<le> sum_list (map rsize rs)"
Chengsong
parents: 434
diff changeset
   330
  apply(induct rs)
Chengsong
parents: 434
diff changeset
   331
  apply simp
Chengsong
parents: 434
diff changeset
   332
  apply(case_tac "a = RZERO")
Chengsong
parents: 434
diff changeset
   333
   apply simp
Chengsong
parents: 434
diff changeset
   334
  apply(case_tac "\<exists>rs1. a = RALTS rs1")
Chengsong
parents: 434
diff changeset
   335
  apply(erule exE)
Chengsong
parents: 434
diff changeset
   336
   apply simp
Chengsong
parents: 434
diff changeset
   337
  apply(subgoal_tac "rflts (a # rs) = a # (rflts rs)")
Chengsong
parents: 434
diff changeset
   338
  prefer 2
Chengsong
parents: 434
diff changeset
   339
  using rflts_def_idiot apply blast
Chengsong
parents: 434
diff changeset
   340
  apply simp
Chengsong
parents: 434
diff changeset
   341
  done
Chengsong
parents: 434
diff changeset
   342
Chengsong
parents: 434
diff changeset
   343
lemma rdistinct_smaller: shows "sum_list (map rsize (rdistinct rs ss)) \<le>
Chengsong
parents: 434
diff changeset
   344
sum_list (map rsize rs )"
Chengsong
parents: 434
diff changeset
   345
  apply (induct rs arbitrary: ss)
Chengsong
parents: 434
diff changeset
   346
   apply simp
Chengsong
parents: 434
diff changeset
   347
  by (simp add: trans_le_add2)
Chengsong
parents: 434
diff changeset
   348
Chengsong
parents: 434
diff changeset
   349
lemma rdistinct_phi_smaller: "sum_list (map rsize (rdistinct rs {})) \<le> sum_list (map rsize rs)"
Chengsong
parents: 434
diff changeset
   350
  by (simp add: rdistinct_smaller)
Chengsong
parents: 434
diff changeset
   351
Chengsong
parents: 434
diff changeset
   352
Chengsong
parents: 434
diff changeset
   353
lemma rsimp_alts_mono :
Chengsong
parents: 434
diff changeset
   354
  shows "\<And>x. (\<And>xa. xa \<in> set x \<Longrightarrow> rsize (rsimp xa) \<le> rsize xa)  \<Longrightarrow>
Chengsong
parents: 434
diff changeset
   355
rsize (rsimp_ALTs (rdistinct (rflts (map rsimp x)) {})) \<le> Suc (sum_list (map rsize x))"
Chengsong
parents: 434
diff changeset
   356
  apply(subgoal_tac "rsize (rsimp_ALTs (rdistinct (rflts (map rsimp x)) {} )) 
Chengsong
parents: 434
diff changeset
   357
                    \<le> rsize (RALTS (rdistinct (rflts (map rsimp x)) {} ))")
Chengsong
parents: 434
diff changeset
   358
  prefer 2
Chengsong
parents: 434
diff changeset
   359
  using rsimp_aalts_smaller apply auto[1]
Chengsong
parents: 434
diff changeset
   360
  apply(subgoal_tac "rsize (RALTS (rdistinct (rflts (map rsimp x)) {})) \<le>Suc( sum_list (map rsize (rdistinct (rflts (map rsimp x)) {})))")
Chengsong
parents: 434
diff changeset
   361
  prefer 2
Chengsong
parents: 434
diff changeset
   362
  using ralts_cap_mono apply blast
Chengsong
parents: 434
diff changeset
   363
  apply(subgoal_tac "sum_list (map rsize (rdistinct (rflts (map rsimp x)) {})) \<le>
Chengsong
parents: 434
diff changeset
   364
                     sum_list (map rsize ( (rflts (map rsimp x))))")
Chengsong
parents: 434
diff changeset
   365
  prefer 2
Chengsong
parents: 434
diff changeset
   366
  using rdistinct_smaller apply presburger
Chengsong
parents: 434
diff changeset
   367
  apply(subgoal_tac "sum_list (map rsize (rflts (map rsimp x))) \<le> 
Chengsong
parents: 434
diff changeset
   368
                     sum_list (map rsize (map rsimp x))")
Chengsong
parents: 434
diff changeset
   369
  prefer 2
Chengsong
parents: 434
diff changeset
   370
  using rflts_mono apply blast
Chengsong
parents: 434
diff changeset
   371
  apply(subgoal_tac "sum_list (map rsize (map rsimp x)) \<le> sum_list (map rsize x)")
Chengsong
parents: 434
diff changeset
   372
  prefer 2
Chengsong
parents: 434
diff changeset
   373
  
Chengsong
parents: 434
diff changeset
   374
  apply (simp add: sum_list_mono)
Chengsong
parents: 434
diff changeset
   375
  by linarith
Chengsong
parents: 434
diff changeset
   376
Chengsong
parents: 434
diff changeset
   377
Chengsong
parents: 434
diff changeset
   378
Chengsong
parents: 434
diff changeset
   379
Chengsong
parents: 434
diff changeset
   380
433
Chengsong
parents:
diff changeset
   381
lemma rsimp_mono:
Chengsong
parents:
diff changeset
   382
  shows "rsize (rsimp r) \<le> rsize r"
435
Chengsong
parents: 434
diff changeset
   383
433
Chengsong
parents:
diff changeset
   384
  apply(induct r)
435
Chengsong
parents: 434
diff changeset
   385
             apply simp_all
Chengsong
parents: 434
diff changeset
   386
433
Chengsong
parents:
diff changeset
   387
  apply(subgoal_tac "rsize (rsimp_SEQ (rsimp r1) (rsimp r2)) \<le> rsize (RSEQ (rsimp r1) (rsimp r2))")
Chengsong
parents:
diff changeset
   388
  
Chengsong
parents:
diff changeset
   389
    apply force
Chengsong
parents:
diff changeset
   390
  using rSEQ_mono
435
Chengsong
parents: 434
diff changeset
   391
   apply presburger
Chengsong
parents: 434
diff changeset
   392
  using rsimp_alts_mono by auto
433
Chengsong
parents:
diff changeset
   393
Chengsong
parents:
diff changeset
   394
lemma idiot:
Chengsong
parents:
diff changeset
   395
  shows "rsimp_SEQ RONE r = r"
Chengsong
parents:
diff changeset
   396
  apply(case_tac r)
Chengsong
parents:
diff changeset
   397
       apply simp_all
Chengsong
parents:
diff changeset
   398
  done
Chengsong
parents:
diff changeset
   399
435
Chengsong
parents: 434
diff changeset
   400
lemma no_alt_short_list_after_simp:
Chengsong
parents: 434
diff changeset
   401
  shows "RALTS rs = rsimp r \<Longrightarrow> rsimp_ALTs rs = RALTS rs"
433
Chengsong
parents:
diff changeset
   402
  sorry
Chengsong
parents:
diff changeset
   403
Chengsong
parents:
diff changeset
   404
lemma no_further_dB_after_simp:
Chengsong
parents:
diff changeset
   405
  shows "RALTS rs = rsimp r \<Longrightarrow> rdistinct rs {} = rs"
435
Chengsong
parents: 434
diff changeset
   406
433
Chengsong
parents:
diff changeset
   407
  sorry
Chengsong
parents:
diff changeset
   408
Chengsong
parents:
diff changeset
   409
Chengsong
parents:
diff changeset
   410
lemma idiot2:
Chengsong
parents:
diff changeset
   411
  shows " \<lbrakk>r1 \<noteq> RZERO; r1 \<noteq> RONE;r2 \<noteq> RZERO\<rbrakk>
Chengsong
parents:
diff changeset
   412
    \<Longrightarrow> rsimp_SEQ r1 r2 = RSEQ r1 r2"
Chengsong
parents:
diff changeset
   413
  apply(case_tac r1)
Chengsong
parents:
diff changeset
   414
       apply(case_tac r2)
Chengsong
parents:
diff changeset
   415
  apply simp_all
Chengsong
parents:
diff changeset
   416
     apply(case_tac r2)
Chengsong
parents:
diff changeset
   417
  apply simp_all
Chengsong
parents:
diff changeset
   418
     apply(case_tac r2)
Chengsong
parents:
diff changeset
   419
  apply simp_all
Chengsong
parents:
diff changeset
   420
   apply(case_tac r2)
Chengsong
parents:
diff changeset
   421
  apply simp_all
Chengsong
parents:
diff changeset
   422
  apply(case_tac r2)
Chengsong
parents:
diff changeset
   423
       apply simp_all
Chengsong
parents:
diff changeset
   424
  done
438
a73b2e553804 templateforPhd
Chengsong
parents: 435
diff changeset
   425
(*
433
Chengsong
parents:
diff changeset
   426
lemma rsimp_aalts_another:
Chengsong
parents:
diff changeset
   427
  shows "\<forall>r \<in> (set  (map rsimp  ((RSEQ (rders r1 s) r2) #
Chengsong
parents:
diff changeset
   428
           (rders_cond_list r2 (nullable_bools r1 (orderedPref s))  (orderedSuf s))  )) ). (rsize r) < N "
Chengsong
parents:
diff changeset
   429
  sorry
Chengsong
parents:
diff changeset
   430
Chengsong
parents:
diff changeset
   431
Chengsong
parents:
diff changeset
   432
Chengsong
parents:
diff changeset
   433
lemma shape_derssimpseq_onechar:
Chengsong
parents:
diff changeset
   434
  shows "   (rders_simp r [c]) =  (rsimp (rders r [c]))"
Chengsong
parents:
diff changeset
   435
and "rders_simp (RSEQ r1 r2) [c] = 
Chengsong
parents:
diff changeset
   436
         rsimp (RALTS  ((RSEQ (rders r1 [c]) r2) #
Chengsong
parents:
diff changeset
   437
           (rders_cond_list r2 (nullable_bools r1 (orderedPref [c]))  (orderedSuf [c]))) )"
Chengsong
parents:
diff changeset
   438
   apply simp
Chengsong
parents:
diff changeset
   439
  apply(simp add: rders.simps)
Chengsong
parents:
diff changeset
   440
  apply(case_tac "rsimp (rder c r1) = RZERO")
Chengsong
parents:
diff changeset
   441
   apply auto
Chengsong
parents:
diff changeset
   442
  apply(case_tac "rsimp (rder c r1) = RONE")
Chengsong
parents:
diff changeset
   443
   apply auto
Chengsong
parents:
diff changeset
   444
   apply(subgoal_tac "rsimp_SEQ RONE (rsimp r2) = rsimp r2")
Chengsong
parents:
diff changeset
   445
  prefer 2
Chengsong
parents:
diff changeset
   446
  using idiot
Chengsong
parents:
diff changeset
   447
    apply simp
Chengsong
parents:
diff changeset
   448
   apply(subgoal_tac "rsimp_SEQ RONE (rsimp r2) = rsimp_ALTs (rdistinct (rflts [rsimp r2]) {})")
Chengsong
parents:
diff changeset
   449
    prefer 2
Chengsong
parents:
diff changeset
   450
    apply auto
Chengsong
parents:
diff changeset
   451
   apply(case_tac "rsimp r2")
Chengsong
parents:
diff changeset
   452
        apply auto
Chengsong
parents:
diff changeset
   453
   apply(subgoal_tac "rdistinct x5 {} = x5")
Chengsong
parents:
diff changeset
   454
  prefer 2
Chengsong
parents:
diff changeset
   455
  using no_further_dB_after_simp
Chengsong
parents:
diff changeset
   456
    apply metis
Chengsong
parents:
diff changeset
   457
   apply(subgoal_tac "rsimp_ALTs (rdistinct x5 {}) = rsimp_ALTs x5")
Chengsong
parents:
diff changeset
   458
    prefer 2
Chengsong
parents:
diff changeset
   459
    apply fastforce  
Chengsong
parents:
diff changeset
   460
   apply auto
Chengsong
parents:
diff changeset
   461
   apply (metis no_alt_short_list_after_simp)
Chengsong
parents:
diff changeset
   462
  apply (case_tac "rsimp r2 = RZERO")
Chengsong
parents:
diff changeset
   463
   apply(subgoal_tac "rsimp_SEQ (rsimp (rder c r1)) (rsimp r2) = RZERO")
Chengsong
parents:
diff changeset
   464
    prefer 2
Chengsong
parents:
diff changeset
   465
    apply(case_tac "rsimp ( rder c r1)")
Chengsong
parents:
diff changeset
   466
         apply auto
Chengsong
parents:
diff changeset
   467
  apply(subgoal_tac "rsimp_SEQ (rsimp (rder c r1)) (rsimp r2) = RSEQ (rsimp (rder c r1)) (rsimp r2)")
Chengsong
parents:
diff changeset
   468
   prefer 2
Chengsong
parents:
diff changeset
   469
   apply auto
Chengsong
parents:
diff changeset
   470
  sorry
438
a73b2e553804 templateforPhd
Chengsong
parents: 435
diff changeset
   471
*)
433
Chengsong
parents:
diff changeset
   472
438
a73b2e553804 templateforPhd
Chengsong
parents: 435
diff changeset
   473
(*
a73b2e553804 templateforPhd
Chengsong
parents: 435
diff changeset
   474
lemma shape_derssimpseq_onechar2:
a73b2e553804 templateforPhd
Chengsong
parents: 435
diff changeset
   475
  shows "rders_simp (RSEQ r1 r2) [c] = 
a73b2e553804 templateforPhd
Chengsong
parents: 435
diff changeset
   476
         rsimp (RALTS  ((RSEQ (rders_simp r1 [c]) r2) #
a73b2e553804 templateforPhd
Chengsong
parents: 435
diff changeset
   477
           (rders_cond_list r2 (nullable_bools r1 (orderedPref [c]))  (orderedSuf [c]))) )"
a73b2e553804 templateforPhd
Chengsong
parents: 435
diff changeset
   478
  sorry
433
Chengsong
parents:
diff changeset
   479
438
a73b2e553804 templateforPhd
Chengsong
parents: 435
diff changeset
   480
*)
a73b2e553804 templateforPhd
Chengsong
parents: 435
diff changeset
   481
a73b2e553804 templateforPhd
Chengsong
parents: 435
diff changeset
   482
lemma shape_derssimpseq_onechar:
a73b2e553804 templateforPhd
Chengsong
parents: 435
diff changeset
   483
  shows "   (rders_simp r [c]) =  (rsimp (rders r [c]))"
a73b2e553804 templateforPhd
Chengsong
parents: 435
diff changeset
   484
and "rders_simp (RSEQ r1 r2) [c] = 
a73b2e553804 templateforPhd
Chengsong
parents: 435
diff changeset
   485
         rsimp (RALTS  ((RSEQ (rders r1 [c]) r2) #
a73b2e553804 templateforPhd
Chengsong
parents: 435
diff changeset
   486
           (rders_cond_list r2 (nullable_bools r1 (orderedPref [c]))  (orderedSuf [c]))) )"
a73b2e553804 templateforPhd
Chengsong
parents: 435
diff changeset
   487
   apply simp
a73b2e553804 templateforPhd
Chengsong
parents: 435
diff changeset
   488
  apply(simp add: rders.simps)
a73b2e553804 templateforPhd
Chengsong
parents: 435
diff changeset
   489
  apply(case_tac "rsimp (rder c r1) = RZERO")
a73b2e553804 templateforPhd
Chengsong
parents: 435
diff changeset
   490
   apply auto
a73b2e553804 templateforPhd
Chengsong
parents: 435
diff changeset
   491
  apply(case_tac "rsimp (rder c r1) = RONE")
a73b2e553804 templateforPhd
Chengsong
parents: 435
diff changeset
   492
   apply auto
a73b2e553804 templateforPhd
Chengsong
parents: 435
diff changeset
   493
   apply(subgoal_tac "rsimp_SEQ RONE (rsimp r2) = rsimp r2")
a73b2e553804 templateforPhd
Chengsong
parents: 435
diff changeset
   494
  prefer 2
a73b2e553804 templateforPhd
Chengsong
parents: 435
diff changeset
   495
  using idiot
a73b2e553804 templateforPhd
Chengsong
parents: 435
diff changeset
   496
    apply simp
a73b2e553804 templateforPhd
Chengsong
parents: 435
diff changeset
   497
   apply(subgoal_tac "rsimp_SEQ RONE (rsimp r2) = rsimp_ALTs (rdistinct (rflts [rsimp r2]) {})")
a73b2e553804 templateforPhd
Chengsong
parents: 435
diff changeset
   498
    prefer 2
a73b2e553804 templateforPhd
Chengsong
parents: 435
diff changeset
   499
    apply auto
a73b2e553804 templateforPhd
Chengsong
parents: 435
diff changeset
   500
   apply(case_tac "rsimp r2")
a73b2e553804 templateforPhd
Chengsong
parents: 435
diff changeset
   501
        apply auto
a73b2e553804 templateforPhd
Chengsong
parents: 435
diff changeset
   502
   apply(subgoal_tac "rdistinct x5 {} = x5")
a73b2e553804 templateforPhd
Chengsong
parents: 435
diff changeset
   503
  prefer 2
a73b2e553804 templateforPhd
Chengsong
parents: 435
diff changeset
   504
  using no_further_dB_after_simp
a73b2e553804 templateforPhd
Chengsong
parents: 435
diff changeset
   505
    apply metis
a73b2e553804 templateforPhd
Chengsong
parents: 435
diff changeset
   506
   apply(subgoal_tac "rsimp_ALTs (rdistinct x5 {}) = rsimp_ALTs x5")
a73b2e553804 templateforPhd
Chengsong
parents: 435
diff changeset
   507
    prefer 2
a73b2e553804 templateforPhd
Chengsong
parents: 435
diff changeset
   508
    apply fastforce  
a73b2e553804 templateforPhd
Chengsong
parents: 435
diff changeset
   509
   apply auto
a73b2e553804 templateforPhd
Chengsong
parents: 435
diff changeset
   510
   apply (metis no_alt_short_list_after_simp)
a73b2e553804 templateforPhd
Chengsong
parents: 435
diff changeset
   511
  apply (case_tac "rsimp r2 = RZERO")
a73b2e553804 templateforPhd
Chengsong
parents: 435
diff changeset
   512
   apply(subgoal_tac "rsimp_SEQ (rsimp (rder c r1)) (rsimp r2) = RZERO")
a73b2e553804 templateforPhd
Chengsong
parents: 435
diff changeset
   513
    prefer 2
a73b2e553804 templateforPhd
Chengsong
parents: 435
diff changeset
   514
    apply(case_tac "rsimp ( rder c r1)")
a73b2e553804 templateforPhd
Chengsong
parents: 435
diff changeset
   515
         apply auto
a73b2e553804 templateforPhd
Chengsong
parents: 435
diff changeset
   516
  apply(subgoal_tac "rsimp_SEQ (rsimp (rder c r1)) (rsimp r2) = RSEQ (rsimp (rder c r1)) (rsimp r2)")
a73b2e553804 templateforPhd
Chengsong
parents: 435
diff changeset
   517
   prefer 2
a73b2e553804 templateforPhd
Chengsong
parents: 435
diff changeset
   518
   apply auto
a73b2e553804 templateforPhd
Chengsong
parents: 435
diff changeset
   519
  sorry
433
Chengsong
parents:
diff changeset
   520
Chengsong
parents:
diff changeset
   521
lemma shape_derssimpseq_onechar2:
Chengsong
parents:
diff changeset
   522
  shows "rders_simp (RSEQ r1 r2) [c] = 
Chengsong
parents:
diff changeset
   523
         rsimp (RALTS  ((RSEQ (rders_simp r1 [c]) r2) #
Chengsong
parents:
diff changeset
   524
           (rders_cond_list r2 (nullable_bools r1 (orderedPref [c]))  (orderedSuf [c]))) )"
Chengsong
parents:
diff changeset
   525
  sorry
Chengsong
parents:
diff changeset
   526
438
a73b2e553804 templateforPhd
Chengsong
parents: 435
diff changeset
   527
(*
a73b2e553804 templateforPhd
Chengsong
parents: 435
diff changeset
   528
lemma simp_helps_der_pierce_dB:
a73b2e553804 templateforPhd
Chengsong
parents: 435
diff changeset
   529
  shows " rsimp
a73b2e553804 templateforPhd
Chengsong
parents: 435
diff changeset
   530
            (rsimp_ALTs
a73b2e553804 templateforPhd
Chengsong
parents: 435
diff changeset
   531
              (map (rder x)
a73b2e553804 templateforPhd
Chengsong
parents: 435
diff changeset
   532
                (rdistinct rs {}))) = 
a73b2e553804 templateforPhd
Chengsong
parents: 435
diff changeset
   533
          rsimp (rsimp_ALTs (rdistinct (map (rder x) rs) {}))"
a73b2e553804 templateforPhd
Chengsong
parents: 435
diff changeset
   534
a73b2e553804 templateforPhd
Chengsong
parents: 435
diff changeset
   535
  sorry
a73b2e553804 templateforPhd
Chengsong
parents: 435
diff changeset
   536
*)
a73b2e553804 templateforPhd
Chengsong
parents: 435
diff changeset
   537
(*
a73b2e553804 templateforPhd
Chengsong
parents: 435
diff changeset
   538
lemma simp_helps_der_pierce_flts:
a73b2e553804 templateforPhd
Chengsong
parents: 435
diff changeset
   539
  shows " rsimp
a73b2e553804 templateforPhd
Chengsong
parents: 435
diff changeset
   540
            (rsimp_ALTs
a73b2e553804 templateforPhd
Chengsong
parents: 435
diff changeset
   541
             (rdistinct 
a73b2e553804 templateforPhd
Chengsong
parents: 435
diff changeset
   542
                (map (rder x)
a73b2e553804 templateforPhd
Chengsong
parents: 435
diff changeset
   543
                  (rflts rs )
a73b2e553804 templateforPhd
Chengsong
parents: 435
diff changeset
   544
                ) {}
a73b2e553804 templateforPhd
Chengsong
parents: 435
diff changeset
   545
             )
a73b2e553804 templateforPhd
Chengsong
parents: 435
diff changeset
   546
            ) = 
a73b2e553804 templateforPhd
Chengsong
parents: 435
diff changeset
   547
          rsimp (rsimp_ALTs (rdistinct (rflts (map (rder x) rs)) {})  )"
a73b2e553804 templateforPhd
Chengsong
parents: 435
diff changeset
   548
a73b2e553804 templateforPhd
Chengsong
parents: 435
diff changeset
   549
  sorry
a73b2e553804 templateforPhd
Chengsong
parents: 435
diff changeset
   550
a73b2e553804 templateforPhd
Chengsong
parents: 435
diff changeset
   551
*)
433
Chengsong
parents:
diff changeset
   552
Chengsong
parents:
diff changeset
   553
lemma rders__onechar:
Chengsong
parents:
diff changeset
   554
  shows " (rders_simp r [c]) =  (rsimp (rders r [c]))"
Chengsong
parents:
diff changeset
   555
  by simp
Chengsong
parents:
diff changeset
   556
Chengsong
parents:
diff changeset
   557
lemma rders_append:
Chengsong
parents:
diff changeset
   558
  "rders c (s1 @ s2) = rders (rders c s1) s2"
Chengsong
parents:
diff changeset
   559
  apply(induct s1 arbitrary: c s2)
Chengsong
parents:
diff changeset
   560
  apply(simp_all)
Chengsong
parents:
diff changeset
   561
  done
Chengsong
parents:
diff changeset
   562
Chengsong
parents:
diff changeset
   563
lemma rders_simp_append:
Chengsong
parents:
diff changeset
   564
  "rders_simp c (s1 @ s2) = rders_simp (rders_simp c s1) s2"
Chengsong
parents:
diff changeset
   565
  apply(induct s1 arbitrary: c s2)
Chengsong
parents:
diff changeset
   566
  apply(simp_all)
Chengsong
parents:
diff changeset
   567
  done
Chengsong
parents:
diff changeset
   568
Chengsong
parents:
diff changeset
   569
lemma inside_simp_removal:
Chengsong
parents:
diff changeset
   570
  shows " rsimp (rder x (rsimp r)) = rsimp (rder x r)"
Chengsong
parents:
diff changeset
   571
  
Chengsong
parents:
diff changeset
   572
  sorry
Chengsong
parents:
diff changeset
   573
Chengsong
parents:
diff changeset
   574
lemma set_related_list:
Chengsong
parents:
diff changeset
   575
  shows "distinct rs  \<Longrightarrow> length rs = card (set rs)"
Chengsong
parents:
diff changeset
   576
  by (simp add: distinct_card)
Chengsong
parents:
diff changeset
   577
(*this section deals with the property of distinctBy: creates a list without duplicates*)
Chengsong
parents:
diff changeset
   578
lemma rdistinct_never_added_twice:
Chengsong
parents:
diff changeset
   579
  shows "rdistinct (a # rs) {a} = rdistinct rs {a}"
Chengsong
parents:
diff changeset
   580
  by force
Chengsong
parents:
diff changeset
   581
Chengsong
parents:
diff changeset
   582
Chengsong
parents:
diff changeset
   583
lemma rdistinct_does_the_job:
Chengsong
parents:
diff changeset
   584
  shows "distinct (rdistinct rs s)"
Chengsong
parents:
diff changeset
   585
  apply(induct rs arbitrary: s)
Chengsong
parents:
diff changeset
   586
   apply simp
Chengsong
parents:
diff changeset
   587
  apply simp
Chengsong
parents:
diff changeset
   588
  sorry
Chengsong
parents:
diff changeset
   589
Chengsong
parents:
diff changeset
   590
Chengsong
parents:
diff changeset
   591
lemma simp_helps_der_pierce:
Chengsong
parents:
diff changeset
   592
  shows " rsimp
Chengsong
parents:
diff changeset
   593
            (rder x
Chengsong
parents:
diff changeset
   594
              (rsimp_ALTs rs)) = 
Chengsong
parents:
diff changeset
   595
          rsimp 
Chengsong
parents:
diff changeset
   596
            (rsimp_ALTs 
Chengsong
parents:
diff changeset
   597
              (map (rder x )
Chengsong
parents:
diff changeset
   598
                rs
Chengsong
parents:
diff changeset
   599
              )
Chengsong
parents:
diff changeset
   600
            )"
Chengsong
parents:
diff changeset
   601
  sorry
Chengsong
parents:
diff changeset
   602
Chengsong
parents:
diff changeset
   603
lemma unfold_ders_simp_inside_only: 
Chengsong
parents:
diff changeset
   604
  shows "    (rders_simp (RSEQ r1 r2) xs =
Chengsong
parents:
diff changeset
   605
           rsimp (RALTS (RSEQ (rders_simp r1 xs) r2 # rders_cond_list r2 (nullable_bools r1 (orderedPref xs)) (orderedSuf xs))))
Chengsong
parents:
diff changeset
   606
       \<Longrightarrow> rsimp (rder x (rders_simp (RSEQ r1 r2) xs)) = rsimp (rder x (rsimp (RALTS(RSEQ (rders_simp r1 xs) r2 # rders_cond_list r2 (nullable_bools r1 (orderedPref xs)) (orderedSuf xs)))))"
Chengsong
parents:
diff changeset
   607
 by presburger
Chengsong
parents:
diff changeset
   608
Chengsong
parents:
diff changeset
   609
Chengsong
parents:
diff changeset
   610
Chengsong
parents:
diff changeset
   611
lemma unfold_ders_simp_inside_only_nosimp: 
Chengsong
parents:
diff changeset
   612
  shows "    (rders_simp (RSEQ r1 r2) xs =
Chengsong
parents:
diff changeset
   613
           rsimp (RALTS (RSEQ (rders_simp r1 xs) r2 # rders_cond_list r2 (nullable_bools r1 (orderedPref xs)) (orderedSuf xs))))
Chengsong
parents:
diff changeset
   614
       \<Longrightarrow> rsimp (rder x (rders_simp (RSEQ r1 r2) xs)) = rsimp (rder x (RALTS(RSEQ (rders_simp r1 xs) r2 # rders_cond_list r2 (nullable_bools r1 (orderedPref xs)) (orderedSuf xs))))"
Chengsong
parents:
diff changeset
   615
  using inside_simp_removal by presburger
Chengsong
parents:
diff changeset
   616
Chengsong
parents:
diff changeset
   617
Chengsong
parents:
diff changeset
   618
Chengsong
parents:
diff changeset
   619
Chengsong
parents:
diff changeset
   620
lemma rders_simp_one_char:
Chengsong
parents:
diff changeset
   621
  shows "rders_simp r [c] = rsimp (rder c r)"
Chengsong
parents:
diff changeset
   622
  apply auto
Chengsong
parents:
diff changeset
   623
  done
Chengsong
parents:
diff changeset
   624
Chengsong
parents:
diff changeset
   625
lemma rsimp_idem:
Chengsong
parents:
diff changeset
   626
  shows "rsimp (rsimp r) = rsimp r"
Chengsong
parents:
diff changeset
   627
  sorry
Chengsong
parents:
diff changeset
   628
434
Chengsong
parents: 433
diff changeset
   629
corollary rsimp_inner_idem1:
Chengsong
parents: 433
diff changeset
   630
  shows "rsimp r = RSEQ r1 r2 \<Longrightarrow> rsimp r1 = r1 \<and> rsimp r2 = r2"
Chengsong
parents: 433
diff changeset
   631
  
Chengsong
parents: 433
diff changeset
   632
  sorry
Chengsong
parents: 433
diff changeset
   633
Chengsong
parents: 433
diff changeset
   634
corollary rsimp_inner_idem2:
Chengsong
parents: 433
diff changeset
   635
  shows "rsimp r = RALTS rs \<Longrightarrow> \<forall>r' \<in> (set rs). rsimp r' = r'"
Chengsong
parents: 433
diff changeset
   636
  sorry
Chengsong
parents: 433
diff changeset
   637
Chengsong
parents: 433
diff changeset
   638
corollary rsimp_inner_idem3:
Chengsong
parents: 433
diff changeset
   639
  shows "rsimp r = RALTS rs \<Longrightarrow> map rsimp rs = rs"
Chengsong
parents: 433
diff changeset
   640
  by (meson map_idI rsimp_inner_idem2)
Chengsong
parents: 433
diff changeset
   641
Chengsong
parents: 433
diff changeset
   642
corollary rsimp_inner_idem4:
Chengsong
parents: 433
diff changeset
   643
  shows "rsimp r = RALTS rs \<Longrightarrow> flts rs = rs"
Chengsong
parents: 433
diff changeset
   644
  sorry
Chengsong
parents: 433
diff changeset
   645
Chengsong
parents: 433
diff changeset
   646
433
Chengsong
parents:
diff changeset
   647
lemma head_one_more_simp:
Chengsong
parents:
diff changeset
   648
  shows "map rsimp (r # rs) = map rsimp (( rsimp r) # rs)"
Chengsong
parents:
diff changeset
   649
  by (simp add: rsimp_idem)
Chengsong
parents:
diff changeset
   650
Chengsong
parents:
diff changeset
   651
lemma head_one_more_dersimp:
Chengsong
parents:
diff changeset
   652
  shows "map rsimp ((rder x (rders_simp r s) # rs)) = map rsimp ((rders_simp r (s@[x]) ) # rs)"
Chengsong
parents:
diff changeset
   653
  using head_one_more_simp rders_simp_append rders_simp_one_char by presburger
Chengsong
parents:
diff changeset
   654
Chengsong
parents:
diff changeset
   655
thm cond_list.simps
Chengsong
parents:
diff changeset
   656
Chengsong
parents:
diff changeset
   657
lemma suffix_plus1char:
Chengsong
parents:
diff changeset
   658
  shows "\<not> (rnullable (rders r1 s)) \<Longrightarrow> cond_list r1 r2 (s@[c]) = map (rder c) (cond_list r1 r2 s)"
Chengsong
parents:
diff changeset
   659
   apply simp
Chengsong
parents:
diff changeset
   660
  sorry
Chengsong
parents:
diff changeset
   661
Chengsong
parents:
diff changeset
   662
lemma suffix_plus1charn:
Chengsong
parents:
diff changeset
   663
shows "rnullable (rders r1 s) \<Longrightarrow> cond_list r1 r2 (s@[c]) = (rder c r2) # (map (rder c) (cond_list r1 r2 s))"
Chengsong
parents:
diff changeset
   664
  sorry
Chengsong
parents:
diff changeset
   665
Chengsong
parents:
diff changeset
   666
lemma ders_simp_nullability:
Chengsong
parents:
diff changeset
   667
  shows "rnullable (rders r s) = rnullable (rders_simp r s)"
Chengsong
parents:
diff changeset
   668
  sorry
Chengsong
parents:
diff changeset
   669
Chengsong
parents:
diff changeset
   670
lemma  first_elem_seqder:
Chengsong
parents:
diff changeset
   671
  shows "\<not>rnullable r1p \<Longrightarrow> map rsimp (rder x (RSEQ r1p r2)
Chengsong
parents:
diff changeset
   672
                   # rs) = map rsimp ((RSEQ (rder x r1p) r2) # rs) "
Chengsong
parents:
diff changeset
   673
  by auto
Chengsong
parents:
diff changeset
   674
Chengsong
parents:
diff changeset
   675
lemma first_elem_seqder1:
Chengsong
parents:
diff changeset
   676
  shows  "\<not>rnullable (rders_simp r xs) \<Longrightarrow> map rsimp ( (rder x (RSEQ (rders_simp r xs) r2)) # rs) = 
Chengsong
parents:
diff changeset
   677
                                          map rsimp ( (RSEQ (rsimp (rder x (rders_simp r xs))) r2) # rs)"
Chengsong
parents:
diff changeset
   678
  by (simp add: rsimp_idem)
Chengsong
parents:
diff changeset
   679
Chengsong
parents:
diff changeset
   680
lemma first_elem_seqdersimps:
Chengsong
parents:
diff changeset
   681
  shows "\<not>rnullable (rders_simp r xs) \<Longrightarrow> map rsimp ( (rder x (RSEQ (rders_simp r xs) r2)) # rs) = 
Chengsong
parents:
diff changeset
   682
                                          map rsimp ( (RSEQ (rders_simp r (xs @ [x])) r2) # rs)"
Chengsong
parents:
diff changeset
   683
  using first_elem_seqder1 rders_simp_append by auto
Chengsong
parents:
diff changeset
   684
Chengsong
parents:
diff changeset
   685
lemma first_elem_seqder_nullable:
Chengsong
parents:
diff changeset
   686
  shows "rnullable (rders_simp r1 xs) \<Longrightarrow> cond_list r1 r2 (xs @ [x]) = rder x r2 # map (rder x) (cond_list r1 r2 xs)"
Chengsong
parents:
diff changeset
   687
  sorry
Chengsong
parents:
diff changeset
   688
Chengsong
parents:
diff changeset
   689
438
a73b2e553804 templateforPhd
Chengsong
parents: 435
diff changeset
   690
a73b2e553804 templateforPhd
Chengsong
parents: 435
diff changeset
   691
a73b2e553804 templateforPhd
Chengsong
parents: 435
diff changeset
   692
lemma seq_update_seq_ders:
a73b2e553804 templateforPhd
Chengsong
parents: 435
diff changeset
   693
  shows "rsimp (rder c ( rsimp (RALTS ((RSEQ (rders_simp r1 s) r2) # 
a73b2e553804 templateforPhd
Chengsong
parents: 435
diff changeset
   694
(map (rders_simp r2) Ss))))) = 
a73b2e553804 templateforPhd
Chengsong
parents: 435
diff changeset
   695
         rsimp (RALTS ((RSEQ (rders_simp r1 (s @ [c])) r2) # 
a73b2e553804 templateforPhd
Chengsong
parents: 435
diff changeset
   696
(map (rders_simp r2) (seq_update c (rders_simp r1 s) Ss))))  "
a73b2e553804 templateforPhd
Chengsong
parents: 435
diff changeset
   697
  sorry
a73b2e553804 templateforPhd
Chengsong
parents: 435
diff changeset
   698
a73b2e553804 templateforPhd
Chengsong
parents: 435
diff changeset
   699
lemma seq_ders_closed_form1:
a73b2e553804 templateforPhd
Chengsong
parents: 435
diff changeset
   700
  shows "\<exists>Ss. rders_simp (RSEQ r1 r2) [c] = rsimp (RALTS ((RSEQ (rders_simp r1 [c]) r2) # 
a73b2e553804 templateforPhd
Chengsong
parents: 435
diff changeset
   701
(map ( rders_simp r2 ) Ss)))"
a73b2e553804 templateforPhd
Chengsong
parents: 435
diff changeset
   702
  apply(case_tac "rnullable r1")
a73b2e553804 templateforPhd
Chengsong
parents: 435
diff changeset
   703
   apply(subgoal_tac " rders_simp (RSEQ r1 r2) [c] = 
a73b2e553804 templateforPhd
Chengsong
parents: 435
diff changeset
   704
rsimp (RALTS ((RSEQ (rders_simp r1 [c]) r2) # (map (rders_simp r2) [[c]])))")
a73b2e553804 templateforPhd
Chengsong
parents: 435
diff changeset
   705
    prefer 2
a73b2e553804 templateforPhd
Chengsong
parents: 435
diff changeset
   706
    apply (simp add: rsimp_idem)
a73b2e553804 templateforPhd
Chengsong
parents: 435
diff changeset
   707
   apply(rule_tac x = "[[c]]" in exI)
a73b2e553804 templateforPhd
Chengsong
parents: 435
diff changeset
   708
   apply simp
a73b2e553804 templateforPhd
Chengsong
parents: 435
diff changeset
   709
  apply(subgoal_tac  " rders_simp (RSEQ r1 r2) [c] = 
a73b2e553804 templateforPhd
Chengsong
parents: 435
diff changeset
   710
rsimp (RALTS ((RSEQ (rders_simp r1 [c]) r2) # (map (rders_simp r2) [])))")
a73b2e553804 templateforPhd
Chengsong
parents: 435
diff changeset
   711
   apply blast
a73b2e553804 templateforPhd
Chengsong
parents: 435
diff changeset
   712
  apply(simp add: rsimp_idem)
a73b2e553804 templateforPhd
Chengsong
parents: 435
diff changeset
   713
  sorry
a73b2e553804 templateforPhd
Chengsong
parents: 435
diff changeset
   714
a73b2e553804 templateforPhd
Chengsong
parents: 435
diff changeset
   715
a73b2e553804 templateforPhd
Chengsong
parents: 435
diff changeset
   716
a73b2e553804 templateforPhd
Chengsong
parents: 435
diff changeset
   717
lemma seq_ders_closed_form:
a73b2e553804 templateforPhd
Chengsong
parents: 435
diff changeset
   718
  shows "s \<noteq> [] \<Longrightarrow> \<exists>Ss. rders_simp (RSEQ r1 r2) s = rsimp (RALTS ((RSEQ (rders_simp r1 s) r2) # 
a73b2e553804 templateforPhd
Chengsong
parents: 435
diff changeset
   719
(map ( rders_simp r2 ) Ss)))"
a73b2e553804 templateforPhd
Chengsong
parents: 435
diff changeset
   720
  apply(induct s rule: rev_induct)
a73b2e553804 templateforPhd
Chengsong
parents: 435
diff changeset
   721
   apply simp
a73b2e553804 templateforPhd
Chengsong
parents: 435
diff changeset
   722
  apply(case_tac xs)
a73b2e553804 templateforPhd
Chengsong
parents: 435
diff changeset
   723
  using seq_ders_closed_form1 apply auto[1]
a73b2e553804 templateforPhd
Chengsong
parents: 435
diff changeset
   724
  apply(subgoal_tac "\<exists>Ss. rders_simp (RSEQ r1 r2) xs = rsimp (RALTS (RSEQ (rders_simp r1 xs) r2 # map (rders_simp r2) Ss))")
a73b2e553804 templateforPhd
Chengsong
parents: 435
diff changeset
   725
  prefer 2
a73b2e553804 templateforPhd
Chengsong
parents: 435
diff changeset
   726
  
a73b2e553804 templateforPhd
Chengsong
parents: 435
diff changeset
   727
   apply blast
a73b2e553804 templateforPhd
Chengsong
parents: 435
diff changeset
   728
  apply(erule exE)
a73b2e553804 templateforPhd
Chengsong
parents: 435
diff changeset
   729
  apply(rule_tac x = "seq_update x (rders_simp r1 xs) Ss" in exI)
a73b2e553804 templateforPhd
Chengsong
parents: 435
diff changeset
   730
  apply(subst rders_simp_append)
a73b2e553804 templateforPhd
Chengsong
parents: 435
diff changeset
   731
  apply(subgoal_tac "rders_simp (rders_simp (RSEQ r1 r2) xs) [x] = rsimp (rder x (rders_simp (RSEQ r1 r2) xs))")
a73b2e553804 templateforPhd
Chengsong
parents: 435
diff changeset
   732
   apply(simp only:)
a73b2e553804 templateforPhd
Chengsong
parents: 435
diff changeset
   733
   apply(subst seq_update_seq_ders)
a73b2e553804 templateforPhd
Chengsong
parents: 435
diff changeset
   734
   apply blast
a73b2e553804 templateforPhd
Chengsong
parents: 435
diff changeset
   735
  using rders_simp_one_char by presburger
a73b2e553804 templateforPhd
Chengsong
parents: 435
diff changeset
   736
a73b2e553804 templateforPhd
Chengsong
parents: 435
diff changeset
   737
a73b2e553804 templateforPhd
Chengsong
parents: 435
diff changeset
   738
433
Chengsong
parents:
diff changeset
   739
(*nullable_seq_with_list1 related *)
Chengsong
parents:
diff changeset
   740
lemma LHS0_def_der_alt:
Chengsong
parents:
diff changeset
   741
  shows "rsimp (rder x (RALTS ( (RSEQ (rders_simp r1 xs) r2) # (cond_list r1 r2 xs)))) = 
Chengsong
parents:
diff changeset
   742
         rsimp (RALTS ((rder x (RSEQ (rders_simp r1 xs) r2)) # (map (rder x) (cond_list r1 r2 xs))))"
Chengsong
parents:
diff changeset
   743
  by fastforce
Chengsong
parents:
diff changeset
   744
Chengsong
parents:
diff changeset
   745
lemma LHS1_def_der_seq:
Chengsong
parents:
diff changeset
   746
  shows "rnullable (rders_simp r1 xs) \<Longrightarrow> 
Chengsong
parents:
diff changeset
   747
rsimp (rder x (RALTS ( (RSEQ (rders_simp r1 xs) r2) # (cond_list r1 r2 xs)))) = 
Chengsong
parents:
diff changeset
   748
rsimp(RALTS ((RALTS ((RSEQ (rders_simp r1 (xs @ [x])) r2) # [rder x r2]) ) # (map (rder x ) (cond_list r1 r2 xs))))"
Chengsong
parents:
diff changeset
   749
  by (simp add: rders_simp_append rsimp_idem)
Chengsong
parents:
diff changeset
   750
Chengsong
parents:
diff changeset
   751
Chengsong
parents:
diff changeset
   752
Chengsong
parents:
diff changeset
   753
Chengsong
parents:
diff changeset
   754
Chengsong
parents:
diff changeset
   755
lemma cond_list_head_last:
Chengsong
parents:
diff changeset
   756
  shows "rnullable (rders r1 s) \<Longrightarrow> 
Chengsong
parents:
diff changeset
   757
        RALTS (r # (cond_list r1 r2 (s @ [c]))) = RALTS (r # ((rder c r2) # (map (rder c) (cond_list r1 r2 s))))"
Chengsong
parents:
diff changeset
   758
  using suffix_plus1charn by blast
Chengsong
parents:
diff changeset
   759
435
Chengsong
parents: 434
diff changeset
   760
lemma simp_flatten2:
Chengsong
parents: 434
diff changeset
   761
  shows "rsimp (RALTS (r # [RALTS rs])) = rsimp (RALTS (r # rs))"
Chengsong
parents: 434
diff changeset
   762
  sorry
Chengsong
parents: 434
diff changeset
   763
433
Chengsong
parents:
diff changeset
   764
Chengsong
parents:
diff changeset
   765
lemma simp_flatten:
Chengsong
parents:
diff changeset
   766
  shows "rsimp (RALTS ((RALTS rsa) # rsb)) = rsimp (RALTS (rsa @ rsb))"
Chengsong
parents:
diff changeset
   767
Chengsong
parents:
diff changeset
   768
  sorry
Chengsong
parents:
diff changeset
   769
Chengsong
parents:
diff changeset
   770
lemma RHS1:
Chengsong
parents:
diff changeset
   771
  shows "rnullable (rders_simp r1 xs) \<Longrightarrow>
Chengsong
parents:
diff changeset
   772
                                    rsimp (RALTS ((RSEQ (rders_simp r1 (xs @ [x])) r2) # 
Chengsong
parents:
diff changeset
   773
(cond_list r1 r2 (xs @[x])))) = 
Chengsong
parents:
diff changeset
   774
                                    rsimp (RALTS ((RSEQ (rders_simp r1 (xs @ [x])) r2) # 
Chengsong
parents:
diff changeset
   775
( ((rder x r2) # (map (rder x) (cond_list r1 r2 xs)))))) "
Chengsong
parents:
diff changeset
   776
  using first_elem_seqder_nullable by presburger
Chengsong
parents:
diff changeset
   777
Chengsong
parents:
diff changeset
   778
Chengsong
parents:
diff changeset
   779
lemma nullable_seq_with_list1:
Chengsong
parents:
diff changeset
   780
  shows " rnullable (rders_simp r1 s) \<Longrightarrow>
Chengsong
parents:
diff changeset
   781
    rsimp (rder c (RALTS ( (RSEQ (rders_simp r1 s) r2) #  (cond_list r1 r2 s)) )) =
Chengsong
parents:
diff changeset
   782
    rsimp (RALTS ( (RSEQ (rders_simp r1 (s @ [c])) r2) # (cond_list r1 r2 (s @ [c])) ) )"
434
Chengsong
parents: 433
diff changeset
   783
  using RHS1 LHS1_def_der_seq cond_list_head_last simp_flatten
Chengsong
parents: 433
diff changeset
   784
  by (metis append.left_neutral append_Cons)
Chengsong
parents: 433
diff changeset
   785
Chengsong
parents: 433
diff changeset
   786
Chengsong
parents: 433
diff changeset
   787
(*^^^^^^^^^nullable_seq_with_list1 related ^^^^^^^^^^^^^^^^*)
Chengsong
parents: 433
diff changeset
   788
Chengsong
parents: 433
diff changeset
   789
Chengsong
parents: 433
diff changeset
   790
Chengsong
parents: 433
diff changeset
   791
Chengsong
parents: 433
diff changeset
   792
Chengsong
parents: 433
diff changeset
   793
433
Chengsong
parents:
diff changeset
   794
Chengsong
parents:
diff changeset
   795
Chengsong
parents:
diff changeset
   796
Chengsong
parents:
diff changeset
   797
Chengsong
parents:
diff changeset
   798
lemma nullable_seq_with_list:
Chengsong
parents:
diff changeset
   799
  shows "rnullable (rders_simp r1 xs) \<Longrightarrow> rsimp (rder x (RALTS ((RSEQ (rders_simp r1 xs) r2) # 
Chengsong
parents:
diff changeset
   800
      (rders_cond_list r2 (nullable_bools r1 (orderedPref xs)) (orderedSuf xs)) ))) = 
Chengsong
parents:
diff changeset
   801
                                          rsimp (RALTS ((RSEQ (rders_simp r1 (xs@[x])) r2) #
Chengsong
parents:
diff changeset
   802
      (rders_cond_list r2 (nullable_bools r1 (orderedPref (xs@[x]))) (orderedSuf (xs@[x]))) ) )
Chengsong
parents:
diff changeset
   803
    "
Chengsong
parents:
diff changeset
   804
  apply(subgoal_tac "rsimp (rder x (RALTS ((RSEQ (rders_simp r1 xs) r2) # (cond_list r1 r2 xs)))) = 
Chengsong
parents:
diff changeset
   805
                     rsimp (RALTS ((RSEQ (rders_simp r1 (xs@[x])) r2) # (cond_list r1 r2 (xs@[x]))))")
Chengsong
parents:
diff changeset
   806
   apply auto[1]
Chengsong
parents:
diff changeset
   807
  using nullable_seq_with_list1 by auto
Chengsong
parents:
diff changeset
   808
Chengsong
parents:
diff changeset
   809
Chengsong
parents:
diff changeset
   810
Chengsong
parents:
diff changeset
   811
Chengsong
parents:
diff changeset
   812
lemma r1r2ders_whole:
Chengsong
parents:
diff changeset
   813
"rsimp
Chengsong
parents:
diff changeset
   814
         (RALTS
Chengsong
parents:
diff changeset
   815
           (rder x (RSEQ (rders_simp r1 xs) r2) #
Chengsong
parents:
diff changeset
   816
            map (rder x) (rders_cond_list r2 (nullable_bools r1 (orderedPref xs)) (orderedSuf xs)))) = 
Chengsong
parents:
diff changeset
   817
      rsimp(    RALTS(   ( (RSEQ (rders_simp r1 (xs@[x])) r2)
Chengsong
parents:
diff changeset
   818
                   #  (rders_cond_list r2 (nullable_bools r1 (orderedPref (xs @ [x]))) (orderedSuf (xs @ [x])))))) "
Chengsong
parents:
diff changeset
   819
  using ders_simp_nullability first_elem_seqdersimps nullable_seq_with_list1 suffix_plus1char by auto
Chengsong
parents:
diff changeset
   820
Chengsong
parents:
diff changeset
   821
lemma rders_simp_same_simpders:
Chengsong
parents:
diff changeset
   822
  shows "s \<noteq> [] \<Longrightarrow> rders_simp r s = rsimp (rders r s)"
Chengsong
parents:
diff changeset
   823
  apply(induct s rule: rev_induct)
Chengsong
parents:
diff changeset
   824
   apply simp
Chengsong
parents:
diff changeset
   825
  apply(case_tac "xs = []")
Chengsong
parents:
diff changeset
   826
   apply simp
Chengsong
parents:
diff changeset
   827
  apply(simp add: rders_append rders_simp_append)
Chengsong
parents:
diff changeset
   828
  using inside_simp_removal by blast
Chengsong
parents:
diff changeset
   829
Chengsong
parents:
diff changeset
   830
lemma shape_derssimp_seq:
Chengsong
parents:
diff changeset
   831
  shows "\<lbrakk>s \<noteq> []\<rbrakk> \<Longrightarrow> rders_simp (RSEQ r1 r2) s = 
Chengsong
parents:
diff changeset
   832
         rsimp (RALTS  ((RSEQ (rders_simp r1 s) r2) #
Chengsong
parents:
diff changeset
   833
           (rders_cond_list r2 (nullable_bools r1 (orderedPref s))  (orderedSuf s))) )"
Chengsong
parents:
diff changeset
   834
Chengsong
parents:
diff changeset
   835
  apply(induct s arbitrary: r1 r2 rule: rev_induct)
Chengsong
parents:
diff changeset
   836
   apply simp
Chengsong
parents:
diff changeset
   837
  apply(case_tac "xs = []")
Chengsong
parents:
diff changeset
   838
  using shape_derssimpseq_onechar2 apply force
Chengsong
parents:
diff changeset
   839
  apply(simp only: rders_simp_append)
Chengsong
parents:
diff changeset
   840
  apply(simp only: rders_simp_one_char)
Chengsong
parents:
diff changeset
   841
Chengsong
parents:
diff changeset
   842
  apply(subgoal_tac "rsimp (rder x (rders_simp (RSEQ r1 r2) xs))
Chengsong
parents:
diff changeset
   843
                   = rsimp (rder x (RALTS(RSEQ (rders_simp r1 xs) r2 # rders_cond_list r2 (nullable_bools r1 (orderedPref xs)) (orderedSuf xs))))")
Chengsong
parents:
diff changeset
   844
   prefer 2
Chengsong
parents:
diff changeset
   845
  using unfold_ders_simp_inside_only_nosimp apply presburger
Chengsong
parents:
diff changeset
   846
  apply(subgoal_tac "rsimp (rder x (RALTS (RSEQ (rders_simp r1 xs) r2
Chengsong
parents:
diff changeset
   847
                   # rders_cond_list r2 (nullable_bools r1 (orderedPref xs)) (orderedSuf xs)))) = 
Chengsong
parents:
diff changeset
   848
                     rsimp ( (RALTS (rder x (RSEQ (rders_simp r1 xs) r2)
Chengsong
parents:
diff changeset
   849
                   # (map (rder x) (rders_cond_list r2 (nullable_bools r1 (orderedPref xs)) (orderedSuf xs))))))
Chengsong
parents:
diff changeset
   850
                      ")
Chengsong
parents:
diff changeset
   851
   prefer 2
Chengsong
parents:
diff changeset
   852
   apply simp
Chengsong
parents:
diff changeset
   853
  using r1r2ders_whole rders_simp_append rders_simp_one_char by presburger
Chengsong
parents:
diff changeset
   854
Chengsong
parents:
diff changeset
   855
Chengsong
parents:
diff changeset
   856
lemma shape_derssimp_alts:
Chengsong
parents:
diff changeset
   857
  shows "s \<noteq> [] \<Longrightarrow> rders_simp (RALTS rs) s = rsimp (RALTS (map (\<lambda>r. rders r s) rs))"
Chengsong
parents:
diff changeset
   858
  apply(case_tac "s")
Chengsong
parents:
diff changeset
   859
   apply simp
Chengsong
parents:
diff changeset
   860
  apply simp
Chengsong
parents:
diff changeset
   861
  sorry
Chengsong
parents:
diff changeset
   862
(*
Chengsong
parents:
diff changeset
   863
fun rexp_encode :: "rrexp \<Rightarrow> nat"
Chengsong
parents:
diff changeset
   864
  where
Chengsong
parents:
diff changeset
   865
"rexp_encode RZERO = 0"
Chengsong
parents:
diff changeset
   866
|"rexp_encode RONE = 1"
Chengsong
parents:
diff changeset
   867
|"rexp_encode (RCHAR c) = 2"
Chengsong
parents:
diff changeset
   868
|"rexp_encode (RSEQ r1 r2) = ( 2 ^ (rexp_encode r1)) "
Chengsong
parents:
diff changeset
   869
*)
438
a73b2e553804 templateforPhd
Chengsong
parents: 435
diff changeset
   870
433
Chengsong
parents:
diff changeset
   871
438
a73b2e553804 templateforPhd
Chengsong
parents: 435
diff changeset
   872
a73b2e553804 templateforPhd
Chengsong
parents: 435
diff changeset
   873
433
Chengsong
parents:
diff changeset
   874
(*
Chengsong
parents:
diff changeset
   875
fun rexp_enum :: "nat \<Rightarrow> rrexp list"
Chengsong
parents:
diff changeset
   876
  where 
Chengsong
parents:
diff changeset
   877
"rexp_enum 0 = []"
Chengsong
parents:
diff changeset
   878
|"rexp_enum (Suc 0) =  RALTS [] # RZERO # (RONE # (map RCHAR (all_chars 255)))"
Chengsong
parents:
diff changeset
   879
|"rexp_enum (Suc n) = [(RSEQ r1 r2). r1 \<in> set (rexp_enum i) \<and> r2 \<in> set (rexp_enum j) \<and> i + j = n]"
Chengsong
parents:
diff changeset
   880
Chengsong
parents:
diff changeset
   881
*)
438
a73b2e553804 templateforPhd
Chengsong
parents: 435
diff changeset
   882
context notes rev_conj_cong[fundef_cong] begin
a73b2e553804 templateforPhd
Chengsong
parents: 435
diff changeset
   883
function (sequential) rexp_enum :: "nat \<Rightarrow> rrexp set"
433
Chengsong
parents:
diff changeset
   884
  where 
Chengsong
parents:
diff changeset
   885
"rexp_enum 0 = {}"
438
a73b2e553804 templateforPhd
Chengsong
parents: 435
diff changeset
   886
|"rexp_enum (Suc 0) =  {RALTS []} \<union> {RZERO} \<union> {RONE} \<union> { (RCHAR c) |c. c \<in>{Achar, Bchar, Cchar, Dchar} }"
a73b2e553804 templateforPhd
Chengsong
parents: 435
diff changeset
   887
|"rexp_enum (Suc n) = {(RSEQ r1 r2)|r1 r2 i j. r1 \<in>  (rexp_enum i) \<and> r2 \<in>  (rexp_enum j) \<and> i + j = n} \<union>
a73b2e553804 templateforPhd
Chengsong
parents: 435
diff changeset
   888
{(RALTS (a # rs)) | a rs i j. a \<in> (rexp_enum i) \<and> (RALTS rs) \<in> (rexp_enum j) \<and> i + j = Suc n \<and> i \<le> n \<and> j \<le> n} \<union>
a73b2e553804 templateforPhd
Chengsong
parents: 435
diff changeset
   889
{RSTAR r0 | r0. r0 \<in> (rexp_enum n)} \<union>
a73b2e553804 templateforPhd
Chengsong
parents: 435
diff changeset
   890
(rexp_enum n)"
a73b2e553804 templateforPhd
Chengsong
parents: 435
diff changeset
   891
  by pat_completeness auto
a73b2e553804 templateforPhd
Chengsong
parents: 435
diff changeset
   892
termination
a73b2e553804 templateforPhd
Chengsong
parents: 435
diff changeset
   893
  by (relation "measure size") auto
a73b2e553804 templateforPhd
Chengsong
parents: 435
diff changeset
   894
end
a73b2e553804 templateforPhd
Chengsong
parents: 435
diff changeset
   895
a73b2e553804 templateforPhd
Chengsong
parents: 435
diff changeset
   896
lemma rexp_enum_inclusion:
a73b2e553804 templateforPhd
Chengsong
parents: 435
diff changeset
   897
  shows "(rexp_enum n) \<subseteq> (rexp_enum (Suc n))"
a73b2e553804 templateforPhd
Chengsong
parents: 435
diff changeset
   898
  apply(induct n)
a73b2e553804 templateforPhd
Chengsong
parents: 435
diff changeset
   899
   apply auto[1]
a73b2e553804 templateforPhd
Chengsong
parents: 435
diff changeset
   900
  apply(simp)
a73b2e553804 templateforPhd
Chengsong
parents: 435
diff changeset
   901
  done
a73b2e553804 templateforPhd
Chengsong
parents: 435
diff changeset
   902
a73b2e553804 templateforPhd
Chengsong
parents: 435
diff changeset
   903
lemma rexp_enum_mono:
a73b2e553804 templateforPhd
Chengsong
parents: 435
diff changeset
   904
  shows "n \<le> m \<Longrightarrow> (rexp_enum n) \<subseteq> (rexp_enum m)"
a73b2e553804 templateforPhd
Chengsong
parents: 435
diff changeset
   905
  by (simp add: lift_Suc_mono_le rexp_enum_inclusion)
a73b2e553804 templateforPhd
Chengsong
parents: 435
diff changeset
   906
a73b2e553804 templateforPhd
Chengsong
parents: 435
diff changeset
   907
lemma enum_inductive_cases:
a73b2e553804 templateforPhd
Chengsong
parents: 435
diff changeset
   908
  shows "rsize (RSEQ r1 r2) = Suc n \<Longrightarrow> \<exists>i j. rsize r1 = i \<and> rsize r2 = j\<and> i + j = n"
a73b2e553804 templateforPhd
Chengsong
parents: 435
diff changeset
   909
  by (metis Suc_inject rsize.simps(5))
a73b2e553804 templateforPhd
Chengsong
parents: 435
diff changeset
   910
thm rsize.simps(5)
a73b2e553804 templateforPhd
Chengsong
parents: 435
diff changeset
   911
a73b2e553804 templateforPhd
Chengsong
parents: 435
diff changeset
   912
lemma enumeration_finite:
a73b2e553804 templateforPhd
Chengsong
parents: 435
diff changeset
   913
  shows "\<exists>Nn. card (rexp_enum n) < Nn"
a73b2e553804 templateforPhd
Chengsong
parents: 435
diff changeset
   914
  apply(simp add:no_top_class.gt_ex)
a73b2e553804 templateforPhd
Chengsong
parents: 435
diff changeset
   915
  done
a73b2e553804 templateforPhd
Chengsong
parents: 435
diff changeset
   916
a73b2e553804 templateforPhd
Chengsong
parents: 435
diff changeset
   917
lemma size1_rexps:
a73b2e553804 templateforPhd
Chengsong
parents: 435
diff changeset
   918
  shows "RCHAR x \<in> rexp_enum 1"
a73b2e553804 templateforPhd
Chengsong
parents: 435
diff changeset
   919
  apply(cases x)
a73b2e553804 templateforPhd
Chengsong
parents: 435
diff changeset
   920
     apply auto
a73b2e553804 templateforPhd
Chengsong
parents: 435
diff changeset
   921
  done
a73b2e553804 templateforPhd
Chengsong
parents: 435
diff changeset
   922
a73b2e553804 templateforPhd
Chengsong
parents: 435
diff changeset
   923
lemma non_zero_size:
a73b2e553804 templateforPhd
Chengsong
parents: 435
diff changeset
   924
  shows "rsize r \<ge> Suc 0"
a73b2e553804 templateforPhd
Chengsong
parents: 435
diff changeset
   925
  apply(induct r)
a73b2e553804 templateforPhd
Chengsong
parents: 435
diff changeset
   926
  apply auto done
a73b2e553804 templateforPhd
Chengsong
parents: 435
diff changeset
   927
a73b2e553804 templateforPhd
Chengsong
parents: 435
diff changeset
   928
corollary size_geq1:
a73b2e553804 templateforPhd
Chengsong
parents: 435
diff changeset
   929
  shows "rsize r \<ge> 1"
a73b2e553804 templateforPhd
Chengsong
parents: 435
diff changeset
   930
  by (simp add: non_zero_size)
a73b2e553804 templateforPhd
Chengsong
parents: 435
diff changeset
   931
a73b2e553804 templateforPhd
Chengsong
parents: 435
diff changeset
   932
a73b2e553804 templateforPhd
Chengsong
parents: 435
diff changeset
   933
lemma rexp_size_induct:
a73b2e553804 templateforPhd
Chengsong
parents: 435
diff changeset
   934
  shows "\<And>N r x5 a list.
a73b2e553804 templateforPhd
Chengsong
parents: 435
diff changeset
   935
       \<lbrakk> rsize r = Suc N; r = RALTS x5;
a73b2e553804 templateforPhd
Chengsong
parents: 435
diff changeset
   936
        x5 = a # list\<rbrakk>  \<Longrightarrow>\<exists>i j. rsize a = i \<and> rsize (RALTS list) = j \<and> i + j =  Suc N \<and> i \<le> N \<and> j \<le> N"
a73b2e553804 templateforPhd
Chengsong
parents: 435
diff changeset
   937
  apply(rule_tac x = "rsize a" in exI)
a73b2e553804 templateforPhd
Chengsong
parents: 435
diff changeset
   938
  apply(rule_tac x = "rsize (RALTS list)" in exI)
a73b2e553804 templateforPhd
Chengsong
parents: 435
diff changeset
   939
  apply(subgoal_tac "rsize a \<ge> 1")
a73b2e553804 templateforPhd
Chengsong
parents: 435
diff changeset
   940
   prefer 2
a73b2e553804 templateforPhd
Chengsong
parents: 435
diff changeset
   941
  using One_nat_def non_zero_size apply presburger
a73b2e553804 templateforPhd
Chengsong
parents: 435
diff changeset
   942
  apply(subgoal_tac "rsize (RALTS list) \<ge> 1 ")
a73b2e553804 templateforPhd
Chengsong
parents: 435
diff changeset
   943
  prefer 2
a73b2e553804 templateforPhd
Chengsong
parents: 435
diff changeset
   944
  using size_geq1 apply blast
a73b2e553804 templateforPhd
Chengsong
parents: 435
diff changeset
   945
  apply simp
a73b2e553804 templateforPhd
Chengsong
parents: 435
diff changeset
   946
  done
433
Chengsong
parents:
diff changeset
   947
438
a73b2e553804 templateforPhd
Chengsong
parents: 435
diff changeset
   948
lemma rexp_enum_case3:
a73b2e553804 templateforPhd
Chengsong
parents: 435
diff changeset
   949
  shows "N \<ge> Suc 0 \<Longrightarrow> rexp_enum (Suc N) =  {(RSEQ r1 r2)|r1 r2 i j. r1 \<in>  (rexp_enum i) \<and> r2 \<in>  (rexp_enum j) \<and> i + j = N} \<union>
a73b2e553804 templateforPhd
Chengsong
parents: 435
diff changeset
   950
{(RALTS (a # rs)) | a rs i j. a \<in> (rexp_enum i) \<and> (RALTS rs) \<in> (rexp_enum j) \<and> i + j = Suc N \<and> i \<le> N \<and> j \<le> N} \<union>
a73b2e553804 templateforPhd
Chengsong
parents: 435
diff changeset
   951
{RSTAR r0 | r0. r0 \<in> (rexp_enum N)} \<union>
a73b2e553804 templateforPhd
Chengsong
parents: 435
diff changeset
   952
(rexp_enum N)"
a73b2e553804 templateforPhd
Chengsong
parents: 435
diff changeset
   953
  apply(case_tac N)
433
Chengsong
parents:
diff changeset
   954
   apply simp
438
a73b2e553804 templateforPhd
Chengsong
parents: 435
diff changeset
   955
  apply auto
a73b2e553804 templateforPhd
Chengsong
parents: 435
diff changeset
   956
  done
a73b2e553804 templateforPhd
Chengsong
parents: 435
diff changeset
   957
a73b2e553804 templateforPhd
Chengsong
parents: 435
diff changeset
   958
a73b2e553804 templateforPhd
Chengsong
parents: 435
diff changeset
   959
a73b2e553804 templateforPhd
Chengsong
parents: 435
diff changeset
   960
lemma def_enum_alts:
a73b2e553804 templateforPhd
Chengsong
parents: 435
diff changeset
   961
  shows "\<lbrakk> r = RALTS x5; x5 = a # list;
a73b2e553804 templateforPhd
Chengsong
parents: 435
diff changeset
   962
        rsize a = i \<and> rsize (RALTS list) = j \<and> i + j = Suc N \<and> a \<in> (rexp_enum i) \<and> (RALTS list) \<in> (rexp_enum j) \<rbrakk>
a73b2e553804 templateforPhd
Chengsong
parents: 435
diff changeset
   963
       \<Longrightarrow> r \<in> rexp_enum (Suc N)"
a73b2e553804 templateforPhd
Chengsong
parents: 435
diff changeset
   964
  apply(subgoal_tac "N \<ge> 1")
a73b2e553804 templateforPhd
Chengsong
parents: 435
diff changeset
   965
  prefer 2
a73b2e553804 templateforPhd
Chengsong
parents: 435
diff changeset
   966
  apply (metis One_nat_def add_is_1 less_Suc0 linorder_le_less_linear non_zero_size)
a73b2e553804 templateforPhd
Chengsong
parents: 435
diff changeset
   967
  apply(subgoal_tac " rexp_enum (Suc N) =  {(RSEQ r1 r2)|r1 r2 i j. r1 \<in>  (rexp_enum i) \<and> r2 \<in>  (rexp_enum j) \<and> i + j = N} \<union>
a73b2e553804 templateforPhd
Chengsong
parents: 435
diff changeset
   968
{(RALTS (a # rs)) | a rs i j. a \<in> (rexp_enum i) \<and> (RALTS rs) \<in> (rexp_enum j) \<and> i + j = Suc N\<and> i \<le> N \<and> j \<le> N} \<union>
a73b2e553804 templateforPhd
Chengsong
parents: 435
diff changeset
   969
{RSTAR r0 | r0. r0 \<in> (rexp_enum N)} \<union>
a73b2e553804 templateforPhd
Chengsong
parents: 435
diff changeset
   970
(rexp_enum N)")
a73b2e553804 templateforPhd
Chengsong
parents: 435
diff changeset
   971
  prefer 2
a73b2e553804 templateforPhd
Chengsong
parents: 435
diff changeset
   972
  using One_nat_def rexp_enum_case3 apply presburger
a73b2e553804 templateforPhd
Chengsong
parents: 435
diff changeset
   973
  apply(subgoal_tac "i \<le> N \<and> j \<le> N")
a73b2e553804 templateforPhd
Chengsong
parents: 435
diff changeset
   974
  prefer 2
a73b2e553804 templateforPhd
Chengsong
parents: 435
diff changeset
   975
  using non_zero_size apply auto[1]
a73b2e553804 templateforPhd
Chengsong
parents: 435
diff changeset
   976
  apply(subgoal_tac "r \<in> {uu.
a73b2e553804 templateforPhd
Chengsong
parents: 435
diff changeset
   977
      \<exists>a rs i j. uu = RALTS (a # rs) \<and> a \<in> rexp_enum i \<and> RALTS rs \<in> rexp_enum j \<and> i + j = Suc N \<and> i \<le> N \<and> j \<le> N}")
a73b2e553804 templateforPhd
Chengsong
parents: 435
diff changeset
   978
   apply auto[1]
a73b2e553804 templateforPhd
Chengsong
parents: 435
diff changeset
   979
  apply(subgoal_tac "RALTS (a # list) \<in>  {uu.
a73b2e553804 templateforPhd
Chengsong
parents: 435
diff changeset
   980
      \<exists>a rs i j. uu = RALTS (a # rs) \<and> a \<in> rexp_enum i \<and> RALTS rs \<in> rexp_enum j \<and> i + j = Suc N \<and> i \<le> N \<and> j \<le> N}")
a73b2e553804 templateforPhd
Chengsong
parents: 435
diff changeset
   981
a73b2e553804 templateforPhd
Chengsong
parents: 435
diff changeset
   982
  
a73b2e553804 templateforPhd
Chengsong
parents: 435
diff changeset
   983
   apply fastforce
a73b2e553804 templateforPhd
Chengsong
parents: 435
diff changeset
   984
  apply(subgoal_tac "a \<in> rexp_enum i")
a73b2e553804 templateforPhd
Chengsong
parents: 435
diff changeset
   985
  prefer 2
a73b2e553804 templateforPhd
Chengsong
parents: 435
diff changeset
   986
  
a73b2e553804 templateforPhd
Chengsong
parents: 435
diff changeset
   987
   apply linarith
a73b2e553804 templateforPhd
Chengsong
parents: 435
diff changeset
   988
  by blast
a73b2e553804 templateforPhd
Chengsong
parents: 435
diff changeset
   989
a73b2e553804 templateforPhd
Chengsong
parents: 435
diff changeset
   990
lemma rexp_enum_covers:
a73b2e553804 templateforPhd
Chengsong
parents: 435
diff changeset
   991
  shows " rsize r \<le> N \<Longrightarrow> r \<in> rexp_enum N \<and> r \<in> rexp_enum (rsize r)"
a73b2e553804 templateforPhd
Chengsong
parents: 435
diff changeset
   992
  apply(induct N arbitrary : r)
a73b2e553804 templateforPhd
Chengsong
parents: 435
diff changeset
   993
   apply simp
a73b2e553804 templateforPhd
Chengsong
parents: 435
diff changeset
   994
  
a73b2e553804 templateforPhd
Chengsong
parents: 435
diff changeset
   995
  using rsize.elims apply auto[1]
a73b2e553804 templateforPhd
Chengsong
parents: 435
diff changeset
   996
  apply(case_tac "rsize r \<le> N")
a73b2e553804 templateforPhd
Chengsong
parents: 435
diff changeset
   997
  using enumeration_finite
a73b2e553804 templateforPhd
Chengsong
parents: 435
diff changeset
   998
  
a73b2e553804 templateforPhd
Chengsong
parents: 435
diff changeset
   999
   apply (meson in_mono rexp_enum_inclusion)
a73b2e553804 templateforPhd
Chengsong
parents: 435
diff changeset
  1000
  apply(subgoal_tac "rsize r = Suc N")
a73b2e553804 templateforPhd
Chengsong
parents: 435
diff changeset
  1001
  prefer 2
a73b2e553804 templateforPhd
Chengsong
parents: 435
diff changeset
  1002
  using le_Suc_eq apply blast
a73b2e553804 templateforPhd
Chengsong
parents: 435
diff changeset
  1003
a73b2e553804 templateforPhd
Chengsong
parents: 435
diff changeset
  1004
  apply(case_tac r)
a73b2e553804 templateforPhd
Chengsong
parents: 435
diff changeset
  1005
       prefer 5
a73b2e553804 templateforPhd
Chengsong
parents: 435
diff changeset
  1006
       apply(case_tac x5)
a73b2e553804 templateforPhd
Chengsong
parents: 435
diff changeset
  1007
        apply(subgoal_tac "rsize r =1")
a73b2e553804 templateforPhd
Chengsong
parents: 435
diff changeset
  1008
  prefer 2
a73b2e553804 templateforPhd
Chengsong
parents: 435
diff changeset
  1009
  using hand_made_def_rlist_size rlist_size.simps(2) rsize.simps(4) apply presburger
a73b2e553804 templateforPhd
Chengsong
parents: 435
diff changeset
  1010
        apply simp
a73b2e553804 templateforPhd
Chengsong
parents: 435
diff changeset
  1011
  apply(subgoal_tac "a \<in> rexp_enum (rsize a)")
a73b2e553804 templateforPhd
Chengsong
parents: 435
diff changeset
  1012
  apply(subgoal_tac "RALTS list \<in> rexp_enum (rsize (RALTS list))")
a73b2e553804 templateforPhd
Chengsong
parents: 435
diff changeset
  1013
  
a73b2e553804 templateforPhd
Chengsong
parents: 435
diff changeset
  1014
         apply (meson def_enum_alts rexp_size_induct)
a73b2e553804 templateforPhd
Chengsong
parents: 435
diff changeset
  1015
        apply(subgoal_tac "rsize (RALTS list) \<le> N")
a73b2e553804 templateforPhd
Chengsong
parents: 435
diff changeset
  1016
         apply(subgoal_tac "RALTS list \<in> rexp_enum N")
a73b2e553804 templateforPhd
Chengsong
parents: 435
diff changeset
  1017
  prefer 2
a73b2e553804 templateforPhd
Chengsong
parents: 435
diff changeset
  1018
          apply presburger
a73b2e553804 templateforPhd
Chengsong
parents: 435
diff changeset
  1019
  
433
Chengsong
parents:
diff changeset
  1020
  sorry
Chengsong
parents:
diff changeset
  1021
Chengsong
parents:
diff changeset
  1022
Chengsong
parents:
diff changeset
  1023
lemma finite_size_finite_regx:
Chengsong
parents:
diff changeset
  1024
  shows " \<exists>l. \<forall>rs. ((\<forall>r \<in> (set rs). rsize r < N) \<and> (distinct rs) \<longrightarrow> (length rs) < l) "
438
a73b2e553804 templateforPhd
Chengsong
parents: 435
diff changeset
  1025
433
Chengsong
parents:
diff changeset
  1026
  sorry
Chengsong
parents:
diff changeset
  1027
Chengsong
parents:
diff changeset
  1028
(*below  probably needs proved concurrently*)
Chengsong
parents:
diff changeset
  1029
Chengsong
parents:
diff changeset
  1030
lemma finite_r1r2_ders_list:
Chengsong
parents:
diff changeset
  1031
  shows "(\<forall>s. rsize (rders_simp r1 s) < N1 \<and> rsize (rders_simp r2 s) < N2)
Chengsong
parents:
diff changeset
  1032
           \<Longrightarrow>  \<exists>l. \<forall>s.
Chengsong
parents:
diff changeset
  1033
(length (rdistinct  (map rsimp (rders_cond_list r2 (nullable_bools r1 (orderedPref s))  (orderedSuf s))) {}) )  < l "
Chengsong
parents:
diff changeset
  1034
  sorry
Chengsong
parents:
diff changeset
  1035
Chengsong
parents:
diff changeset
  1036
(*
Chengsong
parents:
diff changeset
  1037
\<lbrakk>s \<noteq> []\<rbrakk> \<Longrightarrow> rders_simp (RSEQ r1 r2) s = 
Chengsong
parents:
diff changeset
  1038
         rsimp (RALTS  ((RSEQ (rders r1 s) r2) #
Chengsong
parents:
diff changeset
  1039
           (rders_cond_list r2 (nullable_bools r1 (orderedPref s))  (orderedSuf s))) )
Chengsong
parents:
diff changeset
  1040
*)
Chengsong
parents:
diff changeset
  1041
 
Chengsong
parents:
diff changeset
  1042
Chengsong
parents:
diff changeset
  1043
lemma sum_list_size2:
Chengsong
parents:
diff changeset
  1044
  shows "\<forall>z \<in>set rs. (rsize z ) \<le> Nr \<Longrightarrow> rlist_size rs \<le> (length rs) * Nr"
Chengsong
parents:
diff changeset
  1045
  apply(induct rs)
Chengsong
parents:
diff changeset
  1046
   apply simp
Chengsong
parents:
diff changeset
  1047
  by simp
Chengsong
parents:
diff changeset
  1048
Chengsong
parents:
diff changeset
  1049
lemma sum_list_size:
Chengsong
parents:
diff changeset
  1050
  fixes rs
Chengsong
parents:
diff changeset
  1051
  shows " \<forall>r \<in> (set rs). (rsize r) \<le> Nr \<and> (length rs) \<le> l \<Longrightarrow> rlist_size rs \<le> l * Nr"
Chengsong
parents:
diff changeset
  1052
  by (metis dual_order.trans mult.commute mult_le_mono2 mult_zero_right sum_list_size2 zero_le)
Chengsong
parents:
diff changeset
  1053
Chengsong
parents:
diff changeset
  1054
lemma seq_second_term_chain1:
Chengsong
parents:
diff changeset
  1055
  shows " \<forall>s. rlist_size (rders_cond_list r2 (nullable_bools r1 (orderedPref s)) (orderedSuf s)) \<le> 
Chengsong
parents:
diff changeset
  1056
 rlist_size (rders_cond_list r2 (nullable_bools r1 (orderedPref s)) (orderedSuf s))"
Chengsong
parents:
diff changeset
  1057
Chengsong
parents:
diff changeset
  1058
  sorry
Chengsong
parents:
diff changeset
  1059
Chengsong
parents:
diff changeset
  1060
Chengsong
parents:
diff changeset
  1061
lemma seq_second_term_chain2:
Chengsong
parents:
diff changeset
  1062
  shows "\<forall>s.  rlist_size (rders_cond_list r2 (nullable_bools r1 (orderedPref s)) (orderedSuf s)) = 
Chengsong
parents:
diff changeset
  1063
 rlist_size (map rsimp (rders_cond_list r2 (nullable_bools r1 (orderedPref s)) (orderedSuf s)))"
Chengsong
parents:
diff changeset
  1064
Chengsong
parents:
diff changeset
  1065
  oops
Chengsong
parents:
diff changeset
  1066
Chengsong
parents:
diff changeset
  1067
lemma seq_second_term_bounded:
Chengsong
parents:
diff changeset
  1068
  fixes r2 r1
Chengsong
parents:
diff changeset
  1069
  assumes "\<forall>s. rsize (rders_simp r2 s) < N2"
Chengsong
parents:
diff changeset
  1070
  shows "\<exists>N3. \<forall>s. rlist_size (rders_cond_list r2 (nullable_bools r1 (orderedPref s)) (orderedSuf s)) < N3"
Chengsong
parents:
diff changeset
  1071
Chengsong
parents:
diff changeset
  1072
  sorry
Chengsong
parents:
diff changeset
  1073
Chengsong
parents:
diff changeset
  1074
Chengsong
parents:
diff changeset
  1075
lemma seq_first_term_bounded:
Chengsong
parents:
diff changeset
  1076
  fixes r1 r2
Chengsong
parents:
diff changeset
  1077
  shows "\<exists>Nr. \<forall>s. rsize (rders_simp r1 s) \<le> Nr \<Longrightarrow> \<exists>Nr'. \<forall>s. rsize (RSEQ  (rders_simp r1 s) r2) \<le> Nr'"
Chengsong
parents:
diff changeset
  1078
  apply(erule exE)
Chengsong
parents:
diff changeset
  1079
  apply(rule_tac x = "Nr + (rsize r2) + 1" in exI)
Chengsong
parents:
diff changeset
  1080
  by simp
Chengsong
parents:
diff changeset
  1081
Chengsong
parents:
diff changeset
  1082
Chengsong
parents:
diff changeset
  1083
lemma alts_triangle_inequality:
Chengsong
parents:
diff changeset
  1084
  shows "rsize (RALTS (r # rs)) \<le> rsize r + rlist_size rs + 1 "
Chengsong
parents:
diff changeset
  1085
  apply(subgoal_tac "rsize (RALTS (r # rs) ) =  rsize r + rlist_size rs + 1")
Chengsong
parents:
diff changeset
  1086
   apply auto[1]
Chengsong
parents:
diff changeset
  1087
  apply(induct rs)
Chengsong
parents:
diff changeset
  1088
   apply simp
Chengsong
parents:
diff changeset
  1089
  apply auto
Chengsong
parents:
diff changeset
  1090
  done
Chengsong
parents:
diff changeset
  1091
Chengsong
parents:
diff changeset
  1092
lemma seq_equal_term_nosimp_entire_bounded:
Chengsong
parents:
diff changeset
  1093
  shows "(\<forall>s. rsize (rders_simp r1 s) < N1 \<and> rsize (rders_simp r2 s) < N2) 
Chengsong
parents:
diff changeset
  1094
      \<Longrightarrow> \<exists>N3. \<forall>s.  rsize  (RALTS  ((RSEQ (rders_simp r1 s) r2) #
Chengsong
parents:
diff changeset
  1095
          (rdistinct ((rders_cond_list r2 (nullable_bools r1 (orderedPref s))  (orderedSuf s)) ) {}) ) ) \<le> N3"
Chengsong
parents:
diff changeset
  1096
  apply(subgoal_tac "\<exists>N3. \<forall>s. rsize  (RALTS  ((RSEQ (rders_simp r1 s) r2) #
Chengsong
parents:
diff changeset
  1097
           (rders_cond_list r2 (nullable_bools r1 (orderedPref s))  (orderedSuf s))) ) \<le>
Chengsong
parents:
diff changeset
  1098
                                        rsize (RSEQ (rders_simp r1 s) r2) + 
Chengsong
parents:
diff changeset
  1099
            rlist_size (map rsimp (rders_cond_list r2 (nullable_bools r1 (orderedPref s)) (orderedSuf s))) + 1")
Chengsong
parents:
diff changeset
  1100
  prefer 2
Chengsong
parents:
diff changeset
  1101
  using alts_triangle_inequality apply presburger
Chengsong
parents:
diff changeset
  1102
  using seq_first_term_bounded
Chengsong
parents:
diff changeset
  1103
  using seq_second_term_bounded
Chengsong
parents:
diff changeset
  1104
  apply(subgoal_tac "\<exists>N3. \<forall>s. rlist_size (rders_cond_list r2 (nullable_bools r1 (orderedPref s)) (orderedSuf s)) < N3")
Chengsong
parents:
diff changeset
  1105
  prefer 2
Chengsong
parents:
diff changeset
  1106
   apply meson
Chengsong
parents:
diff changeset
  1107
  apply(subgoal_tac "\<exists>Nr'. \<forall>s. rsize (RSEQ  (rders_simp r1 s) r2) \<le> Nr'")
Chengsong
parents:
diff changeset
  1108
   prefer 2
Chengsong
parents:
diff changeset
  1109
  apply (meson order_le_less)
Chengsong
parents:
diff changeset
  1110
  apply(erule exE)
Chengsong
parents:
diff changeset
  1111
  apply(erule exE)
Chengsong
parents:
diff changeset
  1112
  sorry
Chengsong
parents:
diff changeset
  1113
Chengsong
parents:
diff changeset
  1114
lemma alts_simp_bounded_by_sloppy1_version:
Chengsong
parents:
diff changeset
  1115
  shows "\<forall>s. rsize (rsimp (RALTS  ((RSEQ (rders_simp r1 s) r2) #
Chengsong
parents:
diff changeset
  1116
           (rders_cond_list r2 (nullable_bools r1 (orderedPref s))  (orderedSuf s))) )) \<le> 
Chengsong
parents:
diff changeset
  1117
rsize  (RALTS (rdistinct ((RSEQ (rders_simp r1 s) r2) #
Chengsong
parents:
diff changeset
  1118
                          (rders_cond_list r2 (nullable_bools r1 (orderedPref s))  (orderedSuf s))
Chengsong
parents:
diff changeset
  1119
                         ) 
Chengsong
parents:
diff changeset
  1120
                         {}
Chengsong
parents:
diff changeset
  1121
              )
Chengsong
parents:
diff changeset
  1122
        ) "
Chengsong
parents:
diff changeset
  1123
  sorry
Chengsong
parents:
diff changeset
  1124
Chengsong
parents:
diff changeset
  1125
lemma alts_simp_bounded_by_sloppy1:
Chengsong
parents:
diff changeset
  1126
  shows "rsize  (rsimp (RALTS (rdistinct ((RSEQ (rders_simp r1 s) r2) #
Chengsong
parents:
diff changeset
  1127
                          (rders_cond_list r2 (nullable_bools r1 (orderedPref s))  (orderedSuf s))
Chengsong
parents:
diff changeset
  1128
                         ) 
Chengsong
parents:
diff changeset
  1129
                         {}
Chengsong
parents:
diff changeset
  1130
              )
Chengsong
parents:
diff changeset
  1131
        )) \<le>
Chengsong
parents:
diff changeset
  1132
rsize  (RALTS  ((RSEQ (rders_simp r1 s) r2) #
Chengsong
parents:
diff changeset
  1133
                          (rders_cond_list r2 (nullable_bools r1 (orderedPref s))  (orderedSuf s))
Chengsong
parents:
diff changeset
  1134
                         ) 
Chengsong
parents:
diff changeset
  1135
        )"
Chengsong
parents:
diff changeset
  1136
  sorry
Chengsong
parents:
diff changeset
  1137
435
Chengsong
parents: 434
diff changeset
  1138
433
Chengsong
parents:
diff changeset
  1139
Chengsong
parents:
diff changeset
  1140
(*this section deals with the property of distinctBy: creates a list without duplicates*)
Chengsong
parents:
diff changeset
  1141
lemma distinct_mono:
Chengsong
parents:
diff changeset
  1142
  shows "rlist_size (rdistinct (a # s) {}) \<le> rlist_size (a # (rdistinct s {}) )"
Chengsong
parents:
diff changeset
  1143
  sorry
Chengsong
parents:
diff changeset
  1144
Chengsong
parents:
diff changeset
  1145
lemma distinct_acc_mono:
Chengsong
parents:
diff changeset
  1146
  shows "A \<subseteq> B \<Longrightarrow> rlist_size (rdistinct s A) \<ge> rlist_size (rdistinct s B)"
Chengsong
parents:
diff changeset
  1147
  apply(induct s arbitrary: A B)
Chengsong
parents:
diff changeset
  1148
   apply simp
Chengsong
parents:
diff changeset
  1149
  apply(case_tac "a \<in> A")
Chengsong
parents:
diff changeset
  1150
  apply(subgoal_tac "a \<in> B")
Chengsong
parents:
diff changeset
  1151
  
Chengsong
parents:
diff changeset
  1152
  apply simp
Chengsong
parents:
diff changeset
  1153
  
Chengsong
parents:
diff changeset
  1154
   apply blast
Chengsong
parents:
diff changeset
  1155
  apply(subgoal_tac "rlist_size (rdistinct (a # s) A) = rlist_size (a # (rdistinct s (A \<union> {a})))")
Chengsong
parents:
diff changeset
  1156
   apply(case_tac "a \<in> B")
Chengsong
parents:
diff changeset
  1157
  apply(subgoal_tac "rlist_size (rdistinct (a # s) B) = rlist_size ( (rdistinct s B))") 
Chengsong
parents:
diff changeset
  1158
  apply (metis Un_insert_right dual_order.trans insert_subset le_add_same_cancel2 rlist_size.simps(1) sup_bot_right zero_order(1))
Chengsong
parents:
diff changeset
  1159
  apply simp
Chengsong
parents:
diff changeset
  1160
  apply auto
Chengsong
parents:
diff changeset
  1161
  by (meson insert_mono)
Chengsong
parents:
diff changeset
  1162
Chengsong
parents:
diff changeset
  1163
Chengsong
parents:
diff changeset
  1164
lemma distinct_mono2:
Chengsong
parents:
diff changeset
  1165
  shows " rlist_size (rdistinct s {a}) \<le> rlist_size (rdistinct s {})"
Chengsong
parents:
diff changeset
  1166
  apply(induct s)
Chengsong
parents:
diff changeset
  1167
   apply simp
Chengsong
parents:
diff changeset
  1168
  apply simp
Chengsong
parents:
diff changeset
  1169
  using distinct_acc_mono by auto
Chengsong
parents:
diff changeset
  1170
Chengsong
parents:
diff changeset
  1171
Chengsong
parents:
diff changeset
  1172
Chengsong
parents:
diff changeset
  1173
lemma distinct_mono_spares_first_elem:
Chengsong
parents:
diff changeset
  1174
  shows "rsize (RALTS (rdistinct (a # s) {})) \<le> rsize (RALTS (a # (rdistinct s {})))"
Chengsong
parents:
diff changeset
  1175
  apply simp
Chengsong
parents:
diff changeset
  1176
  apply (subgoal_tac "rlist_size ( (rdistinct s {a})) \<le> rlist_size ( (rdistinct s {})) ")
Chengsong
parents:
diff changeset
  1177
  using hand_made_def_rlist_size apply auto[1]
Chengsong
parents:
diff changeset
  1178
  using distinct_mono2 by auto
Chengsong
parents:
diff changeset
  1179
Chengsong
parents:
diff changeset
  1180
lemma sloppy1_bounded_by_sloppiest:
Chengsong
parents:
diff changeset
  1181
  shows "rsize  (RALTS (rdistinct ((RSEQ (rders_simp r1 s) r2) #
Chengsong
parents:
diff changeset
  1182
                          (rders_cond_list r2 (nullable_bools r1 (orderedPref s))  (orderedSuf s))
Chengsong
parents:
diff changeset
  1183
                         ) 
Chengsong
parents:
diff changeset
  1184
                         {}
Chengsong
parents:
diff changeset
  1185
              )
Chengsong
parents:
diff changeset
  1186
        ) \<le> rsize  (RALTS ((RSEQ (rders_simp r1 s) r2) #
Chengsong
parents:
diff changeset
  1187
                          (rdistinct (rders_cond_list r2 (nullable_bools r1 (orderedPref s))  (orderedSuf s)) {})
Chengsong
parents:
diff changeset
  1188
                         
Chengsong
parents:
diff changeset
  1189
                         
Chengsong
parents:
diff changeset
  1190
              )
Chengsong
parents:
diff changeset
  1191
        )"
Chengsong
parents:
diff changeset
  1192
  
Chengsong
parents:
diff changeset
  1193
  sorry
Chengsong
parents:
diff changeset
  1194
Chengsong
parents:
diff changeset
  1195
Chengsong
parents:
diff changeset
  1196
lemma alts_simp_bounded_by_sloppiest_version:
Chengsong
parents:
diff changeset
  1197
  shows "\<forall>s. rsize (rsimp (RALTS  ((RSEQ (rders_simp r1 s) r2) #
Chengsong
parents:
diff changeset
  1198
           (rders_cond_list r2 (nullable_bools r1 (orderedPref s))  (orderedSuf s))) )) \<le> 
Chengsong
parents:
diff changeset
  1199
rsize  (RALTS  ((RSEQ (rders_simp r1 s) r2) #
Chengsong
parents:
diff changeset
  1200
           (rdistinct (rders_cond_list r2 (nullable_bools r1 (orderedPref s))  (orderedSuf s)) {})  ) ) "
Chengsong
parents:
diff changeset
  1201
  by (meson alts_simp_bounded_by_sloppy1_version order_trans sloppy1_bounded_by_sloppiest)
Chengsong
parents:
diff changeset
  1202
Chengsong
parents:
diff changeset
  1203
Chengsong
parents:
diff changeset
  1204
lemma seq_equal_term_entire_bounded:
Chengsong
parents:
diff changeset
  1205
  shows "(\<forall>s. rsize (rders_simp r1 s) < N1 \<and> rsize (rders_simp r2 s) < N2) 
Chengsong
parents:
diff changeset
  1206
      \<Longrightarrow> \<exists>N3. \<forall>s.  rsize (rsimp (RALTS  ((RSEQ (rders_simp r1 s) r2) #
Chengsong
parents:
diff changeset
  1207
           (rders_cond_list r2 (nullable_bools r1 (orderedPref s))  (orderedSuf s))) )) \<le> N3"
Chengsong
parents:
diff changeset
  1208
  using seq_equal_term_nosimp_entire_bounded
Chengsong
parents:
diff changeset
  1209
  apply(subgoal_tac " \<exists>N3. \<forall>s.  rsize  (RALTS  ((RSEQ (rders_simp r1 s) r2) #
Chengsong
parents:
diff changeset
  1210
           (rdistinct  (rders_cond_list r2 (nullable_bools r1 (orderedPref s))  (orderedSuf s)) {}) ) ) \<le> N3")
Chengsong
parents:
diff changeset
  1211
  apply(erule exE)
Chengsong
parents:
diff changeset
  1212
   prefer 2
Chengsong
parents:
diff changeset
  1213
  apply blast
Chengsong
parents:
diff changeset
  1214
  apply(subgoal_tac "\<forall>s. rsize (rsimp (RALTS  ((RSEQ (rders_simp r1 s) r2) #
Chengsong
parents:
diff changeset
  1215
           (rders_cond_list r2 (nullable_bools r1 (orderedPref s))  (orderedSuf s))) )) \<le> 
Chengsong
parents:
diff changeset
  1216
rsize  (RALTS  ((RSEQ (rders_simp r1 s) r2) #
Chengsong
parents:
diff changeset
  1217
           (rdistinct (rders_cond_list r2 (nullable_bools r1 (orderedPref s))  (orderedSuf s)) {})  ) ) ")
Chengsong
parents:
diff changeset
  1218
   prefer 2
Chengsong
parents:
diff changeset
  1219
  using alts_simp_bounded_by_sloppiest_version apply blast
Chengsong
parents:
diff changeset
  1220
  apply(rule_tac x = "Suc N3 " in exI)
Chengsong
parents:
diff changeset
  1221
  apply(rule allI)
Chengsong
parents:
diff changeset
  1222
Chengsong
parents:
diff changeset
  1223
  apply(subgoal_tac " rsize
Chengsong
parents:
diff changeset
  1224
             (rsimp
Chengsong
parents:
diff changeset
  1225
               (RALTS
Chengsong
parents:
diff changeset
  1226
                 (RSEQ (rders_simp r1 s) r2 # rders_cond_list r2 (nullable_bools r1 (orderedPref s)) (orderedSuf s))))
Chengsong
parents:
diff changeset
  1227
            \<le> rsize
Chengsong
parents:
diff changeset
  1228
                (RALTS
Chengsong
parents:
diff changeset
  1229
                  (RSEQ (rders_simp r1 s) r2 #
Chengsong
parents:
diff changeset
  1230
                   rdistinct (rders_cond_list r2 (nullable_bools r1 (orderedPref s)) (orderedSuf s)) {}))")
Chengsong
parents:
diff changeset
  1231
   prefer 2
Chengsong
parents:
diff changeset
  1232
   apply presburger
Chengsong
parents:
diff changeset
  1233
  apply(subgoal_tac "  rsize
Chengsong
parents:
diff changeset
  1234
                (RALTS
Chengsong
parents:
diff changeset
  1235
                  (RSEQ (rders_simp r1 s) r2 #
Chengsong
parents:
diff changeset
  1236
                   rdistinct (rders_cond_list r2 (nullable_bools r1 (orderedPref s)) (orderedSuf s)) {})) \<le> N3")
Chengsong
parents:
diff changeset
  1237
  
Chengsong
parents:
diff changeset
  1238
   apply linarith
Chengsong
parents:
diff changeset
  1239
  apply simp
Chengsong
parents:
diff changeset
  1240
  done
Chengsong
parents:
diff changeset
  1241
Chengsong
parents:
diff changeset
  1242
Chengsong
parents:
diff changeset
  1243
Chengsong
parents:
diff changeset
  1244
lemma M1seq:
Chengsong
parents:
diff changeset
  1245
  fixes r1 r2 
Chengsong
parents:
diff changeset
  1246
  shows "(\<forall>s. rsize (rders_simp r1 s) < N1 \<and> rsize (rders_simp r2 s) < N2)
Chengsong
parents:
diff changeset
  1247
           \<Longrightarrow> \<exists>N3.\<forall>s.(rsize (rders_simp (RSEQ r1 r2) s)) < N3"
Chengsong
parents:
diff changeset
  1248
  apply(frule seq_equal_term_entire_bounded)
Chengsong
parents:
diff changeset
  1249
  apply(erule exE)
Chengsong
parents:
diff changeset
  1250
  apply(rule_tac x = "max (N3+2) (Suc (Suc (rsize r1) + (rsize r2)))" in exI)
Chengsong
parents:
diff changeset
  1251
  apply(rule allI)
Chengsong
parents:
diff changeset
  1252
  apply(case_tac "s = []")
Chengsong
parents:
diff changeset
  1253
   prefer 2
434
Chengsong
parents: 433
diff changeset
  1254
   apply (metis add_2_eq_Suc' le_imp_less_Suc less_SucI max.strict_coboundedI1 shape_derssimp_seq)
Chengsong
parents: 433
diff changeset
  1255
  by (metis add.assoc less_Suc_eq less_max_iff_disj plus_1_eq_Suc rders_simp.simps(1) rsize.simps(5))
Chengsong
parents: 433
diff changeset
  1256
433
Chengsong
parents:
diff changeset
  1257
 (*  apply (simp add: less_SucI shape_derssimp_seq(2))
Chengsong
parents:
diff changeset
  1258
   apply (meson less_SucI less_max_iff_disj)
Chengsong
parents:
diff changeset
  1259
  apply simp
Chengsong
parents:
diff changeset
  1260
  done*)
Chengsong
parents:
diff changeset
  1261
Chengsong
parents:
diff changeset
  1262
(*lemma empty_diff:
Chengsong
parents:
diff changeset
  1263
  shows "s = [] \<Longrightarrow>
Chengsong
parents:
diff changeset
  1264
        (rsize (rders_simp (RSEQ r1 r2) s)) \<le> 
Chengsong
parents:
diff changeset
  1265
        (max 
Chengsong
parents:
diff changeset
  1266
        (rsize (rsimp (RALTS (RSEQ (rders r1 s) r2 # rders_cond_list r2 (nullable_bools r1 (orderedPref s)) (orderedSuf s)))))
Chengsong
parents:
diff changeset
  1267
        (Suc (rsize r1 + rsize r2)) ) "
Chengsong
parents:
diff changeset
  1268
  apply simp
Chengsong
parents:
diff changeset
  1269
  done*)
Chengsong
parents:
diff changeset
  1270
(*For star related  bound*)
Chengsong
parents:
diff changeset
  1271
Chengsong
parents:
diff changeset
  1272
lemma star_is_a_singleton_list_derc:
434
Chengsong
parents: 433
diff changeset
  1273
  shows " \<exists>Ss.  rders_simp (RSTAR r) [c] = rsimp (RALTS ( (map (\<lambda>s1.  rsimp_SEQ (rders_simp r s1) (RSTAR r)) Ss)))"
433
Chengsong
parents:
diff changeset
  1274
  apply simp
Chengsong
parents:
diff changeset
  1275
  apply(rule_tac x = "[[c]]" in exI)
Chengsong
parents:
diff changeset
  1276
  apply auto
434
Chengsong
parents: 433
diff changeset
  1277
  apply(case_tac "rsimp (rder c r)")
Chengsong
parents: 433
diff changeset
  1278
       apply simp
Chengsong
parents: 433
diff changeset
  1279
      apply auto
Chengsong
parents: 433
diff changeset
  1280
   apply(subgoal_tac "rsimp (RSEQ x41 x42) = RSEQ x41 x42")
Chengsong
parents: 433
diff changeset
  1281
  prefer 2
Chengsong
parents: 433
diff changeset
  1282
    apply (metis rsimp_idem)
Chengsong
parents: 433
diff changeset
  1283
   apply(subgoal_tac "rsimp x41 = x41")
Chengsong
parents: 433
diff changeset
  1284
  prefer 2
Chengsong
parents: 433
diff changeset
  1285
  using rsimp_inner_idem1 apply blast
Chengsong
parents: 433
diff changeset
  1286
   apply(subgoal_tac "rsimp x42 = x42")
Chengsong
parents: 433
diff changeset
  1287
  prefer 2
Chengsong
parents: 433
diff changeset
  1288
  using rsimp_inner_idem1 apply blast
Chengsong
parents: 433
diff changeset
  1289
   apply simp
Chengsong
parents: 433
diff changeset
  1290
  apply(subgoal_tac "map rsimp x5 = x5")
Chengsong
parents: 433
diff changeset
  1291
  prefer 2
Chengsong
parents: 433
diff changeset
  1292
  using rsimp_inner_idem3 apply blast
Chengsong
parents: 433
diff changeset
  1293
  apply simp
Chengsong
parents: 433
diff changeset
  1294
  apply(subgoal_tac "rflts x5 = x5")
Chengsong
parents: 433
diff changeset
  1295
   prefer 2
Chengsong
parents: 433
diff changeset
  1296
  using rsimp_inner_idem4 apply blast
Chengsong
parents: 433
diff changeset
  1297
  apply simp
Chengsong
parents: 433
diff changeset
  1298
  using rsimp_inner_idem4 by auto
Chengsong
parents: 433
diff changeset
  1299
  
Chengsong
parents: 433
diff changeset
  1300
433
Chengsong
parents:
diff changeset
  1301
Chengsong
parents:
diff changeset
  1302
lemma rder_rsimp_ALTs_commute:
Chengsong
parents:
diff changeset
  1303
  shows "  (rder x (rsimp_ALTs rs)) = rsimp_ALTs (map (rder x) rs)"
Chengsong
parents:
diff changeset
  1304
  apply(induct rs)
Chengsong
parents:
diff changeset
  1305
   apply simp
Chengsong
parents:
diff changeset
  1306
  apply(case_tac rs)
Chengsong
parents:
diff changeset
  1307
   apply simp
Chengsong
parents:
diff changeset
  1308
  apply auto
Chengsong
parents:
diff changeset
  1309
  done
Chengsong
parents:
diff changeset
  1310
434
Chengsong
parents: 433
diff changeset
  1311
433
Chengsong
parents:
diff changeset
  1312
Chengsong
parents:
diff changeset
  1313
fun star_update :: "char \<Rightarrow> rrexp \<Rightarrow> char list list => char list list" where
Chengsong
parents:
diff changeset
  1314
"star_update c r [] = []"
Chengsong
parents:
diff changeset
  1315
|"star_update c r (s # Ss) = (if (rnullable (rders_simp r s)) 
Chengsong
parents:
diff changeset
  1316
                                then (s@[c]) # [c] # (star_update c r Ss) 
435
Chengsong
parents: 434
diff changeset
  1317
                               else   (s@[c]) # (star_update c r Ss) )"
433
Chengsong
parents:
diff changeset
  1318
434
Chengsong
parents: 433
diff changeset
  1319
lemma star_update_case1:
Chengsong
parents: 433
diff changeset
  1320
  shows "rnullable (rders_simp r s) \<Longrightarrow> star_update c r (s # Ss) = (s @ [c]) # [c] # (star_update c r Ss)"
Chengsong
parents: 433
diff changeset
  1321
  
Chengsong
parents: 433
diff changeset
  1322
  by force
Chengsong
parents: 433
diff changeset
  1323
Chengsong
parents: 433
diff changeset
  1324
lemma star_update_case2:
435
Chengsong
parents: 434
diff changeset
  1325
  shows "\<not>rnullable (rders_simp r s) \<Longrightarrow> star_update c r (s # Ss) = (s @ [c]) # (star_update c r Ss)"
Chengsong
parents: 434
diff changeset
  1326
  by simp
Chengsong
parents: 434
diff changeset
  1327
Chengsong
parents: 434
diff changeset
  1328
lemma bubble_break: shows "rflts [r, RZERO] = rflts [r]"
Chengsong
parents: 434
diff changeset
  1329
  apply(case_tac r)
Chengsong
parents: 434
diff changeset
  1330
       apply simp+
Chengsong
parents: 434
diff changeset
  1331
  done
Chengsong
parents: 434
diff changeset
  1332
Chengsong
parents: 434
diff changeset
  1333
lemma rsimp_alts_idem_aux1:
Chengsong
parents: 434
diff changeset
  1334
  shows "rsimp_ALTs (rdistinct (rflts [rsimp a]) {}) = rsimp (RALTS [a])"
Chengsong
parents: 434
diff changeset
  1335
  by force
Chengsong
parents: 434
diff changeset
  1336
Chengsong
parents: 434
diff changeset
  1337
Chengsong
parents: 434
diff changeset
  1338
Chengsong
parents: 434
diff changeset
  1339
lemma rsimp_alts_idem_aux2:
Chengsong
parents: 434
diff changeset
  1340
  shows "rsimp a = rsimp (RALTS [a])"
Chengsong
parents: 434
diff changeset
  1341
  apply(simp)
Chengsong
parents: 434
diff changeset
  1342
  apply(case_tac "rsimp a")
Chengsong
parents: 434
diff changeset
  1343
       apply simp+
Chengsong
parents: 434
diff changeset
  1344
  apply (metis no_alt_short_list_after_simp no_further_dB_after_simp)
434
Chengsong
parents: 433
diff changeset
  1345
  by simp
Chengsong
parents: 433
diff changeset
  1346
Chengsong
parents: 433
diff changeset
  1347
lemma rsimp_alts_idem:
Chengsong
parents: 433
diff changeset
  1348
  shows "rsimp (rsimp_ALTs (a # as)) = rsimp (rsimp_ALTs (a # [(rsimp (rsimp_ALTs as))] ))"
435
Chengsong
parents: 434
diff changeset
  1349
  apply(induct as)
Chengsong
parents: 434
diff changeset
  1350
   apply(subgoal_tac "rsimp (rsimp_ALTs [a, rsimp (rsimp_ALTs [])]) = rsimp (rsimp_ALTs [a, RZERO])")
Chengsong
parents: 434
diff changeset
  1351
  prefer 2
Chengsong
parents: 434
diff changeset
  1352
    apply simp
Chengsong
parents: 434
diff changeset
  1353
  using bubble_break rsimp_alts_idem_aux2 apply auto[1]
Chengsong
parents: 434
diff changeset
  1354
  apply(case_tac as)
Chengsong
parents: 434
diff changeset
  1355
   apply(subgoal_tac "rsimp_ALTs( aa # as) = aa")
Chengsong
parents: 434
diff changeset
  1356
  prefer 2
Chengsong
parents: 434
diff changeset
  1357
    apply simp
Chengsong
parents: 434
diff changeset
  1358
  using head_one_more_simp apply fastforce
Chengsong
parents: 434
diff changeset
  1359
  apply(subgoal_tac "rsimp_ALTs (aa # as) = RALTS (aa # as)")
Chengsong
parents: 434
diff changeset
  1360
  prefer 2
Chengsong
parents: 434
diff changeset
  1361
  
Chengsong
parents: 434
diff changeset
  1362
  using rsimp_ALTs.simps(3) apply presburger
Chengsong
parents: 434
diff changeset
  1363
  
Chengsong
parents: 434
diff changeset
  1364
  apply(simp only:)
Chengsong
parents: 434
diff changeset
  1365
  apply(subgoal_tac "rsimp_ALTs (a # aa # aaa # list) = RALTS (a # aa # aaa # list)")
Chengsong
parents: 434
diff changeset
  1366
  prefer 2
Chengsong
parents: 434
diff changeset
  1367
  using rsimp_ALTs.simps(3) apply presburger
Chengsong
parents: 434
diff changeset
  1368
  apply(simp only:)
Chengsong
parents: 434
diff changeset
  1369
  apply(subgoal_tac "rsimp_ALTs [a, rsimp (RALTS (aa # aaa # list))] = RALTS (a # [rsimp (RALTS (aa # aaa # list))])")
Chengsong
parents: 434
diff changeset
  1370
  prefer 2
Chengsong
parents: 434
diff changeset
  1371
  
Chengsong
parents: 434
diff changeset
  1372
  using rsimp_ALTs.simps(3) apply presburger
Chengsong
parents: 434
diff changeset
  1373
  apply(simp only:)
Chengsong
parents: 434
diff changeset
  1374
  using simp_flatten2
Chengsong
parents: 434
diff changeset
  1375
  apply(subgoal_tac " rsimp (RALT a (rsimp (RALTS (aa # aaa # list))))  =  rsimp (RALT a ((RALTS (aa # aaa # list)))) ")
Chengsong
parents: 434
diff changeset
  1376
  prefer 2
Chengsong
parents: 434
diff changeset
  1377
Chengsong
parents: 434
diff changeset
  1378
  apply (metis head_one_more_simp list.simps(9) rsimp.simps(2))
Chengsong
parents: 434
diff changeset
  1379
  apply (simp only:)
Chengsong
parents: 434
diff changeset
  1380
  done
Chengsong
parents: 434
diff changeset
  1381
434
Chengsong
parents: 433
diff changeset
  1382
Chengsong
parents: 433
diff changeset
  1383
lemma rsimp_alts_idem2:
Chengsong
parents: 433
diff changeset
  1384
  shows "rsimp (rsimp_ALTs (a # as)) = rsimp (rsimp_ALTs ((rsimp a) # [(rsimp (rsimp_ALTs as))] ))"
435
Chengsong
parents: 434
diff changeset
  1385
  using head_one_more_simp rsimp_alts_idem by auto
Chengsong
parents: 434
diff changeset
  1386
434
Chengsong
parents: 433
diff changeset
  1387
Chengsong
parents: 433
diff changeset
  1388
lemma evolution_step1:
Chengsong
parents: 433
diff changeset
  1389
  shows "rsimp
Chengsong
parents: 433
diff changeset
  1390
        (rsimp_ALTs
Chengsong
parents: 433
diff changeset
  1391
          (rder x (rsimp_SEQ (rders_simp r a) (RSTAR r)) # map (\<lambda>s1. rder x (rsimp_SEQ (rders_simp r s1) (RSTAR r))) Ss)) =
Chengsong
parents: 433
diff changeset
  1392
         rsimp 
Chengsong
parents: 433
diff changeset
  1393
        (rsimp_ALTs
Chengsong
parents: 433
diff changeset
  1394
          (rder x (rsimp_SEQ (rders_simp r a) (RSTAR r)) # [(rsimp (rsimp_ALTs (map (\<lambda>s1. rder x (rsimp_SEQ (rders_simp r s1) (RSTAR r))) Ss)))]))   "
Chengsong
parents: 433
diff changeset
  1395
  using rsimp_alts_idem by auto
Chengsong
parents: 433
diff changeset
  1396
Chengsong
parents: 433
diff changeset
  1397
lemma evolution_step2:
Chengsong
parents: 433
diff changeset
  1398
  assumes " rsimp (rsimp_ALTs (map (\<lambda>s1. rder x (rsimp_SEQ (rders_simp r s1) (RSTAR r))) Ss)) =
Chengsong
parents: 433
diff changeset
  1399
       rsimp (rsimp_ALTs (map (\<lambda>s1. rsimp_SEQ (rders_simp r s1) (RSTAR r)) (star_update x r Ss)))"
Chengsong
parents: 433
diff changeset
  1400
  shows "rsimp 
Chengsong
parents: 433
diff changeset
  1401
        (rsimp_ALTs 
Chengsong
parents: 433
diff changeset
  1402
          (rder x (rsimp_SEQ (rders_simp r a) (RSTAR r)) # map (\<lambda>s1. rder x (rsimp_SEQ (rders_simp r s1) (RSTAR r))) Ss)) = 
Chengsong
parents: 433
diff changeset
  1403
                 rsimp 
Chengsong
parents: 433
diff changeset
  1404
        (rsimp_ALTs
Chengsong
parents: 433
diff changeset
  1405
          (rder x (rsimp_SEQ (rders_simp r a) (RSTAR r)) # [ rsimp (rsimp_ALTs (map (\<lambda>s1. rsimp_SEQ (rders_simp r s1) (RSTAR r)) (star_update x r Ss)))]))  "
Chengsong
parents: 433
diff changeset
  1406
  by (simp add: assms rsimp_alts_idem)
Chengsong
parents: 433
diff changeset
  1407
435
Chengsong
parents: 434
diff changeset
  1408
lemma rsimp_seq_aux1:
Chengsong
parents: 434
diff changeset
  1409
  shows "r = RONE \<and> r2 = RSTAR r0 \<Longrightarrow> rsimp_SEQ r r2 = r2"
Chengsong
parents: 434
diff changeset
  1410
  apply simp
Chengsong
parents: 434
diff changeset
  1411
  done
Chengsong
parents: 434
diff changeset
  1412
Chengsong
parents: 434
diff changeset
  1413
lemma multiple_alts_simp_flatten:
Chengsong
parents: 434
diff changeset
  1414
  shows "rsimp (RALT (RALT r1 r2) (rsimp_ALTs rs)) = rsimp (RALTS (r1 # r2 # rs))"
Chengsong
parents: 434
diff changeset
  1415
  by (metis Cons_eq_appendI append_self_conv2 rsimp_ALTs.simps(2) rsimp_ALTs.simps(3) rsimp_alts_idem simp_flatten)
Chengsong
parents: 434
diff changeset
  1416
Chengsong
parents: 434
diff changeset
  1417
Chengsong
parents: 434
diff changeset
  1418
lemma evo3_main_aux1:
Chengsong
parents: 434
diff changeset
  1419
  shows "rsimp
Chengsong
parents: 434
diff changeset
  1420
            (RALT (RALT (RSEQ (rsimp (rders_simp r (a @ [x]))) (RSTAR r)) (RSEQ (rders_simp r [x]) (RSTAR r)))
Chengsong
parents: 434
diff changeset
  1421
              (rsimp_ALTs (map (\<lambda>s1. rsimp_SEQ (rders_simp r s1) (RSTAR r)) (star_update x r Ss)))) =
Chengsong
parents: 434
diff changeset
  1422
           rsimp
Chengsong
parents: 434
diff changeset
  1423
            (RALTS
Chengsong
parents: 434
diff changeset
  1424
              (RSEQ (rders_simp r (a @ [x])) (RSTAR r) #
Chengsong
parents: 434
diff changeset
  1425
               RSEQ (rders_simp r [x]) (RSTAR r) # map (\<lambda>s1. rsimp_SEQ (rders_simp r s1) (RSTAR r)) (star_update x r Ss)))"
Chengsong
parents: 434
diff changeset
  1426
  apply(subgoal_tac "rsimp
Chengsong
parents: 434
diff changeset
  1427
            (RALT (RALT (RSEQ (rsimp (rders_simp r (a @ [x]))) (RSTAR r)) (RSEQ (rders_simp r [x]) (RSTAR r)))
Chengsong
parents: 434
diff changeset
  1428
              (rsimp_ALTs (map (\<lambda>s1. rsimp_SEQ (rders_simp r s1) (RSTAR r)) (star_update x r Ss)))) =
Chengsong
parents: 434
diff changeset
  1429
rsimp
Chengsong
parents: 434
diff changeset
  1430
            (RALT (RALT (RSEQ ( (rders_simp r (a @ [x]))) (RSTAR r)) (RSEQ (rders_simp r [x]) (RSTAR r)))
Chengsong
parents: 434
diff changeset
  1431
              (rsimp_ALTs (map (\<lambda>s1. rsimp_SEQ (rders_simp r s1) (RSTAR r)) (star_update x r Ss)))) ")
Chengsong
parents: 434
diff changeset
  1432
  prefer 2
Chengsong
parents: 434
diff changeset
  1433
   apply (simp add: rsimp_idem)
Chengsong
parents: 434
diff changeset
  1434
  apply (simp only:)
Chengsong
parents: 434
diff changeset
  1435
  apply(subst multiple_alts_simp_flatten)
Chengsong
parents: 434
diff changeset
  1436
  by simp
Chengsong
parents: 434
diff changeset
  1437
Chengsong
parents: 434
diff changeset
  1438
Chengsong
parents: 434
diff changeset
  1439
lemma evo3_main_nullable:
Chengsong
parents: 434
diff changeset
  1440
  shows "
Chengsong
parents: 434
diff changeset
  1441
\<And>a Ss.
Chengsong
parents: 434
diff changeset
  1442
       \<lbrakk>rsimp (rsimp_ALTs (map (\<lambda>s1. rder x (rsimp_SEQ (rders_simp r s1) (RSTAR r))) Ss)) =
Chengsong
parents: 434
diff changeset
  1443
        rsimp (rsimp_ALTs (map (\<lambda>s1. rsimp_SEQ (rders_simp r s1) (RSTAR r)) (star_update x r Ss)));
Chengsong
parents: 434
diff changeset
  1444
        rders_simp r a \<noteq> RONE; rders_simp r a \<noteq> RZERO; rnullable (rders_simp r a)\<rbrakk>
Chengsong
parents: 434
diff changeset
  1445
       \<Longrightarrow> rsimp
Chengsong
parents: 434
diff changeset
  1446
            (rsimp_ALTs
Chengsong
parents: 434
diff changeset
  1447
              [rder x (RSEQ (rders_simp r a) (RSTAR r)),
Chengsong
parents: 434
diff changeset
  1448
               rsimp (rsimp_ALTs (map (\<lambda>s1. rsimp_SEQ (rders_simp r s1) (RSTAR r)) (star_update x r Ss)))]) =
Chengsong
parents: 434
diff changeset
  1449
           rsimp (rsimp_ALTs (map (\<lambda>s1. rsimp_SEQ (rders_simp r s1) (RSTAR r)) (star_update x r (a # Ss))))"
Chengsong
parents: 434
diff changeset
  1450
  apply(subgoal_tac "rder x (RSEQ (rders_simp r a) (RSTAR r)) 
Chengsong
parents: 434
diff changeset
  1451
                   = RALT (RSEQ (rder x (rders_simp r a)) (RSTAR r)) (RSEQ (rder x r) (RSTAR r))")
Chengsong
parents: 434
diff changeset
  1452
  prefer 2
Chengsong
parents: 434
diff changeset
  1453
   apply simp
Chengsong
parents: 434
diff changeset
  1454
  apply(simp only:)
Chengsong
parents: 434
diff changeset
  1455
  apply(subgoal_tac "star_update x r (a # Ss) = (a @ [x]) # [x] # (star_update x r Ss)")
Chengsong
parents: 434
diff changeset
  1456
   prefer 2
Chengsong
parents: 434
diff changeset
  1457
  using star_update_case1 apply presburger
Chengsong
parents: 434
diff changeset
  1458
  apply(simp only:)
Chengsong
parents: 434
diff changeset
  1459
  apply(subst List.list.map(2))+
Chengsong
parents: 434
diff changeset
  1460
  apply(subgoal_tac "rsimp
Chengsong
parents: 434
diff changeset
  1461
            (rsimp_ALTs
Chengsong
parents: 434
diff changeset
  1462
              [RALT (RSEQ (rder x (rders_simp r a)) (RSTAR r)) (RSEQ (rder x r) (RSTAR r)),
Chengsong
parents: 434
diff changeset
  1463
               rsimp (rsimp_ALTs (map (\<lambda>s1. rsimp_SEQ (rders_simp r s1) (RSTAR r)) (star_update x r Ss)))]) = 
Chengsong
parents: 434
diff changeset
  1464
rsimp
Chengsong
parents: 434
diff changeset
  1465
            (RALTS
Chengsong
parents: 434
diff changeset
  1466
              [RALT (RSEQ (rder x (rders_simp r a)) (RSTAR r)) (RSEQ (rder x r) (RSTAR r)),
Chengsong
parents: 434
diff changeset
  1467
               rsimp (rsimp_ALTs (map (\<lambda>s1. rsimp_SEQ (rders_simp r s1) (RSTAR r)) (star_update x r Ss)))])")
Chengsong
parents: 434
diff changeset
  1468
  prefer 2
Chengsong
parents: 434
diff changeset
  1469
  using rsimp_ALTs.simps(3) apply presburger
Chengsong
parents: 434
diff changeset
  1470
  apply(simp only:)
Chengsong
parents: 434
diff changeset
  1471
  apply(subgoal_tac " rsimp
Chengsong
parents: 434
diff changeset
  1472
            (rsimp_ALTs
Chengsong
parents: 434
diff changeset
  1473
              (rsimp_SEQ (rders_simp r (a @ [x])) (RSTAR r) #
Chengsong
parents: 434
diff changeset
  1474
               rsimp_SEQ (rders_simp r [x]) (RSTAR r) # map (\<lambda>s1. rsimp_SEQ (rders_simp r s1) (RSTAR r)) (star_update x r Ss))) 
Chengsong
parents: 434
diff changeset
  1475
= 
Chengsong
parents: 434
diff changeset
  1476
 rsimp
Chengsong
parents: 434
diff changeset
  1477
            (RALTS
Chengsong
parents: 434
diff changeset
  1478
              (rsimp_SEQ (rders_simp r (a @ [x])) (RSTAR r) #
Chengsong
parents: 434
diff changeset
  1479
               rsimp_SEQ (rders_simp r [x]) (RSTAR r) # map (\<lambda>s1. rsimp_SEQ (rders_simp r s1) (RSTAR r)) (star_update x r Ss)))")
Chengsong
parents: 434
diff changeset
  1480
Chengsong
parents: 434
diff changeset
  1481
  prefer 2
Chengsong
parents: 434
diff changeset
  1482
  using rsimp_ALTs.simps(3) apply presburger
Chengsong
parents: 434
diff changeset
  1483
  apply (simp only:)
Chengsong
parents: 434
diff changeset
  1484
  apply(subgoal_tac " rsimp
Chengsong
parents: 434
diff changeset
  1485
            (RALT (RALT (RSEQ (rder x (rders_simp r a)) (RSTAR r)) (RSEQ ( (rder x r)) (RSTAR r)))
Chengsong
parents: 434
diff changeset
  1486
              (rsimp (rsimp_ALTs (map (\<lambda>s1. rsimp_SEQ (rders_simp r s1) (RSTAR r)) (star_update x r Ss))))) = 
Chengsong
parents: 434
diff changeset
  1487
             rsimp
Chengsong
parents: 434
diff changeset
  1488
            (RALT (RALT (RSEQ (rsimp (rder x (rders_simp r a))) (RSTAR r)) (RSEQ (rsimp (rder x r)) (RSTAR r)))
Chengsong
parents: 434
diff changeset
  1489
              (rsimp (rsimp_ALTs (map (\<lambda>s1. rsimp_SEQ (rders_simp r s1) (RSTAR r)) (star_update x r Ss)))))")
Chengsong
parents: 434
diff changeset
  1490
  prefer 2
Chengsong
parents: 434
diff changeset
  1491
   apply (simp add: rsimp_idem)
Chengsong
parents: 434
diff changeset
  1492
  apply(simp only:)
Chengsong
parents: 434
diff changeset
  1493
  apply(subgoal_tac "             rsimp
Chengsong
parents: 434
diff changeset
  1494
            (RALT (RALT (RSEQ (rsimp (rder x (rders_simp r a))) (RSTAR r)) (RSEQ (rsimp (rder x r)) (RSTAR r)))
Chengsong
parents: 434
diff changeset
  1495
              (rsimp (rsimp_ALTs (map (\<lambda>s1. rsimp_SEQ (rders_simp r s1) (RSTAR r)) (star_update x r Ss))))) = 
Chengsong
parents: 434
diff changeset
  1496
             rsimp
Chengsong
parents: 434
diff changeset
  1497
            (RALT (RALT (RSEQ (rsimp (rders_simp r (a @ [x]))) (RSTAR r)) (RSEQ (rders_simp r [x]) (RSTAR r)))
Chengsong
parents: 434
diff changeset
  1498
              (rsimp (rsimp_ALTs (map (\<lambda>s1. rsimp_SEQ (rders_simp r s1) (RSTAR r)) (star_update x r Ss)))))")
Chengsong
parents: 434
diff changeset
  1499
   prefer 2
Chengsong
parents: 434
diff changeset
  1500
  using rders_simp_append rders_simp_one_char rsimp_idem apply presburger
Chengsong
parents: 434
diff changeset
  1501
  apply(simp only:)
Chengsong
parents: 434
diff changeset
  1502
  apply(subgoal_tac " rsimp
Chengsong
parents: 434
diff changeset
  1503
            (RALTS
Chengsong
parents: 434
diff changeset
  1504
              (rsimp_SEQ (rders_simp r (a @ [x])) (RSTAR r) #
Chengsong
parents: 434
diff changeset
  1505
               rsimp_SEQ (rders_simp r [x]) (RSTAR r) # map (\<lambda>s1. rsimp_SEQ (rders_simp r s1) (RSTAR r)) (star_update x r Ss))) = 
Chengsong
parents: 434
diff changeset
  1506
 rsimp
Chengsong
parents: 434
diff changeset
  1507
            (RALTS
Chengsong
parents: 434
diff changeset
  1508
              (RSEQ (rders_simp r (a @ [x])) (RSTAR r) #
Chengsong
parents: 434
diff changeset
  1509
               RSEQ (rders_simp r [x]) (RSTAR r) # map (\<lambda>s1. rsimp_SEQ (rders_simp r s1) (RSTAR r)) (star_update x r Ss)))")
Chengsong
parents: 434
diff changeset
  1510
  prefer 2
Chengsong
parents: 434
diff changeset
  1511
  apply (smt (z3) idiot2 list.simps(9) rrexp.distinct(9) rsimp.simps(1) rsimp.simps(2) rsimp.simps(3) rsimp.simps(4) rsimp.simps(6) rsimp_idem)
Chengsong
parents: 434
diff changeset
  1512
  apply(simp only:)
Chengsong
parents: 434
diff changeset
  1513
  apply(subgoal_tac "      rsimp
Chengsong
parents: 434
diff changeset
  1514
            (RALT (RALT (RSEQ (rsimp (rders_simp r (a @ [x]))) (RSTAR r)) (RSEQ (rders_simp r [x]) (RSTAR r)))
Chengsong
parents: 434
diff changeset
  1515
              (rsimp (rsimp_ALTs (map (\<lambda>s1. rsimp_SEQ (rders_simp r s1) (RSTAR r)) (star_update x r Ss))))) =
Chengsong
parents: 434
diff changeset
  1516
     rsimp
Chengsong
parents: 434
diff changeset
  1517
            (RALT (RALT (RSEQ (rsimp (rders_simp r (a @ [x]))) (RSTAR r)) (RSEQ (rders_simp r [x]) (RSTAR r)))
Chengsong
parents: 434
diff changeset
  1518
              ( (rsimp_ALTs (map (\<lambda>s1. rsimp_SEQ (rders_simp r s1) (RSTAR r)) (star_update x r Ss)))))  ")
Chengsong
parents: 434
diff changeset
  1519
  prefer 2
Chengsong
parents: 434
diff changeset
  1520
  using rsimp_idem apply force
Chengsong
parents: 434
diff changeset
  1521
  apply(simp only:)
Chengsong
parents: 434
diff changeset
  1522
  using evo3_main_aux1 by blast
Chengsong
parents: 434
diff changeset
  1523
  
Chengsong
parents: 434
diff changeset
  1524
Chengsong
parents: 434
diff changeset
  1525
lemma evo3_main_not1:
Chengsong
parents: 434
diff changeset
  1526
  shows " \<not>rnullable (rders_simp r a) \<Longrightarrow> rder x (RSEQ (rders_simp r a) (RSTAR r)) = RSEQ (rder x (rders_simp r a)) (RSTAR r)"
Chengsong
parents: 434
diff changeset
  1527
  by fastforce
Chengsong
parents: 434
diff changeset
  1528
Chengsong
parents: 434
diff changeset
  1529
Chengsong
parents: 434
diff changeset
  1530
lemma evo3_main_not2:
Chengsong
parents: 434
diff changeset
  1531
  shows "\<not>rnullable (rders_simp r a) \<Longrightarrow>  rsimp
Chengsong
parents: 434
diff changeset
  1532
            (rsimp_ALTs
Chengsong
parents: 434
diff changeset
  1533
              (rder x (RSEQ (rders_simp r a) (RSTAR r)) # rs)) = rsimp
Chengsong
parents: 434
diff changeset
  1534
            (rsimp_ALTs
Chengsong
parents: 434
diff changeset
  1535
              ((RSEQ (rders_simp r (a @ [x])) (RSTAR r)) # rs))"
Chengsong
parents: 434
diff changeset
  1536
  by (simp add: rders_simp_append rsimp_alts_idem2 rsimp_idem)
Chengsong
parents: 434
diff changeset
  1537
Chengsong
parents: 434
diff changeset
  1538
lemma evo3_main_not3:
Chengsong
parents: 434
diff changeset
  1539
  shows "rsimp
Chengsong
parents: 434
diff changeset
  1540
            (rsimp_ALTs
Chengsong
parents: 434
diff changeset
  1541
              (rsimp_SEQ r1 (RSTAR r) # rs)) = 
Chengsong
parents: 434
diff changeset
  1542
         rsimp (rsimp_ALTs
Chengsong
parents: 434
diff changeset
  1543
              (RSEQ r1 (RSTAR r) # rs))"
Chengsong
parents: 434
diff changeset
  1544
  by (metis idiot2 rrexp.distinct(9) rsimp.simps(1) rsimp.simps(3) rsimp.simps(4) rsimp.simps(6) rsimp_alts_idem rsimp_alts_idem2)
Chengsong
parents: 434
diff changeset
  1545
Chengsong
parents: 434
diff changeset
  1546
Chengsong
parents: 434
diff changeset
  1547
lemma evo3_main_notnullable:
Chengsong
parents: 434
diff changeset
  1548
  shows "\<And>a Ss.
Chengsong
parents: 434
diff changeset
  1549
       \<lbrakk>rsimp (rsimp_ALTs (map (\<lambda>s1. rder x (rsimp_SEQ (rders_simp r s1) (RSTAR r))) Ss)) =
Chengsong
parents: 434
diff changeset
  1550
        rsimp (rsimp_ALTs (map (\<lambda>s1. rsimp_SEQ (rders_simp r s1) (RSTAR r)) (star_update x r Ss)));
Chengsong
parents: 434
diff changeset
  1551
        rders_simp r a \<noteq> RONE; rders_simp r a \<noteq> RZERO; \<not>rnullable (rders_simp r a)\<rbrakk>
Chengsong
parents: 434
diff changeset
  1552
       \<Longrightarrow> rsimp
Chengsong
parents: 434
diff changeset
  1553
            (rsimp_ALTs
Chengsong
parents: 434
diff changeset
  1554
              [rder x (RSEQ (rders_simp r a) (RSTAR r)),
Chengsong
parents: 434
diff changeset
  1555
               rsimp (rsimp_ALTs (map (\<lambda>s1. rsimp_SEQ (rders_simp r s1) (RSTAR r)) (star_update x r Ss)))]) =
Chengsong
parents: 434
diff changeset
  1556
           rsimp (rsimp_ALTs (map (\<lambda>s1. rsimp_SEQ (rders_simp r s1) (RSTAR r)) (star_update x r (a # Ss))))"
Chengsong
parents: 434
diff changeset
  1557
  apply(subst star_update_case2)
Chengsong
parents: 434
diff changeset
  1558
   apply simp
Chengsong
parents: 434
diff changeset
  1559
  apply(subst List.list.map(2))
Chengsong
parents: 434
diff changeset
  1560
  apply(subst evo3_main_not2)
Chengsong
parents: 434
diff changeset
  1561
   apply simp
Chengsong
parents: 434
diff changeset
  1562
  apply(subst evo3_main_not3)
Chengsong
parents: 434
diff changeset
  1563
  using rsimp_alts_idem by presburger
Chengsong
parents: 434
diff changeset
  1564
Chengsong
parents: 434
diff changeset
  1565
Chengsong
parents: 434
diff changeset
  1566
lemma evo3_aux2:
Chengsong
parents: 434
diff changeset
  1567
  shows "rders_simp r a = RONE \<Longrightarrow> rsimp_SEQ (rders_simp (rders_simp r a) [x]) (RSTAR r) = RZERO"
Chengsong
parents: 434
diff changeset
  1568
  by simp
Chengsong
parents: 434
diff changeset
  1569
lemma evo3_aux3:
Chengsong
parents: 434
diff changeset
  1570
  shows "rsimp (rsimp_ALTs (RZERO # rs)) = rsimp (rsimp_ALTs rs)"
Chengsong
parents: 434
diff changeset
  1571
  by (metis list.simps(8) list.simps(9) rdistinct.simps(1) rflts.simps(1) rflts.simps(2) rsimp.simps(2) rsimp_ALTs.simps(1) rsimp_ALTs.simps(2) rsimp_ALTs.simps(3) rsimp_alts_idem)
Chengsong
parents: 434
diff changeset
  1572
Chengsong
parents: 434
diff changeset
  1573
lemma evo3_aux4:
Chengsong
parents: 434
diff changeset
  1574
  shows " rsimp
Chengsong
parents: 434
diff changeset
  1575
            (rsimp_ALTs
Chengsong
parents: 434
diff changeset
  1576
              [RSEQ (rder x r) (RSTAR r),
Chengsong
parents: 434
diff changeset
  1577
               rsimp (rsimp_ALTs rs)]) =
Chengsong
parents: 434
diff changeset
  1578
           rsimp
Chengsong
parents: 434
diff changeset
  1579
            (rsimp_ALTs
Chengsong
parents: 434
diff changeset
  1580
              (rsimp_SEQ (rders_simp r [x]) (RSTAR r) # rs))"
Chengsong
parents: 434
diff changeset
  1581
  by (metis rders_simp_one_char rsimp.simps(1) rsimp.simps(6) rsimp_alts_idem rsimp_alts_idem2)
Chengsong
parents: 434
diff changeset
  1582
Chengsong
parents: 434
diff changeset
  1583
lemma evo3_aux5:
Chengsong
parents: 434
diff changeset
  1584
  shows "rders_simp r a \<noteq> RONE \<and> rders_simp r a \<noteq> RZERO \<Longrightarrow> rsimp_SEQ (rders_simp r a) (RSTAR r) = RSEQ (rders_simp r a) (RSTAR r)"
Chengsong
parents: 434
diff changeset
  1585
  using idiot2 by blast
Chengsong
parents: 434
diff changeset
  1586
Chengsong
parents: 434
diff changeset
  1587
Chengsong
parents: 434
diff changeset
  1588
lemma evolution_step3:
Chengsong
parents: 434
diff changeset
  1589
  shows" \<And>a Ss.
Chengsong
parents: 434
diff changeset
  1590
       rsimp (rsimp_ALTs (map (\<lambda>s1. rder x (rsimp_SEQ (rders_simp r s1) (RSTAR r))) Ss)) =
Chengsong
parents: 434
diff changeset
  1591
       rsimp (rsimp_ALTs (map (\<lambda>s1. rsimp_SEQ (rders_simp r s1) (RSTAR r)) (star_update x r Ss))) \<Longrightarrow>
Chengsong
parents: 434
diff changeset
  1592
       rsimp
Chengsong
parents: 434
diff changeset
  1593
        (rsimp_ALTs
Chengsong
parents: 434
diff changeset
  1594
          [rder x (rsimp_SEQ (rders_simp r a) (RSTAR r)),
Chengsong
parents: 434
diff changeset
  1595
           rsimp (rsimp_ALTs (map (\<lambda>s1. rsimp_SEQ (rders_simp r s1) (RSTAR r)) (star_update x r Ss)))]) =
Chengsong
parents: 434
diff changeset
  1596
       rsimp (rsimp_ALTs (map (\<lambda>s1. rsimp_SEQ (rders_simp r s1) (RSTAR r)) (star_update x r (a # Ss))))"
Chengsong
parents: 434
diff changeset
  1597
  apply(case_tac "rders_simp r a = RONE")
Chengsong
parents: 434
diff changeset
  1598
   apply(subst rsimp_seq_aux1)
Chengsong
parents: 434
diff changeset
  1599
    apply simp
Chengsong
parents: 434
diff changeset
  1600
  apply(subst rder.simps(6))
Chengsong
parents: 434
diff changeset
  1601
   apply(subgoal_tac "rnullable (rders_simp r a)")
Chengsong
parents: 434
diff changeset
  1602
    prefer 2
Chengsong
parents: 434
diff changeset
  1603
  using rnullable.simps(2) apply presburger
Chengsong
parents: 434
diff changeset
  1604
   apply(subst star_update_case1)
Chengsong
parents: 434
diff changeset
  1605
    apply simp
Chengsong
parents: 434
diff changeset
  1606
Chengsong
parents: 434
diff changeset
  1607
   apply(subst List.list.map)+
Chengsong
parents: 434
diff changeset
  1608
  apply(subst rders_simp_append)
Chengsong
parents: 434
diff changeset
  1609
   apply(subst evo3_aux2)
Chengsong
parents: 434
diff changeset
  1610
    apply simp
Chengsong
parents: 434
diff changeset
  1611
   apply(subst evo3_aux3)
Chengsong
parents: 434
diff changeset
  1612
   apply(subst evo3_aux4)
Chengsong
parents: 434
diff changeset
  1613
   apply simp
Chengsong
parents: 434
diff changeset
  1614
  apply(case_tac "rders_simp r a = RZERO")
Chengsong
parents: 434
diff changeset
  1615
Chengsong
parents: 434
diff changeset
  1616
   apply (simp add: rsimp_alts_idem2)
Chengsong
parents: 434
diff changeset
  1617
   apply(subgoal_tac "rders_simp r (a @ [x]) = RZERO")
Chengsong
parents: 434
diff changeset
  1618
  prefer 2
Chengsong
parents: 434
diff changeset
  1619
  using rder.simps(1) rders_simp_append rders_simp_one_char rsimp.simps(3) apply presburger
Chengsong
parents: 434
diff changeset
  1620
  using rflts.simps(2) rsimp.simps(3) rsimp_SEQ.simps(1) apply presburger
Chengsong
parents: 434
diff changeset
  1621
  apply(subst evo3_aux5)
Chengsong
parents: 434
diff changeset
  1622
   apply simp
Chengsong
parents: 434
diff changeset
  1623
  apply(case_tac "rnullable (rders_simp r a) ")
Chengsong
parents: 434
diff changeset
  1624
  using evo3_main_nullable apply blast
Chengsong
parents: 434
diff changeset
  1625
  using evo3_main_notnullable apply blast
Chengsong
parents: 434
diff changeset
  1626
  done
434
Chengsong
parents: 433
diff changeset
  1627
Chengsong
parents: 433
diff changeset
  1628
(*
Chengsong
parents: 433
diff changeset
  1629
proof (prove)
Chengsong
parents: 433
diff changeset
  1630
goal (1 subgoal):
Chengsong
parents: 433
diff changeset
  1631
 1. map f (a # s) = f a # map f s 
Chengsong
parents: 433
diff changeset
  1632
Auto solve_direct: the current goal can be solved directly with
Chengsong
parents: 433
diff changeset
  1633
  HOL.nitpick_simp(115): map ?f (?x21.0 # ?x22.0) = ?f ?x21.0 # map ?f ?x22.0
Chengsong
parents: 433
diff changeset
  1634
  List.list.map(2): map ?f (?x21.0 # ?x22.0) = ?f ?x21.0 # map ?f ?x22.0
Chengsong
parents: 433
diff changeset
  1635
  List.list.simps(9): map ?f (?x21.0 # ?x22.0) = ?f ?x21.0 # map ?f ?x22.0
Chengsong
parents: 433
diff changeset
  1636
*)
433
Chengsong
parents:
diff changeset
  1637
lemma starseq_list_evolution:
Chengsong
parents:
diff changeset
  1638
  fixes  r :: rrexp and Ss :: "char list list" and x :: char 
Chengsong
parents:
diff changeset
  1639
  shows "rsimp (rsimp_ALTs (map (\<lambda>s1. rder x (rsimp_SEQ (rders_simp r s1) (RSTAR r))) Ss) ) =
Chengsong
parents:
diff changeset
  1640
         rsimp (rsimp_ALTs (map (\<lambda>s1. rsimp_SEQ (rders_simp r s1) (RSTAR r)) (star_update x r Ss))  )"   
Chengsong
parents:
diff changeset
  1641
  apply(induct Ss)
434
Chengsong
parents: 433
diff changeset
  1642
   apply simp
Chengsong
parents: 433
diff changeset
  1643
  apply(subst List.list.map(2))
Chengsong
parents: 433
diff changeset
  1644
  apply(subst evolution_step2)
Chengsong
parents: 433
diff changeset
  1645
   apply simp
435
Chengsong
parents: 434
diff changeset
  1646
Chengsong
parents: 434
diff changeset
  1647
433
Chengsong
parents:
diff changeset
  1648
  sorry
Chengsong
parents:
diff changeset
  1649
Chengsong
parents:
diff changeset
  1650
Chengsong
parents:
diff changeset
  1651
lemma star_seqs_produce_star_seqs:
Chengsong
parents:
diff changeset
  1652
  shows "rsimp (rsimp_ALTs (map (rder x \<circ> (\<lambda>s1. rsimp_SEQ (rders_simp r s1) (RSTAR r))) Ss))
Chengsong
parents:
diff changeset
  1653
       = rsimp (rsimp_ALTs (map ( (\<lambda>s1. rder x (rsimp_SEQ (rders_simp r s1) (RSTAR r)))) Ss))"
Chengsong
parents:
diff changeset
  1654
  by (meson comp_apply)
Chengsong
parents:
diff changeset
  1655
434
Chengsong
parents: 433
diff changeset
  1656
lemma map_der_lambda_composition:
Chengsong
parents: 433
diff changeset
  1657
  shows "map (rder x) (map (\<lambda>s. f s) Ss) = map (\<lambda>s. (rder x (f s))) Ss"
Chengsong
parents: 433
diff changeset
  1658
  by force
Chengsong
parents: 433
diff changeset
  1659
Chengsong
parents: 433
diff changeset
  1660
lemma ralts_vs_rsimpalts:
Chengsong
parents: 433
diff changeset
  1661
  shows "rsimp (RALTS rs) = rsimp (rsimp_ALTs rs)"
435
Chengsong
parents: 434
diff changeset
  1662
  by (metis evo3_aux3 rsimp_ALTs.simps(2) rsimp_ALTs.simps(3) simp_flatten2)
Chengsong
parents: 434
diff changeset
  1663
  
433
Chengsong
parents:
diff changeset
  1664
Chengsong
parents:
diff changeset
  1665
lemma linearity_of_list_of_star_or_starseqs: 
Chengsong
parents:
diff changeset
  1666
  fixes r::rrexp and Ss::"char list list" and x::char
Chengsong
parents:
diff changeset
  1667
  shows "\<exists>Ssa. rsimp (rder x (rsimp_ALTs (map (\<lambda>s1. rsimp_SEQ (rders_simp r s1) (RSTAR r)) Ss))) =
434
Chengsong
parents: 433
diff changeset
  1668
                 rsimp (RALTS ( (map (\<lambda>s1. rsimp_SEQ (rders_simp r s1) (RSTAR r)) Ssa)))"
Chengsong
parents: 433
diff changeset
  1669
  apply(subst rder_rsimp_ALTs_commute)
Chengsong
parents: 433
diff changeset
  1670
  apply(subst map_der_lambda_composition)
Chengsong
parents: 433
diff changeset
  1671
  using starseq_list_evolution
Chengsong
parents: 433
diff changeset
  1672
  apply(rule_tac x = "star_update x r Ss" in exI)
Chengsong
parents: 433
diff changeset
  1673
  apply(subst ralts_vs_rsimpalts)
Chengsong
parents: 433
diff changeset
  1674
  by simp
Chengsong
parents: 433
diff changeset
  1675
433
Chengsong
parents:
diff changeset
  1676
Chengsong
parents:
diff changeset
  1677
434
Chengsong
parents: 433
diff changeset
  1678
(*certified correctness---does not depend on any previous sorry*)
Chengsong
parents: 433
diff changeset
  1679
lemma star_list_push_der: shows  " \<lbrakk>xs \<noteq> [] \<Longrightarrow> \<exists>Ss. rders_simp (RSTAR r) xs = rsimp (RALTS (map (\<lambda>s1. rsimp_SEQ (rders_simp r s1) (RSTAR r)) Ss));
Chengsong
parents: 433
diff changeset
  1680
        xs @ [x] \<noteq> []; xs \<noteq> []\<rbrakk> \<Longrightarrow>
Chengsong
parents: 433
diff changeset
  1681
     \<exists>Ss. rders_simp (RSTAR r ) (xs @ [x]) = 
Chengsong
parents: 433
diff changeset
  1682
        rsimp (RALTS (map (\<lambda>s1. (rder x (rsimp_SEQ (rders_simp r s1) (RSTAR r))) ) Ss) )"
Chengsong
parents: 433
diff changeset
  1683
  apply(subgoal_tac  "\<exists>Ss. rders_simp (RSTAR r) xs = rsimp (RALTS (map (\<lambda>s1. rsimp_SEQ (rders_simp r s1) (RSTAR r)) Ss))")
Chengsong
parents: 433
diff changeset
  1684
  prefer 2
Chengsong
parents: 433
diff changeset
  1685
  apply blast
Chengsong
parents: 433
diff changeset
  1686
  apply(erule exE)
Chengsong
parents: 433
diff changeset
  1687
  apply(subgoal_tac "rders_simp (RSTAR r) (xs @ [x]) = rsimp (rder x (rsimp (RALTS (map (\<lambda>s1. rsimp_SEQ (rders_simp r s1) (RSTAR r)) Ss))))")
Chengsong
parents: 433
diff changeset
  1688
  prefer 2
Chengsong
parents: 433
diff changeset
  1689
  using rders_simp_append
Chengsong
parents: 433
diff changeset
  1690
  using rders_simp_one_char apply presburger
Chengsong
parents: 433
diff changeset
  1691
  apply(rule_tac x= "Ss" in exI)
Chengsong
parents: 433
diff changeset
  1692
  apply(subgoal_tac " rsimp (rder x (rsimp (RALTS (map (\<lambda>s1. rsimp_SEQ (rders_simp r s1) (RSTAR r)) Ss)))) = 
Chengsong
parents: 433
diff changeset
  1693
                       rsimp (rsimp (rder x (RALTS (map (\<lambda>s1. rsimp_SEQ (rders_simp r s1) (RSTAR r)) Ss))))")
Chengsong
parents: 433
diff changeset
  1694
  prefer 2
Chengsong
parents: 433
diff changeset
  1695
  using inside_simp_removal rsimp_idem apply presburger
Chengsong
parents: 433
diff changeset
  1696
  apply(subgoal_tac "rsimp (rsimp (rder x (RALTS (map (\<lambda>s1. rsimp_SEQ (rders_simp r s1) (RSTAR r)) Ss)))) =
Chengsong
parents: 433
diff changeset
  1697
                     rsimp (rsimp (RALTS (map (rder x) (map (\<lambda>s1. rsimp_SEQ (rders_simp r s1) (RSTAR r)) Ss))))")
Chengsong
parents: 433
diff changeset
  1698
  prefer 2
Chengsong
parents: 433
diff changeset
  1699
  using rder.simps(4) apply presburger
Chengsong
parents: 433
diff changeset
  1700
  apply(subgoal_tac "rsimp (rsimp (RALTS (map (rder x) (map (\<lambda>s1. rsimp_SEQ (rders_simp r s1) (RSTAR r)) Ss)))) =
Chengsong
parents: 433
diff changeset
  1701
                     rsimp (rsimp (RALTS (map (\<lambda>s1. (rder x (rsimp_SEQ (rders_simp r s1) (RSTAR r)))) Ss)))")
Chengsong
parents: 433
diff changeset
  1702
   apply (metis rsimp_idem)
Chengsong
parents: 433
diff changeset
  1703
  by (metis map_der_lambda_composition)
Chengsong
parents: 433
diff changeset
  1704
Chengsong
parents: 433
diff changeset
  1705
lemma simp_in_lambdas : 
Chengsong
parents: 433
diff changeset
  1706
  shows "
Chengsong
parents: 433
diff changeset
  1707
rsimp (RALTS (map (\<lambda>s1. (rder x (rsimp_SEQ (rders_simp r s1) (RSTAR r))) ) Ss) ) = 
Chengsong
parents: 433
diff changeset
  1708
rsimp (RALTS (map (\<lambda>s1. (rsimp (rder x  (rsimp_SEQ (rders_simp r s1) (RSTAR r))))) Ss))"
Chengsong
parents: 433
diff changeset
  1709
  by (metis (no_types, lifting) comp_apply list.map_comp map_eq_conv rsimp.simps(2) rsimp_idem)
Chengsong
parents: 433
diff changeset
  1710
433
Chengsong
parents:
diff changeset
  1711
Chengsong
parents:
diff changeset
  1712
lemma starder_is_a_list_of_stars_or_starseqs:
434
Chengsong
parents: 433
diff changeset
  1713
  shows "s \<noteq> [] \<Longrightarrow> \<exists>Ss.  rders_simp (RSTAR r) s = rsimp (RALTS( (map (\<lambda>s1.  rsimp_SEQ (rders_simp r s1) (RSTAR r)) Ss)))"
433
Chengsong
parents:
diff changeset
  1714
  apply(induct s rule: rev_induct)
Chengsong
parents:
diff changeset
  1715
  apply simp
Chengsong
parents:
diff changeset
  1716
  apply(case_tac "xs = []")
Chengsong
parents:
diff changeset
  1717
  using star_is_a_singleton_list_derc
434
Chengsong
parents: 433
diff changeset
  1718
   apply(simp)
Chengsong
parents: 433
diff changeset
  1719
  apply(subgoal_tac "\<exists>Ss. rders_simp (RSTAR r) (xs @ [x]) = 
Chengsong
parents: 433
diff changeset
  1720
          rsimp (RALTS (map (\<lambda>s1. rder x (rsimp_SEQ (rders_simp r s1) (RSTAR r))) Ss))")
Chengsong
parents: 433
diff changeset
  1721
  prefer 2
Chengsong
parents: 433
diff changeset
  1722
  using star_list_push_der apply presburger
Chengsong
parents: 433
diff changeset
  1723
Chengsong
parents: 433
diff changeset
  1724
435
Chengsong
parents: 434
diff changeset
  1725
  by (metis ralts_vs_rsimpalts starseq_list_evolution)
Chengsong
parents: 434
diff changeset
  1726
Chengsong
parents: 434
diff changeset
  1727
Chengsong
parents: 434
diff changeset
  1728
lemma starder_is_a_list:
Chengsong
parents: 434
diff changeset
  1729
  shows " \<exists>Ss. rders_simp (RSTAR r) s = rsimp (RALTS ( (map (\<lambda>s1. rsimp_SEQ (rders_simp r s1) (RSTAR r)) Ss))) \<or> rders_simp (RSTAR r) s = RSTAR r"
Chengsong
parents: 434
diff changeset
  1730
  apply(case_tac s)
Chengsong
parents: 434
diff changeset
  1731
  prefer 2
Chengsong
parents: 434
diff changeset
  1732
  apply (metis neq_Nil_conv starder_is_a_list_of_stars_or_starseqs)
Chengsong
parents: 434
diff changeset
  1733
  apply simp
Chengsong
parents: 434
diff changeset
  1734
  done
Chengsong
parents: 434
diff changeset
  1735
Chengsong
parents: 434
diff changeset
  1736
Chengsong
parents: 434
diff changeset
  1737
(** start about bounds here**)
Chengsong
parents: 434
diff changeset
  1738
Chengsong
parents: 434
diff changeset
  1739
Chengsong
parents: 434
diff changeset
  1740
lemma list_simp_size:
Chengsong
parents: 434
diff changeset
  1741
  shows "rlist_size (map rsimp rs) \<le> rlist_size rs"
Chengsong
parents: 434
diff changeset
  1742
  apply(induct rs)
Chengsong
parents: 434
diff changeset
  1743
   apply simp
Chengsong
parents: 434
diff changeset
  1744
  apply simp
Chengsong
parents: 434
diff changeset
  1745
  apply (subgoal_tac "rsize (rsimp a) \<le> rsize a")
Chengsong
parents: 434
diff changeset
  1746
  prefer 2
Chengsong
parents: 434
diff changeset
  1747
  using rsimp_mono apply fastforce
Chengsong
parents: 434
diff changeset
  1748
  using add_le_mono by presburger
Chengsong
parents: 434
diff changeset
  1749
Chengsong
parents: 434
diff changeset
  1750
lemma inside_list_simp_inside_list:
Chengsong
parents: 434
diff changeset
  1751
  shows "r \<in> set rs \<Longrightarrow> rsimp r \<in> set (map rsimp rs)"
Chengsong
parents: 434
diff changeset
  1752
  apply (induct rs)
Chengsong
parents: 434
diff changeset
  1753
   apply simp
Chengsong
parents: 434
diff changeset
  1754
  apply auto
Chengsong
parents: 434
diff changeset
  1755
  done
Chengsong
parents: 434
diff changeset
  1756
Chengsong
parents: 434
diff changeset
  1757
Chengsong
parents: 434
diff changeset
  1758
lemma rsize_star_seq_list:
Chengsong
parents: 434
diff changeset
  1759
  shows "(\<forall>s. rsize (rders_simp r0 s) < N0 ) \<Longrightarrow>  \<exists>N3.\<forall>Ss.  
Chengsong
parents: 434
diff changeset
  1760
rlist_size (rdistinct (map (\<lambda>s1. rsimp_SEQ (rders_simp r0 s1) (RSTAR r0)) Ss) {}) < N3"
434
Chengsong
parents: 433
diff changeset
  1761
  sorry
433
Chengsong
parents:
diff changeset
  1762
Chengsong
parents:
diff changeset
  1763
435
Chengsong
parents: 434
diff changeset
  1764
lemma rdistinct_bound_by_no_simp:
Chengsong
parents: 434
diff changeset
  1765
  shows "
Chengsong
parents: 434
diff changeset
  1766
Chengsong
parents: 434
diff changeset
  1767
   rlist_size (rdistinct  (map rsimp rs) (set (map rsimp ss)))
Chengsong
parents: 434
diff changeset
  1768
 \<le> (rlist_size (rdistinct rs (set ss)))
Chengsong
parents: 434
diff changeset
  1769
"
Chengsong
parents: 434
diff changeset
  1770
  apply(induct rs arbitrary: ss)
Chengsong
parents: 434
diff changeset
  1771
   apply simp
Chengsong
parents: 434
diff changeset
  1772
  apply(case_tac "a \<in> set ss")
Chengsong
parents: 434
diff changeset
  1773
   apply(subgoal_tac "rsimp a \<in> set (map rsimp ss)")
Chengsong
parents: 434
diff changeset
  1774
  prefer 2
Chengsong
parents: 434
diff changeset
  1775
  using inside_list_simp_inside_list apply blast
Chengsong
parents: 434
diff changeset
  1776
Chengsong
parents: 434
diff changeset
  1777
   apply simp
Chengsong
parents: 434
diff changeset
  1778
  apply simp
Chengsong
parents: 434
diff changeset
  1779
  by (metis List.set_insert add_le_mono image_insert insert_absorb rsimp_mono trans_le_add2)
Chengsong
parents: 434
diff changeset
  1780
Chengsong
parents: 434
diff changeset
  1781
Chengsong
parents: 434
diff changeset
  1782
lemma starder_closed_form_bound_aux1:
Chengsong
parents: 434
diff changeset
  1783
  shows 
Chengsong
parents: 434
diff changeset
  1784
"\<forall>Ss. rsize (rsimp (RALTS ( (map (\<lambda>s1. rsimp_SEQ (rders_simp r0 s1) (RSTAR r0)) Ss)))) \<le>
Chengsong
parents: 434
diff changeset
  1785
  Suc (rlist_size ( (rdistinct ( ( (map (\<lambda>s1. rsimp_SEQ (rders_simp r0 s1) (RSTAR r0)) Ss))) {}))) "
Chengsong
parents: 434
diff changeset
  1786
  
Chengsong
parents: 434
diff changeset
  1787
  sorry
Chengsong
parents: 434
diff changeset
  1788
Chengsong
parents: 434
diff changeset
  1789
lemma starder_closed_form_bound:
Chengsong
parents: 434
diff changeset
  1790
  shows "(\<forall>s. rsize (rders_simp r0 s) < N0 ) \<Longrightarrow> \<exists>N3.\<forall>Ss.  
Chengsong
parents: 434
diff changeset
  1791
rsize(rsimp (RALTS ( (map (\<lambda>s1. rsimp_SEQ (rders_simp r0 s1) (RSTAR r0)) Ss)))) < N3"
Chengsong
parents: 434
diff changeset
  1792
  apply(subgoal_tac " \<exists>N3.\<forall>Ss.  
Chengsong
parents: 434
diff changeset
  1793
rlist_size (rdistinct (map (\<lambda>s1. rsimp_SEQ (rders_simp r0 s1) (RSTAR r0)) Ss) {}) < N3")
Chengsong
parents: 434
diff changeset
  1794
  prefer 2
Chengsong
parents: 434
diff changeset
  1795
  
Chengsong
parents: 434
diff changeset
  1796
  using rsize_star_seq_list apply auto[1]
Chengsong
parents: 434
diff changeset
  1797
  apply(erule exE)
Chengsong
parents: 434
diff changeset
  1798
  apply(rule_tac x = "Suc N3" in exI)
Chengsong
parents: 434
diff changeset
  1799
  apply(subgoal_tac "\<forall>Ss. rsize (rsimp (RALTS ( (map (\<lambda>s1. rsimp_SEQ (rders_simp r0 s1) (RSTAR r0)) Ss)))) \<le>
Chengsong
parents: 434
diff changeset
  1800
 Suc (rlist_size ( (rdistinct ( ( (map (\<lambda>s1. rsimp_SEQ (rders_simp r0 s1) (RSTAR r0)) Ss))) {})))")
Chengsong
parents: 434
diff changeset
  1801
  prefer 2
Chengsong
parents: 434
diff changeset
  1802
  using starder_closed_form_bound_aux1 apply blast
Chengsong
parents: 434
diff changeset
  1803
  by (meson less_trans_Suc linorder_not_le not_less_eq)
Chengsong
parents: 434
diff changeset
  1804
Chengsong
parents: 434
diff changeset
  1805
  
Chengsong
parents: 434
diff changeset
  1806
thm starder_closed_form_bound_aux1
Chengsong
parents: 434
diff changeset
  1807
Chengsong
parents: 434
diff changeset
  1808
(*
Chengsong
parents: 434
diff changeset
  1809
 "ralts_vs_rsimpalts", , and "starder_closed_form_bound_aux1", which could be due to a bug in Sledgehammer or to inconsistent axioms (including "sorry"s) 
Chengsong
parents: 434
diff changeset
  1810
*)
Chengsong
parents: 434
diff changeset
  1811
Chengsong
parents: 434
diff changeset
  1812
lemma starder_size_bound:
Chengsong
parents: 434
diff changeset
  1813
  shows "(\<forall>s. rsize (rders_simp r0 s) < N0 ) \<Longrightarrow> \<exists>N3.\<forall>Ss.  
Chengsong
parents: 434
diff changeset
  1814
rsize(rsimp (RALTS ( (map (\<lambda>s1. rsimp_SEQ (rders_simp r0 s1) (RSTAR r0)) Ss)))) < N3 \<and>
Chengsong
parents: 434
diff changeset
  1815
rsize (RSTAR r0) < N3"
Chengsong
parents: 434
diff changeset
  1816
  apply(subgoal_tac " \<exists>N3.\<forall>Ss.  
Chengsong
parents: 434
diff changeset
  1817
rsize(rsimp (RALTS ( (map (\<lambda>s1. rsimp_SEQ (rders_simp r0 s1) (RSTAR r0)) Ss)))) < N3")
Chengsong
parents: 434
diff changeset
  1818
  prefer 2
Chengsong
parents: 434
diff changeset
  1819
  using starder_closed_form_bound apply blast
Chengsong
parents: 434
diff changeset
  1820
  apply(erule exE)
Chengsong
parents: 434
diff changeset
  1821
  apply(rule_tac x = "max N3 (Suc (rsize (RSTAR r0)))" in exI)
Chengsong
parents: 434
diff changeset
  1822
  using less_max_iff_disj by blast
Chengsong
parents: 434
diff changeset
  1823
Chengsong
parents: 434
diff changeset
  1824
Chengsong
parents: 434
diff changeset
  1825
Chengsong
parents: 434
diff changeset
  1826
433
Chengsong
parents:
diff changeset
  1827
lemma finite_star:
Chengsong
parents:
diff changeset
  1828
  shows "(\<forall>s. rsize (rders_simp r0 s) < N0 )
Chengsong
parents:
diff changeset
  1829
           \<Longrightarrow> \<exists>N3. \<forall>s.(rsize (rders_simp (RSTAR r0) s)) < N3"
435
Chengsong
parents: 434
diff changeset
  1830
  apply(subgoal_tac  " \<exists>N3. \<forall>Ss. 
Chengsong
parents: 434
diff changeset
  1831
rsize(rsimp (RALTS ( (map (\<lambda>s1. rsimp_SEQ (rders_simp r0 s1) (RSTAR r0)) Ss)))) < N3 \<and>
Chengsong
parents: 434
diff changeset
  1832
rsize (RSTAR r0) < N3")
Chengsong
parents: 434
diff changeset
  1833
  prefer 2
Chengsong
parents: 434
diff changeset
  1834
  using starder_size_bound apply blast
Chengsong
parents: 434
diff changeset
  1835
  apply(erule exE)
Chengsong
parents: 434
diff changeset
  1836
  apply(rule_tac x = N3 in exI)
Chengsong
parents: 434
diff changeset
  1837
  by (metis starder_is_a_list)
433
Chengsong
parents:
diff changeset
  1838
Chengsong
parents:
diff changeset
  1839
Chengsong
parents:
diff changeset
  1840
lemma rderssimp_zero:
Chengsong
parents:
diff changeset
  1841
  shows"rders_simp RZERO s = RZERO"
Chengsong
parents:
diff changeset
  1842
  apply(induction s)
Chengsong
parents:
diff changeset
  1843
  apply simp
Chengsong
parents:
diff changeset
  1844
  by simp
Chengsong
parents:
diff changeset
  1845
Chengsong
parents:
diff changeset
  1846
lemma rderssimp_one:
Chengsong
parents:
diff changeset
  1847
  shows"rders_simp RONE (a # s) = RZERO"
Chengsong
parents:
diff changeset
  1848
  apply(induction s)
Chengsong
parents:
diff changeset
  1849
  apply simp
Chengsong
parents:
diff changeset
  1850
  by simp
Chengsong
parents:
diff changeset
  1851
Chengsong
parents:
diff changeset
  1852
lemma rderssimp_char:
Chengsong
parents:
diff changeset
  1853
  shows "rders_simp (RCHAR c) s = RONE \<or> rders_simp (RCHAR c) s = RZERO \<or> rders_simp (RCHAR c) s = (RCHAR c)"
Chengsong
parents:
diff changeset
  1854
  apply auto
Chengsong
parents:
diff changeset
  1855
  by (metis rder.simps(2) rder.simps(3) rders_simp.elims rders_simp.simps(2) rderssimp_one rsimp.simps(4))
Chengsong
parents:
diff changeset
  1856
Chengsong
parents:
diff changeset
  1857
lemma finite_size_ders:
Chengsong
parents:
diff changeset
  1858
  fixes r
Chengsong
parents:
diff changeset
  1859
  shows " \<exists>Nr. \<forall>s. rsize (rders_simp r s) < Nr"
Chengsong
parents:
diff changeset
  1860
  apply(induct r rule: rrexp.induct)
Chengsong
parents:
diff changeset
  1861
       apply auto
Chengsong
parents:
diff changeset
  1862
  apply(rule_tac x = "2" in exI)
Chengsong
parents:
diff changeset
  1863
  using rderssimp_zero rsize.simps(1) apply presburger
Chengsong
parents:
diff changeset
  1864
      apply(rule_tac x = "2" in exI)
Chengsong
parents:
diff changeset
  1865
      apply (metis Suc_1 lessI rders_simp.elims rderssimp_one rsize.simps(1) rsize.simps(2))
Chengsong
parents:
diff changeset
  1866
     apply(rule_tac x = "2" in meta_spec)
Chengsong
parents:
diff changeset
  1867
     apply (metis lessI rderssimp_char rsize.simps(1) rsize.simps(2) rsize.simps(3))
Chengsong
parents:
diff changeset
  1868
  
Chengsong
parents:
diff changeset
  1869
  using M1seq apply blast
Chengsong
parents:
diff changeset
  1870
   prefer 2
Chengsong
parents:
diff changeset
  1871
Chengsong
parents:
diff changeset
  1872
   apply (simp add: finite_star)
Chengsong
parents:
diff changeset
  1873
  sorry
Chengsong
parents:
diff changeset
  1874
434
Chengsong
parents: 433
diff changeset
  1875
lemma finite_list_of_ders:
Chengsong
parents: 433
diff changeset
  1876
  fixes r
Chengsong
parents: 433
diff changeset
  1877
  shows"\<exists>dersset. ( (finite dersset) \<and> (\<forall>s. (rders_simp r s) \<in> dersset) )"
Chengsong
parents: 433
diff changeset
  1878
  sorry
Chengsong
parents: 433
diff changeset
  1879
Chengsong
parents: 433
diff changeset
  1880
433
Chengsong
parents:
diff changeset
  1881
Chengsong
parents:
diff changeset
  1882
unused_thms
Chengsong
parents:
diff changeset
  1883
lemma seq_ders_shape:
Chengsong
parents:
diff changeset
  1884
  shows "E"
Chengsong
parents:
diff changeset
  1885
Chengsong
parents:
diff changeset
  1886
  oops
Chengsong
parents:
diff changeset
  1887
Chengsong
parents:
diff changeset
  1888
(*rsimp (rders (RSEQ r1 r2) s) =
Chengsong
parents:
diff changeset
  1889
         rsimp RALT [RSEQ (rders r1 s) r2, rders r2 si, ...]
Chengsong
parents:
diff changeset
  1890
         where si is the i-th shortest suffix of s such that si \<in> L r2"
Chengsong
parents:
diff changeset
  1891
*)
Chengsong
parents:
diff changeset
  1892
Chengsong
parents:
diff changeset
  1893
Chengsong
parents:
diff changeset
  1894
end