thys2/BasicIdentities.thy
author Chengsong
Wed, 09 Mar 2022 17:33:08 +0000
changeset 444 a7e98deebb5c
child 465 2e7c7111c0be
permissions -rw-r--r--
restructured sizebound proof
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
444
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
     1
theory BasicIdentities imports 
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
     2
"Lexer"  "PDerivs"
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
     3
begin
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
     4
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
     5
datatype rrexp = 
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
     6
  RZERO
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
     7
| RONE 
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
     8
| RCHAR char
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
     9
| RSEQ rrexp rrexp
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
    10
| RALTS "rrexp list"
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
    11
| RSTAR rrexp
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
    12
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
    13
abbreviation
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
    14
  "RALT r1 r2 \<equiv> RALTS [r1, r2]"
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
    15
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
    16
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
    17
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
    18
fun
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
    19
 rnullable :: "rrexp \<Rightarrow> bool"
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
    20
where
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
    21
  "rnullable (RZERO) = False"
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
    22
| "rnullable (RONE  ) = True"
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
    23
| "rnullable (RCHAR   c) = False"
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
    24
| "rnullable (RALTS   rs) = (\<exists>r \<in> set rs. rnullable r)"
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
    25
| "rnullable (RSEQ  r1 r2) = (rnullable r1 \<and> rnullable r2)"
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
    26
| "rnullable (RSTAR   r) = True"
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
    27
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
    28
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
    29
fun
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
    30
 rder :: "char \<Rightarrow> rrexp \<Rightarrow> rrexp"
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
    31
where
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
    32
  "rder c (RZERO) = RZERO"
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
    33
| "rder c (RONE) = RZERO"
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
    34
| "rder c (RCHAR d) = (if c = d then RONE else RZERO)"
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
    35
| "rder c (RALTS rs) = RALTS (map (rder c) rs)"
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
    36
| "rder c (RSEQ r1 r2) = 
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
    37
     (if rnullable r1
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
    38
      then RALT   (RSEQ (rder c r1) r2) (rder c r2)
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
    39
      else RSEQ   (rder c r1) r2)"
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
    40
| "rder c (RSTAR r) = RSEQ  (rder c r) (RSTAR r)"
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
    41
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
    42
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
    43
fun 
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
    44
  rders :: "rrexp \<Rightarrow> string \<Rightarrow> rrexp"
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
    45
where
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
    46
  "rders r [] = r"
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
    47
| "rders r (c#s) = rders (rder c r) s"
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
    48
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
    49
fun rdistinct :: "'a list \<Rightarrow>'a set \<Rightarrow> 'a list"
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
    50
  where
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
    51
  "rdistinct [] acc = []"
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
    52
| "rdistinct (x#xs)  acc = 
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
    53
     (if x \<in> acc then rdistinct xs  acc 
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
    54
      else x # (rdistinct xs  ({x} \<union> acc)))"
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
    55
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
    56
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
    57
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
    58
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
    59
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
    60
fun rflts :: "rrexp list \<Rightarrow> rrexp list"
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
    61
  where 
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
    62
  "rflts [] = []"
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
    63
| "rflts (RZERO # rs) = rflts rs"
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
    64
| "rflts ((RALTS rs1) # rs) = rs1 @ rflts rs"
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
    65
| "rflts (r1 # rs) = r1 # rflts rs"
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
    66
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
    67
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
    68
fun rsimp_ALTs :: " rrexp list \<Rightarrow> rrexp"
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
    69
  where
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
    70
  "rsimp_ALTs  [] = RZERO"
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
    71
| "rsimp_ALTs [r] =  r"
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
    72
| "rsimp_ALTs rs = RALTS rs"
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
    73
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
    74
fun rsimp_SEQ :: " rrexp \<Rightarrow> rrexp \<Rightarrow> rrexp"
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
    75
  where
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
    76
  "rsimp_SEQ  RZERO _ = RZERO"
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
    77
| "rsimp_SEQ  _ RZERO = RZERO"
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
    78
| "rsimp_SEQ RONE r2 = r2"
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
    79
| "rsimp_SEQ r1 r2 = RSEQ r1 r2"
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
    80
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
    81
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
    82
fun rsimp :: "rrexp \<Rightarrow> rrexp" 
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
    83
  where
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
    84
  "rsimp (RSEQ r1 r2) = rsimp_SEQ  (rsimp r1) (rsimp r2)"
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
    85
| "rsimp (RALTS rs) = rsimp_ALTs  (rdistinct (rflts (map rsimp rs))  {}) "
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
    86
| "rsimp r = r"
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
    87
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
    88
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
    89
fun 
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
    90
  rders_simp :: "rrexp \<Rightarrow> string \<Rightarrow> rrexp"
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
    91
where
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
    92
  "rders_simp r [] = r"
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
    93
| "rders_simp r (c#s) = rders_simp (rsimp (rder c r)) s"
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
    94
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
    95
fun rsize :: "rrexp \<Rightarrow> nat" where
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
    96
  "rsize RZERO = 1"
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
    97
| "rsize (RONE) = 1" 
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
    98
| "rsize (RCHAR  c) = 1"
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
    99
| "rsize (RALTS  rs) = Suc (sum_list (map rsize rs))"
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   100
| "rsize (RSEQ  r1 r2) = Suc (rsize r1 + rsize r2)"
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   101
| "rsize (RSTAR  r) = Suc (rsize r)"
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   102
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   103
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   104
lemma rder_rsimp_ALTs_commute:
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   105
  shows "  (rder x (rsimp_ALTs rs)) = rsimp_ALTs (map (rder x) rs)"
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   106
  apply(induct rs)
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   107
   apply simp
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   108
  apply(case_tac rs)
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   109
   apply simp
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   110
  apply auto
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   111
  done
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   112
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   113
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   114
lemma rsimp_aalts_smaller:
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   115
  shows "rsize (rsimp_ALTs  rs) \<le> rsize (RALTS rs)"
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   116
  apply(induct rs)
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   117
   apply simp
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   118
  apply simp
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   119
  apply(case_tac "rs = []")
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   120
   apply simp
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   121
  apply(subgoal_tac "\<exists>rsp ap. rs = ap # rsp")
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   122
   apply(erule exE)+
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   123
   apply simp
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   124
  apply simp
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   125
  by(meson neq_Nil_conv)
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   126
  
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   127
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   128
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   129
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   130
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   131
lemma rSEQ_mono:
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   132
  shows "rsize (rsimp_SEQ r1 r2) \<le>rsize ( RSEQ r1 r2)"
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   133
  apply auto
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   134
  apply(induct r1)
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   135
       apply auto
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   136
      apply(case_tac "r2")
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   137
       apply simp_all
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   138
     apply(case_tac r2)
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   139
          apply simp_all
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   140
     apply(case_tac r2)
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   141
         apply simp_all
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   142
     apply(case_tac r2)
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   143
        apply simp_all
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   144
     apply(case_tac r2)
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   145
  apply simp_all
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   146
  done
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   147
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   148
lemma ralts_cap_mono:
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   149
  shows "rsize (RALTS rs) \<le> Suc ( sum_list (map rsize rs)) "
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   150
  by simp
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   151
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   152
lemma rflts_def_idiot:
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   153
  shows "\<lbrakk> a \<noteq> RZERO; \<nexists>rs1. a = RALTS rs1\<rbrakk>
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   154
       \<Longrightarrow> rflts (a # rs) = a # rflts rs"
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   155
  apply(case_tac a)
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   156
       apply simp_all
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   157
  done
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   158
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   159
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   160
lemma rflts_mono:
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   161
  shows "sum_list (map rsize (rflts rs))\<le> sum_list (map rsize rs)"
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   162
  apply(induct rs)
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   163
  apply simp
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   164
  apply(case_tac "a = RZERO")
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   165
   apply simp
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   166
  apply(case_tac "\<exists>rs1. a = RALTS rs1")
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   167
  apply(erule exE)
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   168
   apply simp
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   169
  apply(subgoal_tac "rflts (a # rs) = a # (rflts rs)")
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   170
  prefer 2
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   171
  using rflts_def_idiot apply blast
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   172
  apply simp
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   173
  done
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   174
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   175
lemma rdistinct_smaller: shows "sum_list (map rsize (rdistinct rs ss)) \<le>
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   176
sum_list (map rsize rs )"
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   177
  apply (induct rs arbitrary: ss)
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   178
   apply simp
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   179
  by (simp add: trans_le_add2)
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   180
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   181
lemma rdistinct_phi_smaller: "sum_list (map rsize (rdistinct rs {})) \<le> sum_list (map rsize rs)"
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   182
  by (simp add: rdistinct_smaller)
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   183
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   184
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   185
lemma rsimp_alts_mono :
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   186
  shows "\<And>x. (\<And>xa. xa \<in> set x \<Longrightarrow> rsize (rsimp xa) \<le> rsize xa)  \<Longrightarrow>
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   187
rsize (rsimp_ALTs (rdistinct (rflts (map rsimp x)) {})) \<le> Suc (sum_list (map rsize x))"
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   188
  apply(subgoal_tac "rsize (rsimp_ALTs (rdistinct (rflts (map rsimp x)) {} )) 
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   189
                    \<le> rsize (RALTS (rdistinct (rflts (map rsimp x)) {} ))")
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   190
  prefer 2
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   191
  using rsimp_aalts_smaller apply auto[1]
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   192
  apply(subgoal_tac "rsize (RALTS (rdistinct (rflts (map rsimp x)) {})) \<le>Suc( sum_list (map rsize (rdistinct (rflts (map rsimp x)) {})))")
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   193
  prefer 2
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   194
  using ralts_cap_mono apply blast
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   195
  apply(subgoal_tac "sum_list (map rsize (rdistinct (rflts (map rsimp x)) {})) \<le>
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   196
                     sum_list (map rsize ( (rflts (map rsimp x))))")
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   197
  prefer 2
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   198
  using rdistinct_smaller apply presburger
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   199
  apply(subgoal_tac "sum_list (map rsize (rflts (map rsimp x))) \<le> 
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   200
                     sum_list (map rsize (map rsimp x))")
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   201
  prefer 2
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   202
  using rflts_mono apply blast
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   203
  apply(subgoal_tac "sum_list (map rsize (map rsimp x)) \<le> sum_list (map rsize x)")
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   204
  prefer 2
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   205
  
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   206
  apply (simp add: sum_list_mono)
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   207
  by linarith
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   208
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   209
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   210
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   211
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   212
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   213
lemma rsimp_mono:
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   214
  shows "rsize (rsimp r) \<le> rsize r"
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   215
  apply(induct r)
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   216
  apply simp_all
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   217
  apply(subgoal_tac "rsize (rsimp_SEQ (rsimp r1) (rsimp r2)) \<le> rsize (RSEQ (rsimp r1) (rsimp r2))")
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   218
    apply force
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   219
  using rSEQ_mono
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   220
   apply presburger
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   221
  using rsimp_alts_mono by auto
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   222
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   223
lemma idiot:
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   224
  shows "rsimp_SEQ RONE r = r"
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   225
  apply(case_tac r)
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   226
       apply simp_all
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   227
  done
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   228
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   229
lemma no_alt_short_list_after_simp:
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   230
  shows "RALTS rs = rsimp r \<Longrightarrow> rsimp_ALTs rs = RALTS rs"
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   231
  sorry
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   232
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   233
lemma no_further_dB_after_simp:
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   234
  shows "RALTS rs = rsimp r \<Longrightarrow> rdistinct rs {} = rs"
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   235
  sorry
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   236
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   237
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   238
lemma idiot2:
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   239
  shows " \<lbrakk>r1 \<noteq> RZERO; r1 \<noteq> RONE;r2 \<noteq> RZERO\<rbrakk>
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   240
    \<Longrightarrow> rsimp_SEQ r1 r2 = RSEQ r1 r2"
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   241
  apply(case_tac r1)
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   242
       apply(case_tac r2)
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   243
  apply simp_all
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   244
     apply(case_tac r2)
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   245
  apply simp_all
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   246
     apply(case_tac r2)
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   247
  apply simp_all
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   248
   apply(case_tac r2)
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   249
  apply simp_all
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   250
  apply(case_tac r2)
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   251
       apply simp_all
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   252
  done
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   253
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   254
lemma rders__onechar:
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   255
  shows " (rders_simp r [c]) =  (rsimp (rders r [c]))"
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   256
  by simp
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   257
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   258
lemma rders_append:
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   259
  "rders c (s1 @ s2) = rders (rders c s1) s2"
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   260
  apply(induct s1 arbitrary: c s2)
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   261
  apply(simp_all)
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   262
  done
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   263
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   264
lemma rders_simp_append:
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   265
  "rders_simp c (s1 @ s2) = rders_simp (rders_simp c s1) s2"
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   266
  apply(induct s1 arbitrary: c s2)
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   267
  apply(simp_all)
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   268
  done
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   269
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   270
lemma inside_simp_removal:
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   271
  shows " rsimp (rder x (rsimp r)) = rsimp (rder x r)"
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   272
  sorry
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   273
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   274
lemma set_related_list:
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   275
  shows "distinct rs  \<Longrightarrow> length rs = card (set rs)"
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   276
  by (simp add: distinct_card)
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   277
(*this section deals with the property of distinctBy: creates a list without duplicates*)
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   278
lemma rdistinct_never_added_twice:
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   279
  shows "rdistinct (a # rs) {a} = rdistinct rs {a}"
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   280
  by force
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   281
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   282
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   283
lemma rdistinct_does_the_job:
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   284
  shows "distinct (rdistinct rs s)"
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   285
  apply(induct rs arbitrary: s)
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   286
   apply simp
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   287
  apply simp
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   288
  sorry
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   289
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   290
lemma rders_simp_same_simpders:
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   291
  shows "s \<noteq> [] \<Longrightarrow> rders_simp r s = rsimp (rders r s)"
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   292
  apply(induct s rule: rev_induct)
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   293
   apply simp
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   294
  apply(case_tac "xs = []")
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   295
   apply simp
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   296
  apply(simp add: rders_append rders_simp_append)
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   297
  using inside_simp_removal by blast
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   298
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   299
lemma simp_helps_der_pierce:
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   300
  shows " rsimp
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   301
            (rder x
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   302
              (rsimp_ALTs rs)) = 
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   303
          rsimp 
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   304
            (rsimp_ALTs 
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   305
              (map (rder x )
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   306
                rs
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   307
              )
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   308
            )"
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   309
  sorry
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   310
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   311
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   312
lemma rders_simp_one_char:
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   313
  shows "rders_simp r [c] = rsimp (rder c r)"
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   314
  apply auto
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   315
  done
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   316
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   317
lemma rsimp_idem:
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   318
  shows "rsimp (rsimp r) = rsimp r"
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   319
  sorry
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   320
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   321
corollary rsimp_inner_idem1:
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   322
  shows "rsimp r = RSEQ r1 r2 \<Longrightarrow> rsimp r1 = r1 \<and> rsimp r2 = r2"
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   323
  
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   324
  sorry
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   325
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   326
corollary rsimp_inner_idem2:
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   327
  shows "rsimp r = RALTS rs \<Longrightarrow> \<forall>r' \<in> (set rs). rsimp r' = r'"
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   328
  sorry
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   329
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   330
corollary rsimp_inner_idem3:
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   331
  shows "rsimp r = RALTS rs \<Longrightarrow> map rsimp rs = rs"
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   332
  by (meson map_idI rsimp_inner_idem2)
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   333
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   334
corollary rsimp_inner_idem4:
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   335
  shows "rsimp r = RALTS rs \<Longrightarrow> flts rs = rs"
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   336
  sorry
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   337
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   338
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   339
lemma head_one_more_simp:
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   340
  shows "map rsimp (r # rs) = map rsimp (( rsimp r) # rs)"
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   341
  by (simp add: rsimp_idem)
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   342
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   343
lemma head_one_more_dersimp:
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   344
  shows "map rsimp ((rder x (rders_simp r s) # rs)) = map rsimp ((rders_simp r (s@[x]) ) # rs)"
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   345
  using head_one_more_simp rders_simp_append rders_simp_one_char by presburger
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   346
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   347
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   348
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   349
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   350
lemma ders_simp_nullability:
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   351
  shows "rnullable (rders r s) = rnullable (rders_simp r s)"
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   352
  sorry
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   353
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   354
lemma  first_elem_seqder:
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   355
  shows "\<not>rnullable r1p \<Longrightarrow> map rsimp (rder x (RSEQ r1p r2)
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   356
                   # rs) = map rsimp ((RSEQ (rder x r1p) r2) # rs) "
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   357
  by auto
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   358
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   359
lemma first_elem_seqder1:
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   360
  shows  "\<not>rnullable (rders_simp r xs) \<Longrightarrow> map rsimp ( (rder x (RSEQ (rders_simp r xs) r2)) # rs) = 
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   361
                                          map rsimp ( (RSEQ (rsimp (rder x (rders_simp r xs))) r2) # rs)"
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   362
  by (simp add: rsimp_idem)
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   363
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   364
lemma first_elem_seqdersimps:
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   365
  shows "\<not>rnullable (rders_simp r xs) \<Longrightarrow> map rsimp ( (rder x (RSEQ (rders_simp r xs) r2)) # rs) = 
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   366
                                          map rsimp ( (RSEQ (rders_simp r (xs @ [x])) r2) # rs)"
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   367
  using first_elem_seqder1 rders_simp_append by auto
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   368
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   369
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   370
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   371
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   372
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   373
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   374
lemma seq_ders_closed_form1:
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   375
  shows "\<exists>Ss. rders_simp (RSEQ r1 r2) [c] = rsimp (RALTS ((RSEQ (rders_simp r1 [c]) r2) # 
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   376
(map ( rders_simp r2 ) Ss)))"
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   377
  apply(case_tac "rnullable r1")
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   378
   apply(subgoal_tac " rders_simp (RSEQ r1 r2) [c] = 
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   379
rsimp (RALTS ((RSEQ (rders_simp r1 [c]) r2) # (map (rders_simp r2) [[c]])))")
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   380
    prefer 2
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   381
    apply (simp add: rsimp_idem)
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   382
   apply(rule_tac x = "[[c]]" in exI)
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   383
   apply simp
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   384
  apply(subgoal_tac  " rders_simp (RSEQ r1 r2) [c] = 
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   385
rsimp (RALTS ((RSEQ (rders_simp r1 [c]) r2) # (map (rders_simp r2) [])))")
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   386
   apply blast
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   387
  apply(simp add: rsimp_idem)
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   388
  sorry
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   389
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   390
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   391
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   392
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   393
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   394
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   395
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   396
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   397
lemma simp_flatten2:
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   398
  shows "rsimp (RALTS (r # [RALTS rs])) = rsimp (RALTS (r # rs))"
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   399
  sorry
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   400
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   401
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   402
lemma simp_flatten:
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   403
  shows "rsimp (RALTS ((RALTS rsa) # rsb)) = rsimp (RALTS (rsa @ rsb))"
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   404
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   405
  sorry
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   406
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   407
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   408
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   409
fun vsuf :: "char list \<Rightarrow> rrexp \<Rightarrow> char list list" where
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   410
"vsuf [] _ = []"
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   411
|"vsuf (c#cs) r1 = (if (rnullable r1) then  (vsuf cs (rder c r1)) @ [c # cs]
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   412
                                      else  (vsuf cs (rder c r1))
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   413
                   ) "
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   414
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   415
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   416
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   417
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   418
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   419
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   420
fun star_update :: "char \<Rightarrow> rrexp \<Rightarrow> char list list \<Rightarrow> char list list" where
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   421
"star_update c r [] = []"
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   422
|"star_update c r (s # Ss) = (if (rnullable (rders_simp r s)) 
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   423
                                then (s@[c]) # [c] # (star_update c r Ss) 
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   424
                               else   (s@[c]) # (star_update c r Ss) )"
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   425
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   426
fun star_updates :: "char list \<Rightarrow> rrexp \<Rightarrow> char list list \<Rightarrow> char list list"
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   427
  where
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   428
"star_updates [] r Ss = Ss"
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   429
| "star_updates (c # cs) r Ss = star_updates cs r (star_update c r Ss)"
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   430
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   431
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   432
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   433
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   434
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   435
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   436
(*some basic facts about rsimp*)
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   437
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   438
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   439
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   440
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   441
end