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