thys2/SizeBound6CT.thy
author Chengsong
Sun, 20 Feb 2022 22:39:56 +0000
changeset 433 210df4cd512b
child 434 0cce1aee0fb2
permissions -rw-r--r--
hi
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
Chengsong
parents:
diff changeset
    24
fun orderedPref :: "char list \<Rightarrow> char list list"
Chengsong
parents:
diff changeset
    25
  where
Chengsong
parents:
diff changeset
    26
"orderedPref s = orderedPrefAux (length s) s"
Chengsong
parents:
diff changeset
    27
Chengsong
parents:
diff changeset
    28
lemma shape_of_pref_1list:
Chengsong
parents:
diff changeset
    29
  shows "orderedPref [c] = [[]]"
Chengsong
parents:
diff changeset
    30
  apply auto
Chengsong
parents:
diff changeset
    31
  done
Chengsong
parents:
diff changeset
    32
Chengsong
parents:
diff changeset
    33
lemma shape_of_suf_1list:
Chengsong
parents:
diff changeset
    34
  shows "orderedSuf [c] = [[c]]"
Chengsong
parents:
diff changeset
    35
  by auto
Chengsong
parents:
diff changeset
    36
Chengsong
parents:
diff changeset
    37
lemma shape_of_suf_2list:
Chengsong
parents:
diff changeset
    38
  shows "orderedSuf [c2, c3] = [[c3], [c2,c3]]"
Chengsong
parents:
diff changeset
    39
  by auto
Chengsong
parents:
diff changeset
    40
Chengsong
parents:
diff changeset
    41
lemma shape_of_prf_2list:
Chengsong
parents:
diff changeset
    42
  shows "orderedPref [c1, c2] = [[c1], []]"
Chengsong
parents:
diff changeset
    43
  by auto
Chengsong
parents:
diff changeset
    44
Chengsong
parents:
diff changeset
    45
Chengsong
parents:
diff changeset
    46
lemma shape_of_suf_3list:
Chengsong
parents:
diff changeset
    47
  shows "orderedSuf [c1, c2, c3] = [[c3], [c2, c3], [c1, c2, c3]]"
Chengsong
parents:
diff changeset
    48
  by auto
Chengsong
parents:
diff changeset
    49
Chengsong
parents:
diff changeset
    50
lemma throwing_elem_around:
Chengsong
parents:
diff changeset
    51
  shows "orderedSuf (s1 @ [a] @ s) = (orderedSuf s) @ (map (\<lambda>s11. s11 @ s) (orderedSuf ( s1 @ [a]) ))"
Chengsong
parents:
diff changeset
    52
and "orderedSuf (s1 @ [a] @ s) = (orderedSuf ([a] @ s) @ (map (\<lambda>s11. s11 @ ([a] @ s))) (orderedSuf s1) )"
Chengsong
parents:
diff changeset
    53
  sorry
Chengsong
parents:
diff changeset
    54
Chengsong
parents:
diff changeset
    55
Chengsong
parents:
diff changeset
    56
lemma suf_cons:
Chengsong
parents:
diff changeset
    57
  shows "orderedSuf (s1 @ s) = (orderedSuf s) @ (map (\<lambda>s11. s11 @ s) (orderedSuf s1))"
Chengsong
parents:
diff changeset
    58
  apply(induct s arbitrary: s1)
Chengsong
parents:
diff changeset
    59
   apply simp
Chengsong
parents:
diff changeset
    60
  apply(subgoal_tac "s1 @ a # s = (s1 @ [a]) @ s")
Chengsong
parents:
diff changeset
    61
  prefer 2
Chengsong
parents:
diff changeset
    62
   apply simp
Chengsong
parents:
diff changeset
    63
  apply(subgoal_tac "orderedSuf (s1 @ a # s) = orderedSuf ((s1 @ [a]) @ s)")
Chengsong
parents:
diff changeset
    64
  prefer 2
Chengsong
parents:
diff changeset
    65
   apply presburger
Chengsong
parents:
diff changeset
    66
  apply(drule_tac x="s1 @ [a]" in meta_spec)
Chengsong
parents:
diff changeset
    67
  sorry
Chengsong
parents:
diff changeset
    68
Chengsong
parents:
diff changeset
    69
Chengsong
parents:
diff changeset
    70
Chengsong
parents:
diff changeset
    71
lemma shape_of_prf_3list:
Chengsong
parents:
diff changeset
    72
  shows "orderedPref [c1, c2, c3] = [[c1, c2], [c1], []]"
Chengsong
parents:
diff changeset
    73
  by auto
Chengsong
parents:
diff changeset
    74
Chengsong
parents:
diff changeset
    75
fun zip_concat :: "char list list \<Rightarrow> char list list \<Rightarrow> char list list"
Chengsong
parents:
diff changeset
    76
  where 
Chengsong
parents:
diff changeset
    77
    "zip_concat (s1#ss1) (s2#ss2) = (s1@s2) # (zip_concat ss1 ss2)"
Chengsong
parents:
diff changeset
    78
  |   "zip_concat [] [] = []"
Chengsong
parents:
diff changeset
    79
  | "zip_concat [] (s2#ss2) = s2 # (zip_concat [] ss2)"
Chengsong
parents:
diff changeset
    80
  | "zip_concat (s1#ss1) [] = s1 # (zip_concat ss1 [])"
Chengsong
parents:
diff changeset
    81
Chengsong
parents:
diff changeset
    82
Chengsong
parents:
diff changeset
    83
Chengsong
parents:
diff changeset
    84
lemma compliment_pref_suf:
Chengsong
parents:
diff changeset
    85
  shows "zip_concat (orderedPref s) (orderedSuf s) = replicate (length s) s "
Chengsong
parents:
diff changeset
    86
  apply(induct s)
Chengsong
parents:
diff changeset
    87
   apply auto[1]
Chengsong
parents:
diff changeset
    88
  sorry
Chengsong
parents:
diff changeset
    89
Chengsong
parents:
diff changeset
    90
Chengsong
parents:
diff changeset
    91
Chengsong
parents:
diff changeset
    92
Chengsong
parents:
diff changeset
    93
datatype rrexp = 
Chengsong
parents:
diff changeset
    94
  RZERO
Chengsong
parents:
diff changeset
    95
| RONE 
Chengsong
parents:
diff changeset
    96
| RCHAR char
Chengsong
parents:
diff changeset
    97
| RSEQ rrexp rrexp
Chengsong
parents:
diff changeset
    98
| RALTS "rrexp list"
Chengsong
parents:
diff changeset
    99
| RSTAR rrexp
Chengsong
parents:
diff changeset
   100
Chengsong
parents:
diff changeset
   101
abbreviation
Chengsong
parents:
diff changeset
   102
  "RALT r1 r2 \<equiv> RALTS [r1, r2]"
Chengsong
parents:
diff changeset
   103
Chengsong
parents:
diff changeset
   104
Chengsong
parents:
diff changeset
   105
Chengsong
parents:
diff changeset
   106
fun
Chengsong
parents:
diff changeset
   107
 rnullable :: "rrexp \<Rightarrow> bool"
Chengsong
parents:
diff changeset
   108
where
Chengsong
parents:
diff changeset
   109
  "rnullable (RZERO) = False"
Chengsong
parents:
diff changeset
   110
| "rnullable (RONE  ) = True"
Chengsong
parents:
diff changeset
   111
| "rnullable (RCHAR   c) = False"
Chengsong
parents:
diff changeset
   112
| "rnullable (RALTS   rs) = (\<exists>r \<in> set rs. rnullable r)"
Chengsong
parents:
diff changeset
   113
| "rnullable (RSEQ  r1 r2) = (rnullable r1 \<and> rnullable r2)"
Chengsong
parents:
diff changeset
   114
| "rnullable (RSTAR   r) = True"
Chengsong
parents:
diff changeset
   115
Chengsong
parents:
diff changeset
   116
Chengsong
parents:
diff changeset
   117
fun
Chengsong
parents:
diff changeset
   118
 rder :: "char \<Rightarrow> rrexp \<Rightarrow> rrexp"
Chengsong
parents:
diff changeset
   119
where
Chengsong
parents:
diff changeset
   120
  "rder c (RZERO) = RZERO"
Chengsong
parents:
diff changeset
   121
| "rder c (RONE) = RZERO"
Chengsong
parents:
diff changeset
   122
| "rder c (RCHAR d) = (if c = d then RONE else RZERO)"
Chengsong
parents:
diff changeset
   123
| "rder c (RALTS rs) = RALTS (map (rder c) rs)"
Chengsong
parents:
diff changeset
   124
| "rder c (RSEQ r1 r2) = 
Chengsong
parents:
diff changeset
   125
     (if rnullable r1
Chengsong
parents:
diff changeset
   126
      then RALT   (RSEQ (rder c r1) r2) (rder c r2)
Chengsong
parents:
diff changeset
   127
      else RSEQ   (rder c r1) r2)"
Chengsong
parents:
diff changeset
   128
| "rder c (RSTAR r) = RSEQ  (rder c r) (RSTAR r)"
Chengsong
parents:
diff changeset
   129
Chengsong
parents:
diff changeset
   130
Chengsong
parents:
diff changeset
   131
fun 
Chengsong
parents:
diff changeset
   132
  rders :: "rrexp \<Rightarrow> string \<Rightarrow> rrexp"
Chengsong
parents:
diff changeset
   133
where
Chengsong
parents:
diff changeset
   134
  "rders r [] = r"
Chengsong
parents:
diff changeset
   135
| "rders r (c#s) = rders (rder c r) s"
Chengsong
parents:
diff changeset
   136
Chengsong
parents:
diff changeset
   137
fun rdistinct :: "'a list \<Rightarrow>'a set \<Rightarrow> 'a list"
Chengsong
parents:
diff changeset
   138
  where
Chengsong
parents:
diff changeset
   139
  "rdistinct [] acc = []"
Chengsong
parents:
diff changeset
   140
| "rdistinct (x#xs)  acc = 
Chengsong
parents:
diff changeset
   141
     (if x \<in> acc then rdistinct xs  acc 
Chengsong
parents:
diff changeset
   142
      else x # (rdistinct xs  ({x} \<union> acc)))"
Chengsong
parents:
diff changeset
   143
Chengsong
parents:
diff changeset
   144
lemma rdistinct_idem:
Chengsong
parents:
diff changeset
   145
  shows "rdistinct (x # (rdistinct rs {x})) {} = x # (rdistinct rs {x})"
Chengsong
parents:
diff changeset
   146
  
Chengsong
parents:
diff changeset
   147
  sorry
Chengsong
parents:
diff changeset
   148
Chengsong
parents:
diff changeset
   149
Chengsong
parents:
diff changeset
   150
Chengsong
parents:
diff changeset
   151
Chengsong
parents:
diff changeset
   152
Chengsong
parents:
diff changeset
   153
fun rflts :: "rrexp list \<Rightarrow> rrexp list"
Chengsong
parents:
diff changeset
   154
  where 
Chengsong
parents:
diff changeset
   155
  "rflts [] = []"
Chengsong
parents:
diff changeset
   156
| "rflts (RZERO # rs) = rflts rs"
Chengsong
parents:
diff changeset
   157
| "rflts ((RALTS rs1) # rs) = rs1 @ rflts rs"
Chengsong
parents:
diff changeset
   158
| "rflts (r1 # rs) = r1 # rflts rs"
Chengsong
parents:
diff changeset
   159
Chengsong
parents:
diff changeset
   160
Chengsong
parents:
diff changeset
   161
fun rsimp_ALTs :: " rrexp list \<Rightarrow> rrexp"
Chengsong
parents:
diff changeset
   162
  where
Chengsong
parents:
diff changeset
   163
  "rsimp_ALTs  [] = RZERO"
Chengsong
parents:
diff changeset
   164
| "rsimp_ALTs [r] =  r"
Chengsong
parents:
diff changeset
   165
| "rsimp_ALTs rs = RALTS rs"
Chengsong
parents:
diff changeset
   166
Chengsong
parents:
diff changeset
   167
fun rsimp_SEQ :: " rrexp \<Rightarrow> rrexp \<Rightarrow> rrexp"
Chengsong
parents:
diff changeset
   168
  where
Chengsong
parents:
diff changeset
   169
  "rsimp_SEQ  RZERO _ = RZERO"
Chengsong
parents:
diff changeset
   170
| "rsimp_SEQ  _ RZERO = RZERO"
Chengsong
parents:
diff changeset
   171
| "rsimp_SEQ RONE r2 = r2"
Chengsong
parents:
diff changeset
   172
| "rsimp_SEQ r1 r2 = RSEQ r1 r2"
Chengsong
parents:
diff changeset
   173
Chengsong
parents:
diff changeset
   174
Chengsong
parents:
diff changeset
   175
fun rsimp :: "rrexp \<Rightarrow> rrexp" 
Chengsong
parents:
diff changeset
   176
  where
Chengsong
parents:
diff changeset
   177
  "rsimp (RSEQ r1 r2) = rsimp_SEQ  (rsimp r1) (rsimp r2)"
Chengsong
parents:
diff changeset
   178
| "rsimp (RALTS rs) = rsimp_ALTs  (rdistinct (rflts (map rsimp rs))  {}) "
Chengsong
parents:
diff changeset
   179
| "rsimp r = r"
Chengsong
parents:
diff changeset
   180
Chengsong
parents:
diff changeset
   181
Chengsong
parents:
diff changeset
   182
fun 
Chengsong
parents:
diff changeset
   183
  rders_simp :: "rrexp \<Rightarrow> string \<Rightarrow> rrexp"
Chengsong
parents:
diff changeset
   184
where
Chengsong
parents:
diff changeset
   185
  "rders_simp r [] = r"
Chengsong
parents:
diff changeset
   186
| "rders_simp r (c#s) = rders_simp (rsimp (rder c r)) s"
Chengsong
parents:
diff changeset
   187
Chengsong
parents:
diff changeset
   188
fun rsize :: "rrexp \<Rightarrow> nat" where
Chengsong
parents:
diff changeset
   189
  "rsize RZERO = 1"
Chengsong
parents:
diff changeset
   190
| "rsize (RONE) = 1" 
Chengsong
parents:
diff changeset
   191
| "rsize (RCHAR  c) = 1"
Chengsong
parents:
diff changeset
   192
| "rsize (RALTS  rs) = Suc (sum_list (map rsize rs))"
Chengsong
parents:
diff changeset
   193
| "rsize (RSEQ  r1 r2) = Suc (rsize r1 + rsize r2)"
Chengsong
parents:
diff changeset
   194
| "rsize (RSTAR  r) = Suc (rsize r)"
Chengsong
parents:
diff changeset
   195
Chengsong
parents:
diff changeset
   196
Chengsong
parents:
diff changeset
   197
fun rlist_size :: "rrexp list \<Rightarrow> nat" where
Chengsong
parents:
diff changeset
   198
"rlist_size (r # rs) = rsize r + rlist_size rs" 
Chengsong
parents:
diff changeset
   199
| "rlist_size [] = 0"
Chengsong
parents:
diff changeset
   200
Chengsong
parents:
diff changeset
   201
thm neq_Nil_conv
Chengsong
parents:
diff changeset
   202
Chengsong
parents:
diff changeset
   203
Chengsong
parents:
diff changeset
   204
lemma rsimp_aalts_smaller:
Chengsong
parents:
diff changeset
   205
  shows "rsize (rsimp_ALTs  rs) \<le> rsize (RALTS rs)"
Chengsong
parents:
diff changeset
   206
  apply(induct rs)
Chengsong
parents:
diff changeset
   207
   apply simp
Chengsong
parents:
diff changeset
   208
  apply simp
Chengsong
parents:
diff changeset
   209
  apply(case_tac "rs = []")
Chengsong
parents:
diff changeset
   210
   apply simp
Chengsong
parents:
diff changeset
   211
  apply(subgoal_tac "\<exists>rsp ap. rs = ap # rsp")
Chengsong
parents:
diff changeset
   212
   apply(erule exE)+
Chengsong
parents:
diff changeset
   213
   apply simp
Chengsong
parents:
diff changeset
   214
  apply simp
Chengsong
parents:
diff changeset
   215
  by(meson neq_Nil_conv)
Chengsong
parents:
diff changeset
   216
  
Chengsong
parents:
diff changeset
   217
Chengsong
parents:
diff changeset
   218
lemma finite_list_of_ders:
Chengsong
parents:
diff changeset
   219
  shows"\<exists>dersset. ( (finite dersset) \<and> (\<forall>s. (rders_simp r s) \<in> dersset) )"
Chengsong
parents:
diff changeset
   220
  sorry
Chengsong
parents:
diff changeset
   221
Chengsong
parents:
diff changeset
   222
Chengsong
parents:
diff changeset
   223
Chengsong
parents:
diff changeset
   224
Chengsong
parents:
diff changeset
   225
Chengsong
parents:
diff changeset
   226
Chengsong
parents:
diff changeset
   227
(*
Chengsong
parents:
diff changeset
   228
lemma rders_shape:
Chengsong
parents:
diff changeset
   229
  shows "s \<noteq> [] \<Longrightarrow> rders_simp (RSEQ r1 r2) s = 
Chengsong
parents:
diff changeset
   230
         rsimp (RALTS  ((RSEQ (rders r1 s) r2) #
Chengsong
parents:
diff changeset
   231
           (map (rders r2) (orderedSuf s))) )"
Chengsong
parents:
diff changeset
   232
  apply(induct s arbitrary: r1 r2 rule: rev_induct)
Chengsong
parents:
diff changeset
   233
   apply simp
Chengsong
parents:
diff changeset
   234
  apply simp
Chengsong
parents:
diff changeset
   235
Chengsong
parents:
diff changeset
   236
  sorry
Chengsong
parents:
diff changeset
   237
*)
Chengsong
parents:
diff changeset
   238
Chengsong
parents:
diff changeset
   239
Chengsong
parents:
diff changeset
   240
Chengsong
parents:
diff changeset
   241
fun rders_cond_list :: "rrexp \<Rightarrow> bool list \<Rightarrow> char list list \<Rightarrow> rrexp list"
Chengsong
parents:
diff changeset
   242
  where
Chengsong
parents:
diff changeset
   243
"rders_cond_list r2 (True # bs) (s # strs) = (rders_simp r2 s) # (rders_cond_list r2 bs strs)"
Chengsong
parents:
diff changeset
   244
| "rders_cond_list r2 (False # bs) (s # strs) = rders_cond_list r2 bs strs"
Chengsong
parents:
diff changeset
   245
| "rders_cond_list r2 [] s = []"
Chengsong
parents:
diff changeset
   246
| "rders_cond_list r2 bs [] = []"
Chengsong
parents:
diff changeset
   247
Chengsong
parents:
diff changeset
   248
fun nullable_bools :: "rrexp \<Rightarrow> char list list \<Rightarrow> bool list"
Chengsong
parents:
diff changeset
   249
  where
Chengsong
parents:
diff changeset
   250
"nullable_bools r (s#strs) = (rnullable (rders r s)) # (nullable_bools r strs) "
Chengsong
parents:
diff changeset
   251
|"nullable_bools r [] = []"
Chengsong
parents:
diff changeset
   252
Chengsong
parents:
diff changeset
   253
fun cond_list :: "rrexp \<Rightarrow> rrexp \<Rightarrow> char list \<Rightarrow> rrexp list"
Chengsong
parents:
diff changeset
   254
  where
Chengsong
parents:
diff changeset
   255
"cond_list r1 r2 s = rders_cond_list r2 (nullable_bools r1 (orderedPref s) ) (orderedSuf s)"
Chengsong
parents:
diff changeset
   256
Chengsong
parents:
diff changeset
   257
thm rsimp_SEQ.simps
Chengsong
parents:
diff changeset
   258
lemma rSEQ_mono:
Chengsong
parents:
diff changeset
   259
  shows "rsize (rsimp_SEQ r1 r2) \<le>rsize ( RSEQ r1 r2)"
Chengsong
parents:
diff changeset
   260
  apply auto
Chengsong
parents:
diff changeset
   261
  apply(induct r1)
Chengsong
parents:
diff changeset
   262
       apply auto
Chengsong
parents:
diff changeset
   263
      apply(case_tac "r2")
Chengsong
parents:
diff changeset
   264
       apply simp_all
Chengsong
parents:
diff changeset
   265
     apply(case_tac r2)
Chengsong
parents:
diff changeset
   266
          apply simp_all
Chengsong
parents:
diff changeset
   267
     apply(case_tac r2)
Chengsong
parents:
diff changeset
   268
         apply simp_all
Chengsong
parents:
diff changeset
   269
     apply(case_tac r2)
Chengsong
parents:
diff changeset
   270
        apply simp_all
Chengsong
parents:
diff changeset
   271
     apply(case_tac r2)
Chengsong
parents:
diff changeset
   272
  apply simp_all
Chengsong
parents:
diff changeset
   273
  done
Chengsong
parents:
diff changeset
   274
Chengsong
parents:
diff changeset
   275
lemma rsimp_mono:
Chengsong
parents:
diff changeset
   276
  shows "rsize (rsimp r) \<le> rsize r"
Chengsong
parents:
diff changeset
   277
  apply(induct r)
Chengsong
parents:
diff changeset
   278
       apply simp_all
Chengsong
parents:
diff changeset
   279
  apply(subgoal_tac "rsize (rsimp_SEQ (rsimp r1) (rsimp r2)) \<le> rsize (RSEQ (rsimp r1) (rsimp r2))")
Chengsong
parents:
diff changeset
   280
  
Chengsong
parents:
diff changeset
   281
    apply force
Chengsong
parents:
diff changeset
   282
  using rSEQ_mono
Chengsong
parents:
diff changeset
   283
  apply presburger
Chengsong
parents:
diff changeset
   284
  sorry
Chengsong
parents:
diff changeset
   285
Chengsong
parents:
diff changeset
   286
lemma idiot:
Chengsong
parents:
diff changeset
   287
  shows "rsimp_SEQ RONE r = r"
Chengsong
parents:
diff changeset
   288
  apply(case_tac r)
Chengsong
parents:
diff changeset
   289
       apply simp_all
Chengsong
parents:
diff changeset
   290
  done
Chengsong
parents:
diff changeset
   291
Chengsong
parents:
diff changeset
   292
lemma no_dup_after_simp:
Chengsong
parents:
diff changeset
   293
  shows "RALTS rs = rsimp r \<Longrightarrow> distinct rs"
Chengsong
parents:
diff changeset
   294
  sorry
Chengsong
parents:
diff changeset
   295
Chengsong
parents:
diff changeset
   296
lemma no_further_dB_after_simp:
Chengsong
parents:
diff changeset
   297
  shows "RALTS rs = rsimp r \<Longrightarrow> rdistinct rs {} = rs"
Chengsong
parents:
diff changeset
   298
  sorry
Chengsong
parents:
diff changeset
   299
Chengsong
parents:
diff changeset
   300
lemma longlist_withstands_rsimp_alts:
Chengsong
parents:
diff changeset
   301
  shows "length rs \<ge> 2 \<Longrightarrow> rsimp_ALTs rs = RALTS rs"
Chengsong
parents:
diff changeset
   302
  sorry
Chengsong
parents:
diff changeset
   303
Chengsong
parents:
diff changeset
   304
lemma no_alt_short_list_after_simp:
Chengsong
parents:
diff changeset
   305
  shows "RALTS rs = rsimp r \<Longrightarrow> rsimp_ALTs rs = RALTS rs"
Chengsong
parents:
diff changeset
   306
  sorry
Chengsong
parents:
diff changeset
   307
Chengsong
parents:
diff changeset
   308
lemma idiot2:
Chengsong
parents:
diff changeset
   309
  shows " \<lbrakk>r1 \<noteq> RZERO; r1 \<noteq> RONE;r2 \<noteq> RZERO\<rbrakk>
Chengsong
parents:
diff changeset
   310
    \<Longrightarrow> rsimp_SEQ r1 r2 = RSEQ r1 r2"
Chengsong
parents:
diff changeset
   311
  apply(case_tac r1)
Chengsong
parents:
diff changeset
   312
       apply(case_tac r2)
Chengsong
parents:
diff changeset
   313
  apply simp_all
Chengsong
parents:
diff changeset
   314
     apply(case_tac r2)
Chengsong
parents:
diff changeset
   315
  apply simp_all
Chengsong
parents:
diff changeset
   316
     apply(case_tac r2)
Chengsong
parents:
diff changeset
   317
  apply simp_all
Chengsong
parents:
diff changeset
   318
   apply(case_tac r2)
Chengsong
parents:
diff changeset
   319
  apply simp_all
Chengsong
parents:
diff changeset
   320
  apply(case_tac r2)
Chengsong
parents:
diff changeset
   321
       apply simp_all
Chengsong
parents:
diff changeset
   322
  done
Chengsong
parents:
diff changeset
   323
Chengsong
parents:
diff changeset
   324
lemma rsimp_aalts_another:
Chengsong
parents:
diff changeset
   325
  shows "\<forall>r \<in> (set  (map rsimp  ((RSEQ (rders r1 s) r2) #
Chengsong
parents:
diff changeset
   326
           (rders_cond_list r2 (nullable_bools r1 (orderedPref s))  (orderedSuf s))  )) ). (rsize r) < N "
Chengsong
parents:
diff changeset
   327
  sorry
Chengsong
parents:
diff changeset
   328
Chengsong
parents:
diff changeset
   329
Chengsong
parents:
diff changeset
   330
Chengsong
parents:
diff changeset
   331
lemma shape_derssimpseq_onechar:
Chengsong
parents:
diff changeset
   332
  shows "   (rders_simp r [c]) =  (rsimp (rders r [c]))"
Chengsong
parents:
diff changeset
   333
and "rders_simp (RSEQ r1 r2) [c] = 
Chengsong
parents:
diff changeset
   334
         rsimp (RALTS  ((RSEQ (rders r1 [c]) r2) #
Chengsong
parents:
diff changeset
   335
           (rders_cond_list r2 (nullable_bools r1 (orderedPref [c]))  (orderedSuf [c]))) )"
Chengsong
parents:
diff changeset
   336
   apply simp
Chengsong
parents:
diff changeset
   337
  apply(simp add: rders.simps)
Chengsong
parents:
diff changeset
   338
  apply(case_tac "rsimp (rder c r1) = RZERO")
Chengsong
parents:
diff changeset
   339
   apply auto
Chengsong
parents:
diff changeset
   340
  apply(case_tac "rsimp (rder c r1) = RONE")
Chengsong
parents:
diff changeset
   341
   apply auto
Chengsong
parents:
diff changeset
   342
   apply(subgoal_tac "rsimp_SEQ RONE (rsimp r2) = rsimp r2")
Chengsong
parents:
diff changeset
   343
  prefer 2
Chengsong
parents:
diff changeset
   344
  using idiot
Chengsong
parents:
diff changeset
   345
    apply simp
Chengsong
parents:
diff changeset
   346
   apply(subgoal_tac "rsimp_SEQ RONE (rsimp r2) = rsimp_ALTs (rdistinct (rflts [rsimp r2]) {})")
Chengsong
parents:
diff changeset
   347
    prefer 2
Chengsong
parents:
diff changeset
   348
    apply auto
Chengsong
parents:
diff changeset
   349
   apply(case_tac "rsimp r2")
Chengsong
parents:
diff changeset
   350
        apply auto
Chengsong
parents:
diff changeset
   351
   apply(subgoal_tac "rdistinct x5 {} = x5")
Chengsong
parents:
diff changeset
   352
  prefer 2
Chengsong
parents:
diff changeset
   353
  using no_further_dB_after_simp
Chengsong
parents:
diff changeset
   354
    apply metis
Chengsong
parents:
diff changeset
   355
   apply(subgoal_tac "rsimp_ALTs (rdistinct x5 {}) = rsimp_ALTs x5")
Chengsong
parents:
diff changeset
   356
    prefer 2
Chengsong
parents:
diff changeset
   357
    apply fastforce  
Chengsong
parents:
diff changeset
   358
   apply auto
Chengsong
parents:
diff changeset
   359
   apply (metis no_alt_short_list_after_simp)
Chengsong
parents:
diff changeset
   360
  apply (case_tac "rsimp r2 = RZERO")
Chengsong
parents:
diff changeset
   361
   apply(subgoal_tac "rsimp_SEQ (rsimp (rder c r1)) (rsimp r2) = RZERO")
Chengsong
parents:
diff changeset
   362
    prefer 2
Chengsong
parents:
diff changeset
   363
    apply(case_tac "rsimp ( rder c r1)")
Chengsong
parents:
diff changeset
   364
         apply auto
Chengsong
parents:
diff changeset
   365
  apply(subgoal_tac "rsimp_SEQ (rsimp (rder c r1)) (rsimp r2) = RSEQ (rsimp (rder c r1)) (rsimp r2)")
Chengsong
parents:
diff changeset
   366
   prefer 2
Chengsong
parents:
diff changeset
   367
   apply auto
Chengsong
parents:
diff changeset
   368
  sorry
Chengsong
parents:
diff changeset
   369
Chengsong
parents:
diff changeset
   370
Chengsong
parents:
diff changeset
   371
Chengsong
parents:
diff changeset
   372
lemma shape_derssimpseq_onechar2:
Chengsong
parents:
diff changeset
   373
  shows "rders_simp (RSEQ r1 r2) [c] = 
Chengsong
parents:
diff changeset
   374
         rsimp (RALTS  ((RSEQ (rders_simp r1 [c]) r2) #
Chengsong
parents:
diff changeset
   375
           (rders_cond_list r2 (nullable_bools r1 (orderedPref [c]))  (orderedSuf [c]))) )"
Chengsong
parents:
diff changeset
   376
  sorry
Chengsong
parents:
diff changeset
   377
Chengsong
parents:
diff changeset
   378
Chengsong
parents:
diff changeset
   379
lemma rders__onechar:
Chengsong
parents:
diff changeset
   380
  shows " (rders_simp r [c]) =  (rsimp (rders r [c]))"
Chengsong
parents:
diff changeset
   381
  by simp
Chengsong
parents:
diff changeset
   382
Chengsong
parents:
diff changeset
   383
lemma rders_append:
Chengsong
parents:
diff changeset
   384
  "rders c (s1 @ s2) = rders (rders c s1) s2"
Chengsong
parents:
diff changeset
   385
  apply(induct s1 arbitrary: c s2)
Chengsong
parents:
diff changeset
   386
  apply(simp_all)
Chengsong
parents:
diff changeset
   387
  done
Chengsong
parents:
diff changeset
   388
Chengsong
parents:
diff changeset
   389
lemma rders_simp_append:
Chengsong
parents:
diff changeset
   390
  "rders_simp c (s1 @ s2) = rders_simp (rders_simp c s1) s2"
Chengsong
parents:
diff changeset
   391
  apply(induct s1 arbitrary: c s2)
Chengsong
parents:
diff changeset
   392
  apply(simp_all)
Chengsong
parents:
diff changeset
   393
  done
Chengsong
parents:
diff changeset
   394
Chengsong
parents:
diff changeset
   395
lemma inside_simp_removal:
Chengsong
parents:
diff changeset
   396
  shows " rsimp (rder x (rsimp r)) = rsimp (rder x r)"
Chengsong
parents:
diff changeset
   397
  
Chengsong
parents:
diff changeset
   398
  sorry
Chengsong
parents:
diff changeset
   399
Chengsong
parents:
diff changeset
   400
lemma set_related_list:
Chengsong
parents:
diff changeset
   401
  shows "distinct rs  \<Longrightarrow> length rs = card (set rs)"
Chengsong
parents:
diff changeset
   402
  by (simp add: distinct_card)
Chengsong
parents:
diff changeset
   403
(*this section deals with the property of distinctBy: creates a list without duplicates*)
Chengsong
parents:
diff changeset
   404
lemma rdistinct_never_added_twice:
Chengsong
parents:
diff changeset
   405
  shows "rdistinct (a # rs) {a} = rdistinct rs {a}"
Chengsong
parents:
diff changeset
   406
  by force
Chengsong
parents:
diff changeset
   407
Chengsong
parents:
diff changeset
   408
Chengsong
parents:
diff changeset
   409
lemma rdistinct_does_the_job:
Chengsong
parents:
diff changeset
   410
  shows "distinct (rdistinct rs s)"
Chengsong
parents:
diff changeset
   411
  apply(induct rs arbitrary: s)
Chengsong
parents:
diff changeset
   412
   apply simp
Chengsong
parents:
diff changeset
   413
  apply simp
Chengsong
parents:
diff changeset
   414
  sorry
Chengsong
parents:
diff changeset
   415
Chengsong
parents:
diff changeset
   416
Chengsong
parents:
diff changeset
   417
lemma simp_helps_der_pierce:
Chengsong
parents:
diff changeset
   418
  shows " rsimp
Chengsong
parents:
diff changeset
   419
            (rder x
Chengsong
parents:
diff changeset
   420
              (rsimp_ALTs rs)) = 
Chengsong
parents:
diff changeset
   421
          rsimp 
Chengsong
parents:
diff changeset
   422
            (rsimp_ALTs 
Chengsong
parents:
diff changeset
   423
              (map (rder x )
Chengsong
parents:
diff changeset
   424
                rs
Chengsong
parents:
diff changeset
   425
              )
Chengsong
parents:
diff changeset
   426
            )"
Chengsong
parents:
diff changeset
   427
  sorry
Chengsong
parents:
diff changeset
   428
Chengsong
parents:
diff changeset
   429
lemma simp_helps_der_pierce_dB:
Chengsong
parents:
diff changeset
   430
  shows " rsimp
Chengsong
parents:
diff changeset
   431
            (rsimp_ALTs
Chengsong
parents:
diff changeset
   432
              (map (rder x)
Chengsong
parents:
diff changeset
   433
                (rdistinct rs {}))) = 
Chengsong
parents:
diff changeset
   434
          rsimp (rsimp_ALTs (rdistinct (map (rder x) rs) {}))"
Chengsong
parents:
diff changeset
   435
Chengsong
parents:
diff changeset
   436
  sorry
Chengsong
parents:
diff changeset
   437
Chengsong
parents:
diff changeset
   438
lemma simp_helps_der_pierce_flts:
Chengsong
parents:
diff changeset
   439
  shows " rsimp
Chengsong
parents:
diff changeset
   440
            (rsimp_ALTs
Chengsong
parents:
diff changeset
   441
             (rdistinct 
Chengsong
parents:
diff changeset
   442
                (map (rder x)
Chengsong
parents:
diff changeset
   443
                  (rflts rs )
Chengsong
parents:
diff changeset
   444
                ) {}
Chengsong
parents:
diff changeset
   445
             )
Chengsong
parents:
diff changeset
   446
            ) = 
Chengsong
parents:
diff changeset
   447
          rsimp (rsimp_ALTs (rdistinct (rflts (map (rder x) rs)) {})  )"
Chengsong
parents:
diff changeset
   448
Chengsong
parents:
diff changeset
   449
  sorry
Chengsong
parents:
diff changeset
   450
Chengsong
parents:
diff changeset
   451
Chengsong
parents:
diff changeset
   452
lemma unfold_ders_simp_inside_only: 
Chengsong
parents:
diff changeset
   453
  shows "    (rders_simp (RSEQ r1 r2) xs =
Chengsong
parents:
diff changeset
   454
           rsimp (RALTS (RSEQ (rders_simp r1 xs) r2 # rders_cond_list r2 (nullable_bools r1 (orderedPref xs)) (orderedSuf xs))))
Chengsong
parents:
diff changeset
   455
       \<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
   456
 by presburger
Chengsong
parents:
diff changeset
   457
Chengsong
parents:
diff changeset
   458
Chengsong
parents:
diff changeset
   459
Chengsong
parents:
diff changeset
   460
lemma unfold_ders_simp_inside_only_nosimp: 
Chengsong
parents:
diff changeset
   461
  shows "    (rders_simp (RSEQ r1 r2) xs =
Chengsong
parents:
diff changeset
   462
           rsimp (RALTS (RSEQ (rders_simp r1 xs) r2 # rders_cond_list r2 (nullable_bools r1 (orderedPref xs)) (orderedSuf xs))))
Chengsong
parents:
diff changeset
   463
       \<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
   464
  using inside_simp_removal by presburger
Chengsong
parents:
diff changeset
   465
Chengsong
parents:
diff changeset
   466
Chengsong
parents:
diff changeset
   467
Chengsong
parents:
diff changeset
   468
Chengsong
parents:
diff changeset
   469
lemma rders_simp_one_char:
Chengsong
parents:
diff changeset
   470
  shows "rders_simp r [c] = rsimp (rder c r)"
Chengsong
parents:
diff changeset
   471
  apply auto
Chengsong
parents:
diff changeset
   472
  done
Chengsong
parents:
diff changeset
   473
Chengsong
parents:
diff changeset
   474
lemma rsimp_idem:
Chengsong
parents:
diff changeset
   475
  shows "rsimp (rsimp r) = rsimp r"
Chengsong
parents:
diff changeset
   476
  sorry
Chengsong
parents:
diff changeset
   477
Chengsong
parents:
diff changeset
   478
lemma head_one_more_simp:
Chengsong
parents:
diff changeset
   479
  shows "map rsimp (r # rs) = map rsimp (( rsimp r) # rs)"
Chengsong
parents:
diff changeset
   480
  by (simp add: rsimp_idem)
Chengsong
parents:
diff changeset
   481
Chengsong
parents:
diff changeset
   482
lemma head_one_more_dersimp:
Chengsong
parents:
diff changeset
   483
  shows "map rsimp ((rder x (rders_simp r s) # rs)) = map rsimp ((rders_simp r (s@[x]) ) # rs)"
Chengsong
parents:
diff changeset
   484
  using head_one_more_simp rders_simp_append rders_simp_one_char by presburger
Chengsong
parents:
diff changeset
   485
Chengsong
parents:
diff changeset
   486
thm cond_list.simps
Chengsong
parents:
diff changeset
   487
Chengsong
parents:
diff changeset
   488
lemma suffix_plus1char:
Chengsong
parents:
diff changeset
   489
  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
   490
   apply simp
Chengsong
parents:
diff changeset
   491
  sorry
Chengsong
parents:
diff changeset
   492
Chengsong
parents:
diff changeset
   493
lemma suffix_plus1charn:
Chengsong
parents:
diff changeset
   494
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
   495
  sorry
Chengsong
parents:
diff changeset
   496
Chengsong
parents:
diff changeset
   497
lemma ders_simp_nullability:
Chengsong
parents:
diff changeset
   498
  shows "rnullable (rders r s) = rnullable (rders_simp r s)"
Chengsong
parents:
diff changeset
   499
  sorry
Chengsong
parents:
diff changeset
   500
Chengsong
parents:
diff changeset
   501
lemma  first_elem_seqder:
Chengsong
parents:
diff changeset
   502
  shows "\<not>rnullable r1p \<Longrightarrow> map rsimp (rder x (RSEQ r1p r2)
Chengsong
parents:
diff changeset
   503
                   # rs) = map rsimp ((RSEQ (rder x r1p) r2) # rs) "
Chengsong
parents:
diff changeset
   504
  by auto
Chengsong
parents:
diff changeset
   505
Chengsong
parents:
diff changeset
   506
lemma first_elem_seqder1:
Chengsong
parents:
diff changeset
   507
  shows  "\<not>rnullable (rders_simp r xs) \<Longrightarrow> map rsimp ( (rder x (RSEQ (rders_simp r xs) r2)) # rs) = 
Chengsong
parents:
diff changeset
   508
                                          map rsimp ( (RSEQ (rsimp (rder x (rders_simp r xs))) r2) # rs)"
Chengsong
parents:
diff changeset
   509
  by (simp add: rsimp_idem)
Chengsong
parents:
diff changeset
   510
Chengsong
parents:
diff changeset
   511
lemma first_elem_seqdersimps:
Chengsong
parents:
diff changeset
   512
  shows "\<not>rnullable (rders_simp r xs) \<Longrightarrow> map rsimp ( (rder x (RSEQ (rders_simp r xs) r2)) # rs) = 
Chengsong
parents:
diff changeset
   513
                                          map rsimp ( (RSEQ (rders_simp r (xs @ [x])) r2) # rs)"
Chengsong
parents:
diff changeset
   514
  using first_elem_seqder1 rders_simp_append by auto
Chengsong
parents:
diff changeset
   515
Chengsong
parents:
diff changeset
   516
lemma first_elem_seqder_nullable:
Chengsong
parents:
diff changeset
   517
  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
   518
  sorry
Chengsong
parents:
diff changeset
   519
Chengsong
parents:
diff changeset
   520
Chengsong
parents:
diff changeset
   521
(*nullable_seq_with_list1 related *)
Chengsong
parents:
diff changeset
   522
lemma LHS0_def_der_alt:
Chengsong
parents:
diff changeset
   523
  shows "rsimp (rder x (RALTS ( (RSEQ (rders_simp r1 xs) r2) # (cond_list r1 r2 xs)))) = 
Chengsong
parents:
diff changeset
   524
         rsimp (RALTS ((rder x (RSEQ (rders_simp r1 xs) r2)) # (map (rder x) (cond_list r1 r2 xs))))"
Chengsong
parents:
diff changeset
   525
  by fastforce
Chengsong
parents:
diff changeset
   526
Chengsong
parents:
diff changeset
   527
lemma LHS1_def_der_seq:
Chengsong
parents:
diff changeset
   528
  shows "rnullable (rders_simp r1 xs) \<Longrightarrow> 
Chengsong
parents:
diff changeset
   529
rsimp (rder x (RALTS ( (RSEQ (rders_simp r1 xs) r2) # (cond_list r1 r2 xs)))) = 
Chengsong
parents:
diff changeset
   530
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
   531
  by (simp add: rders_simp_append rsimp_idem)
Chengsong
parents:
diff changeset
   532
Chengsong
parents:
diff changeset
   533
Chengsong
parents:
diff changeset
   534
Chengsong
parents:
diff changeset
   535
Chengsong
parents:
diff changeset
   536
Chengsong
parents:
diff changeset
   537
lemma cond_list_head_last:
Chengsong
parents:
diff changeset
   538
  shows "rnullable (rders r1 s) \<Longrightarrow> 
Chengsong
parents:
diff changeset
   539
        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
   540
  using suffix_plus1charn by blast
Chengsong
parents:
diff changeset
   541
Chengsong
parents:
diff changeset
   542
Chengsong
parents:
diff changeset
   543
lemma simp_flatten:
Chengsong
parents:
diff changeset
   544
  shows "rsimp (RALTS ((RALTS rsa) # rsb)) = rsimp (RALTS (rsa @ rsb))"
Chengsong
parents:
diff changeset
   545
Chengsong
parents:
diff changeset
   546
  sorry
Chengsong
parents:
diff changeset
   547
Chengsong
parents:
diff changeset
   548
lemma RHS1:
Chengsong
parents:
diff changeset
   549
  shows "rnullable (rders_simp r1 xs) \<Longrightarrow>
Chengsong
parents:
diff changeset
   550
                                    rsimp (RALTS ((RSEQ (rders_simp r1 (xs @ [x])) r2) # 
Chengsong
parents:
diff changeset
   551
(cond_list r1 r2 (xs @[x])))) = 
Chengsong
parents:
diff changeset
   552
                                    rsimp (RALTS ((RSEQ (rders_simp r1 (xs @ [x])) r2) # 
Chengsong
parents:
diff changeset
   553
( ((rder x r2) # (map (rder x) (cond_list r1 r2 xs)))))) "
Chengsong
parents:
diff changeset
   554
  using first_elem_seqder_nullable by presburger
Chengsong
parents:
diff changeset
   555
Chengsong
parents:
diff changeset
   556
Chengsong
parents:
diff changeset
   557
lemma nullable_seq_with_list1:
Chengsong
parents:
diff changeset
   558
  shows " rnullable (rders_simp r1 s) \<Longrightarrow>
Chengsong
parents:
diff changeset
   559
    rsimp (rder c (RALTS ( (RSEQ (rders_simp r1 s) r2) #  (cond_list r1 r2 s)) )) =
Chengsong
parents:
diff changeset
   560
    rsimp (RALTS ( (RSEQ (rders_simp r1 (s @ [c])) r2) # (cond_list r1 r2 (s @ [c])) ) )"
Chengsong
parents:
diff changeset
   561
  by (metis LHS1_def_der_seq append.left_neutral append_Cons first_elem_seqder_nullable simp_flatten)
Chengsong
parents:
diff changeset
   562
Chengsong
parents:
diff changeset
   563
Chengsong
parents:
diff changeset
   564
Chengsong
parents:
diff changeset
   565
Chengsong
parents:
diff changeset
   566
lemma nullable_seq_with_list:
Chengsong
parents:
diff changeset
   567
  shows "rnullable (rders_simp r1 xs) \<Longrightarrow> rsimp (rder x (RALTS ((RSEQ (rders_simp r1 xs) r2) # 
Chengsong
parents:
diff changeset
   568
      (rders_cond_list r2 (nullable_bools r1 (orderedPref xs)) (orderedSuf xs)) ))) = 
Chengsong
parents:
diff changeset
   569
                                          rsimp (RALTS ((RSEQ (rders_simp r1 (xs@[x])) r2) #
Chengsong
parents:
diff changeset
   570
      (rders_cond_list r2 (nullable_bools r1 (orderedPref (xs@[x]))) (orderedSuf (xs@[x]))) ) )
Chengsong
parents:
diff changeset
   571
    "
Chengsong
parents:
diff changeset
   572
  apply(subgoal_tac "rsimp (rder x (RALTS ((RSEQ (rders_simp r1 xs) r2) # (cond_list r1 r2 xs)))) = 
Chengsong
parents:
diff changeset
   573
                     rsimp (RALTS ((RSEQ (rders_simp r1 (xs@[x])) r2) # (cond_list r1 r2 (xs@[x]))))")
Chengsong
parents:
diff changeset
   574
   apply auto[1]
Chengsong
parents:
diff changeset
   575
  using nullable_seq_with_list1 by auto
Chengsong
parents:
diff changeset
   576
Chengsong
parents:
diff changeset
   577
Chengsong
parents:
diff changeset
   578
Chengsong
parents:
diff changeset
   579
Chengsong
parents:
diff changeset
   580
lemma r1r2ders_whole:
Chengsong
parents:
diff changeset
   581
"rsimp
Chengsong
parents:
diff changeset
   582
         (RALTS
Chengsong
parents:
diff changeset
   583
           (rder x (RSEQ (rders_simp r1 xs) r2) #
Chengsong
parents:
diff changeset
   584
            map (rder x) (rders_cond_list r2 (nullable_bools r1 (orderedPref xs)) (orderedSuf xs)))) = 
Chengsong
parents:
diff changeset
   585
      rsimp(    RALTS(   ( (RSEQ (rders_simp r1 (xs@[x])) r2)
Chengsong
parents:
diff changeset
   586
                   #  (rders_cond_list r2 (nullable_bools r1 (orderedPref (xs @ [x]))) (orderedSuf (xs @ [x])))))) "
Chengsong
parents:
diff changeset
   587
  using ders_simp_nullability first_elem_seqdersimps nullable_seq_with_list1 suffix_plus1char by auto
Chengsong
parents:
diff changeset
   588
Chengsong
parents:
diff changeset
   589
lemma rders_simp_same_simpders:
Chengsong
parents:
diff changeset
   590
  shows "s \<noteq> [] \<Longrightarrow> rders_simp r s = rsimp (rders r s)"
Chengsong
parents:
diff changeset
   591
  apply(induct s rule: rev_induct)
Chengsong
parents:
diff changeset
   592
   apply simp
Chengsong
parents:
diff changeset
   593
  apply(case_tac "xs = []")
Chengsong
parents:
diff changeset
   594
   apply simp
Chengsong
parents:
diff changeset
   595
  apply(simp add: rders_append rders_simp_append)
Chengsong
parents:
diff changeset
   596
  using inside_simp_removal by blast
Chengsong
parents:
diff changeset
   597
Chengsong
parents:
diff changeset
   598
lemma shape_derssimp_seq:
Chengsong
parents:
diff changeset
   599
  shows "\<lbrakk>s \<noteq> []\<rbrakk> \<Longrightarrow> rders_simp (RSEQ r1 r2) s = 
Chengsong
parents:
diff changeset
   600
         rsimp (RALTS  ((RSEQ (rders_simp r1 s) r2) #
Chengsong
parents:
diff changeset
   601
           (rders_cond_list r2 (nullable_bools r1 (orderedPref s))  (orderedSuf s))) )"
Chengsong
parents:
diff changeset
   602
Chengsong
parents:
diff changeset
   603
  apply(induct s arbitrary: r1 r2 rule: rev_induct)
Chengsong
parents:
diff changeset
   604
   apply simp
Chengsong
parents:
diff changeset
   605
  apply(case_tac "xs = []")
Chengsong
parents:
diff changeset
   606
  using shape_derssimpseq_onechar2 apply force
Chengsong
parents:
diff changeset
   607
  apply(simp only: rders_simp_append)
Chengsong
parents:
diff changeset
   608
  apply(simp only: rders_simp_one_char)
Chengsong
parents:
diff changeset
   609
Chengsong
parents:
diff changeset
   610
  apply(subgoal_tac "rsimp (rder x (rders_simp (RSEQ r1 r2) xs))
Chengsong
parents:
diff changeset
   611
                   = 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
   612
   prefer 2
Chengsong
parents:
diff changeset
   613
  using unfold_ders_simp_inside_only_nosimp apply presburger
Chengsong
parents:
diff changeset
   614
  apply(subgoal_tac "rsimp (rder x (RALTS (RSEQ (rders_simp r1 xs) r2
Chengsong
parents:
diff changeset
   615
                   # rders_cond_list r2 (nullable_bools r1 (orderedPref xs)) (orderedSuf xs)))) = 
Chengsong
parents:
diff changeset
   616
                     rsimp ( (RALTS (rder x (RSEQ (rders_simp r1 xs) r2)
Chengsong
parents:
diff changeset
   617
                   # (map (rder x) (rders_cond_list r2 (nullable_bools r1 (orderedPref xs)) (orderedSuf xs))))))
Chengsong
parents:
diff changeset
   618
                      ")
Chengsong
parents:
diff changeset
   619
   prefer 2
Chengsong
parents:
diff changeset
   620
   apply simp
Chengsong
parents:
diff changeset
   621
  using r1r2ders_whole rders_simp_append rders_simp_one_char by presburger
Chengsong
parents:
diff changeset
   622
Chengsong
parents:
diff changeset
   623
(*
Chengsong
parents:
diff changeset
   624
Chengsong
parents:
diff changeset
   625
  apply(subgoal_tac " rsimp
Chengsong
parents:
diff changeset
   626
            (rder x
Chengsong
parents:
diff changeset
   627
              (rsimp_ALTs
Chengsong
parents:
diff changeset
   628
                (rdistinct
Chengsong
parents:
diff changeset
   629
                  (rflts
Chengsong
parents:
diff changeset
   630
                    (rsimp_SEQ (rsimp (rders_simp r1 xs)) (rsimp r2) #
Chengsong
parents:
diff changeset
   631
                     map rsimp
Chengsong
parents:
diff changeset
   632
                      (rders_cond_list r2 (nullable_bools r1 (orderedPrefAux (length xs) xs)) (orderedSufAux (length xs) xs))))
Chengsong
parents:
diff changeset
   633
                  {}))) =  
Chengsong
parents:
diff changeset
   634
                      rsimp
Chengsong
parents:
diff changeset
   635
            (
Chengsong
parents:
diff changeset
   636
              (rsimp_ALTs
Chengsong
parents:
diff changeset
   637
               (map (rder x)
Chengsong
parents:
diff changeset
   638
                (rdistinct
Chengsong
parents:
diff changeset
   639
                  (rflts
Chengsong
parents:
diff changeset
   640
                    (rsimp_SEQ (rsimp (rders_simp r1 xs)) (rsimp r2) #
Chengsong
parents:
diff changeset
   641
                     map rsimp
Chengsong
parents:
diff changeset
   642
                      (rders_cond_list r2 (nullable_bools r1 (orderedPrefAux (length xs) xs)) (orderedSufAux (length xs) xs))))
Chengsong
parents:
diff changeset
   643
                  {})
Chengsong
parents:
diff changeset
   644
               )
Chengsong
parents:
diff changeset
   645
              )
Chengsong
parents:
diff changeset
   646
            ) ")
Chengsong
parents:
diff changeset
   647
   prefer 2
Chengsong
parents:
diff changeset
   648
*)
Chengsong
parents:
diff changeset
   649
Chengsong
parents:
diff changeset
   650
lemma shape_derssimp_alts:
Chengsong
parents:
diff changeset
   651
  shows "s \<noteq> [] \<Longrightarrow> rders_simp (RALTS rs) s = rsimp (RALTS (map (\<lambda>r. rders r s) rs))"
Chengsong
parents:
diff changeset
   652
  apply(case_tac "s")
Chengsong
parents:
diff changeset
   653
   apply simp
Chengsong
parents:
diff changeset
   654
  apply simp
Chengsong
parents:
diff changeset
   655
  sorry
Chengsong
parents:
diff changeset
   656
(*
Chengsong
parents:
diff changeset
   657
fun rexp_encode :: "rrexp \<Rightarrow> nat"
Chengsong
parents:
diff changeset
   658
  where
Chengsong
parents:
diff changeset
   659
"rexp_encode RZERO = 0"
Chengsong
parents:
diff changeset
   660
|"rexp_encode RONE = 1"
Chengsong
parents:
diff changeset
   661
|"rexp_encode (RCHAR c) = 2"
Chengsong
parents:
diff changeset
   662
|"rexp_encode (RSEQ r1 r2) = ( 2 ^ (rexp_encode r1)) "
Chengsong
parents:
diff changeset
   663
*)
Chengsong
parents:
diff changeset
   664
lemma finite_chars:
Chengsong
parents:
diff changeset
   665
  shows " \<exists>N. ( (\<forall>r \<in> (set rs). \<exists>c. r = RCHAR c) \<and> (distinct rs) \<longrightarrow> length rs < N)"
Chengsong
parents:
diff changeset
   666
  apply(rule_tac x = "Suc 256" in exI)
Chengsong
parents:
diff changeset
   667
  sorry
Chengsong
parents:
diff changeset
   668
Chengsong
parents:
diff changeset
   669
definition all_chars :: "int \<Rightarrow> char list"
Chengsong
parents:
diff changeset
   670
  where "all_chars n = map char_of [0..n]"
Chengsong
parents:
diff changeset
   671
(*
Chengsong
parents:
diff changeset
   672
fun rexp_enum :: "nat \<Rightarrow> rrexp list"
Chengsong
parents:
diff changeset
   673
  where 
Chengsong
parents:
diff changeset
   674
"rexp_enum 0 = []"
Chengsong
parents:
diff changeset
   675
|"rexp_enum (Suc 0) =  RALTS [] # RZERO # (RONE # (map RCHAR (all_chars 255)))"
Chengsong
parents:
diff changeset
   676
|"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
   677
Chengsong
parents:
diff changeset
   678
*)
Chengsong
parents:
diff changeset
   679
Chengsong
parents:
diff changeset
   680
fun rexp_enum :: "nat \<Rightarrow> rrexp set"
Chengsong
parents:
diff changeset
   681
  where 
Chengsong
parents:
diff changeset
   682
"rexp_enum 0 = {}"
Chengsong
parents:
diff changeset
   683
|"rexp_enum (Suc 0) =  {RALTS []} \<union> {RZERO} \<union> {RONE} \<union> { (RCHAR c) |c. c \<in> set (all_chars 255)}"
Chengsong
parents:
diff changeset
   684
|"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}"
Chengsong
parents:
diff changeset
   685
Chengsong
parents:
diff changeset
   686
Chengsong
parents:
diff changeset
   687
lemma finite_sized_rexp_forms_finite_set:
Chengsong
parents:
diff changeset
   688
  shows " \<exists>SN. ( \<forall>r.( rsize r < N \<longrightarrow> r \<in> SN)) \<and> (finite SN)"
Chengsong
parents:
diff changeset
   689
  apply(induct N)
Chengsong
parents:
diff changeset
   690
   apply simp
Chengsong
parents:
diff changeset
   691
   apply auto
Chengsong
parents:
diff changeset
   692
 (*\<lbrakk>\<forall>r. rsize r < N \<longrightarrow> r \<in> SN; finite SN\<rbrakk> \<Longrightarrow> \<exists>SN. (\<forall>r. rsize r < Suc N \<longrightarrow> r \<in> SN) \<and> finite SN*)
Chengsong
parents:
diff changeset
   693
 (* \<And>N. \<exists>SN. (\<forall>r. rsize r < N \<longrightarrow> r \<in> SN) \<and> finite SN \<Longrightarrow> \<exists>SN. (\<forall>r. rsize r < Suc N \<longrightarrow> r \<in> SN) \<and> finite SN*)
Chengsong
parents:
diff changeset
   694
  sorry
Chengsong
parents:
diff changeset
   695
Chengsong
parents:
diff changeset
   696
Chengsong
parents:
diff changeset
   697
lemma finite_size_finite_regx:
Chengsong
parents:
diff changeset
   698
  shows " \<exists>l. \<forall>rs. ((\<forall>r \<in> (set rs). rsize r < N) \<and> (distinct rs) \<longrightarrow> (length rs) < l) "
Chengsong
parents:
diff changeset
   699
  sorry
Chengsong
parents:
diff changeset
   700
Chengsong
parents:
diff changeset
   701
(*below  probably needs proved concurrently*)
Chengsong
parents:
diff changeset
   702
Chengsong
parents:
diff changeset
   703
lemma finite_r1r2_ders_list:
Chengsong
parents:
diff changeset
   704
  shows "(\<forall>s. rsize (rders_simp r1 s) < N1 \<and> rsize (rders_simp r2 s) < N2)
Chengsong
parents:
diff changeset
   705
           \<Longrightarrow>  \<exists>l. \<forall>s.
Chengsong
parents:
diff changeset
   706
(length (rdistinct  (map rsimp (rders_cond_list r2 (nullable_bools r1 (orderedPref s))  (orderedSuf s))) {}) )  < l "
Chengsong
parents:
diff changeset
   707
  sorry
Chengsong
parents:
diff changeset
   708
Chengsong
parents:
diff changeset
   709
(*
Chengsong
parents:
diff changeset
   710
\<lbrakk>s \<noteq> []\<rbrakk> \<Longrightarrow> rders_simp (RSEQ r1 r2) s = 
Chengsong
parents:
diff changeset
   711
         rsimp (RALTS  ((RSEQ (rders r1 s) r2) #
Chengsong
parents:
diff changeset
   712
           (rders_cond_list r2 (nullable_bools r1 (orderedPref s))  (orderedSuf s))) )
Chengsong
parents:
diff changeset
   713
*)
Chengsong
parents:
diff changeset
   714
 
Chengsong
parents:
diff changeset
   715
Chengsong
parents:
diff changeset
   716
lemma sum_list_size2:
Chengsong
parents:
diff changeset
   717
  shows "\<forall>z \<in>set rs. (rsize z ) \<le> Nr \<Longrightarrow> rlist_size rs \<le> (length rs) * Nr"
Chengsong
parents:
diff changeset
   718
  apply(induct rs)
Chengsong
parents:
diff changeset
   719
   apply simp
Chengsong
parents:
diff changeset
   720
  by simp
Chengsong
parents:
diff changeset
   721
Chengsong
parents:
diff changeset
   722
lemma sum_list_size:
Chengsong
parents:
diff changeset
   723
  fixes rs
Chengsong
parents:
diff changeset
   724
  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
   725
  by (metis dual_order.trans mult.commute mult_le_mono2 mult_zero_right sum_list_size2 zero_le)
Chengsong
parents:
diff changeset
   726
Chengsong
parents:
diff changeset
   727
lemma seq_second_term_chain1:
Chengsong
parents:
diff changeset
   728
  shows " \<forall>s. rlist_size (rders_cond_list r2 (nullable_bools r1 (orderedPref s)) (orderedSuf s)) \<le> 
Chengsong
parents:
diff changeset
   729
 rlist_size (rders_cond_list r2 (nullable_bools r1 (orderedPref s)) (orderedSuf s))"
Chengsong
parents:
diff changeset
   730
Chengsong
parents:
diff changeset
   731
  sorry
Chengsong
parents:
diff changeset
   732
Chengsong
parents:
diff changeset
   733
Chengsong
parents:
diff changeset
   734
lemma seq_second_term_chain2:
Chengsong
parents:
diff changeset
   735
  shows "\<forall>s.  rlist_size (rders_cond_list r2 (nullable_bools r1 (orderedPref s)) (orderedSuf s)) = 
Chengsong
parents:
diff changeset
   736
 rlist_size (map rsimp (rders_cond_list r2 (nullable_bools r1 (orderedPref s)) (orderedSuf s)))"
Chengsong
parents:
diff changeset
   737
Chengsong
parents:
diff changeset
   738
  oops
Chengsong
parents:
diff changeset
   739
Chengsong
parents:
diff changeset
   740
lemma seq_second_term_bounded:
Chengsong
parents:
diff changeset
   741
  fixes r2 r1
Chengsong
parents:
diff changeset
   742
  assumes "\<forall>s. rsize (rders_simp r2 s) < N2"
Chengsong
parents:
diff changeset
   743
  shows "\<exists>N3. \<forall>s. rlist_size (rders_cond_list r2 (nullable_bools r1 (orderedPref s)) (orderedSuf s)) < N3"
Chengsong
parents:
diff changeset
   744
Chengsong
parents:
diff changeset
   745
  sorry
Chengsong
parents:
diff changeset
   746
Chengsong
parents:
diff changeset
   747
Chengsong
parents:
diff changeset
   748
lemma seq_first_term_bounded:
Chengsong
parents:
diff changeset
   749
  fixes r1 r2
Chengsong
parents:
diff changeset
   750
  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
   751
  apply(erule exE)
Chengsong
parents:
diff changeset
   752
  apply(rule_tac x = "Nr + (rsize r2) + 1" in exI)
Chengsong
parents:
diff changeset
   753
  by simp
Chengsong
parents:
diff changeset
   754
Chengsong
parents:
diff changeset
   755
Chengsong
parents:
diff changeset
   756
lemma alts_triangle_inequality:
Chengsong
parents:
diff changeset
   757
  shows "rsize (RALTS (r # rs)) \<le> rsize r + rlist_size rs + 1 "
Chengsong
parents:
diff changeset
   758
  apply(subgoal_tac "rsize (RALTS (r # rs) ) =  rsize r + rlist_size rs + 1")
Chengsong
parents:
diff changeset
   759
   apply auto[1]
Chengsong
parents:
diff changeset
   760
  apply(induct rs)
Chengsong
parents:
diff changeset
   761
   apply simp
Chengsong
parents:
diff changeset
   762
  apply auto
Chengsong
parents:
diff changeset
   763
  done
Chengsong
parents:
diff changeset
   764
Chengsong
parents:
diff changeset
   765
lemma seq_equal_term_nosimp_entire_bounded:
Chengsong
parents:
diff changeset
   766
  shows "(\<forall>s. rsize (rders_simp r1 s) < N1 \<and> rsize (rders_simp r2 s) < N2) 
Chengsong
parents:
diff changeset
   767
      \<Longrightarrow> \<exists>N3. \<forall>s.  rsize  (RALTS  ((RSEQ (rders_simp r1 s) r2) #
Chengsong
parents:
diff changeset
   768
          (rdistinct ((rders_cond_list r2 (nullable_bools r1 (orderedPref s))  (orderedSuf s)) ) {}) ) ) \<le> N3"
Chengsong
parents:
diff changeset
   769
  apply(subgoal_tac "\<exists>N3. \<forall>s. rsize  (RALTS  ((RSEQ (rders_simp r1 s) r2) #
Chengsong
parents:
diff changeset
   770
           (rders_cond_list r2 (nullable_bools r1 (orderedPref s))  (orderedSuf s))) ) \<le>
Chengsong
parents:
diff changeset
   771
                                        rsize (RSEQ (rders_simp r1 s) r2) + 
Chengsong
parents:
diff changeset
   772
            rlist_size (map rsimp (rders_cond_list r2 (nullable_bools r1 (orderedPref s)) (orderedSuf s))) + 1")
Chengsong
parents:
diff changeset
   773
  prefer 2
Chengsong
parents:
diff changeset
   774
  using alts_triangle_inequality apply presburger
Chengsong
parents:
diff changeset
   775
  using seq_first_term_bounded
Chengsong
parents:
diff changeset
   776
  using seq_second_term_bounded
Chengsong
parents:
diff changeset
   777
  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
   778
  prefer 2
Chengsong
parents:
diff changeset
   779
   apply meson
Chengsong
parents:
diff changeset
   780
  apply(subgoal_tac "\<exists>Nr'. \<forall>s. rsize (RSEQ  (rders_simp r1 s) r2) \<le> Nr'")
Chengsong
parents:
diff changeset
   781
   prefer 2
Chengsong
parents:
diff changeset
   782
  apply (meson order_le_less)
Chengsong
parents:
diff changeset
   783
  apply(erule exE)
Chengsong
parents:
diff changeset
   784
  apply(erule exE)
Chengsong
parents:
diff changeset
   785
  apply(erule exE)
Chengsong
parents:
diff changeset
   786
  apply(rule_tac x = "N3a + Nr'" in exI)
Chengsong
parents:
diff changeset
   787
  sorry
Chengsong
parents:
diff changeset
   788
Chengsong
parents:
diff changeset
   789
lemma alts_simp_bounded_by_sloppy1_version:
Chengsong
parents:
diff changeset
   790
  shows "\<forall>s. rsize (rsimp (RALTS  ((RSEQ (rders_simp r1 s) r2) #
Chengsong
parents:
diff changeset
   791
           (rders_cond_list r2 (nullable_bools r1 (orderedPref s))  (orderedSuf s))) )) \<le> 
Chengsong
parents:
diff changeset
   792
rsize  (RALTS (rdistinct ((RSEQ (rders_simp r1 s) r2) #
Chengsong
parents:
diff changeset
   793
                          (rders_cond_list r2 (nullable_bools r1 (orderedPref s))  (orderedSuf s))
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
  sorry
Chengsong
parents:
diff changeset
   799
Chengsong
parents:
diff changeset
   800
lemma alts_simp_bounded_by_sloppy1:
Chengsong
parents:
diff changeset
   801
  shows "rsize  (rsimp (RALTS (rdistinct ((RSEQ (rders_simp r1 s) r2) #
Chengsong
parents:
diff changeset
   802
                          (rders_cond_list r2 (nullable_bools r1 (orderedPref s))  (orderedSuf s))
Chengsong
parents:
diff changeset
   803
                         ) 
Chengsong
parents:
diff changeset
   804
                         {}
Chengsong
parents:
diff changeset
   805
              )
Chengsong
parents:
diff changeset
   806
        )) \<le>
Chengsong
parents:
diff changeset
   807
rsize  (RALTS  ((RSEQ (rders_simp r1 s) r2) #
Chengsong
parents:
diff changeset
   808
                          (rders_cond_list r2 (nullable_bools r1 (orderedPref s))  (orderedSuf s))
Chengsong
parents:
diff changeset
   809
                         ) 
Chengsong
parents:
diff changeset
   810
        )"
Chengsong
parents:
diff changeset
   811
  sorry
Chengsong
parents:
diff changeset
   812
Chengsong
parents:
diff changeset
   813
lemma hand_made_def_rlist_size:
Chengsong
parents:
diff changeset
   814
  shows "rlist_size rs = sum_list (map rsize rs)"
Chengsong
parents:
diff changeset
   815
proof (induct rs)
Chengsong
parents:
diff changeset
   816
  case Nil show ?case by simp
Chengsong
parents:
diff changeset
   817
next
Chengsong
parents:
diff changeset
   818
  case (Cons a rs) thus ?case
Chengsong
parents:
diff changeset
   819
    by simp
Chengsong
parents:
diff changeset
   820
qed
Chengsong
parents:
diff changeset
   821
Chengsong
parents:
diff changeset
   822
(*this section deals with the property of distinctBy: creates a list without duplicates*)
Chengsong
parents:
diff changeset
   823
lemma distinct_mono:
Chengsong
parents:
diff changeset
   824
  shows "rlist_size (rdistinct (a # s) {}) \<le> rlist_size (a # (rdistinct s {}) )"
Chengsong
parents:
diff changeset
   825
  sorry
Chengsong
parents:
diff changeset
   826
Chengsong
parents:
diff changeset
   827
lemma distinct_acc_mono:
Chengsong
parents:
diff changeset
   828
  shows "A \<subseteq> B \<Longrightarrow> rlist_size (rdistinct s A) \<ge> rlist_size (rdistinct s B)"
Chengsong
parents:
diff changeset
   829
  apply(induct s arbitrary: A B)
Chengsong
parents:
diff changeset
   830
   apply simp
Chengsong
parents:
diff changeset
   831
  apply(case_tac "a \<in> A")
Chengsong
parents:
diff changeset
   832
  apply(subgoal_tac "a \<in> B")
Chengsong
parents:
diff changeset
   833
  
Chengsong
parents:
diff changeset
   834
  apply simp
Chengsong
parents:
diff changeset
   835
  
Chengsong
parents:
diff changeset
   836
   apply blast
Chengsong
parents:
diff changeset
   837
  apply(subgoal_tac "rlist_size (rdistinct (a # s) A) = rlist_size (a # (rdistinct s (A \<union> {a})))")
Chengsong
parents:
diff changeset
   838
   apply(case_tac "a \<in> B")
Chengsong
parents:
diff changeset
   839
  apply(subgoal_tac "rlist_size (rdistinct (a # s) B) = rlist_size ( (rdistinct s B))") 
Chengsong
parents:
diff changeset
   840
  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
   841
  apply simp
Chengsong
parents:
diff changeset
   842
  apply auto
Chengsong
parents:
diff changeset
   843
  by (meson insert_mono)
Chengsong
parents:
diff changeset
   844
Chengsong
parents:
diff changeset
   845
Chengsong
parents:
diff changeset
   846
lemma distinct_mono2:
Chengsong
parents:
diff changeset
   847
  shows " rlist_size (rdistinct s {a}) \<le> rlist_size (rdistinct s {})"
Chengsong
parents:
diff changeset
   848
  apply(induct s)
Chengsong
parents:
diff changeset
   849
   apply simp
Chengsong
parents:
diff changeset
   850
  apply simp
Chengsong
parents:
diff changeset
   851
  using distinct_acc_mono by auto
Chengsong
parents:
diff changeset
   852
Chengsong
parents:
diff changeset
   853
Chengsong
parents:
diff changeset
   854
Chengsong
parents:
diff changeset
   855
lemma distinct_mono_spares_first_elem:
Chengsong
parents:
diff changeset
   856
  shows "rsize (RALTS (rdistinct (a # s) {})) \<le> rsize (RALTS (a # (rdistinct s {})))"
Chengsong
parents:
diff changeset
   857
  apply simp
Chengsong
parents:
diff changeset
   858
  apply (subgoal_tac "rlist_size ( (rdistinct s {a})) \<le> rlist_size ( (rdistinct s {})) ")
Chengsong
parents:
diff changeset
   859
  using hand_made_def_rlist_size apply auto[1]
Chengsong
parents:
diff changeset
   860
  using distinct_mono2 by auto
Chengsong
parents:
diff changeset
   861
Chengsong
parents:
diff changeset
   862
lemma sloppy1_bounded_by_sloppiest:
Chengsong
parents:
diff changeset
   863
  shows "rsize  (RALTS (rdistinct ((RSEQ (rders_simp r1 s) r2) #
Chengsong
parents:
diff changeset
   864
                          (rders_cond_list r2 (nullable_bools r1 (orderedPref s))  (orderedSuf s))
Chengsong
parents:
diff changeset
   865
                         ) 
Chengsong
parents:
diff changeset
   866
                         {}
Chengsong
parents:
diff changeset
   867
              )
Chengsong
parents:
diff changeset
   868
        ) \<le> rsize  (RALTS ((RSEQ (rders_simp r1 s) r2) #
Chengsong
parents:
diff changeset
   869
                          (rdistinct (rders_cond_list r2 (nullable_bools r1 (orderedPref s))  (orderedSuf s)) {})
Chengsong
parents:
diff changeset
   870
                         
Chengsong
parents:
diff changeset
   871
                         
Chengsong
parents:
diff changeset
   872
              )
Chengsong
parents:
diff changeset
   873
        )"
Chengsong
parents:
diff changeset
   874
  
Chengsong
parents:
diff changeset
   875
  sorry
Chengsong
parents:
diff changeset
   876
Chengsong
parents:
diff changeset
   877
Chengsong
parents:
diff changeset
   878
lemma alts_simp_bounded_by_sloppiest_version:
Chengsong
parents:
diff changeset
   879
  shows "\<forall>s. rsize (rsimp (RALTS  ((RSEQ (rders_simp r1 s) r2) #
Chengsong
parents:
diff changeset
   880
           (rders_cond_list r2 (nullable_bools r1 (orderedPref s))  (orderedSuf s))) )) \<le> 
Chengsong
parents:
diff changeset
   881
rsize  (RALTS  ((RSEQ (rders_simp r1 s) r2) #
Chengsong
parents:
diff changeset
   882
           (rdistinct (rders_cond_list r2 (nullable_bools r1 (orderedPref s))  (orderedSuf s)) {})  ) ) "
Chengsong
parents:
diff changeset
   883
  by (meson alts_simp_bounded_by_sloppy1_version order_trans sloppy1_bounded_by_sloppiest)
Chengsong
parents:
diff changeset
   884
Chengsong
parents:
diff changeset
   885
Chengsong
parents:
diff changeset
   886
lemma seq_equal_term_entire_bounded:
Chengsong
parents:
diff changeset
   887
  shows "(\<forall>s. rsize (rders_simp r1 s) < N1 \<and> rsize (rders_simp r2 s) < N2) 
Chengsong
parents:
diff changeset
   888
      \<Longrightarrow> \<exists>N3. \<forall>s.  rsize (rsimp (RALTS  ((RSEQ (rders_simp r1 s) r2) #
Chengsong
parents:
diff changeset
   889
           (rders_cond_list r2 (nullable_bools r1 (orderedPref s))  (orderedSuf s))) )) \<le> N3"
Chengsong
parents:
diff changeset
   890
  using seq_equal_term_nosimp_entire_bounded
Chengsong
parents:
diff changeset
   891
  apply(subgoal_tac " \<exists>N3. \<forall>s.  rsize  (RALTS  ((RSEQ (rders_simp r1 s) r2) #
Chengsong
parents:
diff changeset
   892
           (rdistinct  (rders_cond_list r2 (nullable_bools r1 (orderedPref s))  (orderedSuf s)) {}) ) ) \<le> N3")
Chengsong
parents:
diff changeset
   893
  apply(erule exE)
Chengsong
parents:
diff changeset
   894
   prefer 2
Chengsong
parents:
diff changeset
   895
  apply blast
Chengsong
parents:
diff changeset
   896
  apply(subgoal_tac "\<forall>s. rsize (rsimp (RALTS  ((RSEQ (rders_simp r1 s) r2) #
Chengsong
parents:
diff changeset
   897
           (rders_cond_list r2 (nullable_bools r1 (orderedPref s))  (orderedSuf s))) )) \<le> 
Chengsong
parents:
diff changeset
   898
rsize  (RALTS  ((RSEQ (rders_simp r1 s) r2) #
Chengsong
parents:
diff changeset
   899
           (rdistinct (rders_cond_list r2 (nullable_bools r1 (orderedPref s))  (orderedSuf s)) {})  ) ) ")
Chengsong
parents:
diff changeset
   900
   prefer 2
Chengsong
parents:
diff changeset
   901
  using alts_simp_bounded_by_sloppiest_version apply blast
Chengsong
parents:
diff changeset
   902
  apply(rule_tac x = "Suc N3 " in exI)
Chengsong
parents:
diff changeset
   903
  apply(rule allI)
Chengsong
parents:
diff changeset
   904
Chengsong
parents:
diff changeset
   905
  apply(subgoal_tac " rsize
Chengsong
parents:
diff changeset
   906
             (rsimp
Chengsong
parents:
diff changeset
   907
               (RALTS
Chengsong
parents:
diff changeset
   908
                 (RSEQ (rders_simp r1 s) r2 # rders_cond_list r2 (nullable_bools r1 (orderedPref s)) (orderedSuf s))))
Chengsong
parents:
diff changeset
   909
            \<le> rsize
Chengsong
parents:
diff changeset
   910
                (RALTS
Chengsong
parents:
diff changeset
   911
                  (RSEQ (rders_simp r1 s) r2 #
Chengsong
parents:
diff changeset
   912
                   rdistinct (rders_cond_list r2 (nullable_bools r1 (orderedPref s)) (orderedSuf s)) {}))")
Chengsong
parents:
diff changeset
   913
   prefer 2
Chengsong
parents:
diff changeset
   914
   apply presburger
Chengsong
parents:
diff changeset
   915
  apply(subgoal_tac "  rsize
Chengsong
parents:
diff changeset
   916
                (RALTS
Chengsong
parents:
diff changeset
   917
                  (RSEQ (rders_simp r1 s) r2 #
Chengsong
parents:
diff changeset
   918
                   rdistinct (rders_cond_list r2 (nullable_bools r1 (orderedPref s)) (orderedSuf s)) {})) \<le> N3")
Chengsong
parents:
diff changeset
   919
  
Chengsong
parents:
diff changeset
   920
   apply linarith
Chengsong
parents:
diff changeset
   921
  apply simp
Chengsong
parents:
diff changeset
   922
  done
Chengsong
parents:
diff changeset
   923
Chengsong
parents:
diff changeset
   924
Chengsong
parents:
diff changeset
   925
Chengsong
parents:
diff changeset
   926
lemma M1seq:
Chengsong
parents:
diff changeset
   927
  fixes r1 r2 
Chengsong
parents:
diff changeset
   928
  shows "(\<forall>s. rsize (rders_simp r1 s) < N1 \<and> rsize (rders_simp r2 s) < N2)
Chengsong
parents:
diff changeset
   929
           \<Longrightarrow> \<exists>N3.\<forall>s.(rsize (rders_simp (RSEQ r1 r2) s)) < N3"
Chengsong
parents:
diff changeset
   930
  apply(frule seq_equal_term_entire_bounded)
Chengsong
parents:
diff changeset
   931
  apply(erule exE)
Chengsong
parents:
diff changeset
   932
  apply(rule_tac x = "max (N3+2) (Suc (Suc (rsize r1) + (rsize r2)))" in exI)
Chengsong
parents:
diff changeset
   933
  apply(rule allI)
Chengsong
parents:
diff changeset
   934
  apply(case_tac "s = []")
Chengsong
parents:
diff changeset
   935
   prefer 2
Chengsong
parents:
diff changeset
   936
   apply (metis add_2_eq_Suc' le_imp_less_Suc less_SucI max.strict_coboundedI1 shape_derssimp_seq(2))
Chengsong
parents:
diff changeset
   937
  by (metis add.assoc less_Suc_eq max.strict_coboundedI2 plus_1_eq_Suc rders_simp.simps(1) rsize.simps(5))
Chengsong
parents:
diff changeset
   938
 (*  apply (simp add: less_SucI shape_derssimp_seq(2))
Chengsong
parents:
diff changeset
   939
   apply (meson less_SucI less_max_iff_disj)
Chengsong
parents:
diff changeset
   940
  apply simp
Chengsong
parents:
diff changeset
   941
  done*)
Chengsong
parents:
diff changeset
   942
Chengsong
parents:
diff changeset
   943
(*lemma empty_diff:
Chengsong
parents:
diff changeset
   944
  shows "s = [] \<Longrightarrow>
Chengsong
parents:
diff changeset
   945
        (rsize (rders_simp (RSEQ r1 r2) s)) \<le> 
Chengsong
parents:
diff changeset
   946
        (max 
Chengsong
parents:
diff changeset
   947
        (rsize (rsimp (RALTS (RSEQ (rders r1 s) r2 # rders_cond_list r2 (nullable_bools r1 (orderedPref s)) (orderedSuf s)))))
Chengsong
parents:
diff changeset
   948
        (Suc (rsize r1 + rsize r2)) ) "
Chengsong
parents:
diff changeset
   949
  apply simp
Chengsong
parents:
diff changeset
   950
  done*)
Chengsong
parents:
diff changeset
   951
(*For star related  bound*)
Chengsong
parents:
diff changeset
   952
Chengsong
parents:
diff changeset
   953
lemma star_is_a_singleton_list_derc:
Chengsong
parents:
diff changeset
   954
  shows " \<exists>Ss.  rders_simp (RSTAR r) [c] = rsimp_ALTs (map (\<lambda>s1.  rsimp_SEQ (rders_simp r s1) (RSTAR r)) Ss)"
Chengsong
parents:
diff changeset
   955
  apply simp
Chengsong
parents:
diff changeset
   956
  apply(rule_tac x = "[[c]]" in exI)
Chengsong
parents:
diff changeset
   957
  apply auto
Chengsong
parents:
diff changeset
   958
  done
Chengsong
parents:
diff changeset
   959
Chengsong
parents:
diff changeset
   960
lemma rder_rsimp_ALTs_commute:
Chengsong
parents:
diff changeset
   961
  shows "  (rder x (rsimp_ALTs rs)) = rsimp_ALTs (map (rder x) rs)"
Chengsong
parents:
diff changeset
   962
  apply(induct rs)
Chengsong
parents:
diff changeset
   963
   apply simp
Chengsong
parents:
diff changeset
   964
  apply(case_tac rs)
Chengsong
parents:
diff changeset
   965
   apply simp
Chengsong
parents:
diff changeset
   966
  apply auto
Chengsong
parents:
diff changeset
   967
  done
Chengsong
parents:
diff changeset
   968
Chengsong
parents:
diff changeset
   969
lemma double_nested_ALTs_under_rsimp:
Chengsong
parents:
diff changeset
   970
  shows "rsimp (rsimp_ALTs ((RALTS rs1) # rs)) = rsimp (RALTS (rs1 @ rs))"
Chengsong
parents:
diff changeset
   971
  apply(case_tac rs1)
Chengsong
parents:
diff changeset
   972
  apply simp
Chengsong
parents:
diff changeset
   973
  
Chengsong
parents:
diff changeset
   974
   apply (metis list.simps(8) list.simps(9) neq_Nil_conv rdistinct.simps(1) rflts.simps(1) rflts.simps(2) rsimp.simps(2) rsimp_ALTs.simps(1) rsimp_ALTs.simps(2) rsimp_ALTs.simps(3))
Chengsong
parents:
diff changeset
   975
  apply(case_tac rs)
Chengsong
parents:
diff changeset
   976
   apply simp
Chengsong
parents:
diff changeset
   977
  apply auto
Chengsong
parents:
diff changeset
   978
  sorry
Chengsong
parents:
diff changeset
   979
Chengsong
parents:
diff changeset
   980
fun star_update :: "char \<Rightarrow> rrexp \<Rightarrow> char list list => char list list" where
Chengsong
parents:
diff changeset
   981
"star_update c r [] = []"
Chengsong
parents:
diff changeset
   982
|"star_update c r (s # Ss) = (if (rnullable (rders_simp r s)) 
Chengsong
parents:
diff changeset
   983
                                then (s@[c]) # [c] # (star_update c r Ss) 
Chengsong
parents:
diff changeset
   984
                               else   s # (star_update c r Ss) )"
Chengsong
parents:
diff changeset
   985
Chengsong
parents:
diff changeset
   986
lemma starseq_list_evolution:
Chengsong
parents:
diff changeset
   987
  fixes  r :: rrexp and Ss :: "char list list" and x :: char 
Chengsong
parents:
diff changeset
   988
  shows "rsimp (rsimp_ALTs (map (\<lambda>s1. rder x (rsimp_SEQ (rders_simp r s1) (RSTAR r))) Ss) ) =
Chengsong
parents:
diff changeset
   989
         rsimp (rsimp_ALTs (map (\<lambda>s1. rsimp_SEQ (rders_simp r s1) (RSTAR r)) (star_update x r Ss))  )"   
Chengsong
parents:
diff changeset
   990
  apply(induct Ss)
Chengsong
parents:
diff changeset
   991
  apply simp
Chengsong
parents:
diff changeset
   992
  sorry
Chengsong
parents:
diff changeset
   993
Chengsong
parents:
diff changeset
   994
Chengsong
parents:
diff changeset
   995
lemma star_seqs_produce_star_seqs:
Chengsong
parents:
diff changeset
   996
  shows "rsimp (rsimp_ALTs (map (rder x \<circ> (\<lambda>s1. rsimp_SEQ (rders_simp r s1) (RSTAR r))) Ss))
Chengsong
parents:
diff changeset
   997
       = rsimp (rsimp_ALTs (map ( (\<lambda>s1. rder x (rsimp_SEQ (rders_simp r s1) (RSTAR r)))) Ss))"
Chengsong
parents:
diff changeset
   998
  by (meson comp_apply)
Chengsong
parents:
diff changeset
   999
Chengsong
parents:
diff changeset
  1000
lemma der_seqstar_res:
Chengsong
parents:
diff changeset
  1001
  shows "rder x (RSEQ r1 r2) = RSEQ r3 r4"
Chengsong
parents:
diff changeset
  1002
  oops
Chengsong
parents:
diff changeset
  1003
Chengsong
parents:
diff changeset
  1004
lemma linearity_of_list_of_star_or_starseqs: 
Chengsong
parents:
diff changeset
  1005
  fixes r::rrexp and Ss::"char list list" and x::char
Chengsong
parents:
diff changeset
  1006
  shows "\<exists>Ssa. rsimp (rder x (rsimp_ALTs (map (\<lambda>s1. rsimp_SEQ (rders_simp r s1) (RSTAR r)) Ss))) =
Chengsong
parents:
diff changeset
  1007
                 rsimp_ALTs (map (\<lambda>s1. rsimp_SEQ (rders_simp r s1) (RSTAR r)) Ssa)"
Chengsong
parents:
diff changeset
  1008
  apply(simp add: rder_rsimp_ALTs_commute)
Chengsong
parents:
diff changeset
  1009
  apply(induct Ss)
Chengsong
parents:
diff changeset
  1010
   apply simp
Chengsong
parents:
diff changeset
  1011
   apply (metis list.simps(8) rsimp_ALTs.simps(1))
Chengsong
parents:
diff changeset
  1012
Chengsong
parents:
diff changeset
  1013
Chengsong
parents:
diff changeset
  1014
  sorry
Chengsong
parents:
diff changeset
  1015
Chengsong
parents:
diff changeset
  1016
lemma starder_is_a_list_of_stars_or_starseqs:
Chengsong
parents:
diff changeset
  1017
  shows "s \<noteq> [] \<Longrightarrow> \<exists>Ss.  rders_simp (RSTAR r) s = rsimp_ALTs (map (\<lambda>s1.  rsimp_SEQ (rders_simp r s1) (RSTAR r)) Ss)"
Chengsong
parents:
diff changeset
  1018
  apply(induct s rule: rev_induct)
Chengsong
parents:
diff changeset
  1019
  apply simp
Chengsong
parents:
diff changeset
  1020
  apply(case_tac "xs = []")
Chengsong
parents:
diff changeset
  1021
  using star_is_a_singleton_list_derc
Chengsong
parents:
diff changeset
  1022
  apply(simp)
Chengsong
parents:
diff changeset
  1023
  apply auto
Chengsong
parents:
diff changeset
  1024
  apply(simp add: rders_simp_append)
Chengsong
parents:
diff changeset
  1025
  using linearity_of_list_of_star_or_starseqs by blast
Chengsong
parents:
diff changeset
  1026
Chengsong
parents:
diff changeset
  1027
Chengsong
parents:
diff changeset
  1028
lemma finite_star:
Chengsong
parents:
diff changeset
  1029
  shows "(\<forall>s. rsize (rders_simp r0 s) < N0 )
Chengsong
parents:
diff changeset
  1030
           \<Longrightarrow> \<exists>N3. \<forall>s.(rsize (rders_simp (RSTAR r0) s)) < N3"
Chengsong
parents:
diff changeset
  1031
Chengsong
parents:
diff changeset
  1032
  sorry
Chengsong
parents:
diff changeset
  1033
Chengsong
parents:
diff changeset
  1034
Chengsong
parents:
diff changeset
  1035
lemma rderssimp_zero:
Chengsong
parents:
diff changeset
  1036
  shows"rders_simp RZERO s = RZERO"
Chengsong
parents:
diff changeset
  1037
  apply(induction s)
Chengsong
parents:
diff changeset
  1038
  apply simp
Chengsong
parents:
diff changeset
  1039
  by simp
Chengsong
parents:
diff changeset
  1040
Chengsong
parents:
diff changeset
  1041
lemma rderssimp_one:
Chengsong
parents:
diff changeset
  1042
  shows"rders_simp RONE (a # s) = RZERO"
Chengsong
parents:
diff changeset
  1043
  apply(induction s)
Chengsong
parents:
diff changeset
  1044
  apply simp
Chengsong
parents:
diff changeset
  1045
  by simp
Chengsong
parents:
diff changeset
  1046
Chengsong
parents:
diff changeset
  1047
lemma rderssimp_char:
Chengsong
parents:
diff changeset
  1048
  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
  1049
  apply auto
Chengsong
parents:
diff changeset
  1050
  by (metis rder.simps(2) rder.simps(3) rders_simp.elims rders_simp.simps(2) rderssimp_one rsimp.simps(4))
Chengsong
parents:
diff changeset
  1051
Chengsong
parents:
diff changeset
  1052
lemma finite_size_ders:
Chengsong
parents:
diff changeset
  1053
  fixes r
Chengsong
parents:
diff changeset
  1054
  shows " \<exists>Nr. \<forall>s. rsize (rders_simp r s) < Nr"
Chengsong
parents:
diff changeset
  1055
  apply(induct r rule: rrexp.induct)
Chengsong
parents:
diff changeset
  1056
       apply auto
Chengsong
parents:
diff changeset
  1057
  apply(rule_tac x = "2" in exI)
Chengsong
parents:
diff changeset
  1058
  using rderssimp_zero rsize.simps(1) apply presburger
Chengsong
parents:
diff changeset
  1059
      apply(rule_tac x = "2" in exI)
Chengsong
parents:
diff changeset
  1060
      apply (metis Suc_1 lessI rders_simp.elims rderssimp_one rsize.simps(1) rsize.simps(2))
Chengsong
parents:
diff changeset
  1061
     apply(rule_tac x = "2" in meta_spec)
Chengsong
parents:
diff changeset
  1062
     apply (metis lessI rderssimp_char rsize.simps(1) rsize.simps(2) rsize.simps(3))
Chengsong
parents:
diff changeset
  1063
  
Chengsong
parents:
diff changeset
  1064
  using M1seq apply blast
Chengsong
parents:
diff changeset
  1065
   prefer 2
Chengsong
parents:
diff changeset
  1066
Chengsong
parents:
diff changeset
  1067
   apply (simp add: finite_star)
Chengsong
parents:
diff changeset
  1068
  sorry
Chengsong
parents:
diff changeset
  1069
Chengsong
parents:
diff changeset
  1070
Chengsong
parents:
diff changeset
  1071
unused_thms
Chengsong
parents:
diff changeset
  1072
lemma seq_ders_shape:
Chengsong
parents:
diff changeset
  1073
  shows "E"
Chengsong
parents:
diff changeset
  1074
Chengsong
parents:
diff changeset
  1075
  oops
Chengsong
parents:
diff changeset
  1076
Chengsong
parents:
diff changeset
  1077
(*rsimp (rders (RSEQ r1 r2) s) =
Chengsong
parents:
diff changeset
  1078
         rsimp RALT [RSEQ (rders r1 s) r2, rders r2 si, ...]
Chengsong
parents:
diff changeset
  1079
         where si is the i-th shortest suffix of s such that si \<in> L r2"
Chengsong
parents:
diff changeset
  1080
*)
Chengsong
parents:
diff changeset
  1081
Chengsong
parents:
diff changeset
  1082
Chengsong
parents:
diff changeset
  1083
end