thys2/BasicIdentities.thy
author Chengsong
Thu, 24 Mar 2022 21:11:12 +0000
changeset 467 599239394c51
parent 465 2e7c7111c0be
child 475 10fd25fba2ba
permissions -rw-r--r--
forget
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
467
Chengsong
parents: 465
diff changeset
    57
lemma distinct_not_exist:
Chengsong
parents: 465
diff changeset
    58
  shows "a \<notin> set rs \<Longrightarrow> rdistinct rs rset = rdistinct rs (insert a rset)"
Chengsong
parents: 465
diff changeset
    59
  apply(induct rs arbitrary: rset)
Chengsong
parents: 465
diff changeset
    60
   apply simp
Chengsong
parents: 465
diff changeset
    61
  apply(case_tac "aa \<in> rset")
Chengsong
parents: 465
diff changeset
    62
   apply simp
Chengsong
parents: 465
diff changeset
    63
  apply(subgoal_tac "a \<noteq> aa")
Chengsong
parents: 465
diff changeset
    64
   prefer 2
Chengsong
parents: 465
diff changeset
    65
  apply simp
Chengsong
parents: 465
diff changeset
    66
  apply simp
Chengsong
parents: 465
diff changeset
    67
  done
444
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
    68
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
    69
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
    70
fun rflts :: "rrexp list \<Rightarrow> rrexp list"
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
    71
  where 
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
    72
  "rflts [] = []"
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
    73
| "rflts (RZERO # rs) = rflts rs"
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
    74
| "rflts ((RALTS rs1) # rs) = rs1 @ rflts rs"
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
    75
| "rflts (r1 # rs) = r1 # rflts rs"
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
    76
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
    77
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
    78
fun rsimp_ALTs :: " rrexp list \<Rightarrow> rrexp"
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
    79
  where
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
    80
  "rsimp_ALTs  [] = RZERO"
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
    81
| "rsimp_ALTs [r] =  r"
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
    82
| "rsimp_ALTs rs = RALTS rs"
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
    83
465
Chengsong
parents: 444
diff changeset
    84
lemma rsimpalts_gte2elems:
Chengsong
parents: 444
diff changeset
    85
  shows "size rlist \<ge> 2 \<Longrightarrow> rsimp_ALTs rlist = RALTS rlist"
Chengsong
parents: 444
diff changeset
    86
  apply(induct rlist)
Chengsong
parents: 444
diff changeset
    87
   apply simp
Chengsong
parents: 444
diff changeset
    88
  apply(induct rlist)
Chengsong
parents: 444
diff changeset
    89
   apply simp
Chengsong
parents: 444
diff changeset
    90
  apply (metis Suc_le_length_iff rsimp_ALTs.simps(3))
Chengsong
parents: 444
diff changeset
    91
  by blast
Chengsong
parents: 444
diff changeset
    92
Chengsong
parents: 444
diff changeset
    93
lemma rsimpalts_conscons:
Chengsong
parents: 444
diff changeset
    94
  shows "rsimp_ALTs (r1 # rsa @ r2 # rsb) = RALTS (r1 # rsa @ r2 # rsb)"
Chengsong
parents: 444
diff changeset
    95
  by (metis Nil_is_append_conv list.exhaust rsimp_ALTs.simps(3))
Chengsong
parents: 444
diff changeset
    96
Chengsong
parents: 444
diff changeset
    97
444
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
    98
fun rsimp_SEQ :: " rrexp \<Rightarrow> rrexp \<Rightarrow> rrexp"
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
    99
  where
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   100
  "rsimp_SEQ  RZERO _ = RZERO"
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   101
| "rsimp_SEQ  _ RZERO = RZERO"
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   102
| "rsimp_SEQ RONE r2 = r2"
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   103
| "rsimp_SEQ r1 r2 = RSEQ r1 r2"
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   104
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   105
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   106
fun rsimp :: "rrexp \<Rightarrow> rrexp" 
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   107
  where
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   108
  "rsimp (RSEQ r1 r2) = rsimp_SEQ  (rsimp r1) (rsimp r2)"
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   109
| "rsimp (RALTS rs) = rsimp_ALTs  (rdistinct (rflts (map rsimp rs))  {}) "
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   110
| "rsimp r = r"
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   111
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   112
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   113
fun 
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   114
  rders_simp :: "rrexp \<Rightarrow> string \<Rightarrow> rrexp"
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   115
where
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   116
  "rders_simp r [] = r"
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   117
| "rders_simp r (c#s) = rders_simp (rsimp (rder c r)) s"
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   118
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   119
fun rsize :: "rrexp \<Rightarrow> nat" where
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   120
  "rsize RZERO = 1"
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   121
| "rsize (RONE) = 1" 
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   122
| "rsize (RCHAR  c) = 1"
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   123
| "rsize (RALTS  rs) = Suc (sum_list (map rsize rs))"
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   124
| "rsize (RSEQ  r1 r2) = Suc (rsize r1 + rsize r2)"
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   125
| "rsize (RSTAR  r) = Suc (rsize r)"
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
lemma rder_rsimp_ALTs_commute:
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   129
  shows "  (rder x (rsimp_ALTs rs)) = rsimp_ALTs (map (rder x) rs)"
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   130
  apply(induct rs)
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   131
   apply simp
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   132
  apply(case_tac rs)
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   133
   apply simp
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   134
  apply auto
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   135
  done
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   136
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   137
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   138
lemma rsimp_aalts_smaller:
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   139
  shows "rsize (rsimp_ALTs  rs) \<le> rsize (RALTS rs)"
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   140
  apply(induct rs)
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   141
   apply simp
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   142
  apply simp
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   143
  apply(case_tac "rs = []")
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   144
   apply simp
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   145
  apply(subgoal_tac "\<exists>rsp ap. rs = ap # rsp")
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   146
   apply(erule exE)+
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   147
   apply simp
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   148
  apply simp
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   149
  by(meson neq_Nil_conv)
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   150
  
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   151
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   152
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   153
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   154
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   155
lemma rSEQ_mono:
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   156
  shows "rsize (rsimp_SEQ r1 r2) \<le>rsize ( RSEQ r1 r2)"
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   157
  apply auto
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   158
  apply(induct r1)
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   159
       apply auto
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   160
      apply(case_tac "r2")
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   161
       apply simp_all
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   162
     apply(case_tac r2)
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   163
          apply simp_all
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   164
     apply(case_tac r2)
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   165
         apply simp_all
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   166
     apply(case_tac r2)
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   167
        apply simp_all
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   168
     apply(case_tac r2)
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   169
  apply simp_all
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   170
  done
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   171
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   172
lemma ralts_cap_mono:
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   173
  shows "rsize (RALTS rs) \<le> Suc ( sum_list (map rsize rs)) "
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   174
  by simp
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   175
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   176
lemma rflts_def_idiot:
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   177
  shows "\<lbrakk> a \<noteq> RZERO; \<nexists>rs1. a = RALTS rs1\<rbrakk>
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   178
       \<Longrightarrow> rflts (a # rs) = a # rflts rs"
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   179
  apply(case_tac a)
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   180
       apply simp_all
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   181
  done
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   182
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   183
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   184
lemma rflts_mono:
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   185
  shows "sum_list (map rsize (rflts rs))\<le> sum_list (map rsize rs)"
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   186
  apply(induct rs)
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   187
  apply simp
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   188
  apply(case_tac "a = RZERO")
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   189
   apply simp
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   190
  apply(case_tac "\<exists>rs1. a = RALTS rs1")
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   191
  apply(erule exE)
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   192
   apply simp
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   193
  apply(subgoal_tac "rflts (a # rs) = a # (rflts rs)")
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   194
  prefer 2
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   195
  using rflts_def_idiot apply blast
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   196
  apply simp
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   197
  done
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   198
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   199
lemma rdistinct_smaller: shows "sum_list (map rsize (rdistinct rs ss)) \<le>
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   200
sum_list (map rsize rs )"
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   201
  apply (induct rs arbitrary: ss)
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   202
   apply simp
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   203
  by (simp add: trans_le_add2)
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   204
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   205
lemma rdistinct_phi_smaller: "sum_list (map rsize (rdistinct rs {})) \<le> sum_list (map rsize rs)"
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   206
  by (simp add: rdistinct_smaller)
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   207
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   208
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   209
lemma rsimp_alts_mono :
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   210
  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
   211
rsize (rsimp_ALTs (rdistinct (rflts (map rsimp x)) {})) \<le> Suc (sum_list (map rsize x))"
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   212
  apply(subgoal_tac "rsize (rsimp_ALTs (rdistinct (rflts (map rsimp x)) {} )) 
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   213
                    \<le> rsize (RALTS (rdistinct (rflts (map rsimp x)) {} ))")
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   214
  prefer 2
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   215
  using rsimp_aalts_smaller apply auto[1]
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   216
  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
   217
  prefer 2
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   218
  using ralts_cap_mono apply blast
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   219
  apply(subgoal_tac "sum_list (map rsize (rdistinct (rflts (map rsimp x)) {})) \<le>
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   220
                     sum_list (map rsize ( (rflts (map rsimp x))))")
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   221
  prefer 2
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   222
  using rdistinct_smaller apply presburger
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   223
  apply(subgoal_tac "sum_list (map rsize (rflts (map rsimp x))) \<le> 
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   224
                     sum_list (map rsize (map rsimp x))")
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   225
  prefer 2
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   226
  using rflts_mono apply blast
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   227
  apply(subgoal_tac "sum_list (map rsize (map rsimp x)) \<le> sum_list (map rsize x)")
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   228
  prefer 2
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   229
  
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   230
  apply (simp add: sum_list_mono)
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   231
  by linarith
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   232
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   233
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   234
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   235
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   236
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   237
lemma rsimp_mono:
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   238
  shows "rsize (rsimp r) \<le> rsize r"
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   239
  apply(induct r)
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   240
  apply simp_all
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   241
  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
   242
    apply force
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   243
  using rSEQ_mono
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   244
   apply presburger
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   245
  using rsimp_alts_mono by auto
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   246
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   247
lemma idiot:
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   248
  shows "rsimp_SEQ RONE r = r"
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   249
  apply(case_tac r)
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   250
       apply simp_all
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   251
  done
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   252
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   253
lemma no_alt_short_list_after_simp:
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   254
  shows "RALTS rs = rsimp r \<Longrightarrow> rsimp_ALTs rs = RALTS rs"
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   255
  sorry
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   256
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   257
lemma no_further_dB_after_simp:
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   258
  shows "RALTS rs = rsimp r \<Longrightarrow> rdistinct rs {} = rs"
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   259
  sorry
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   260
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   261
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   262
lemma idiot2:
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   263
  shows " \<lbrakk>r1 \<noteq> RZERO; r1 \<noteq> RONE;r2 \<noteq> RZERO\<rbrakk>
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   264
    \<Longrightarrow> rsimp_SEQ r1 r2 = RSEQ r1 r2"
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   265
  apply(case_tac r1)
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   266
       apply(case_tac r2)
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   267
  apply simp_all
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   268
     apply(case_tac r2)
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   269
  apply simp_all
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   270
     apply(case_tac r2)
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   271
  apply simp_all
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   272
   apply(case_tac r2)
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   273
  apply simp_all
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   274
  apply(case_tac r2)
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   275
       apply simp_all
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   276
  done
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   277
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   278
lemma rders__onechar:
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   279
  shows " (rders_simp r [c]) =  (rsimp (rders r [c]))"
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   280
  by simp
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   281
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   282
lemma rders_append:
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   283
  "rders c (s1 @ s2) = rders (rders c s1) s2"
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   284
  apply(induct s1 arbitrary: c s2)
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   285
  apply(simp_all)
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   286
  done
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   287
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   288
lemma rders_simp_append:
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   289
  "rders_simp c (s1 @ s2) = rders_simp (rders_simp c s1) s2"
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   290
  apply(induct s1 arbitrary: c s2)
465
Chengsong
parents: 444
diff changeset
   291
   apply(simp_all)
444
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   292
  done
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   293
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   294
lemma inside_simp_removal:
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   295
  shows " rsimp (rder x (rsimp r)) = rsimp (rder x r)"
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   296
  sorry
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   297
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   298
lemma set_related_list:
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   299
  shows "distinct rs  \<Longrightarrow> length rs = card (set rs)"
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   300
  by (simp add: distinct_card)
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   301
(*this section deals with the property of distinctBy: creates a list without duplicates*)
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   302
lemma rdistinct_never_added_twice:
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   303
  shows "rdistinct (a # rs) {a} = rdistinct rs {a}"
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   304
  by force
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   305
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   306
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   307
lemma rdistinct_does_the_job:
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   308
  shows "distinct (rdistinct rs s)"
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   309
  apply(induct rs arbitrary: s)
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   310
   apply simp
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   311
  apply simp
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   312
  sorry
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   313
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   314
lemma rders_simp_same_simpders:
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   315
  shows "s \<noteq> [] \<Longrightarrow> rders_simp r s = rsimp (rders r s)"
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   316
  apply(induct s rule: rev_induct)
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   317
   apply simp
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   318
  apply(case_tac "xs = []")
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   319
   apply simp
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   320
  apply(simp add: rders_append rders_simp_append)
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   321
  using inside_simp_removal by blast
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   322
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   323
lemma simp_helps_der_pierce:
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   324
  shows " rsimp
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   325
            (rder x
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   326
              (rsimp_ALTs rs)) = 
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   327
          rsimp 
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   328
            (rsimp_ALTs 
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   329
              (map (rder x )
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   330
                rs
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   331
              )
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   332
            )"
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   333
  sorry
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   334
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   335
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   336
lemma rders_simp_one_char:
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   337
  shows "rders_simp r [c] = rsimp (rder c r)"
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   338
  apply auto
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   339
  done
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   340
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   341
lemma rsimp_idem:
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   342
  shows "rsimp (rsimp r) = rsimp r"
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   343
  sorry
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   344
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   345
corollary rsimp_inner_idem1:
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   346
  shows "rsimp r = RSEQ r1 r2 \<Longrightarrow> rsimp r1 = r1 \<and> rsimp r2 = r2"
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   347
  
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   348
  sorry
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   349
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   350
corollary rsimp_inner_idem2:
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   351
  shows "rsimp r = RALTS rs \<Longrightarrow> \<forall>r' \<in> (set rs). rsimp r' = r'"
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
corollary rsimp_inner_idem3:
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   355
  shows "rsimp r = RALTS rs \<Longrightarrow> map rsimp rs = rs"
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   356
  by (meson map_idI rsimp_inner_idem2)
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   357
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   358
corollary rsimp_inner_idem4:
465
Chengsong
parents: 444
diff changeset
   359
  shows "rsimp r = RALTS rs \<Longrightarrow> rflts rs = rs"
444
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   360
  sorry
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   361
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   362
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   363
lemma head_one_more_simp:
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   364
  shows "map rsimp (r # rs) = map rsimp (( rsimp r) # rs)"
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   365
  by (simp add: rsimp_idem)
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   366
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   367
lemma head_one_more_dersimp:
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   368
  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
   369
  using head_one_more_simp rders_simp_append rders_simp_one_char by presburger
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 ders_simp_nullability:
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   375
  shows "rnullable (rders r s) = rnullable (rders_simp r s)"
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   376
  sorry
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   377
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   378
lemma  first_elem_seqder:
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   379
  shows "\<not>rnullable r1p \<Longrightarrow> map rsimp (rder x (RSEQ r1p r2)
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   380
                   # rs) = map rsimp ((RSEQ (rder x r1p) r2) # rs) "
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   381
  by auto
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   382
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   383
lemma first_elem_seqder1:
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   384
  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
   385
                                          map rsimp ( (RSEQ (rsimp (rder x (rders_simp r xs))) r2) # rs)"
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   386
  by (simp add: rsimp_idem)
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   387
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   388
lemma first_elem_seqdersimps:
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   389
  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
   390
                                          map rsimp ( (RSEQ (rders_simp r (xs @ [x])) r2) # rs)"
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   391
  using first_elem_seqder1 rders_simp_append by auto
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
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   398
lemma seq_ders_closed_form1:
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   399
  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
   400
(map ( rders_simp r2 ) Ss)))"
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   401
  apply(case_tac "rnullable r1")
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   402
   apply(subgoal_tac " rders_simp (RSEQ r1 r2) [c] = 
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   403
rsimp (RALTS ((RSEQ (rders_simp r1 [c]) r2) # (map (rders_simp r2) [[c]])))")
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   404
    prefer 2
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   405
    apply (simp add: rsimp_idem)
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   406
   apply(rule_tac x = "[[c]]" in exI)
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   407
   apply simp
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   408
  apply(subgoal_tac  " rders_simp (RSEQ r1 r2) [c] = 
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   409
rsimp (RALTS ((RSEQ (rders_simp r1 [c]) r2) # (map (rders_simp r2) [])))")
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   410
   apply blast
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   411
  apply(simp add: rsimp_idem)
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   412
  sorry
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
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   421
lemma simp_flatten2:
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   422
  shows "rsimp (RALTS (r # [RALTS rs])) = rsimp (RALTS (r # rs))"
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   423
  sorry
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   424
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   425
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   426
lemma simp_flatten:
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   427
  shows "rsimp (RALTS ((RALTS rsa) # rsb)) = rsimp (RALTS (rsa @ rsb))"
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   428
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   429
  sorry
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
fun vsuf :: "char list \<Rightarrow> rrexp \<Rightarrow> char list list" where
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   434
"vsuf [] _ = []"
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   435
|"vsuf (c#cs) r1 = (if (rnullable r1) then  (vsuf cs (rder c r1)) @ [c # cs]
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   436
                                      else  (vsuf cs (rder c r1))
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
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   442
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   443
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   444
fun star_update :: "char \<Rightarrow> rrexp \<Rightarrow> char list list \<Rightarrow> char list list" where
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   445
"star_update c r [] = []"
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   446
|"star_update c r (s # Ss) = (if (rnullable (rders_simp r s)) 
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   447
                                then (s@[c]) # [c] # (star_update c r Ss) 
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   448
                               else   (s@[c]) # (star_update c r Ss) )"
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   449
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   450
fun star_updates :: "char list \<Rightarrow> rrexp \<Rightarrow> char list list \<Rightarrow> char list list"
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   451
  where
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   452
"star_updates [] r Ss = Ss"
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   453
| "star_updates (c # cs) r Ss = star_updates cs r (star_update c r Ss)"
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   454
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   455
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   456
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   457
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   458
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   459
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   460
(*some basic facts about rsimp*)
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   461
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   462
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   463
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   464
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   465
end