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