thys2/BasicIdentities.thy
author Chengsong
Wed, 30 Mar 2022 11:18:51 +0100
changeset 475 10fd25fba2ba
parent 467 599239394c51
child 476 56837303ce61
permissions -rw-r--r--
identities
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
Chengsong
parents: 444
diff changeset
   107
444
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   108
fun rsimp_SEQ :: " rrexp \<Rightarrow> rrexp \<Rightarrow> rrexp"
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   109
  where
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   110
  "rsimp_SEQ  RZERO _ = RZERO"
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   111
| "rsimp_SEQ  _ RZERO = RZERO"
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   112
| "rsimp_SEQ RONE r2 = r2"
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   113
| "rsimp_SEQ r1 r2 = RSEQ r1 r2"
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   114
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   115
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   116
fun rsimp :: "rrexp \<Rightarrow> rrexp" 
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   117
  where
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   118
  "rsimp (RSEQ r1 r2) = rsimp_SEQ  (rsimp r1) (rsimp r2)"
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   119
| "rsimp (RALTS rs) = rsimp_ALTs  (rdistinct (rflts (map rsimp rs))  {}) "
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   120
| "rsimp r = r"
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   121
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   122
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   123
fun 
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   124
  rders_simp :: "rrexp \<Rightarrow> string \<Rightarrow> rrexp"
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   125
where
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   126
  "rders_simp r [] = r"
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   127
| "rders_simp r (c#s) = rders_simp (rsimp (rder c r)) s"
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   128
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   129
fun rsize :: "rrexp \<Rightarrow> nat" where
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   130
  "rsize RZERO = 1"
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   131
| "rsize (RONE) = 1" 
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   132
| "rsize (RCHAR  c) = 1"
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   133
| "rsize (RALTS  rs) = Suc (sum_list (map rsize rs))"
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   134
| "rsize (RSEQ  r1 r2) = Suc (rsize r1 + rsize r2)"
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   135
| "rsize (RSTAR  r) = Suc (rsize r)"
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   136
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   137
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   138
lemma rder_rsimp_ALTs_commute:
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   139
  shows "  (rder x (rsimp_ALTs rs)) = rsimp_ALTs (map (rder x) rs)"
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   140
  apply(induct rs)
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   141
   apply simp
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   142
  apply(case_tac rs)
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   143
   apply simp
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   144
  apply auto
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   145
  done
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   146
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   147
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   148
lemma rsimp_aalts_smaller:
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   149
  shows "rsize (rsimp_ALTs  rs) \<le> rsize (RALTS rs)"
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   150
  apply(induct rs)
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   151
   apply simp
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   152
  apply simp
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   153
  apply(case_tac "rs = []")
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   154
   apply simp
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   155
  apply(subgoal_tac "\<exists>rsp ap. rs = ap # rsp")
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   156
   apply(erule exE)+
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   157
   apply simp
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   158
  apply simp
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   159
  by(meson neq_Nil_conv)
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   160
  
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   161
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   162
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   163
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   164
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   165
lemma rSEQ_mono:
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   166
  shows "rsize (rsimp_SEQ r1 r2) \<le>rsize ( RSEQ r1 r2)"
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   167
  apply auto
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   168
  apply(induct r1)
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   169
       apply auto
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   170
      apply(case_tac "r2")
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   171
       apply simp_all
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   172
     apply(case_tac r2)
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   173
          apply simp_all
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
  done
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   181
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   182
lemma ralts_cap_mono:
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   183
  shows "rsize (RALTS rs) \<le> Suc ( sum_list (map rsize rs)) "
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   184
  by simp
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   185
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   186
lemma rflts_def_idiot:
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   187
  shows "\<lbrakk> a \<noteq> RZERO; \<nexists>rs1. a = RALTS rs1\<rbrakk>
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   188
       \<Longrightarrow> rflts (a # rs) = a # rflts rs"
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   189
  apply(case_tac a)
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   190
       apply simp_all
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   191
  done
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   192
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   193
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   194
lemma rflts_mono:
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   195
  shows "sum_list (map rsize (rflts rs))\<le> sum_list (map rsize rs)"
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   196
  apply(induct rs)
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   197
  apply simp
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   198
  apply(case_tac "a = RZERO")
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   199
   apply simp
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   200
  apply(case_tac "\<exists>rs1. a = RALTS rs1")
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   201
  apply(erule exE)
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   202
   apply simp
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   203
  apply(subgoal_tac "rflts (a # rs) = a # (rflts rs)")
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   204
  prefer 2
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   205
  using rflts_def_idiot apply blast
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   206
  apply simp
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   207
  done
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   208
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   209
lemma rdistinct_smaller: shows "sum_list (map rsize (rdistinct rs ss)) \<le>
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   210
sum_list (map rsize rs )"
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   211
  apply (induct rs arbitrary: ss)
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   212
   apply simp
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   213
  by (simp add: trans_le_add2)
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   214
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   215
lemma rdistinct_phi_smaller: "sum_list (map rsize (rdistinct rs {})) \<le> sum_list (map rsize rs)"
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   216
  by (simp add: rdistinct_smaller)
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   217
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   218
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   219
lemma rsimp_alts_mono :
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   220
  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
   221
rsize (rsimp_ALTs (rdistinct (rflts (map rsimp x)) {})) \<le> Suc (sum_list (map rsize x))"
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   222
  apply(subgoal_tac "rsize (rsimp_ALTs (rdistinct (rflts (map rsimp x)) {} )) 
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   223
                    \<le> rsize (RALTS (rdistinct (rflts (map rsimp x)) {} ))")
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   224
  prefer 2
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   225
  using rsimp_aalts_smaller apply auto[1]
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   226
  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
   227
  prefer 2
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   228
  using ralts_cap_mono apply blast
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   229
  apply(subgoal_tac "sum_list (map rsize (rdistinct (rflts (map rsimp x)) {})) \<le>
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   230
                     sum_list (map rsize ( (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 rdistinct_smaller apply presburger
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   233
  apply(subgoal_tac "sum_list (map rsize (rflts (map rsimp x))) \<le> 
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   234
                     sum_list (map rsize (map rsimp x))")
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   235
  prefer 2
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   236
  using rflts_mono apply blast
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   237
  apply(subgoal_tac "sum_list (map rsize (map rsimp x)) \<le> sum_list (map rsize x)")
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   238
  prefer 2
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   239
  
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   240
  apply (simp add: sum_list_mono)
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   241
  by linarith
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   242
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   243
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   244
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   245
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   246
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   247
lemma rsimp_mono:
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   248
  shows "rsize (rsimp r) \<le> rsize r"
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   249
  apply(induct r)
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   250
  apply simp_all
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   251
  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
   252
    apply force
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   253
  using rSEQ_mono
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   254
   apply presburger
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   255
  using rsimp_alts_mono by auto
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   256
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   257
lemma idiot:
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   258
  shows "rsimp_SEQ RONE r = r"
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   259
  apply(case_tac r)
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   260
       apply simp_all
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   261
  done
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   262
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   263
lemma no_alt_short_list_after_simp:
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   264
  shows "RALTS rs = rsimp r \<Longrightarrow> rsimp_ALTs rs = RALTS rs"
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   265
  sorry
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   266
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   267
lemma no_further_dB_after_simp:
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   268
  shows "RALTS rs = rsimp r \<Longrightarrow> rdistinct rs {} = 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
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   272
lemma idiot2:
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   273
  shows " \<lbrakk>r1 \<noteq> RZERO; r1 \<noteq> RONE;r2 \<noteq> RZERO\<rbrakk>
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   274
    \<Longrightarrow> rsimp_SEQ r1 r2 = RSEQ r1 r2"
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   275
  apply(case_tac r1)
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   276
       apply(case_tac r2)
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   277
  apply simp_all
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   278
     apply(case_tac r2)
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   279
  apply simp_all
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
  done
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   287
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   288
lemma rders__onechar:
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   289
  shows " (rders_simp r [c]) =  (rsimp (rders r [c]))"
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   290
  by simp
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   291
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   292
lemma rders_append:
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   293
  "rders c (s1 @ s2) = rders (rders c s1) s2"
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   294
  apply(induct s1 arbitrary: c s2)
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   295
  apply(simp_all)
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   296
  done
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   297
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   298
lemma rders_simp_append:
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   299
  "rders_simp c (s1 @ s2) = rders_simp (rders_simp c s1) s2"
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   300
  apply(induct s1 arbitrary: c s2)
465
Chengsong
parents: 444
diff changeset
   301
   apply(simp_all)
444
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   302
  done
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   303
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   304
lemma inside_simp_removal:
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   305
  shows " rsimp (rder x (rsimp r)) = rsimp (rder x r)"
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   306
  sorry
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   307
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   308
lemma set_related_list:
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   309
  shows "distinct rs  \<Longrightarrow> length rs = card (set rs)"
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   310
  by (simp add: distinct_card)
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   311
(*this section deals with the property of distinctBy: creates a list without duplicates*)
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   312
lemma rdistinct_never_added_twice:
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   313
  shows "rdistinct (a # rs) {a} = rdistinct rs {a}"
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   314
  by force
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   315
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   316
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   317
lemma rdistinct_does_the_job:
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   318
  shows "distinct (rdistinct rs s)"
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   319
  apply(induct rs arbitrary: s)
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   320
   apply simp
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   321
  apply simp
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   322
  sorry
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   323
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   324
lemma rders_simp_same_simpders:
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   325
  shows "s \<noteq> [] \<Longrightarrow> rders_simp r s = rsimp (rders r s)"
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   326
  apply(induct s rule: rev_induct)
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   327
   apply simp
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   328
  apply(case_tac "xs = []")
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   329
   apply simp
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   330
  apply(simp add: rders_append rders_simp_append)
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   331
  using inside_simp_removal by blast
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   332
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   333
lemma simp_helps_der_pierce:
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   334
  shows " rsimp
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   335
            (rder x
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   336
              (rsimp_ALTs rs)) = 
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   337
          rsimp 
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   338
            (rsimp_ALTs 
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   339
              (map (rder x )
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   340
                rs
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   341
              )
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   342
            )"
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   343
  sorry
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   344
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   345
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   346
lemma rders_simp_one_char:
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   347
  shows "rders_simp r [c] = rsimp (rder c r)"
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   348
  apply auto
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   349
  done
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   350
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   351
lemma rsimp_idem:
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   352
  shows "rsimp (rsimp r) = rsimp r"
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   353
  sorry
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   354
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   355
corollary rsimp_inner_idem1:
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   356
  shows "rsimp r = RSEQ r1 r2 \<Longrightarrow> rsimp r1 = r1 \<and> rsimp r2 = r2"
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   357
  
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   358
  sorry
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   359
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   360
corollary rsimp_inner_idem2:
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   361
  shows "rsimp r = RALTS rs \<Longrightarrow> \<forall>r' \<in> (set rs). rsimp r' = r'"
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   362
  sorry
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   363
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   364
corollary rsimp_inner_idem3:
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   365
  shows "rsimp r = RALTS rs \<Longrightarrow> map rsimp rs = rs"
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   366
  by (meson map_idI rsimp_inner_idem2)
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   367
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   368
corollary rsimp_inner_idem4:
465
Chengsong
parents: 444
diff changeset
   369
  shows "rsimp r = RALTS rs \<Longrightarrow> rflts rs = rs"
444
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   370
  sorry
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   371
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   372
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   373
lemma head_one_more_simp:
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   374
  shows "map rsimp (r # rs) = map rsimp (( rsimp r) # rs)"
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   375
  by (simp add: rsimp_idem)
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   376
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   377
lemma head_one_more_dersimp:
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   378
  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
   379
  using head_one_more_simp rders_simp_append rders_simp_one_char by presburger
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   380
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   381
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
lemma ders_simp_nullability:
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   385
  shows "rnullable (rders r s) = rnullable (rders_simp r s)"
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   386
  sorry
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   387
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   388
lemma  first_elem_seqder:
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   389
  shows "\<not>rnullable r1p \<Longrightarrow> map rsimp (rder x (RSEQ r1p r2)
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   390
                   # rs) = map rsimp ((RSEQ (rder x r1p) r2) # rs) "
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   391
  by auto
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   392
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   393
lemma first_elem_seqder1:
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   394
  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
   395
                                          map rsimp ( (RSEQ (rsimp (rder x (rders_simp r xs))) r2) # rs)"
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   396
  by (simp add: rsimp_idem)
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   397
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   398
lemma first_elem_seqdersimps:
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   399
  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
   400
                                          map rsimp ( (RSEQ (rders_simp r (xs @ [x])) r2) # rs)"
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   401
  using first_elem_seqder1 rders_simp_append by auto
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   402
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
lemma seq_ders_closed_form1:
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   409
  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
   410
(map ( rders_simp r2 ) Ss)))"
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   411
  apply(case_tac "rnullable r1")
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) [[c]])))")
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   414
    prefer 2
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   415
    apply (simp add: rsimp_idem)
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   416
   apply(rule_tac x = "[[c]]" in exI)
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   417
   apply simp
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   418
  apply(subgoal_tac  " rders_simp (RSEQ r1 r2) [c] = 
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   419
rsimp (RALTS ((RSEQ (rders_simp r1 [c]) r2) # (map (rders_simp r2) [])))")
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   420
   apply blast
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   421
  apply(simp add: rsimp_idem)
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   422
  sorry
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   423
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   424
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   425
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   426
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
lemma simp_flatten2:
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   432
  shows "rsimp (RALTS (r # [RALTS rs])) = rsimp (RALTS (r # rs))"
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   433
  sorry
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   434
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   435
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   436
lemma simp_flatten:
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   437
  shows "rsimp (RALTS ((RALTS rsa) # rsb)) = rsimp (RALTS (rsa @ rsb))"
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   438
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   439
  sorry
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
fun vsuf :: "char list \<Rightarrow> rrexp \<Rightarrow> char list list" where
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   444
"vsuf [] _ = []"
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   445
|"vsuf (c#cs) r1 = (if (rnullable r1) then  (vsuf cs (rder c r1)) @ [c # cs]
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   446
                                      else  (vsuf cs (rder c r1))
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
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
fun star_update :: "char \<Rightarrow> rrexp \<Rightarrow> char list list \<Rightarrow> char list list" where
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   455
"star_update c r [] = []"
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   456
|"star_update c r (s # Ss) = (if (rnullable (rders_simp r s)) 
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   457
                                then (s@[c]) # [c] # (star_update c r Ss) 
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   458
                               else   (s@[c]) # (star_update c r Ss) )"
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   459
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   460
fun star_updates :: "char list \<Rightarrow> rrexp \<Rightarrow> char list list \<Rightarrow> char list list"
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   461
  where
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   462
"star_updates [] r Ss = Ss"
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   463
| "star_updates (c # cs) r Ss = star_updates cs r (star_update c r Ss)"
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
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   468
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   469
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   470
(*some basic facts about rsimp*)
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   471
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   472
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   473
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   474
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   475
end