thys2/BasicIdentities.thy
author Chengsong
Wed, 13 Apr 2022 22:20:08 +0100
changeset 488 370dae790b30
parent 486 f5b96a532c85
child 489 2b5b3f83e2b6
permissions -rw-r--r--
more sorrys fileld
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
488
370dae790b30 more sorrys fileld
Chengsong
parents: 486
diff changeset
    56
lemma rdistinct1:
370dae790b30 more sorrys fileld
Chengsong
parents: 486
diff changeset
    57
  assumes "a \<in> acc"
370dae790b30 more sorrys fileld
Chengsong
parents: 486
diff changeset
    58
  shows "a \<notin> set (rdistinct rs acc)"
370dae790b30 more sorrys fileld
Chengsong
parents: 486
diff changeset
    59
  using assms
370dae790b30 more sorrys fileld
Chengsong
parents: 486
diff changeset
    60
  apply(induct rs arbitrary: acc a)
370dae790b30 more sorrys fileld
Chengsong
parents: 486
diff changeset
    61
   apply(auto)
370dae790b30 more sorrys fileld
Chengsong
parents: 486
diff changeset
    62
  done
370dae790b30 more sorrys fileld
Chengsong
parents: 486
diff changeset
    63
370dae790b30 more sorrys fileld
Chengsong
parents: 486
diff changeset
    64
478
Chengsong
parents: 476
diff changeset
    65
lemma rdistinct_does_the_job:
Chengsong
parents: 476
diff changeset
    66
  shows "distinct (rdistinct rs s)"
Chengsong
parents: 476
diff changeset
    67
  apply(induct rs arbitrary: s)
488
370dae790b30 more sorrys fileld
Chengsong
parents: 486
diff changeset
    68
  apply simp
478
Chengsong
parents: 476
diff changeset
    69
  apply simp
488
370dae790b30 more sorrys fileld
Chengsong
parents: 486
diff changeset
    70
  apply(auto)
370dae790b30 more sorrys fileld
Chengsong
parents: 486
diff changeset
    71
  by (simp add: rdistinct1)
370dae790b30 more sorrys fileld
Chengsong
parents: 486
diff changeset
    72
370dae790b30 more sorrys fileld
Chengsong
parents: 486
diff changeset
    73
478
Chengsong
parents: 476
diff changeset
    74
Chengsong
parents: 476
diff changeset
    75
475
10fd25fba2ba identities
Chengsong
parents: 467
diff changeset
    76
lemma rdistinct_concat:
10fd25fba2ba identities
Chengsong
parents: 467
diff changeset
    77
  shows "set rs \<subseteq> rset \<Longrightarrow> rdistinct (rs @ rsa) rset = rdistinct rsa rset"
10fd25fba2ba identities
Chengsong
parents: 467
diff changeset
    78
  apply(induct rs)
10fd25fba2ba identities
Chengsong
parents: 467
diff changeset
    79
   apply simp+
10fd25fba2ba identities
Chengsong
parents: 467
diff changeset
    80
  done
10fd25fba2ba identities
Chengsong
parents: 467
diff changeset
    81
10fd25fba2ba identities
Chengsong
parents: 467
diff changeset
    82
lemma rdistinct_concat2:
10fd25fba2ba identities
Chengsong
parents: 467
diff changeset
    83
  shows "\<forall>r \<in> set rs. r \<in> rset \<Longrightarrow> rdistinct (rs @ rsa) rset = rdistinct rsa rset"
10fd25fba2ba identities
Chengsong
parents: 467
diff changeset
    84
  by (simp add: rdistinct_concat subsetI)
10fd25fba2ba identities
Chengsong
parents: 467
diff changeset
    85
444
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
    86
467
Chengsong
parents: 465
diff changeset
    87
lemma distinct_not_exist:
Chengsong
parents: 465
diff changeset
    88
  shows "a \<notin> set rs \<Longrightarrow> rdistinct rs rset = rdistinct rs (insert a rset)"
Chengsong
parents: 465
diff changeset
    89
  apply(induct rs arbitrary: rset)
Chengsong
parents: 465
diff changeset
    90
   apply simp
Chengsong
parents: 465
diff changeset
    91
  apply(case_tac "aa \<in> rset")
Chengsong
parents: 465
diff changeset
    92
   apply simp
Chengsong
parents: 465
diff changeset
    93
  apply(subgoal_tac "a \<noteq> aa")
Chengsong
parents: 465
diff changeset
    94
   prefer 2
Chengsong
parents: 465
diff changeset
    95
  apply simp
Chengsong
parents: 465
diff changeset
    96
  apply simp
Chengsong
parents: 465
diff changeset
    97
  done
444
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
    98
478
Chengsong
parents: 476
diff changeset
    99
lemma rdistinct_on_distinct:
Chengsong
parents: 476
diff changeset
   100
  shows "distinct rs \<Longrightarrow> rdistinct rs {} = rs"
Chengsong
parents: 476
diff changeset
   101
  apply(induct rs)
Chengsong
parents: 476
diff changeset
   102
   apply simp
Chengsong
parents: 476
diff changeset
   103
  apply(subgoal_tac "rdistinct rs {} = rs")
Chengsong
parents: 476
diff changeset
   104
   prefer 2
Chengsong
parents: 476
diff changeset
   105
  apply simp
Chengsong
parents: 476
diff changeset
   106
  using distinct_not_exist by fastforce
Chengsong
parents: 476
diff changeset
   107
481
feacb89b784c christian's
Chengsong
parents: 480
diff changeset
   108
478
Chengsong
parents: 476
diff changeset
   109
lemma distinct_rdistinct_append:
481
feacb89b784c christian's
Chengsong
parents: 480
diff changeset
   110
  assumes "distinct rs1" "\<forall>r \<in> set rs1. r \<notin> acc"
feacb89b784c christian's
Chengsong
parents: 480
diff changeset
   111
  shows "rdistinct (rs1 @ rsa) acc = rs1 @ (rdistinct rsa (acc \<union> set rs1))"
feacb89b784c christian's
Chengsong
parents: 480
diff changeset
   112
  using assms
feacb89b784c christian's
Chengsong
parents: 480
diff changeset
   113
  apply(induct rs1 arbitrary: rsa acc)
feacb89b784c christian's
Chengsong
parents: 480
diff changeset
   114
   apply(auto)[1]
feacb89b784c christian's
Chengsong
parents: 480
diff changeset
   115
  apply(auto)[1]
feacb89b784c christian's
Chengsong
parents: 480
diff changeset
   116
  apply(drule_tac x="rsa" in meta_spec)
feacb89b784c christian's
Chengsong
parents: 480
diff changeset
   117
  apply(drule_tac x="{a} \<union> acc" in meta_spec)
feacb89b784c christian's
Chengsong
parents: 480
diff changeset
   118
  apply(simp)
feacb89b784c christian's
Chengsong
parents: 480
diff changeset
   119
  apply(drule meta_mp)
feacb89b784c christian's
Chengsong
parents: 480
diff changeset
   120
   apply(auto)[1]
feacb89b784c christian's
Chengsong
parents: 480
diff changeset
   121
  apply(simp)
feacb89b784c christian's
Chengsong
parents: 480
diff changeset
   122
  done
feacb89b784c christian's
Chengsong
parents: 480
diff changeset
   123
  
478
Chengsong
parents: 476
diff changeset
   124
488
370dae790b30 more sorrys fileld
Chengsong
parents: 486
diff changeset
   125
370dae790b30 more sorrys fileld
Chengsong
parents: 486
diff changeset
   126
370dae790b30 more sorrys fileld
Chengsong
parents: 486
diff changeset
   127
370dae790b30 more sorrys fileld
Chengsong
parents: 486
diff changeset
   128
lemma rdistinct_set_equality1:
370dae790b30 more sorrys fileld
Chengsong
parents: 486
diff changeset
   129
  shows "set (rdistinct rs acc) = set rs - acc"
370dae790b30 more sorrys fileld
Chengsong
parents: 486
diff changeset
   130
  apply(induct rs acc rule: rdistinct.induct)
370dae790b30 more sorrys fileld
Chengsong
parents: 486
diff changeset
   131
   apply(auto)
370dae790b30 more sorrys fileld
Chengsong
parents: 486
diff changeset
   132
  done
478
Chengsong
parents: 476
diff changeset
   133
Chengsong
parents: 476
diff changeset
   134
lemma rdistinct_set_equality:
Chengsong
parents: 476
diff changeset
   135
  shows "set (rdistinct rs {}) = set rs"
488
370dae790b30 more sorrys fileld
Chengsong
parents: 486
diff changeset
   136
  by (simp add: rdistinct_set_equality1)
478
Chengsong
parents: 476
diff changeset
   137
444
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   138
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   139
fun rflts :: "rrexp list \<Rightarrow> rrexp list"
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   140
  where 
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   141
  "rflts [] = []"
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   142
| "rflts (RZERO # rs) = rflts rs"
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   143
| "rflts ((RALTS rs1) # rs) = rs1 @ rflts rs"
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   144
| "rflts (r1 # rs) = r1 # rflts rs"
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   145
478
Chengsong
parents: 476
diff changeset
   146
lemma rflts_def_idiot:
Chengsong
parents: 476
diff changeset
   147
  shows "\<lbrakk> a \<noteq> RZERO; \<nexists>rs1. a = RALTS rs1\<rbrakk>
Chengsong
parents: 476
diff changeset
   148
       \<Longrightarrow> rflts (a # rs) = a # rflts rs"
Chengsong
parents: 476
diff changeset
   149
  apply(case_tac a)
Chengsong
parents: 476
diff changeset
   150
       apply simp_all
Chengsong
parents: 476
diff changeset
   151
  done
Chengsong
parents: 476
diff changeset
   152
Chengsong
parents: 476
diff changeset
   153
lemma rflts_def_idiot2:
Chengsong
parents: 476
diff changeset
   154
  shows "\<lbrakk>a \<noteq> RZERO; \<nexists>rs1. a = RALTS rs1; a \<in> set rs\<rbrakk> \<Longrightarrow> a \<in> set (rflts rs)"
Chengsong
parents: 476
diff changeset
   155
  apply(induct rs)
Chengsong
parents: 476
diff changeset
   156
   apply simp
Chengsong
parents: 476
diff changeset
   157
  by (metis append.assoc in_set_conv_decomp insert_iff list.simps(15) rflts.simps(2) rflts.simps(3) rflts_def_idiot)
Chengsong
parents: 476
diff changeset
   158
Chengsong
parents: 476
diff changeset
   159
Chengsong
parents: 476
diff changeset
   160
Chengsong
parents: 476
diff changeset
   161
lemma flts_append:
Chengsong
parents: 476
diff changeset
   162
  shows "rflts (rs1 @ rs2) = rflts rs1 @ rflts rs2"
Chengsong
parents: 476
diff changeset
   163
  apply(induct rs1)
Chengsong
parents: 476
diff changeset
   164
   apply simp
Chengsong
parents: 476
diff changeset
   165
  apply(case_tac a)
Chengsong
parents: 476
diff changeset
   166
       apply simp+
Chengsong
parents: 476
diff changeset
   167
  done
Chengsong
parents: 476
diff changeset
   168
444
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   169
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   170
fun rsimp_ALTs :: " rrexp list \<Rightarrow> rrexp"
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   171
  where
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   172
  "rsimp_ALTs  [] = RZERO"
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   173
| "rsimp_ALTs [r] =  r"
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   174
| "rsimp_ALTs rs = RALTS rs"
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   175
465
Chengsong
parents: 444
diff changeset
   176
lemma rsimpalts_gte2elems:
Chengsong
parents: 444
diff changeset
   177
  shows "size rlist \<ge> 2 \<Longrightarrow> rsimp_ALTs rlist = RALTS rlist"
Chengsong
parents: 444
diff changeset
   178
  apply(induct rlist)
Chengsong
parents: 444
diff changeset
   179
   apply simp
Chengsong
parents: 444
diff changeset
   180
  apply(induct rlist)
Chengsong
parents: 444
diff changeset
   181
   apply simp
Chengsong
parents: 444
diff changeset
   182
  apply (metis Suc_le_length_iff rsimp_ALTs.simps(3))
Chengsong
parents: 444
diff changeset
   183
  by blast
Chengsong
parents: 444
diff changeset
   184
Chengsong
parents: 444
diff changeset
   185
lemma rsimpalts_conscons:
Chengsong
parents: 444
diff changeset
   186
  shows "rsimp_ALTs (r1 # rsa @ r2 # rsb) = RALTS (r1 # rsa @ r2 # rsb)"
Chengsong
parents: 444
diff changeset
   187
  by (metis Nil_is_append_conv list.exhaust rsimp_ALTs.simps(3))
Chengsong
parents: 444
diff changeset
   188
476
Chengsong
parents: 475
diff changeset
   189
lemma rsimp_alts_equal:
Chengsong
parents: 475
diff changeset
   190
  shows "rsimp_ALTs (rsa @ a # rsb @ a # rsc) = RALTS (rsa @ a # rsb @ a # rsc) "
Chengsong
parents: 475
diff changeset
   191
  by (metis append_Cons append_Nil neq_Nil_conv rsimpalts_conscons)
Chengsong
parents: 475
diff changeset
   192
465
Chengsong
parents: 444
diff changeset
   193
444
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   194
fun rsimp_SEQ :: " rrexp \<Rightarrow> rrexp \<Rightarrow> rrexp"
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   195
  where
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   196
  "rsimp_SEQ  RZERO _ = RZERO"
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   197
| "rsimp_SEQ  _ RZERO = RZERO"
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   198
| "rsimp_SEQ RONE r2 = r2"
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   199
| "rsimp_SEQ r1 r2 = RSEQ r1 r2"
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   200
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   201
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   202
fun rsimp :: "rrexp \<Rightarrow> rrexp" 
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   203
  where
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   204
  "rsimp (RSEQ r1 r2) = rsimp_SEQ  (rsimp r1) (rsimp r2)"
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   205
| "rsimp (RALTS rs) = rsimp_ALTs  (rdistinct (rflts (map rsimp rs))  {}) "
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   206
| "rsimp r = r"
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   207
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   208
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   209
fun 
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   210
  rders_simp :: "rrexp \<Rightarrow> string \<Rightarrow> rrexp"
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   211
where
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   212
  "rders_simp r [] = r"
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   213
| "rders_simp r (c#s) = rders_simp (rsimp (rder c r)) s"
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   214
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   215
fun rsize :: "rrexp \<Rightarrow> nat" where
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   216
  "rsize RZERO = 1"
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   217
| "rsize (RONE) = 1" 
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   218
| "rsize (RCHAR  c) = 1"
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   219
| "rsize (RALTS  rs) = Suc (sum_list (map rsize rs))"
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   220
| "rsize (RSEQ  r1 r2) = Suc (rsize r1 + rsize r2)"
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   221
| "rsize (RSTAR  r) = Suc (rsize r)"
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   222
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   223
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   224
lemma rder_rsimp_ALTs_commute:
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   225
  shows "  (rder x (rsimp_ALTs rs)) = rsimp_ALTs (map (rder x) rs)"
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   226
  apply(induct rs)
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   227
   apply simp
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   228
  apply(case_tac rs)
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   229
   apply simp
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   230
  apply auto
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   231
  done
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   232
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   233
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   234
lemma rsimp_aalts_smaller:
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   235
  shows "rsize (rsimp_ALTs  rs) \<le> rsize (RALTS rs)"
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   236
  apply(induct rs)
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   237
   apply simp
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   238
  apply simp
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   239
  apply(case_tac "rs = []")
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   240
   apply simp
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   241
  apply(subgoal_tac "\<exists>rsp ap. rs = ap # rsp")
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   242
   apply(erule exE)+
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   243
   apply simp
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   244
  apply simp
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   245
  by(meson neq_Nil_conv)
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 rSEQ_mono:
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   252
  shows "rsize (rsimp_SEQ r1 r2) \<le>rsize ( RSEQ r1 r2)"
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   253
  apply auto
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   254
  apply(induct r1)
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   255
       apply auto
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   256
      apply(case_tac "r2")
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   257
       apply simp_all
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   258
     apply(case_tac r2)
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   259
          apply simp_all
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   260
     apply(case_tac r2)
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   261
         apply simp_all
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   262
     apply(case_tac r2)
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   263
        apply simp_all
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   264
     apply(case_tac r2)
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   265
  apply simp_all
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   266
  done
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   267
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   268
lemma ralts_cap_mono:
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   269
  shows "rsize (RALTS rs) \<le> Suc ( sum_list (map rsize rs)) "
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   270
  by simp
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   271
478
Chengsong
parents: 476
diff changeset
   272
444
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   273
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   274
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   275
lemma rflts_mono:
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   276
  shows "sum_list (map rsize (rflts rs))\<le> sum_list (map rsize rs)"
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   277
  apply(induct rs)
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   278
  apply simp
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   279
  apply(case_tac "a = RZERO")
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   280
   apply simp
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   281
  apply(case_tac "\<exists>rs1. a = RALTS rs1")
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   282
  apply(erule exE)
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   283
   apply simp
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   284
  apply(subgoal_tac "rflts (a # rs) = a # (rflts rs)")
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   285
  prefer 2
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   286
  using rflts_def_idiot apply blast
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   287
  apply simp
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   288
  done
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   289
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   290
lemma rdistinct_smaller: shows "sum_list (map rsize (rdistinct rs ss)) \<le>
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   291
sum_list (map rsize rs )"
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   292
  apply (induct rs arbitrary: ss)
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   293
   apply simp
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   294
  by (simp add: trans_le_add2)
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   295
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   296
lemma rdistinct_phi_smaller: "sum_list (map rsize (rdistinct rs {})) \<le> sum_list (map rsize rs)"
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   297
  by (simp add: rdistinct_smaller)
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   298
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   299
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   300
lemma rsimp_alts_mono :
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   301
  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
   302
rsize (rsimp_ALTs (rdistinct (rflts (map rsimp x)) {})) \<le> Suc (sum_list (map rsize x))"
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   303
  apply(subgoal_tac "rsize (rsimp_ALTs (rdistinct (rflts (map rsimp x)) {} )) 
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   304
                    \<le> rsize (RALTS (rdistinct (rflts (map rsimp x)) {} ))")
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   305
  prefer 2
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   306
  using rsimp_aalts_smaller apply auto[1]
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   307
  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
   308
  prefer 2
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   309
  using ralts_cap_mono apply blast
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   310
  apply(subgoal_tac "sum_list (map rsize (rdistinct (rflts (map rsimp x)) {})) \<le>
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   311
                     sum_list (map rsize ( (rflts (map rsimp x))))")
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   312
  prefer 2
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   313
  using rdistinct_smaller apply presburger
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   314
  apply(subgoal_tac "sum_list (map rsize (rflts (map rsimp x))) \<le> 
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   315
                     sum_list (map rsize (map rsimp x))")
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   316
  prefer 2
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   317
  using rflts_mono apply blast
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   318
  apply(subgoal_tac "sum_list (map rsize (map rsimp x)) \<le> sum_list (map rsize x)")
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   319
  prefer 2
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   320
  
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   321
  apply (simp add: sum_list_mono)
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   322
  by linarith
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   323
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   324
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   325
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   326
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   327
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   328
lemma rsimp_mono:
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   329
  shows "rsize (rsimp r) \<le> rsize r"
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   330
  apply(induct r)
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   331
  apply simp_all
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   332
  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
   333
    apply force
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   334
  using rSEQ_mono
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   335
   apply presburger
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   336
  using rsimp_alts_mono by auto
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   337
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   338
lemma idiot:
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   339
  shows "rsimp_SEQ RONE r = r"
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   340
  apply(case_tac r)
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   341
       apply simp_all
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   342
  done
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   343
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   344
lemma no_alt_short_list_after_simp:
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   345
  shows "RALTS rs = rsimp r \<Longrightarrow> rsimp_ALTs rs = RALTS rs"
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   346
  sorry
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   347
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   348
lemma no_further_dB_after_simp:
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   349
  shows "RALTS rs = rsimp r \<Longrightarrow> rdistinct rs {} = rs"
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   350
  sorry
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   351
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   352
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   353
lemma idiot2:
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   354
  shows " \<lbrakk>r1 \<noteq> RZERO; r1 \<noteq> RONE;r2 \<noteq> RZERO\<rbrakk>
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   355
    \<Longrightarrow> rsimp_SEQ r1 r2 = RSEQ r1 r2"
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   356
  apply(case_tac r1)
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   357
       apply(case_tac r2)
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   358
  apply simp_all
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   359
     apply(case_tac r2)
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   360
  apply simp_all
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   361
     apply(case_tac r2)
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   362
  apply simp_all
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   363
   apply(case_tac r2)
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   364
  apply simp_all
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   365
  apply(case_tac r2)
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   366
       apply simp_all
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   367
  done
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   368
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   369
lemma rders__onechar:
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   370
  shows " (rders_simp r [c]) =  (rsimp (rders r [c]))"
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   371
  by simp
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   372
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   373
lemma rders_append:
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   374
  "rders c (s1 @ s2) = rders (rders c s1) s2"
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   375
  apply(induct s1 arbitrary: c s2)
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   376
  apply(simp_all)
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   377
  done
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   378
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   379
lemma rders_simp_append:
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   380
  "rders_simp c (s1 @ s2) = rders_simp (rders_simp c s1) s2"
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   381
  apply(induct s1 arbitrary: c s2)
465
Chengsong
parents: 444
diff changeset
   382
   apply(simp_all)
444
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   383
  done
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   384
480
574749f5190b a few more
Chengsong
parents: 478
diff changeset
   385
444
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   386
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   387
lemma set_related_list:
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   388
  shows "distinct rs  \<Longrightarrow> length rs = card (set rs)"
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   389
  by (simp add: distinct_card)
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   390
(*this section deals with the property of distinctBy: creates a list without duplicates*)
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   391
lemma rdistinct_never_added_twice:
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   392
  shows "rdistinct (a # rs) {a} = rdistinct rs {a}"
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   393
  by force
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   394
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   395
478
Chengsong
parents: 476
diff changeset
   396
444
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   397
476
Chengsong
parents: 475
diff changeset
   398
444
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
lemma rders_simp_one_char:
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   402
  shows "rders_simp r [c] = rsimp (rder c r)"
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   403
  apply auto
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   404
  done
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   405
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   406
lemma rsimp_idem:
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   407
  shows "rsimp (rsimp r) = rsimp r"
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   408
  sorry
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   409
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   410
corollary rsimp_inner_idem1:
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   411
  shows "rsimp r = RSEQ r1 r2 \<Longrightarrow> rsimp r1 = r1 \<and> rsimp r2 = r2"
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   412
  
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   413
  sorry
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   414
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   415
corollary rsimp_inner_idem2:
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   416
  shows "rsimp r = RALTS rs \<Longrightarrow> \<forall>r' \<in> (set rs). rsimp r' = r'"
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   417
  sorry
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   418
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   419
corollary rsimp_inner_idem3:
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   420
  shows "rsimp r = RALTS rs \<Longrightarrow> map rsimp rs = rs"
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   421
  by (meson map_idI rsimp_inner_idem2)
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   422
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   423
corollary rsimp_inner_idem4:
465
Chengsong
parents: 444
diff changeset
   424
  shows "rsimp r = RALTS rs \<Longrightarrow> rflts rs = rs"
444
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   425
  sorry
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 head_one_more_simp:
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   429
  shows "map rsimp (r # rs) = map rsimp (( rsimp r) # rs)"
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   430
  by (simp add: rsimp_idem)
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   431
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   432
lemma head_one_more_dersimp:
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   433
  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
   434
  using head_one_more_simp rders_simp_append rders_simp_one_char by presburger
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   435
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   436
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   437
488
370dae790b30 more sorrys fileld
Chengsong
parents: 486
diff changeset
   438
fun
370dae790b30 more sorrys fileld
Chengsong
parents: 486
diff changeset
   439
  RL :: "rrexp \<Rightarrow> string set"
370dae790b30 more sorrys fileld
Chengsong
parents: 486
diff changeset
   440
where
370dae790b30 more sorrys fileld
Chengsong
parents: 486
diff changeset
   441
  "RL (RZERO) = {}"
370dae790b30 more sorrys fileld
Chengsong
parents: 486
diff changeset
   442
| "RL (RONE) = {[]}"
370dae790b30 more sorrys fileld
Chengsong
parents: 486
diff changeset
   443
| "RL (RCHAR c) = {[c]}"
370dae790b30 more sorrys fileld
Chengsong
parents: 486
diff changeset
   444
| "RL (RSEQ r1 r2) = (RL r1) ;; (RL r2)"
370dae790b30 more sorrys fileld
Chengsong
parents: 486
diff changeset
   445
| "RL (RALTS rs) = (\<Union> (set (map RL rs)))"
370dae790b30 more sorrys fileld
Chengsong
parents: 486
diff changeset
   446
| "RL (RSTAR r) = (RL r)\<star>"
370dae790b30 more sorrys fileld
Chengsong
parents: 486
diff changeset
   447
370dae790b30 more sorrys fileld
Chengsong
parents: 486
diff changeset
   448
370dae790b30 more sorrys fileld
Chengsong
parents: 486
diff changeset
   449
lemma RL_rnullable:
370dae790b30 more sorrys fileld
Chengsong
parents: 486
diff changeset
   450
  shows "rnullable r = ([] \<in> RL r)"
370dae790b30 more sorrys fileld
Chengsong
parents: 486
diff changeset
   451
  apply(induct r)
370dae790b30 more sorrys fileld
Chengsong
parents: 486
diff changeset
   452
  apply(auto simp add: Sequ_def)
370dae790b30 more sorrys fileld
Chengsong
parents: 486
diff changeset
   453
  done
370dae790b30 more sorrys fileld
Chengsong
parents: 486
diff changeset
   454
370dae790b30 more sorrys fileld
Chengsong
parents: 486
diff changeset
   455
lemma RL_rder:
370dae790b30 more sorrys fileld
Chengsong
parents: 486
diff changeset
   456
  shows "RL (rder c r) = Der c (RL r)"
370dae790b30 more sorrys fileld
Chengsong
parents: 486
diff changeset
   457
  apply(induct r)
370dae790b30 more sorrys fileld
Chengsong
parents: 486
diff changeset
   458
  apply(auto simp add: Sequ_def Der_def)
370dae790b30 more sorrys fileld
Chengsong
parents: 486
diff changeset
   459
        apply (metis append_Cons)
370dae790b30 more sorrys fileld
Chengsong
parents: 486
diff changeset
   460
  using RL_rnullable apply blast
370dae790b30 more sorrys fileld
Chengsong
parents: 486
diff changeset
   461
  apply (metis append_eq_Cons_conv)
370dae790b30 more sorrys fileld
Chengsong
parents: 486
diff changeset
   462
  apply (metis append_Cons)
370dae790b30 more sorrys fileld
Chengsong
parents: 486
diff changeset
   463
  apply (metis RL_rnullable append_eq_Cons_conv)
370dae790b30 more sorrys fileld
Chengsong
parents: 486
diff changeset
   464
  apply (metis Star.step append_Cons)
370dae790b30 more sorrys fileld
Chengsong
parents: 486
diff changeset
   465
  using Star_decomp by auto
370dae790b30 more sorrys fileld
Chengsong
parents: 486
diff changeset
   466
370dae790b30 more sorrys fileld
Chengsong
parents: 486
diff changeset
   467
370dae790b30 more sorrys fileld
Chengsong
parents: 486
diff changeset
   468
370dae790b30 more sorrys fileld
Chengsong
parents: 486
diff changeset
   469
370dae790b30 more sorrys fileld
Chengsong
parents: 486
diff changeset
   470
lemma RL_rsimp_RSEQ:
370dae790b30 more sorrys fileld
Chengsong
parents: 486
diff changeset
   471
  shows "RL (rsimp_SEQ r1 r2) = (RL r1 ;; RL r2)"
370dae790b30 more sorrys fileld
Chengsong
parents: 486
diff changeset
   472
  apply(induct r1 r2 rule: rsimp_SEQ.induct)
370dae790b30 more sorrys fileld
Chengsong
parents: 486
diff changeset
   473
  apply(simp_all)
370dae790b30 more sorrys fileld
Chengsong
parents: 486
diff changeset
   474
  done
370dae790b30 more sorrys fileld
Chengsong
parents: 486
diff changeset
   475
370dae790b30 more sorrys fileld
Chengsong
parents: 486
diff changeset
   476
lemma RL_rsimp_RALTS:
370dae790b30 more sorrys fileld
Chengsong
parents: 486
diff changeset
   477
  shows "RL (rsimp_ALTs rs) = (\<Union> (set (map RL rs)))"
370dae790b30 more sorrys fileld
Chengsong
parents: 486
diff changeset
   478
  apply(induct rs rule: rsimp_ALTs.induct)
370dae790b30 more sorrys fileld
Chengsong
parents: 486
diff changeset
   479
  apply(simp_all)
370dae790b30 more sorrys fileld
Chengsong
parents: 486
diff changeset
   480
  done
370dae790b30 more sorrys fileld
Chengsong
parents: 486
diff changeset
   481
370dae790b30 more sorrys fileld
Chengsong
parents: 486
diff changeset
   482
lemma RL_rsimp_rdistinct:
370dae790b30 more sorrys fileld
Chengsong
parents: 486
diff changeset
   483
  shows "(\<Union> (set (map RL (rdistinct rs {})))) = (\<Union> (set (map RL rs)))"
370dae790b30 more sorrys fileld
Chengsong
parents: 486
diff changeset
   484
  apply(auto)
370dae790b30 more sorrys fileld
Chengsong
parents: 486
diff changeset
   485
  apply (metis rdistinct_set_equality)
370dae790b30 more sorrys fileld
Chengsong
parents: 486
diff changeset
   486
  by (metis rdistinct_set_equality)
370dae790b30 more sorrys fileld
Chengsong
parents: 486
diff changeset
   487
370dae790b30 more sorrys fileld
Chengsong
parents: 486
diff changeset
   488
lemma RL_rsimp_rflts:
370dae790b30 more sorrys fileld
Chengsong
parents: 486
diff changeset
   489
  shows "(\<Union> (set (map RL (rflts rs)))) = (\<Union> (set (map RL rs)))"
370dae790b30 more sorrys fileld
Chengsong
parents: 486
diff changeset
   490
  apply(induct rs rule: rflts.induct)
370dae790b30 more sorrys fileld
Chengsong
parents: 486
diff changeset
   491
  apply(simp_all)
370dae790b30 more sorrys fileld
Chengsong
parents: 486
diff changeset
   492
  done
370dae790b30 more sorrys fileld
Chengsong
parents: 486
diff changeset
   493
370dae790b30 more sorrys fileld
Chengsong
parents: 486
diff changeset
   494
lemma RL_rsimp:
370dae790b30 more sorrys fileld
Chengsong
parents: 486
diff changeset
   495
  shows "RL r = RL (rsimp r)"
370dae790b30 more sorrys fileld
Chengsong
parents: 486
diff changeset
   496
  apply(induct r rule: rsimp.induct)
370dae790b30 more sorrys fileld
Chengsong
parents: 486
diff changeset
   497
       apply(auto simp add: Sequ_def RL_rsimp_RSEQ)
370dae790b30 more sorrys fileld
Chengsong
parents: 486
diff changeset
   498
  using RL_rsimp_RALTS RL_rsimp_rdistinct RL_rsimp_rflts apply auto[1]
370dae790b30 more sorrys fileld
Chengsong
parents: 486
diff changeset
   499
  by (smt (verit, del_insts) RL_rsimp_RALTS RL_rsimp_rdistinct RL_rsimp_rflts UN_E image_iff list.set_map)
370dae790b30 more sorrys fileld
Chengsong
parents: 486
diff changeset
   500
370dae790b30 more sorrys fileld
Chengsong
parents: 486
diff changeset
   501
lemma RL_rders:
370dae790b30 more sorrys fileld
Chengsong
parents: 486
diff changeset
   502
  shows "RL (rders_simp r s) = RL (rders r s)"
370dae790b30 more sorrys fileld
Chengsong
parents: 486
diff changeset
   503
  apply(induct s arbitrary: r rule: rev_induct)
370dae790b30 more sorrys fileld
Chengsong
parents: 486
diff changeset
   504
   apply(simp)
370dae790b30 more sorrys fileld
Chengsong
parents: 486
diff changeset
   505
  apply(simp add: rders_append rders_simp_append) 
370dae790b30 more sorrys fileld
Chengsong
parents: 486
diff changeset
   506
  apply(subst RL_rsimp[symmetric])
370dae790b30 more sorrys fileld
Chengsong
parents: 486
diff changeset
   507
  using RL_rder by force
370dae790b30 more sorrys fileld
Chengsong
parents: 486
diff changeset
   508
  
370dae790b30 more sorrys fileld
Chengsong
parents: 486
diff changeset
   509
370dae790b30 more sorrys fileld
Chengsong
parents: 486
diff changeset
   510
lemma der_simp_nullability:
370dae790b30 more sorrys fileld
Chengsong
parents: 486
diff changeset
   511
  shows "rnullable r = rnullable (rsimp r)"
370dae790b30 more sorrys fileld
Chengsong
parents: 486
diff changeset
   512
  using RL_rnullable RL_rsimp by auto
370dae790b30 more sorrys fileld
Chengsong
parents: 486
diff changeset
   513
  
444
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   514
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   515
lemma ders_simp_nullability:
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   516
  shows "rnullable (rders r s) = rnullable (rders_simp r s)"
488
370dae790b30 more sorrys fileld
Chengsong
parents: 486
diff changeset
   517
  apply(induct s arbitrary: r rule: rev_induct)
370dae790b30 more sorrys fileld
Chengsong
parents: 486
diff changeset
   518
   apply(simp)
370dae790b30 more sorrys fileld
Chengsong
parents: 486
diff changeset
   519
  apply(simp add: rders_append rders_simp_append)
370dae790b30 more sorrys fileld
Chengsong
parents: 486
diff changeset
   520
  apply(simp only: RL_rnullable)
370dae790b30 more sorrys fileld
Chengsong
parents: 486
diff changeset
   521
  apply(simp only: RL_rder)
370dae790b30 more sorrys fileld
Chengsong
parents: 486
diff changeset
   522
  apply(subst RL_rsimp[symmetric])
370dae790b30 more sorrys fileld
Chengsong
parents: 486
diff changeset
   523
  apply(simp only: RL_rder)
370dae790b30 more sorrys fileld
Chengsong
parents: 486
diff changeset
   524
  by (simp add: RL_rders)
444
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   525
488
370dae790b30 more sorrys fileld
Chengsong
parents: 486
diff changeset
   526
370dae790b30 more sorrys fileld
Chengsong
parents: 486
diff changeset
   527
370dae790b30 more sorrys fileld
Chengsong
parents: 486
diff changeset
   528
480
574749f5190b a few more
Chengsong
parents: 478
diff changeset
   529
574749f5190b a few more
Chengsong
parents: 478
diff changeset
   530
444
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   531
lemma  first_elem_seqder:
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   532
  shows "\<not>rnullable r1p \<Longrightarrow> map rsimp (rder x (RSEQ r1p r2)
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   533
                   # rs) = map rsimp ((RSEQ (rder x r1p) r2) # rs) "
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   534
  by auto
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   535
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   536
lemma first_elem_seqder1:
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   537
  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
   538
                                          map rsimp ( (RSEQ (rsimp (rder x (rders_simp r xs))) r2) # rs)"
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   539
  by (simp add: rsimp_idem)
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   540
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   541
lemma first_elem_seqdersimps:
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   542
  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
   543
                                          map rsimp ( (RSEQ (rders_simp r (xs @ [x])) r2) # rs)"
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   544
  using first_elem_seqder1 rders_simp_append by auto
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   545
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   546
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   547
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   548
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   549
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   550
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   551
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   552
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   553
478
Chengsong
parents: 476
diff changeset
   554
lemma idem_after_simp1:
Chengsong
parents: 476
diff changeset
   555
  shows "rsimp_ALTs (rdistinct (rflts [rsimp aa]) {}) = rsimp aa"
Chengsong
parents: 476
diff changeset
   556
  apply(case_tac "rsimp aa")
Chengsong
parents: 476
diff changeset
   557
  apply simp+
Chengsong
parents: 476
diff changeset
   558
  apply (metis no_alt_short_list_after_simp no_further_dB_after_simp)
Chengsong
parents: 476
diff changeset
   559
  by simp
Chengsong
parents: 476
diff changeset
   560
Chengsong
parents: 476
diff changeset
   561
lemma identity_wwo0:
Chengsong
parents: 476
diff changeset
   562
  shows "rsimp (rsimp_ALTs (RZERO # rs)) = rsimp (rsimp_ALTs rs)"
Chengsong
parents: 476
diff changeset
   563
  by (metis idem_after_simp1 list.exhaust list.simps(8) list.simps(9) rflts.simps(2) rsimp.simps(2) rsimp.simps(3) rsimp_ALTs.simps(1) rsimp_ALTs.simps(2) rsimp_ALTs.simps(3))
Chengsong
parents: 476
diff changeset
   564
Chengsong
parents: 476
diff changeset
   565
Chengsong
parents: 476
diff changeset
   566
lemma distinct_removes_last:
Chengsong
parents: 476
diff changeset
   567
  shows "\<lbrakk>a \<in> set as\<rbrakk>
Chengsong
parents: 476
diff changeset
   568
    \<Longrightarrow> rdistinct as rset = rdistinct (as @ [a]) rset"
Chengsong
parents: 476
diff changeset
   569
and "rdistinct (ab # as @ [ab]) rset1 = rdistinct (ab # as) rset1"
Chengsong
parents: 476
diff changeset
   570
  apply(induct as arbitrary: rset ab rset1 a)
Chengsong
parents: 476
diff changeset
   571
     apply simp
Chengsong
parents: 476
diff changeset
   572
    apply simp
Chengsong
parents: 476
diff changeset
   573
  apply(case_tac "aa \<in> rset")
Chengsong
parents: 476
diff changeset
   574
   apply(case_tac "a = aa")
Chengsong
parents: 476
diff changeset
   575
  apply (metis append_Cons)
Chengsong
parents: 476
diff changeset
   576
    apply simp
Chengsong
parents: 476
diff changeset
   577
   apply(case_tac "a \<in> set as")
Chengsong
parents: 476
diff changeset
   578
  apply (metis append_Cons rdistinct.simps(2) set_ConsD)
Chengsong
parents: 476
diff changeset
   579
   apply(case_tac "a = aa")
Chengsong
parents: 476
diff changeset
   580
    prefer 2
Chengsong
parents: 476
diff changeset
   581
    apply simp
Chengsong
parents: 476
diff changeset
   582
   apply (metis append_Cons)
Chengsong
parents: 476
diff changeset
   583
  apply(case_tac "ab \<in> rset1")
Chengsong
parents: 476
diff changeset
   584
  prefer 2
Chengsong
parents: 476
diff changeset
   585
   apply(subgoal_tac "rdistinct (ab # (a # as) @ [ab]) rset1 = 
Chengsong
parents: 476
diff changeset
   586
               ab # (rdistinct ((a # as) @ [ab]) (insert ab rset1))")
Chengsong
parents: 476
diff changeset
   587
  prefer 2
Chengsong
parents: 476
diff changeset
   588
  apply force
Chengsong
parents: 476
diff changeset
   589
  apply(simp only:)
Chengsong
parents: 476
diff changeset
   590
     apply(subgoal_tac "rdistinct (ab # a # as) rset1 = ab # (rdistinct (a # as) (insert ab rset1))")
Chengsong
parents: 476
diff changeset
   591
    apply(simp only:)
Chengsong
parents: 476
diff changeset
   592
    apply(subgoal_tac "rdistinct ((a # as) @ [ab]) (insert ab rset1) = rdistinct (a # as) (insert ab rset1)")
Chengsong
parents: 476
diff changeset
   593
     apply blast
Chengsong
parents: 476
diff changeset
   594
    apply(case_tac "a \<in> insert ab rset1")
Chengsong
parents: 476
diff changeset
   595
     apply simp
Chengsong
parents: 476
diff changeset
   596
     apply (metis insertI1)
Chengsong
parents: 476
diff changeset
   597
    apply simp
Chengsong
parents: 476
diff changeset
   598
    apply (meson insertI1)
Chengsong
parents: 476
diff changeset
   599
   apply simp
Chengsong
parents: 476
diff changeset
   600
  apply(subgoal_tac "rdistinct ((a # as) @ [ab]) rset1 = rdistinct (a # as) rset1")
Chengsong
parents: 476
diff changeset
   601
   apply simp
Chengsong
parents: 476
diff changeset
   602
  by (metis append_Cons insert_iff insert_is_Un rdistinct.simps(2))
Chengsong
parents: 476
diff changeset
   603
Chengsong
parents: 476
diff changeset
   604
Chengsong
parents: 476
diff changeset
   605
lemma distinct_removes_middle:
Chengsong
parents: 476
diff changeset
   606
  shows  "\<lbrakk>a \<in> set as\<rbrakk>
Chengsong
parents: 476
diff changeset
   607
    \<Longrightarrow> rdistinct (as @ as2) rset = rdistinct (as @ [a] @ as2) rset"
Chengsong
parents: 476
diff changeset
   608
and "rdistinct (ab # as @ [ab] @ as3) rset1 = rdistinct (ab # as @ as3) rset1"
Chengsong
parents: 476
diff changeset
   609
   apply(induct as arbitrary: rset rset1 ab as2 as3 a)
Chengsong
parents: 476
diff changeset
   610
     apply simp
Chengsong
parents: 476
diff changeset
   611
    apply simp
Chengsong
parents: 476
diff changeset
   612
   apply(case_tac "a \<in> rset")
Chengsong
parents: 476
diff changeset
   613
    apply simp
Chengsong
parents: 476
diff changeset
   614
    apply metis
Chengsong
parents: 476
diff changeset
   615
   apply simp
Chengsong
parents: 476
diff changeset
   616
   apply (metis insertI1)
Chengsong
parents: 476
diff changeset
   617
  apply(case_tac "a = ab")
Chengsong
parents: 476
diff changeset
   618
   apply simp
Chengsong
parents: 476
diff changeset
   619
   apply(case_tac "ab \<in> rset")
Chengsong
parents: 476
diff changeset
   620
    apply simp
Chengsong
parents: 476
diff changeset
   621
    apply presburger
Chengsong
parents: 476
diff changeset
   622
   apply (meson insertI1)
Chengsong
parents: 476
diff changeset
   623
  apply(case_tac "a \<in> rset")
Chengsong
parents: 476
diff changeset
   624
  apply (metis (no_types, opaque_lifting) Un_insert_left append_Cons insert_iff rdistinct.simps(2) sup_bot_left)
Chengsong
parents: 476
diff changeset
   625
  apply(case_tac "ab \<in> rset")
Chengsong
parents: 476
diff changeset
   626
  apply simp
Chengsong
parents: 476
diff changeset
   627
   apply (meson insert_iff)
Chengsong
parents: 476
diff changeset
   628
  apply simp
Chengsong
parents: 476
diff changeset
   629
  by (metis insertI1)
Chengsong
parents: 476
diff changeset
   630
Chengsong
parents: 476
diff changeset
   631
Chengsong
parents: 476
diff changeset
   632
lemma distinct_removes_middle3:
Chengsong
parents: 476
diff changeset
   633
  shows  "\<lbrakk>a \<in> set as\<rbrakk>
Chengsong
parents: 476
diff changeset
   634
    \<Longrightarrow> rdistinct (as @ a #as2) rset = rdistinct (as @ as2) rset"
Chengsong
parents: 476
diff changeset
   635
  using distinct_removes_middle(1) by fastforce
Chengsong
parents: 476
diff changeset
   636
Chengsong
parents: 476
diff changeset
   637
lemma distinct_removes_last2:
Chengsong
parents: 476
diff changeset
   638
  shows "\<lbrakk>a \<in> set as\<rbrakk>
Chengsong
parents: 476
diff changeset
   639
    \<Longrightarrow> rdistinct as rset = rdistinct (as @ [a]) rset"
Chengsong
parents: 476
diff changeset
   640
  by (simp add: distinct_removes_last(1))
Chengsong
parents: 476
diff changeset
   641
Chengsong
parents: 476
diff changeset
   642
lemma distinct_removes_middle2:
Chengsong
parents: 476
diff changeset
   643
  shows "a \<in> set as \<Longrightarrow> rdistinct (as @ [a] @ rs) {} = rdistinct (as @ rs) {}"
Chengsong
parents: 476
diff changeset
   644
  by (metis distinct_removes_middle(1))
Chengsong
parents: 476
diff changeset
   645
Chengsong
parents: 476
diff changeset
   646
lemma distinct_removes_list:
Chengsong
parents: 476
diff changeset
   647
  shows "\<lbrakk> \<forall>r \<in> set rs. r \<in> set as\<rbrakk> \<Longrightarrow> rdistinct (as @ rs) {} = rdistinct as {}"
Chengsong
parents: 476
diff changeset
   648
  apply(induct rs)
Chengsong
parents: 476
diff changeset
   649
   apply simp+
Chengsong
parents: 476
diff changeset
   650
  apply(subgoal_tac "rdistinct (as @ a # rs) {} = rdistinct (as @ rs) {}")
Chengsong
parents: 476
diff changeset
   651
   prefer 2
Chengsong
parents: 476
diff changeset
   652
  apply (metis append_Cons append_Nil distinct_removes_middle(1))
Chengsong
parents: 476
diff changeset
   653
  by presburger
Chengsong
parents: 476
diff changeset
   654
Chengsong
parents: 476
diff changeset
   655
Chengsong
parents: 476
diff changeset
   656
lemma spawn_simp_rsimpalts:
Chengsong
parents: 476
diff changeset
   657
  shows "rsimp (rsimp_ALTs rs) = rsimp (rsimp_ALTs (map rsimp rs))"
Chengsong
parents: 476
diff changeset
   658
  apply(cases rs)
Chengsong
parents: 476
diff changeset
   659
   apply simp
Chengsong
parents: 476
diff changeset
   660
  apply(case_tac list)
Chengsong
parents: 476
diff changeset
   661
   apply simp
Chengsong
parents: 476
diff changeset
   662
   apply(subst rsimp_idem[symmetric])
Chengsong
parents: 476
diff changeset
   663
   apply simp
Chengsong
parents: 476
diff changeset
   664
  apply(subgoal_tac "rsimp_ALTs rs = RALTS rs")
Chengsong
parents: 476
diff changeset
   665
   apply(simp only:)
Chengsong
parents: 476
diff changeset
   666
   apply(subgoal_tac "rsimp_ALTs (map rsimp rs) = RALTS (map rsimp rs)")
Chengsong
parents: 476
diff changeset
   667
    apply(simp only:)
Chengsong
parents: 476
diff changeset
   668
  prefer 2
Chengsong
parents: 476
diff changeset
   669
  apply simp
Chengsong
parents: 476
diff changeset
   670
   prefer 2
Chengsong
parents: 476
diff changeset
   671
  using rsimp_ALTs.simps(3) apply presburger
Chengsong
parents: 476
diff changeset
   672
  apply auto
Chengsong
parents: 476
diff changeset
   673
  apply(subst rsimp_idem)+
Chengsong
parents: 476
diff changeset
   674
  by (metis comp_apply rsimp_idem)
444
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   675
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   676
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   677
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   678
478
Chengsong
parents: 476
diff changeset
   679
inductive good1 :: "rrexp \<Rightarrow> bool"
Chengsong
parents: 476
diff changeset
   680
  where
Chengsong
parents: 476
diff changeset
   681
"\<lbrakk>RZERO \<notin> set rs; \<nexists>rs1. RALTS rs1 \<in> set rs\<rbrakk> \<Longrightarrow> good1 (RALTS rs)"
Chengsong
parents: 476
diff changeset
   682
|"good1 RZERO"
Chengsong
parents: 476
diff changeset
   683
|"good1 RONE"
Chengsong
parents: 476
diff changeset
   684
|"good1 (RCHAR c)"
Chengsong
parents: 476
diff changeset
   685
|"good1 (RSEQ r1 r2)"
Chengsong
parents: 476
diff changeset
   686
|"good1 (RSTAR r0)"
444
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   687
478
Chengsong
parents: 476
diff changeset
   688
inductive goods :: "rrexp list \<Rightarrow> bool"
Chengsong
parents: 476
diff changeset
   689
  where
Chengsong
parents: 476
diff changeset
   690
 "goods []"
Chengsong
parents: 476
diff changeset
   691
|"\<lbrakk>goods rs; r \<noteq> RZERO; \<nexists>rs1. RALTS rs1 = r\<rbrakk> \<Longrightarrow> goods (r # rs)"
Chengsong
parents: 476
diff changeset
   692
Chengsong
parents: 476
diff changeset
   693
lemma goods_good1:
Chengsong
parents: 476
diff changeset
   694
  shows "goods rs = good1 (RALTS rs)"
Chengsong
parents: 476
diff changeset
   695
  apply(induct rs)
Chengsong
parents: 476
diff changeset
   696
  apply (simp add: good1.intros(1) goods.intros(1))
Chengsong
parents: 476
diff changeset
   697
  apply(case_tac "goods rs")
Chengsong
parents: 476
diff changeset
   698
   apply(case_tac a)
Chengsong
parents: 476
diff changeset
   699
        apply simp
Chengsong
parents: 476
diff changeset
   700
  using good1.simps goods.cases apply auto[1]
Chengsong
parents: 476
diff changeset
   701
  apply (simp add: good1.simps goods.intros(2))
Chengsong
parents: 476
diff changeset
   702
  apply (simp add: good1.simps goods.intros(2))
Chengsong
parents: 476
diff changeset
   703
     apply (simp add: good1.simps goods.intros(2))
Chengsong
parents: 476
diff changeset
   704
  using good1.simps goods.cases apply auto[1]
Chengsong
parents: 476
diff changeset
   705
  apply (metis good1.cases good1.intros(1) goods.intros(2) rrexp.distinct(15) rrexp.distinct(21) rrexp.distinct(25) rrexp.distinct(29) rrexp.distinct(7) rrexp.distinct(9) rrexp.inject(3) set_ConsD)
Chengsong
parents: 476
diff changeset
   706
  apply simp
Chengsong
parents: 476
diff changeset
   707
  by (metis good1.cases good1.intros(1) goods.cases list.distinct(1) list.inject list.set_intros(2) rrexp.distinct(15) rrexp.distinct(29) rrexp.distinct(7) rrexp.inject(3) rrexp.simps(26) rrexp.simps(30))
Chengsong
parents: 476
diff changeset
   708
488
370dae790b30 more sorrys fileld
Chengsong
parents: 486
diff changeset
   709
lemma rsimp_good10:
370dae790b30 more sorrys fileld
Chengsong
parents: 486
diff changeset
   710
  shows "good1 (rsimp r)"
370dae790b30 more sorrys fileld
Chengsong
parents: 486
diff changeset
   711
  apply(induct r)
370dae790b30 more sorrys fileld
Chengsong
parents: 486
diff changeset
   712
       apply simp
370dae790b30 more sorrys fileld
Chengsong
parents: 486
diff changeset
   713
  
370dae790b30 more sorrys fileld
Chengsong
parents: 486
diff changeset
   714
       apply (simp add: good1.intros(2))
370dae790b30 more sorrys fileld
Chengsong
parents: 486
diff changeset
   715
      apply simp
370dae790b30 more sorrys fileld
Chengsong
parents: 486
diff changeset
   716
370dae790b30 more sorrys fileld
Chengsong
parents: 486
diff changeset
   717
      apply (simp add: good1.intros(3))
370dae790b30 more sorrys fileld
Chengsong
parents: 486
diff changeset
   718
  
370dae790b30 more sorrys fileld
Chengsong
parents: 486
diff changeset
   719
  apply (simp add: good1.intros(4))
370dae790b30 more sorrys fileld
Chengsong
parents: 486
diff changeset
   720
  sledgehammer
370dae790b30 more sorrys fileld
Chengsong
parents: 486
diff changeset
   721
370dae790b30 more sorrys fileld
Chengsong
parents: 486
diff changeset
   722
  sorry
370dae790b30 more sorrys fileld
Chengsong
parents: 486
diff changeset
   723
478
Chengsong
parents: 476
diff changeset
   724
lemma rsimp_good1:
Chengsong
parents: 476
diff changeset
   725
  shows "rsimp r = r1 \<Longrightarrow> good1 r1"
488
370dae790b30 more sorrys fileld
Chengsong
parents: 486
diff changeset
   726
  using rsimp_good10 by blast
478
Chengsong
parents: 476
diff changeset
   727
488
370dae790b30 more sorrys fileld
Chengsong
parents: 486
diff changeset
   728
  
478
Chengsong
parents: 476
diff changeset
   729
Chengsong
parents: 476
diff changeset
   730
lemma rsimp_no_dup:
Chengsong
parents: 476
diff changeset
   731
  shows "rsimp r = RALTS rs \<Longrightarrow> distinct rs"
Chengsong
parents: 476
diff changeset
   732
  sorry
Chengsong
parents: 476
diff changeset
   733
Chengsong
parents: 476
diff changeset
   734
Chengsong
parents: 476
diff changeset
   735
lemma rsimp_good1_2:
Chengsong
parents: 476
diff changeset
   736
  shows "map rsimp rsa = [RALTS rs] \<Longrightarrow> good1 (RALTS rs)"
Chengsong
parents: 476
diff changeset
   737
  by (metis Cons_eq_map_D rsimp_good1)
Chengsong
parents: 476
diff changeset
   738
  
Chengsong
parents: 476
diff changeset
   739
Chengsong
parents: 476
diff changeset
   740
Chengsong
parents: 476
diff changeset
   741
lemma simp_singlealt_flatten:
Chengsong
parents: 476
diff changeset
   742
  shows "rsimp (RALTS [RALTS rsa]) = rsimp (RALTS (rsa @ []))"
Chengsong
parents: 476
diff changeset
   743
  apply(induct rsa)
Chengsong
parents: 476
diff changeset
   744
   apply simp
Chengsong
parents: 476
diff changeset
   745
  apply simp
Chengsong
parents: 476
diff changeset
   746
  by (metis idem_after_simp1 list.simps(9) rsimp.simps(2))
Chengsong
parents: 476
diff changeset
   747
Chengsong
parents: 476
diff changeset
   748
Chengsong
parents: 476
diff changeset
   749
lemma good1_rsimpalts:
Chengsong
parents: 476
diff changeset
   750
  shows "rsimp r = RALTS rs \<Longrightarrow> rsimp_ALTs rs = RALTS rs"
Chengsong
parents: 476
diff changeset
   751
  by (metis no_alt_short_list_after_simp) 
Chengsong
parents: 476
diff changeset
   752
  
Chengsong
parents: 476
diff changeset
   753
Chengsong
parents: 476
diff changeset
   754
lemma good1_flts:
Chengsong
parents: 476
diff changeset
   755
  shows "good1 (RALTS rs1) \<Longrightarrow> rflts rs1 = rs1"
Chengsong
parents: 476
diff changeset
   756
  apply(induct rs1)
Chengsong
parents: 476
diff changeset
   757
   apply simp 
Chengsong
parents: 476
diff changeset
   758
  by (metis good1.cases good1.intros(1) list.set_intros(1) rflts_def_idiot rrexp.distinct(21) rrexp.distinct(25) rrexp.distinct(29) rrexp.inject(3) rsimp.simps(3) rsimp.simps(4) rsimp_inner_idem4 set_subset_Cons subsetD)
Chengsong
parents: 476
diff changeset
   759
 
Chengsong
parents: 476
diff changeset
   760
Chengsong
parents: 476
diff changeset
   761
Chengsong
parents: 476
diff changeset
   762
lemma good1_flatten:
Chengsong
parents: 476
diff changeset
   763
  shows "\<lbrakk> rsimp r =  (RALTS rs1)\<rbrakk>
Chengsong
parents: 476
diff changeset
   764
       \<Longrightarrow> rflts (rsimp_ALTs rs1 # map rsimp rsb) = rflts (rs1 @ map rsimp rsb)"
Chengsong
parents: 476
diff changeset
   765
  apply(subst good1_rsimpalts)
Chengsong
parents: 476
diff changeset
   766
   apply simp+
Chengsong
parents: 476
diff changeset
   767
  apply(subgoal_tac "rflts (rs1 @ map rsimp rsb) = rs1 @ rflts (map rsimp rsb)")
Chengsong
parents: 476
diff changeset
   768
   apply simp
Chengsong
parents: 476
diff changeset
   769
  apply(subgoal_tac "good1 (RALTS rs1)")
Chengsong
parents: 476
diff changeset
   770
  prefer 2
Chengsong
parents: 476
diff changeset
   771
  using rsimp_good1 apply blast
Chengsong
parents: 476
diff changeset
   772
  using flts_append good1_flts by presburger
Chengsong
parents: 476
diff changeset
   773
Chengsong
parents: 476
diff changeset
   774
lemma flatten_rsimpalts:
Chengsong
parents: 476
diff changeset
   775
  shows "rflts (rsimp_ALTs (rdistinct (rflts (map rsimp rsa)) {}) # map rsimp rsb) = 
Chengsong
parents: 476
diff changeset
   776
         rflts ( (rdistinct (rflts (map rsimp rsa)) {}) @ map rsimp rsb)"
Chengsong
parents: 476
diff changeset
   777
  apply(case_tac "map rsimp rsa")
Chengsong
parents: 476
diff changeset
   778
   apply simp
Chengsong
parents: 476
diff changeset
   779
  apply(case_tac "list")
Chengsong
parents: 476
diff changeset
   780
   apply simp
Chengsong
parents: 476
diff changeset
   781
   apply(case_tac a)
Chengsong
parents: 476
diff changeset
   782
        apply simp+
Chengsong
parents: 476
diff changeset
   783
    apply(rename_tac rs1)
Chengsong
parents: 476
diff changeset
   784
    apply(subgoal_tac "good1 (RALTS rs1)")
Chengsong
parents: 476
diff changeset
   785
     apply(subgoal_tac "distinct rs1")
Chengsong
parents: 476
diff changeset
   786
  apply(subst rdistinct_on_distinct)
Chengsong
parents: 476
diff changeset
   787
  apply blast
Chengsong
parents: 476
diff changeset
   788
  apply(subst rdistinct_on_distinct)
Chengsong
parents: 476
diff changeset
   789
       apply blast
Chengsong
parents: 476
diff changeset
   790
  using good1_flatten apply blast
Chengsong
parents: 476
diff changeset
   791
 
Chengsong
parents: 476
diff changeset
   792
  using rsimp_no_dup apply force
Chengsong
parents: 476
diff changeset
   793
  
Chengsong
parents: 476
diff changeset
   794
  using rsimp_good1_2 apply presburger
Chengsong
parents: 476
diff changeset
   795
Chengsong
parents: 476
diff changeset
   796
   apply simp+
Chengsong
parents: 476
diff changeset
   797
  apply(case_tac "rflts (a # aa # lista)")
Chengsong
parents: 476
diff changeset
   798
   apply simp
Chengsong
parents: 476
diff changeset
   799
  by (smt (verit) append_Cons append_Nil empty_iff good1_flatten list.distinct(1) rdistinct.simps(2) rsimp.simps(2) rsimp_ALTs.elims rsimp_good1)
Chengsong
parents: 476
diff changeset
   800
Chengsong
parents: 476
diff changeset
   801
Chengsong
parents: 476
diff changeset
   802
lemma flts_good_good:
Chengsong
parents: 476
diff changeset
   803
  shows "\<forall>r \<in> set rs. good1 r \<Longrightarrow> good1 (RALTS (rflts rs ))"
Chengsong
parents: 476
diff changeset
   804
  apply(induct rs)
Chengsong
parents: 476
diff changeset
   805
   apply simp
Chengsong
parents: 476
diff changeset
   806
  using goods.intros(1) goods_good1 apply auto[1]
Chengsong
parents: 476
diff changeset
   807
  apply(case_tac  "a")
Chengsong
parents: 476
diff changeset
   808
  apply simp
Chengsong
parents: 476
diff changeset
   809
  apply (metis goods.intros(2) goods_good1 list.set_intros(2) rflts.simps(4) rrexp.distinct(1) rrexp.distinct(15))
Chengsong
parents: 476
diff changeset
   810
     apply simp
Chengsong
parents: 476
diff changeset
   811
  using goods.intros(2) goods_good1 apply blast
Chengsong
parents: 476
diff changeset
   812
  using goods.intros(2) goods_good1 apply auto[1]
Chengsong
parents: 476
diff changeset
   813
   apply(subgoal_tac "good1 a")
Chengsong
parents: 476
diff changeset
   814
  apply (metis Un_iff good1.cases good1.intros(1) list.set_intros(2) rflts.simps(3) rrexp.distinct(15) rrexp.distinct(21) rrexp.distinct(25) rrexp.distinct(29) rrexp.distinct(7) rrexp.inject(3) set_append)
Chengsong
parents: 476
diff changeset
   815
  apply simp
Chengsong
parents: 476
diff changeset
   816
  by (metis goods.intros(2) goods_good1 list.set_intros(2) rflts.simps(7) rrexp.distinct(29) rrexp.distinct(9))
Chengsong
parents: 476
diff changeset
   817
Chengsong
parents: 476
diff changeset
   818
Chengsong
parents: 476
diff changeset
   819
lemma simp_flatten_aux1:
Chengsong
parents: 476
diff changeset
   820
  shows "\<forall>r \<in> set (map rsimp rsa). good1 r"
Chengsong
parents: 476
diff changeset
   821
  apply(induct rsa)
Chengsong
parents: 476
diff changeset
   822
   apply(simp add: goods.intros)
Chengsong
parents: 476
diff changeset
   823
  using rsimp_good1 by auto
Chengsong
parents: 476
diff changeset
   824
Chengsong
parents: 476
diff changeset
   825
Chengsong
parents: 476
diff changeset
   826
Chengsong
parents: 476
diff changeset
   827
lemma simp_flatten_aux:
Chengsong
parents: 476
diff changeset
   828
  shows "\<forall>r \<in> set rs. good1 r \<Longrightarrow> rflts (rdistinct (rflts rs) {}) = (rdistinct (rflts rs) {})"
Chengsong
parents: 476
diff changeset
   829
  sorry
476
Chengsong
parents: 475
diff changeset
   830
444
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   831
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   832
488
370dae790b30 more sorrys fileld
Chengsong
parents: 486
diff changeset
   833
lemma rdistinct_concat_general:
370dae790b30 more sorrys fileld
Chengsong
parents: 486
diff changeset
   834
  shows "rdistinct (rs1 @ rs2) {} = (rdistinct rs1 {}) @ (rdistinct rs2 (set rs1))"
370dae790b30 more sorrys fileld
Chengsong
parents: 486
diff changeset
   835
  
370dae790b30 more sorrys fileld
Chengsong
parents: 486
diff changeset
   836
  sorry
370dae790b30 more sorrys fileld
Chengsong
parents: 486
diff changeset
   837
370dae790b30 more sorrys fileld
Chengsong
parents: 486
diff changeset
   838
lemma distinct_once_enough:
370dae790b30 more sorrys fileld
Chengsong
parents: 486
diff changeset
   839
  shows "rdistinct (rs @ rsa) {} = rdistinct (rdistinct rs {} @ rsa) {}"
370dae790b30 more sorrys fileld
Chengsong
parents: 486
diff changeset
   840
  apply(subgoal_tac "distinct (rdistinct rs {})")
370dae790b30 more sorrys fileld
Chengsong
parents: 486
diff changeset
   841
   apply(subgoal_tac 
370dae790b30 more sorrys fileld
Chengsong
parents: 486
diff changeset
   842
" rdistinct (rdistinct rs {} @ rsa) {} = rdistinct rs {} @ (rdistinct rsa (set rs))")
370dae790b30 more sorrys fileld
Chengsong
parents: 486
diff changeset
   843
  apply(simp only:)
370dae790b30 more sorrys fileld
Chengsong
parents: 486
diff changeset
   844
  using rdistinct_concat_general apply blast
370dae790b30 more sorrys fileld
Chengsong
parents: 486
diff changeset
   845
  apply (simp add: distinct_rdistinct_append rdistinct_set_equality)
370dae790b30 more sorrys fileld
Chengsong
parents: 486
diff changeset
   846
  by (simp add: rdistinct_does_the_job)
370dae790b30 more sorrys fileld
Chengsong
parents: 486
diff changeset
   847
  
370dae790b30 more sorrys fileld
Chengsong
parents: 486
diff changeset
   848
444
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   849
lemma simp_flatten:
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   850
  shows "rsimp (RALTS ((RALTS rsa) # rsb)) = rsimp (RALTS (rsa @ rsb))"
478
Chengsong
parents: 476
diff changeset
   851
  apply simp
Chengsong
parents: 476
diff changeset
   852
  apply(subst flatten_rsimpalts)
Chengsong
parents: 476
diff changeset
   853
  apply(simp add: flts_append)
Chengsong
parents: 476
diff changeset
   854
  apply(subgoal_tac "\<forall>r \<in> set (map rsimp rsa). good1 r")
Chengsong
parents: 476
diff changeset
   855
  apply (metis distinct_once_enough simp_flatten_aux)
Chengsong
parents: 476
diff changeset
   856
  using simp_flatten_aux1 by blast
444
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   857
478
Chengsong
parents: 476
diff changeset
   858
lemma simp_flatten3:
Chengsong
parents: 476
diff changeset
   859
  shows "rsimp (RALTS (rsa @ [RALTS rs] @ rsb)) = rsimp (RALTS (rsa @ rs @ rsb))"
444
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   860
  sorry
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   861
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   862
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   863
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   864
fun vsuf :: "char list \<Rightarrow> rrexp \<Rightarrow> char list list" where
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   865
"vsuf [] _ = []"
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   866
|"vsuf (c#cs) r1 = (if (rnullable r1) then  (vsuf cs (rder c r1)) @ [c # cs]
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   867
                                      else  (vsuf cs (rder c r1))
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   868
                   ) "
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   869
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   870
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   871
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   872
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   873
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   874
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   875
fun star_update :: "char \<Rightarrow> rrexp \<Rightarrow> char list list \<Rightarrow> char list list" where
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   876
"star_update c r [] = []"
486
f5b96a532c85 starclosed
Chengsong
parents: 481
diff changeset
   877
|"star_update c r (s # Ss) = (if (rnullable (rders r s)) 
444
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   878
                                then (s@[c]) # [c] # (star_update c r Ss) 
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   879
                               else   (s@[c]) # (star_update c r Ss) )"
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   880
486
f5b96a532c85 starclosed
Chengsong
parents: 481
diff changeset
   881
444
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   882
fun star_updates :: "char list \<Rightarrow> rrexp \<Rightarrow> char list list \<Rightarrow> char list list"
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   883
  where
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   884
"star_updates [] r Ss = Ss"
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   885
| "star_updates (c # cs) r Ss = star_updates cs r (star_update c r Ss)"
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   886
486
f5b96a532c85 starclosed
Chengsong
parents: 481
diff changeset
   887
lemma stupdates_append: shows 
f5b96a532c85 starclosed
Chengsong
parents: 481
diff changeset
   888
"star_updates (s @ [c]) r Ss = star_update c r (star_updates s r Ss)"
f5b96a532c85 starclosed
Chengsong
parents: 481
diff changeset
   889
  apply(induct s arbitrary: Ss)
f5b96a532c85 starclosed
Chengsong
parents: 481
diff changeset
   890
   apply simp
f5b96a532c85 starclosed
Chengsong
parents: 481
diff changeset
   891
  apply simp
f5b96a532c85 starclosed
Chengsong
parents: 481
diff changeset
   892
  done
f5b96a532c85 starclosed
Chengsong
parents: 481
diff changeset
   893
444
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   894
478
Chengsong
parents: 476
diff changeset
   895
lemma distinct_flts_no0:
Chengsong
parents: 476
diff changeset
   896
  shows "  rflts (map rsimp (rdistinct rs (insert RZERO rset)))  =
Chengsong
parents: 476
diff changeset
   897
           rflts (map rsimp (rdistinct rs rset))  "
Chengsong
parents: 476
diff changeset
   898
  
Chengsong
parents: 476
diff changeset
   899
  apply(induct rs arbitrary: rset)
Chengsong
parents: 476
diff changeset
   900
   apply simp
Chengsong
parents: 476
diff changeset
   901
  apply(case_tac a)
Chengsong
parents: 476
diff changeset
   902
  apply simp+
Chengsong
parents: 476
diff changeset
   903
    apply (smt (verit, ccfv_SIG) rflts.simps(2) rflts.simps(3) rflts_def_idiot)
Chengsong
parents: 476
diff changeset
   904
  prefer 2
Chengsong
parents: 476
diff changeset
   905
  apply simp  
Chengsong
parents: 476
diff changeset
   906
  by (smt (verit, ccfv_threshold) Un_insert_right insert_iff list.simps(9) rdistinct.simps(2) rflts.simps(2) rflts.simps(3) rflts_def_idiot rrexp.distinct(7))
444
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   907
478
Chengsong
parents: 476
diff changeset
   908
lemma flts_removes0:
Chengsong
parents: 476
diff changeset
   909
  shows "  rflts (rs @ [RZERO])  =
Chengsong
parents: 476
diff changeset
   910
           rflts rs"
Chengsong
parents: 476
diff changeset
   911
  apply(induct rs)
Chengsong
parents: 476
diff changeset
   912
   apply simp
Chengsong
parents: 476
diff changeset
   913
  by (metis append_Cons rflts.simps(2) rflts.simps(3) rflts_def_idiot)
Chengsong
parents: 476
diff changeset
   914
  
Chengsong
parents: 476
diff changeset
   915
Chengsong
parents: 476
diff changeset
   916
lemma rflts_spills_last:
Chengsong
parents: 476
diff changeset
   917
  shows "a = RALTS rs \<Longrightarrow> rflts (rs1 @ [a]) = rflts rs1 @ rs"
Chengsong
parents: 476
diff changeset
   918
  apply (induct rs1)
Chengsong
parents: 476
diff changeset
   919
  apply simp
Chengsong
parents: 476
diff changeset
   920
  by (metis append.assoc append_Cons rflts.simps(2) rflts.simps(3) rflts_def_idiot)
Chengsong
parents: 476
diff changeset
   921
Chengsong
parents: 476
diff changeset
   922
lemma flts_keeps1:
Chengsong
parents: 476
diff changeset
   923
  shows " rflts (rs @ [RONE]) = 
Chengsong
parents: 476
diff changeset
   924
          rflts  rs @ [RONE] "
Chengsong
parents: 476
diff changeset
   925
  apply (induct rs)
Chengsong
parents: 476
diff changeset
   926
   apply simp
Chengsong
parents: 476
diff changeset
   927
  by (metis append.assoc append_Cons rflts.simps(2) rflts.simps(3) rflts_def_idiot)
Chengsong
parents: 476
diff changeset
   928
Chengsong
parents: 476
diff changeset
   929
lemma flts_keeps_others:
Chengsong
parents: 476
diff changeset
   930
  shows "\<lbrakk>a \<noteq> RZERO; \<nexists>rs1. a = RALTS rs1\<rbrakk> \<Longrightarrow>rflts (rs @ [a]) = rflts rs @ [a]"
Chengsong
parents: 476
diff changeset
   931
  apply(induct rs)
Chengsong
parents: 476
diff changeset
   932
   apply simp
Chengsong
parents: 476
diff changeset
   933
  apply (simp add: rflts_def_idiot)
Chengsong
parents: 476
diff changeset
   934
  apply(case_tac a)
Chengsong
parents: 476
diff changeset
   935
       apply simp
Chengsong
parents: 476
diff changeset
   936
  using flts_keeps1 apply blast
Chengsong
parents: 476
diff changeset
   937
     apply (metis append.assoc append_Cons rflts.simps(2) rflts.simps(3) rflts_def_idiot)
Chengsong
parents: 476
diff changeset
   938
  apply (metis append.assoc append_Cons rflts.simps(2) rflts.simps(3) rflts_def_idiot)
Chengsong
parents: 476
diff changeset
   939
  apply blast
Chengsong
parents: 476
diff changeset
   940
  by (metis append.assoc append_Cons rflts.simps(2) rflts.simps(3) rflts_def_idiot)
Chengsong
parents: 476
diff changeset
   941
Chengsong
parents: 476
diff changeset
   942
lemma spilled_alts_contained:
Chengsong
parents: 476
diff changeset
   943
  shows "\<lbrakk>a = RALTS rs ; a \<in> set rs1\<rbrakk> \<Longrightarrow> \<forall>r \<in> set rs. r \<in> set (rflts rs1)"
Chengsong
parents: 476
diff changeset
   944
  apply(induct rs1)
Chengsong
parents: 476
diff changeset
   945
   apply simp 
Chengsong
parents: 476
diff changeset
   946
  apply(case_tac "a = aa")
Chengsong
parents: 476
diff changeset
   947
   apply simp
Chengsong
parents: 476
diff changeset
   948
  apply(subgoal_tac " a \<in> set rs1")
Chengsong
parents: 476
diff changeset
   949
  prefer 2
Chengsong
parents: 476
diff changeset
   950
   apply (meson set_ConsD)
Chengsong
parents: 476
diff changeset
   951
  apply(case_tac aa)
Chengsong
parents: 476
diff changeset
   952
  using rflts.simps(2) apply presburger
Chengsong
parents: 476
diff changeset
   953
      apply fastforce
Chengsong
parents: 476
diff changeset
   954
  apply fastforce
Chengsong
parents: 476
diff changeset
   955
  apply fastforce
Chengsong
parents: 476
diff changeset
   956
  apply fastforce
Chengsong
parents: 476
diff changeset
   957
  by fastforce
Chengsong
parents: 476
diff changeset
   958
Chengsong
parents: 476
diff changeset
   959
Chengsong
parents: 476
diff changeset
   960
lemma distinct_removes_duplicate_flts:
Chengsong
parents: 476
diff changeset
   961
  shows " a \<in> set rsa
Chengsong
parents: 476
diff changeset
   962
       \<Longrightarrow> rdistinct (rflts (map rsimp rsa @ [rsimp a])) {} =
Chengsong
parents: 476
diff changeset
   963
           rdistinct (rflts (map rsimp rsa)) {}"
Chengsong
parents: 476
diff changeset
   964
  apply(subgoal_tac "rsimp a \<in> set (map rsimp rsa)")
Chengsong
parents: 476
diff changeset
   965
  prefer 2
Chengsong
parents: 476
diff changeset
   966
  apply simp
Chengsong
parents: 476
diff changeset
   967
  apply(induct "rsimp a")
Chengsong
parents: 476
diff changeset
   968
       apply simp
Chengsong
parents: 476
diff changeset
   969
  using flts_removes0 apply presburger
Chengsong
parents: 476
diff changeset
   970
      apply(subgoal_tac " rdistinct (rflts (map rsimp rsa @ [rsimp a])) {} =  
Chengsong
parents: 476
diff changeset
   971
                          rdistinct (rflts (map rsimp rsa @ [RONE])) {}")
Chengsong
parents: 476
diff changeset
   972
      apply (simp only:)
Chengsong
parents: 476
diff changeset
   973
       apply(subst flts_keeps1)
Chengsong
parents: 476
diff changeset
   974
  apply (metis distinct_removes_last2 rflts_def_idiot2 rrexp.simps(20) rrexp.simps(6))
Chengsong
parents: 476
diff changeset
   975
      apply presburger
Chengsong
parents: 476
diff changeset
   976
        apply(subgoal_tac " rdistinct (rflts (map rsimp rsa @ [rsimp a]))    {} =  
Chengsong
parents: 476
diff changeset
   977
                            rdistinct ((rflts (map rsimp rsa)) @ [RCHAR x]) {}")
Chengsong
parents: 476
diff changeset
   978
      apply (simp only:)
Chengsong
parents: 476
diff changeset
   979
      prefer 2
Chengsong
parents: 476
diff changeset
   980
      apply (metis flts_keeps_others rrexp.distinct(21) rrexp.distinct(3))
Chengsong
parents: 476
diff changeset
   981
  apply (metis distinct_removes_last2 rflts_def_idiot2 rrexp.distinct(21) rrexp.distinct(3))
Chengsong
parents: 476
diff changeset
   982
Chengsong
parents: 476
diff changeset
   983
    apply (metis distinct_removes_last2 flts_keeps_others rflts_def_idiot2 rrexp.distinct(25) rrexp.distinct(5))
Chengsong
parents: 476
diff changeset
   984
   prefer 2
Chengsong
parents: 476
diff changeset
   985
   apply (metis distinct_removes_last2 flts_keeps_others flts_removes0 rflts_def_idiot2 rrexp.distinct(29))
Chengsong
parents: 476
diff changeset
   986
  apply(subgoal_tac "rflts (map rsimp rsa @ [rsimp a]) = rflts (map rsimp rsa) @ x")
Chengsong
parents: 476
diff changeset
   987
  prefer 2
Chengsong
parents: 476
diff changeset
   988
  apply (simp add: rflts_spills_last)
Chengsong
parents: 476
diff changeset
   989
  apply(simp only:)
Chengsong
parents: 476
diff changeset
   990
  apply(subgoal_tac "\<forall> r \<in> set x. r \<in> set (rflts (map rsimp rsa))")
Chengsong
parents: 476
diff changeset
   991
  prefer 2
Chengsong
parents: 476
diff changeset
   992
  using spilled_alts_contained apply presburger
Chengsong
parents: 476
diff changeset
   993
  using distinct_removes_list by blast
444
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   994
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   995
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   996
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   997
(*some basic facts about rsimp*)
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   998
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   999
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
  1000
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
  1001
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
  1002
end