thys2/BasicIdentities.thy
author Christian Urban <christian.urban@kcl.ac.uk>
Sat, 30 Apr 2022 00:55:30 +0100
changeset 497 04b5e904a220
parent 489 2b5b3f83e2b6
child 553 0f00d440f484
permissions -rw-r--r--
cleaned up
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
489
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   345
444
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   346
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   347
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   348
lemma idiot2:
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   349
  shows " \<lbrakk>r1 \<noteq> RZERO; r1 \<noteq> RONE;r2 \<noteq> RZERO\<rbrakk>
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   350
    \<Longrightarrow> rsimp_SEQ r1 r2 = RSEQ r1 r2"
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   351
  apply(case_tac r1)
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   352
       apply(case_tac r2)
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   353
  apply simp_all
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   354
     apply(case_tac r2)
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   355
  apply simp_all
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   356
     apply(case_tac r2)
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   357
  apply simp_all
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   358
   apply(case_tac r2)
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   359
  apply simp_all
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   360
  apply(case_tac r2)
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   361
       apply simp_all
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   362
  done
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   363
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   364
lemma rders__onechar:
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   365
  shows " (rders_simp r [c]) =  (rsimp (rders r [c]))"
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   366
  by simp
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   367
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   368
lemma rders_append:
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   369
  "rders c (s1 @ s2) = rders (rders c s1) s2"
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   370
  apply(induct s1 arbitrary: c s2)
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   371
  apply(simp_all)
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   372
  done
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   373
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   374
lemma rders_simp_append:
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   375
  "rders_simp c (s1 @ s2) = rders_simp (rders_simp c s1) s2"
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   376
  apply(induct s1 arbitrary: c s2)
465
Chengsong
parents: 444
diff changeset
   377
   apply(simp_all)
444
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   378
  done
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   379
480
574749f5190b a few more
Chengsong
parents: 478
diff changeset
   380
444
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   381
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   382
lemma set_related_list:
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   383
  shows "distinct rs  \<Longrightarrow> length rs = card (set rs)"
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   384
  by (simp add: distinct_card)
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   385
(*this section deals with the property of distinctBy: creates a list without duplicates*)
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   386
lemma rdistinct_never_added_twice:
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   387
  shows "rdistinct (a # rs) {a} = rdistinct rs {a}"
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   388
  by force
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   389
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   390
478
Chengsong
parents: 476
diff changeset
   391
444
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   392
476
Chengsong
parents: 475
diff changeset
   393
444
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   394
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   395
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   396
lemma rders_simp_one_char:
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   397
  shows "rders_simp r [c] = rsimp (rder c r)"
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   398
  apply auto
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   399
  done
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   400
489
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   401
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   402
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   403
fun nonalt :: "rrexp \<Rightarrow> bool"
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   404
  where
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   405
  "nonalt (RALTS  rs) = False"
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   406
| "nonalt r = True"
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   407
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   408
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   409
fun good :: "rrexp \<Rightarrow> bool" where
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   410
  "good RZERO = False"
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   411
| "good (RONE) = True" 
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   412
| "good (RCHAR c) = True"
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   413
| "good (RALTS []) = False"
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   414
| "good (RALTS [r]) = False"
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   415
| "good (RALTS (r1 # r2 # rs)) = ((distinct ( (r1 # r2 # rs))) \<and>(\<forall>r' \<in> set (r1 # r2 # rs). good r' \<and> nonalt r'))"
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   416
| "good (RSEQ RZERO _) = False"
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   417
| "good (RSEQ RONE _) = False"
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   418
| "good (RSEQ  _ RZERO) = False"
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   419
| "good (RSEQ r1 r2) = (good r1 \<and> good r2)"
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   420
| "good (RSTAR r) = True"
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   421
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   422
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   423
lemma  k0a:
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   424
  shows "rflts [RALTS rs] =   rs"
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   425
  apply(simp)
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   426
  done
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   427
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   428
lemma bbbbs:
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   429
  assumes "good r" "r = RALTS rs"
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   430
  shows "rsimp_ALTs  (rflts [r]) = RALTS rs"
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   431
  using  assms
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   432
  by (metis good.simps(4) good.simps(5) k0a rsimp_ALTs.elims)
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   433
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   434
lemma bbbbs1:
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   435
  shows "nonalt r \<or> (\<exists> rs. r  = RALTS  rs)"
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   436
  by (meson nonalt.elims(3))
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   437
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   438
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   439
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   440
lemma good0:
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   441
  assumes "rs \<noteq> Nil" "\<forall>r \<in> set rs. nonalt r" "distinct rs"
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   442
  shows "good (rsimp_ALTs rs) \<longleftrightarrow> (\<forall>r \<in> set rs. good r)"
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   443
  using  assms
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   444
  apply(induct  rs rule: rsimp_ALTs.induct)
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   445
  apply(auto)
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   446
  done
444
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   447
489
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   448
lemma good0a:
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   449
  assumes "rflts (map rsimp rs) \<noteq> Nil" "\<forall>r \<in> set (rflts (map rsimp rs)). nonalt r"
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   450
  shows "good (rsimp (RALTS rs)) \<longleftrightarrow> (\<forall>r \<in> set (rflts (map rsimp rs)). good r)"
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   451
  using  assms
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   452
  apply(simp)
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   453
  apply(auto)
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   454
   apply(subst (asm) good0)
444
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   455
  
489
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   456
  apply (metis rdistinct_set_equality set_empty)
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   457
   apply(simp)
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   458
    apply(auto)
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   459
     apply (metis rdistinct_set_equality)
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   460
  using rdistinct_does_the_job apply blast
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   461
  apply (metis rdistinct_set_equality)
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   462
  by (metis good0 rdistinct_does_the_job rdistinct_set_equality set_empty)
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   463
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   464
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   465
lemma flts0:
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   466
  assumes "r \<noteq> RZERO" "nonalt r"
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   467
  shows "rflts [r] \<noteq> []"
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   468
  using  assms
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   469
  apply(induct r)
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   470
       apply(simp_all)
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   471
  done
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   472
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   473
lemma flts1:
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   474
  assumes "good r" 
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   475
  shows "rflts [r] \<noteq> []"
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   476
  using  assms
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   477
  apply(induct r)
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   478
       apply(simp_all)
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   479
  using good.simps(4) by blast
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   480
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   481
lemma flts2:
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   482
  assumes "good r" 
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   483
  shows "\<forall>r' \<in> set (rflts [r]). good r' \<and> nonalt r'"
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   484
  using  assms
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   485
  apply(induct r)
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   486
       apply(simp)
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   487
      apply(simp)
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   488
     apply(simp)
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   489
    prefer 2
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   490
    apply(simp)
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   491
    apply(auto)[1]
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   492
  
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   493
     apply (metis flts1 good.simps(5) good.simps(6) k0a neq_Nil_conv)
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   494
    apply (metis flts1 good.simps(5) good.simps(6) k0a neq_Nil_conv)
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   495
   apply fastforce
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   496
  apply(simp)
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   497
  done  
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   498
444
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   499
489
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   500
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   501
lemma flts3:
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   502
  assumes "\<forall>r \<in> set rs. good r \<or> r = RZERO" 
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   503
  shows "\<forall>r \<in> set (rflts rs). good r"
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   504
  using  assms
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   505
  apply(induct rs arbitrary: rule: rflts.induct)
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   506
        apply(simp_all)
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   507
  by (metis UnE flts2 k0a)
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   508
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   509
lemma flts3b:
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   510
  assumes "\<exists>r\<in>set rs. good r"
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   511
  shows "rflts rs \<noteq> []"
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   512
  using  assms
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   513
  apply(induct rs arbitrary: rule: rflts.induct)
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   514
        apply(simp)
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   515
       apply(simp)
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   516
      apply(simp)
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   517
      apply(auto)
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   518
  done
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   519
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   520
lemma flts4:
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   521
  assumes "rsimp_ALTs (rflts rs) = RZERO"
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   522
  shows "\<forall>r \<in> set rs. \<not> good r"
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   523
  using assms
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   524
  apply(induct rs  rule: rflts.induct)
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   525
        apply(auto)
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   526
        defer
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   527
  apply (metis (no_types, lifting) Nil_is_append_conv append_self_conv2 rsimp_ALTs.elims butlast.simps(2) butlast_append flts3b nonalt.simps(1) nonalt.simps(2))
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   528
  using rsimp_ALTs.elims apply auto[1]
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   529
  using rsimp_ALTs.elims apply auto[1]
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   530
  using rsimp_ALTs.elims apply auto[1]
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   531
  using rsimp_ALTs.elims apply auto[1]
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   532
  using rsimp_ALTs.elims apply auto[1]
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   533
  by (smt (verit, del_insts) append_Cons append_is_Nil_conv bbbbs k0a list.inject rrexp.distinct(7) rsimp_ALTs.elims)
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   534
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   535
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   536
lemma  k0:
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   537
  shows "rflts (r # rs1) = rflts [r] @ rflts rs1"
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   538
  apply(induct r arbitrary: rs1)
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   539
   apply(auto)
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   540
  done
444
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   541
489
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   542
lemma flts_nil2:
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   543
  assumes "\<forall>y. rsize y < Suc (sum_list (map rsize rs)) \<longrightarrow>
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   544
            good (rsimp y) \<or> rsimp y = RZERO"
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   545
  and "rsimp_ALTs  (rflts (map rsimp rs)) = RZERO"
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   546
  shows "rflts (map rsimp rs) = []"
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   547
  using assms
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   548
  apply(induct rs)
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   549
   apply(simp)
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   550
  apply(simp)
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   551
  apply(subst k0)
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   552
  apply(simp)
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   553
  apply(subst (asm) k0)
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   554
  apply(auto)
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   555
  apply (metis rflts.simps(1) rflts.simps(2) flts4 k0 less_add_Suc1 list.set_intros(1))
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   556
  by (metis flts4 k0 less_add_Suc1 list.set_intros(1) rflts.simps(2))
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   557
444
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   558
489
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   559
lemma good_SEQ:
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   560
  assumes "r1 \<noteq> RZERO" "r2 \<noteq> RZERO" " r1 \<noteq> RONE"
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   561
  shows "good (RSEQ r1 r2) = (good r1 \<and> good r2)"
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   562
  using assms
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   563
  apply(case_tac r1)
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   564
       apply(simp_all)
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   565
  apply(case_tac r2)
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   566
          apply(simp_all)
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   567
  apply(case_tac r2)
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   568
         apply(simp_all)
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   569
  apply(case_tac r2)
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   570
        apply(simp_all)
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   571
  apply(case_tac r2)
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   572
       apply(simp_all)
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   573
  done
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   574
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   575
lemma rsize0:
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   576
  shows "0 < rsize r"
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   577
  apply(induct  r)
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   578
       apply(auto)
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   579
  done
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   580
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   581
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   582
fun nonnested :: "rrexp \<Rightarrow> bool"
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   583
  where
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   584
  "nonnested (RALTS []) = True"
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   585
| "nonnested (RALTS ((RALTS rs1) # rs2)) = False"
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   586
| "nonnested (RALTS (r # rs2)) = nonnested (RALTS rs2)"
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   587
| "nonnested r = True"
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   588
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   589
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   590
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   591
lemma  k00:
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   592
  shows "rflts (rs1 @ rs2) = rflts rs1 @ rflts rs2"
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   593
  apply(induct rs1 arbitrary: rs2)
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   594
   apply(auto)
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   595
  by (metis append.assoc k0)
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   596
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   597
444
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   598
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   599
489
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   600
lemma k0b:
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   601
  assumes "nonalt r" "r \<noteq> RZERO"
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   602
  shows "rflts [r] = [r]"
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   603
  using assms
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   604
  apply(case_tac  r)
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   605
  apply(simp_all)
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   606
  done
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   607
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   608
lemma nn1:
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   609
  assumes "nonnested (RALTS rs)"
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   610
  shows "\<nexists> rs1. rflts rs = [RALTS rs1]"
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   611
  using assms
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   612
  apply(induct rs rule: rflts.induct)
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   613
  apply(auto)
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   614
  done
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   615
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   616
lemma nn1q:
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   617
  assumes "nonnested (RALTS rs)"
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   618
  shows "\<nexists>rs1. RALTS rs1 \<in> set (rflts rs)"
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   619
  using assms
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   620
  apply(induct rs rule: rflts.induct)
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   621
  apply(auto)
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   622
  done
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   623
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   624
lemma nn1qq:
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   625
  assumes "nonnested (RALTS rs)"
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   626
  shows "\<nexists> rs1. RALTS rs1 \<in> set rs"
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   627
  using assms
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   628
  apply(induct rs rule: rflts.induct)
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   629
  apply(auto)
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   630
  done
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   631
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   632
 
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   633
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   634
lemma n0:
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   635
  shows "nonnested (RALTS rs) \<longleftrightarrow> (\<forall>r \<in> set rs. nonalt r)"
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   636
  apply(induct rs )
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   637
   apply(auto)
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   638
    apply (metis list.set_intros(1) nn1qq nonalt.elims(3))
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   639
  apply (metis nonalt.elims(2) nonnested.simps(3) nonnested.simps(4) nonnested.simps(5) nonnested.simps(6) nonnested.simps(7))
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   640
  using bbbbs1 apply fastforce
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   641
  by (metis bbbbs1 list.set_intros(2) nn1qq)
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   642
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   643
  
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   644
  
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   645
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   646
lemma nn1c:
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   647
  assumes "\<forall>r \<in> set rs. nonnested r"
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   648
  shows "\<forall>r \<in> set (rflts rs). nonalt r"
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   649
  using assms
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   650
  apply(induct rs rule: rflts.induct)
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   651
        apply(auto)
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   652
  using n0 by blast
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   653
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   654
lemma nn1bb:
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   655
  assumes "\<forall>r \<in> set rs. nonalt r"
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   656
  shows "nonnested (rsimp_ALTs  rs)"
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   657
  using assms
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   658
  apply(induct  rs rule: rsimp_ALTs.induct)
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   659
    apply(auto)
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   660
  using nonalt.simps(1) nonnested.elims(3) apply blast
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   661
  using n0 by auto
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   662
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   663
lemma bsimp_ASEQ0:
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   664
  shows "rsimp_SEQ  r1 RZERO = RZERO"
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   665
  apply(induct r1)
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   666
  apply(auto)
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   667
  done
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   668
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   669
lemma nn1b:
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   670
  shows "nonnested (rsimp r)"
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   671
  apply(induct r)
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   672
       apply(simp_all)
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   673
  apply(case_tac "rsimp r1 = RZERO")
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   674
    apply(simp)
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   675
 apply(case_tac "rsimp r2 = RZERO")
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   676
   apply(simp)
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   677
    apply(subst bsimp_ASEQ0)
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   678
  apply(simp)
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   679
  apply(case_tac "\<exists>bs. rsimp r1 = RONE")
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   680
    apply(auto)[1]
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   681
  using idiot apply fastforce
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   682
  using idiot2 nonnested.simps(11) apply presburger
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   683
  by (metis (mono_tags, lifting) image_iff list.set_map nn1bb nn1c rdistinct_set_equality)
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   684
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   685
  
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   686
lemma nn1d:
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   687
  assumes "rsimp r = RALTS rs"
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   688
  shows "\<forall>r1 \<in> set rs. \<forall>  bs. r1 \<noteq> RALTS  rs2"
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   689
  using nn1b assms
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   690
  by (metis nn1qq)
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   691
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   692
lemma nn_flts:
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   693
  assumes "nonnested (RALTS rs)"
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   694
  shows "\<forall>r \<in>  set (rflts rs). nonalt r"
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   695
  using assms
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   696
  apply(induct rs rule: rflts.induct)
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   697
        apply(auto)
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   698
  done
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   699
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   700
lemma nonalt_flts_rd:
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   701
  shows "\<lbrakk>xa \<in> set (rdistinct (rflts (map rsimp rs)) {})\<rbrakk>
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   702
       \<Longrightarrow> nonalt xa"
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   703
  by (metis ex_map_conv nn1b nn1c rdistinct_set_equality)
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   704
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   705
lemma distinct_accLarge_empty:
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   706
  shows "rset \<subseteq> rset' \<Longrightarrow> rdistinct rs rset = [] \<Longrightarrow> rdistinct rs rset' = []"
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   707
  apply(induct rs arbitrary: rset rset')
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   708
   apply simp+
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   709
  by (metis list.distinct(1) subsetD)
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   710
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   711
lemma rsimpalts_implies1:
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   712
  shows " rsimp_ALTs (a # rdistinct rs {a}) = RZERO \<Longrightarrow> a = RZERO"
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   713
  using rsimp_ALTs.elims by auto
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   714
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   715
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   716
lemma rsimpalts_implies2:
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   717
  shows "rsimp_ALTs (a # rdistinct rs rset) = RZERO \<Longrightarrow> rdistinct rs rset = []"
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   718
  by (metis append_butlast_last_id rrexp.distinct(7) rsimpalts_conscons)
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   719
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   720
lemma rsimpalts_implies21:
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   721
  shows "rsimp_ALTs (a # rdistinct rs {a}) = RZERO \<Longrightarrow> rdistinct rs {a} = []"
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   722
  using rsimpalts_implies2 by blast
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   723
444
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   724
489
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   725
lemma hollow_removemore_hollow:
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   726
  shows "rsimp_ALTs (rdistinct rs {}) = RZERO \<Longrightarrow> 
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   727
rsimp_ALTs (rdistinct rs rset) = RZERO "
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   728
  apply(induct rs arbitrary: rset)
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   729
   apply simp
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   730
  apply simp
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   731
  apply(case_tac " a \<in> rset")
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   732
   apply simp
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   733
   apply(drule_tac x = "rset" in meta_spec)
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   734
  apply (smt (verit, best) Un_insert_left empty_iff rdistinct.elims rdistinct.simps(2) rrexp.distinct(7) rsimp_ALTs.simps(1) rsimp_ALTs.simps(3) singletonD sup_bot_left)
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   735
  apply simp
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   736
  apply(subgoal_tac "a = RZERO")
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   737
  apply(subgoal_tac "rdistinct rs (insert a rset) = []")
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   738
  using rsimp_ALTs.simps(2) apply presburger
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   739
   apply(subgoal_tac "rdistinct rs {a} = []")
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   740
  apply(subgoal_tac "{a} \<subseteq> insert a rset")
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   741
  apply (meson distinct_accLarge_empty)
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   742
    apply blast
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   743
  using rsimpalts_implies21 apply blast
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   744
  using rsimpalts_implies1 by blast
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   745
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   746
lemma bsimp_ASEQ2:
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   747
  shows "rsimp_SEQ RONE r2 =  r2"
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   748
  apply(induct r2)
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   749
  apply(auto)
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   750
  done
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   751
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   752
lemma elem_smaller_than_set:
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   753
  shows "xa \<in> set  list \<Longrightarrow> rsize xa < Suc ( sum_list (map rsize list))"
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   754
  apply(induct list)
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   755
   apply simp
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   756
  by (metis image_eqI le_imp_less_Suc list.set_map member_le_sum_list)
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   757
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   758
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   759
lemma smaller_corresponding:
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   760
  shows "xa \<in> set (map rsimp list) \<Longrightarrow> \<exists>xa' \<in> set list. rsize xa \<le> rsize xa'"
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   761
  apply(induct list)
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   762
   apply simp
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   763
  by (metis list.set_intros(1) list.set_intros(2) list.simps(9) rsimp_mono set_ConsD)
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   764
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   765
lemma simpelem_smaller_than_set:
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   766
  shows "xa \<in> set (map rsimp list) \<Longrightarrow> rsize xa < Suc ( sum_list (map rsize ( list)))"
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   767
  apply(subgoal_tac "\<exists>xa' \<in> set list. rsize xa \<le> rsize xa'")
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   768
   
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   769
  using elem_smaller_than_set order_le_less_trans apply blast
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   770
  using smaller_corresponding by presburger
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   771
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   772
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   773
lemma rsimp_list_mono:
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   774
  shows "sum_list (map rsize (map rsimp rs)) \<le> sum_list (map rsize rs)"
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   775
  apply(induct rs)
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   776
   apply simp+
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   777
  by (simp add: add_mono_thms_linordered_semiring(1) rsimp_mono)
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   778
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   779
lemma good1_obvious_but_isabelle_needs_clarification:
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   780
  shows "       \<lbrakk>\<forall>y. rsize y < Suc (rsize a + sum_list (map rsize list)) \<longrightarrow> good (rsimp y) \<or> rsimp y = RZERO;
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   781
        rsimp_ALTs (rdistinct (rflts (map rsimp list)) {}) = RZERO; good (rsimp a);
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   782
        xa \<in> set (rdistinct (rflts (rsimp a # map rsimp list)) {})\<rbrakk>
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   783
       \<Longrightarrow> rsize xa < Suc (rsize a + sum_list (map rsize list))"
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   784
  apply(subgoal_tac "rsize xa \<le> 
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   785
          sum_list (map rsize (rdistinct (rflts (rsimp a # map rsimp list)) {}))")
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   786
  apply(subgoal_tac "  sum_list (map rsize (rdistinct (rflts (rsimp a # map rsimp list)) {})) \<le>
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   787
                       sum_list (map rsize ( (rflts (rsimp a # map rsimp list))))")
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   788
  apply(subgoal_tac " sum_list (map rsize ( (rflts (rsimp a # map rsimp list)))) \<le>
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   789
                      sum_list (map rsize  (rsimp a # map rsimp list))")
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   790
  apply(subgoal_tac " sum_list (map rsize (rsimp a # map rsimp list)) \<le>
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   791
                      sum_list (map rsize (a # list))")
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   792
  apply simp
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   793
  apply (metis Cons_eq_map_conv rsimp_list_mono)
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   794
  using rflts_mono apply blast
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   795
  using rdistinct_phi_smaller apply blast
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   796
  using elem_smaller_than_set less_Suc_eq_le by blast
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   797
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   798
(*says anything coming out of simp+flts+db will be good*)
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   799
lemma good2_obv_simplified:
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   800
  shows " \<lbrakk>\<forall>y. rsize y < Suc (sum_list (map rsize rs)) \<longrightarrow> good (rsimp y) \<or> rsimp y = RZERO;
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   801
           xa \<in> set (rdistinct (rflts (map rsimp rs)) {}); good (rsimp xa) \<or> rsimp xa = RZERO\<rbrakk> \<Longrightarrow> good xa"
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   802
  apply(subgoal_tac " \<forall>xa' \<in> set (map rsimp rs). good xa' \<or> xa' = RZERO")
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   803
  prefer 2
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   804
  apply (simp add: elem_smaller_than_set)
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   805
  by (metis flts3 rdistinct_set_equality)
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   806
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   807
  
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   808
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   809
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   810
lemma good2_obvious_but_isabelle_needs_clarification:
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   811
  shows "\<And>a list xa.
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   812
       \<lbrakk>\<forall>y. rsize y < Suc (rsize a + sum_list (map rsize list)) \<longrightarrow> good (rsimp y) \<or> rsimp y = RZERO;
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   813
        rsimp_ALTs (rdistinct (rflts (map rsimp list)) {}) = RZERO; good (rsimp a);
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   814
        xa \<in> set (rdistinct (rflts (rsimp a # map rsimp list)) {}); good (rsimp xa) \<or> rsimp xa = RZERO\<rbrakk>
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   815
       \<Longrightarrow> good xa"
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   816
  by (metis good2_obv_simplified list.simps(9) sum_list.Cons)
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   817
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   818
  
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   819
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   820
lemma good1:
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   821
  shows "good (rsimp a) \<or> rsimp a = RZERO"
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   822
  apply(induct a taking: rsize rule: measure_induct)
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   823
  apply(case_tac x)
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   824
  apply(simp)
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   825
  apply(simp)
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   826
  apply(simp)
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   827
  prefer 3
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   828
    apply(simp)
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   829
   prefer 2
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   830
   apply(simp only:)
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   831
   apply simp
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   832
  apply (smt (verit, ccfv_threshold) add_mono_thms_linordered_semiring(1) elem_smaller_than_set good0 good2_obv_simplified le_eq_less_or_eq nonalt_flts_rd order_less_trans plus_1_eq_Suc rdistinct_does_the_job rdistinct_phi_smaller rflts_mono rsimp_ALTs.simps(1) rsimp_list_mono)
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   833
  apply simp
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   834
  apply(subgoal_tac "good (rsimp x41) \<or> rsimp x41 = RZERO")
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   835
   apply(subgoal_tac "good (rsimp x42) \<or> rsimp x42 = RZERO")
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   836
    apply(case_tac "rsimp x41 = RZERO")
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   837
     apply simp
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   838
    apply(case_tac "rsimp x42 = RZERO")
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   839
     apply simp
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   840
  using bsimp_ASEQ0 apply blast
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   841
    apply(subgoal_tac "good (rsimp x41)")
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   842
     apply(subgoal_tac "good (rsimp x42)")
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   843
      apply simp
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   844
  apply (metis bsimp_ASEQ2 good_SEQ idiot2)
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   845
  apply blast
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   846
  apply fastforce
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   847
  using less_add_Suc2 apply blast  
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   848
  using less_iff_Suc_add by blast
444
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   849
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   850
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
   851
488
370dae790b30 more sorrys fileld
Chengsong
parents: 486
diff changeset
   852
fun
370dae790b30 more sorrys fileld
Chengsong
parents: 486
diff changeset
   853
  RL :: "rrexp \<Rightarrow> string set"
370dae790b30 more sorrys fileld
Chengsong
parents: 486
diff changeset
   854
where
370dae790b30 more sorrys fileld
Chengsong
parents: 486
diff changeset
   855
  "RL (RZERO) = {}"
370dae790b30 more sorrys fileld
Chengsong
parents: 486
diff changeset
   856
| "RL (RONE) = {[]}"
370dae790b30 more sorrys fileld
Chengsong
parents: 486
diff changeset
   857
| "RL (RCHAR c) = {[c]}"
370dae790b30 more sorrys fileld
Chengsong
parents: 486
diff changeset
   858
| "RL (RSEQ r1 r2) = (RL r1) ;; (RL r2)"
370dae790b30 more sorrys fileld
Chengsong
parents: 486
diff changeset
   859
| "RL (RALTS rs) = (\<Union> (set (map RL rs)))"
370dae790b30 more sorrys fileld
Chengsong
parents: 486
diff changeset
   860
| "RL (RSTAR r) = (RL r)\<star>"
370dae790b30 more sorrys fileld
Chengsong
parents: 486
diff changeset
   861
370dae790b30 more sorrys fileld
Chengsong
parents: 486
diff changeset
   862
370dae790b30 more sorrys fileld
Chengsong
parents: 486
diff changeset
   863
lemma RL_rnullable:
370dae790b30 more sorrys fileld
Chengsong
parents: 486
diff changeset
   864
  shows "rnullable r = ([] \<in> RL r)"
370dae790b30 more sorrys fileld
Chengsong
parents: 486
diff changeset
   865
  apply(induct r)
370dae790b30 more sorrys fileld
Chengsong
parents: 486
diff changeset
   866
  apply(auto simp add: Sequ_def)
370dae790b30 more sorrys fileld
Chengsong
parents: 486
diff changeset
   867
  done
370dae790b30 more sorrys fileld
Chengsong
parents: 486
diff changeset
   868
370dae790b30 more sorrys fileld
Chengsong
parents: 486
diff changeset
   869
lemma RL_rder:
370dae790b30 more sorrys fileld
Chengsong
parents: 486
diff changeset
   870
  shows "RL (rder c r) = Der c (RL r)"
370dae790b30 more sorrys fileld
Chengsong
parents: 486
diff changeset
   871
  apply(induct r)
370dae790b30 more sorrys fileld
Chengsong
parents: 486
diff changeset
   872
  apply(auto simp add: Sequ_def Der_def)
370dae790b30 more sorrys fileld
Chengsong
parents: 486
diff changeset
   873
        apply (metis append_Cons)
370dae790b30 more sorrys fileld
Chengsong
parents: 486
diff changeset
   874
  using RL_rnullable apply blast
370dae790b30 more sorrys fileld
Chengsong
parents: 486
diff changeset
   875
  apply (metis append_eq_Cons_conv)
370dae790b30 more sorrys fileld
Chengsong
parents: 486
diff changeset
   876
  apply (metis append_Cons)
370dae790b30 more sorrys fileld
Chengsong
parents: 486
diff changeset
   877
  apply (metis RL_rnullable append_eq_Cons_conv)
370dae790b30 more sorrys fileld
Chengsong
parents: 486
diff changeset
   878
  apply (metis Star.step append_Cons)
370dae790b30 more sorrys fileld
Chengsong
parents: 486
diff changeset
   879
  using Star_decomp by auto
370dae790b30 more sorrys fileld
Chengsong
parents: 486
diff changeset
   880
370dae790b30 more sorrys fileld
Chengsong
parents: 486
diff changeset
   881
370dae790b30 more sorrys fileld
Chengsong
parents: 486
diff changeset
   882
370dae790b30 more sorrys fileld
Chengsong
parents: 486
diff changeset
   883
370dae790b30 more sorrys fileld
Chengsong
parents: 486
diff changeset
   884
lemma RL_rsimp_RSEQ:
370dae790b30 more sorrys fileld
Chengsong
parents: 486
diff changeset
   885
  shows "RL (rsimp_SEQ r1 r2) = (RL r1 ;; RL r2)"
370dae790b30 more sorrys fileld
Chengsong
parents: 486
diff changeset
   886
  apply(induct r1 r2 rule: rsimp_SEQ.induct)
370dae790b30 more sorrys fileld
Chengsong
parents: 486
diff changeset
   887
  apply(simp_all)
370dae790b30 more sorrys fileld
Chengsong
parents: 486
diff changeset
   888
  done
370dae790b30 more sorrys fileld
Chengsong
parents: 486
diff changeset
   889
370dae790b30 more sorrys fileld
Chengsong
parents: 486
diff changeset
   890
lemma RL_rsimp_RALTS:
370dae790b30 more sorrys fileld
Chengsong
parents: 486
diff changeset
   891
  shows "RL (rsimp_ALTs rs) = (\<Union> (set (map RL rs)))"
370dae790b30 more sorrys fileld
Chengsong
parents: 486
diff changeset
   892
  apply(induct rs rule: rsimp_ALTs.induct)
370dae790b30 more sorrys fileld
Chengsong
parents: 486
diff changeset
   893
  apply(simp_all)
370dae790b30 more sorrys fileld
Chengsong
parents: 486
diff changeset
   894
  done
370dae790b30 more sorrys fileld
Chengsong
parents: 486
diff changeset
   895
370dae790b30 more sorrys fileld
Chengsong
parents: 486
diff changeset
   896
lemma RL_rsimp_rdistinct:
370dae790b30 more sorrys fileld
Chengsong
parents: 486
diff changeset
   897
  shows "(\<Union> (set (map RL (rdistinct rs {})))) = (\<Union> (set (map RL rs)))"
370dae790b30 more sorrys fileld
Chengsong
parents: 486
diff changeset
   898
  apply(auto)
370dae790b30 more sorrys fileld
Chengsong
parents: 486
diff changeset
   899
  apply (metis rdistinct_set_equality)
370dae790b30 more sorrys fileld
Chengsong
parents: 486
diff changeset
   900
  by (metis rdistinct_set_equality)
370dae790b30 more sorrys fileld
Chengsong
parents: 486
diff changeset
   901
370dae790b30 more sorrys fileld
Chengsong
parents: 486
diff changeset
   902
lemma RL_rsimp_rflts:
370dae790b30 more sorrys fileld
Chengsong
parents: 486
diff changeset
   903
  shows "(\<Union> (set (map RL (rflts rs)))) = (\<Union> (set (map RL rs)))"
370dae790b30 more sorrys fileld
Chengsong
parents: 486
diff changeset
   904
  apply(induct rs rule: rflts.induct)
370dae790b30 more sorrys fileld
Chengsong
parents: 486
diff changeset
   905
  apply(simp_all)
370dae790b30 more sorrys fileld
Chengsong
parents: 486
diff changeset
   906
  done
370dae790b30 more sorrys fileld
Chengsong
parents: 486
diff changeset
   907
370dae790b30 more sorrys fileld
Chengsong
parents: 486
diff changeset
   908
lemma RL_rsimp:
370dae790b30 more sorrys fileld
Chengsong
parents: 486
diff changeset
   909
  shows "RL r = RL (rsimp r)"
370dae790b30 more sorrys fileld
Chengsong
parents: 486
diff changeset
   910
  apply(induct r rule: rsimp.induct)
370dae790b30 more sorrys fileld
Chengsong
parents: 486
diff changeset
   911
       apply(auto simp add: Sequ_def RL_rsimp_RSEQ)
370dae790b30 more sorrys fileld
Chengsong
parents: 486
diff changeset
   912
  using RL_rsimp_RALTS RL_rsimp_rdistinct RL_rsimp_rflts apply auto[1]
370dae790b30 more sorrys fileld
Chengsong
parents: 486
diff changeset
   913
  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
   914
370dae790b30 more sorrys fileld
Chengsong
parents: 486
diff changeset
   915
lemma RL_rders:
370dae790b30 more sorrys fileld
Chengsong
parents: 486
diff changeset
   916
  shows "RL (rders_simp r s) = RL (rders r s)"
370dae790b30 more sorrys fileld
Chengsong
parents: 486
diff changeset
   917
  apply(induct s arbitrary: r rule: rev_induct)
370dae790b30 more sorrys fileld
Chengsong
parents: 486
diff changeset
   918
   apply(simp)
370dae790b30 more sorrys fileld
Chengsong
parents: 486
diff changeset
   919
  apply(simp add: rders_append rders_simp_append) 
370dae790b30 more sorrys fileld
Chengsong
parents: 486
diff changeset
   920
  apply(subst RL_rsimp[symmetric])
370dae790b30 more sorrys fileld
Chengsong
parents: 486
diff changeset
   921
  using RL_rder by force
370dae790b30 more sorrys fileld
Chengsong
parents: 486
diff changeset
   922
  
370dae790b30 more sorrys fileld
Chengsong
parents: 486
diff changeset
   923
489
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   924
lemma good1a:
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   925
  assumes "RL a \<noteq> {}"
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   926
  shows "good (rsimp a)"
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   927
  using good1 assms
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   928
  by (metis RL.simps(1) RL_rsimp)
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   929
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   930
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   931
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   932
lemma g1:
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   933
  assumes "good (rsimp_ALTs  rs)"
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   934
  shows "rsimp_ALTs  rs = RALTS rs \<or> (\<exists>r. rs = [r] \<and> rsimp_ALTs  [r] =  r)"
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   935
using assms
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   936
    apply(induct rs)
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   937
  apply(simp)
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   938
  apply(case_tac rs)
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   939
  apply(simp only:)
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   940
  apply(simp)
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   941
  apply(case_tac  list)
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   942
  apply(simp)
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   943
  by simp
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   944
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   945
lemma flts_0:
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   946
  assumes "nonnested (RALTS   rs)"
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   947
  shows "\<forall>r \<in> set (rflts rs). r \<noteq> RZERO"
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   948
  using assms
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   949
  apply(induct rs  rule: rflts.induct)
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   950
        apply(simp) 
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   951
       apply(simp) 
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   952
      defer
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   953
      apply(simp) 
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   954
     apply(simp) 
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   955
    apply(simp) 
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   956
apply(simp) 
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   957
  apply(rule ballI)
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   958
  apply(simp)
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   959
  done
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   960
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   961
lemma flts_0a:
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   962
  assumes "nonnested (RALTS   rs)"
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   963
  shows "RZERO \<notin> set (rflts rs)"
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   964
  using assms
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   965
  using flts_0 by blast 
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   966
  
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   967
lemma qqq1:
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   968
  shows "RZERO \<notin> set (rflts (map rsimp rs))"
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   969
  by (metis ex_map_conv flts3 good.simps(1) good1)
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   970
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   971
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   972
fun nonazero :: "rrexp \<Rightarrow> bool"
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   973
  where
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   974
  "nonazero RZERO = False"
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   975
| "nonazero r = True"
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   976
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   977
lemma flts_concat:
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   978
  shows "rflts rs = concat (map (\<lambda>r. rflts [r]) rs)"
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   979
  apply(induct rs)
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   980
   apply(auto)
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   981
  apply(subst k0)
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   982
  apply(simp)
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   983
  done
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   984
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   985
lemma flts_single1:
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   986
  assumes "nonalt r" "nonazero r"
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   987
  shows "rflts [r] = [r]"
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   988
  using assms
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   989
  apply(induct r)
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   990
  apply(auto)
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   991
  done
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   992
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   993
lemma flts_qq:
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   994
  assumes "\<forall>y. rsize y < Suc (sum_list (map rsize rs)) \<longrightarrow> good y \<longrightarrow> rsimp y = y" 
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   995
          "\<forall>r'\<in>set rs. good r' \<and> nonalt r'"
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   996
  shows "rflts (map rsimp rs) = rs"
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   997
  using assms
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   998
  apply(induct rs)
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
   999
   apply(simp)
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
  1000
  apply(simp)
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
  1001
  apply(subst k0)
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
  1002
  apply(subgoal_tac "rflts [rsimp a] =  [a]")
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
  1003
   prefer 2
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
  1004
   apply(drule_tac x="a" in spec)
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
  1005
   apply(drule mp)
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
  1006
    apply(simp)
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
  1007
   apply(auto)[1]
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
  1008
  using good.simps(1) k0b apply blast
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
  1009
  apply(auto)[1]  
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
  1010
  done
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
  1011
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
  1012
lemma sublist_distinct:
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
  1013
  shows "distinct (rs1 @ rs2 ) \<Longrightarrow> distinct rs1 \<and> distinct rs2"
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
  1014
  using distinct_append by blast
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
  1015
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
  1016
lemma first2elem_distinct:
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
  1017
  shows "distinct (a # b # rs) \<Longrightarrow> a \<noteq> b"
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
  1018
  by force
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
  1019
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
  1020
lemma rdistinct_does_not_remove:
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
  1021
  shows "((\<forall>r \<in> rset. r \<notin> set rs) \<and> (distinct rs)) \<Longrightarrow> rdistinct rs rset = rs"
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
  1022
  by (metis append.right_neutral distinct_rdistinct_append rdistinct.simps(1))
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
  1023
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
  1024
lemma nonalt0_flts_keeps:
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
  1025
  shows "(a \<noteq> RZERO) \<and> (\<forall>rs. a \<noteq> RALTS rs) \<Longrightarrow> rflts (a # xs) = a # rflts xs"
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
  1026
  apply(case_tac a)
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
  1027
       apply simp+
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
  1028
  done
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
  1029
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
  1030
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
  1031
lemma nonalt0_fltseq:
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
  1032
  shows "\<forall>r \<in> set rs. r \<noteq> RZERO \<and> nonalt r \<Longrightarrow> rflts rs = rs"
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
  1033
  apply(induct rs)
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
  1034
   apply simp
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
  1035
  apply(case_tac "a = RZERO")
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
  1036
   apply fastforce
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
  1037
  apply(case_tac "\<exists>rs1. a = RALTS rs1")
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
  1038
   apply(erule exE)
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
  1039
   apply simp+
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
  1040
  using nonalt0_flts_keeps by presburger
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
  1041
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
  1042
  
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
  1043
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
  1044
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
  1045
lemma goodalts_nonalt:
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
  1046
  shows "good (RALTS rs) \<Longrightarrow> rflts rs = rs"
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
  1047
  apply(induct x == "RALTS rs" arbitrary: rs rule: good.induct)
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
  1048
    apply simp
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
  1049
  
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
  1050
  using good.simps(5) apply blast
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
  1051
  apply simp
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
  1052
  apply(case_tac "r1 = RZERO")
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
  1053
  using good.simps(1) apply force
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
  1054
  apply(case_tac "r2 = RZERO")
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
  1055
  using good.simps(1) apply force
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
  1056
  apply(subgoal_tac "rflts (r1 # r2 # rs) = r1 # r2 # rflts rs")
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
  1057
  prefer 2
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
  1058
   apply (metis nonalt.simps(1) rflts_def_idiot)
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
  1059
  apply(subgoal_tac "\<forall>r \<in> set rs. r \<noteq> RZERO \<and> nonalt r")
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
  1060
   apply(subgoal_tac "rflts rs = rs")
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
  1061
    apply presburger
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
  1062
  using nonalt0_fltseq apply presburger
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
  1063
  using good.simps(1) by blast
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
  1064
  
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
  1065
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
  1066
  
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
  1067
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
  1068
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
  1069
lemma test:
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
  1070
  assumes "good r"
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
  1071
  shows "rsimp r = r"
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
  1072
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
  1073
  using assms
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
  1074
  apply(induct rule: good.induct)
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
  1075
                      apply simp
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
  1076
                      apply simp
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
  1077
                      apply simp
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
  1078
                      apply simp
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
  1079
                      apply simp
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
  1080
                      apply(subgoal_tac "distinct (r1 # r2 # rs)")
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
  1081
  prefer 2
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
  1082
  using good.simps(6) apply blast
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
  1083
  apply(subgoal_tac "rflts (r1 # r2 # rs ) = r1 # r2 # rs")
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
  1084
  prefer 2
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
  1085
  using goodalts_nonalt apply blast
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
  1086
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
  1087
                      apply(subgoal_tac "r1 \<noteq> r2")
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
  1088
  prefer 2
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
  1089
                      apply (meson distinct_length_2_or_more)
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
  1090
                      apply(subgoal_tac "r1 \<notin> set rs")
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
  1091
                      apply(subgoal_tac "r2 \<notin> set rs")
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
  1092
                      apply(subgoal_tac "\<forall>r \<in> set rs. rsimp r = r")
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
  1093
                      apply(subgoal_tac "map rsimp rs = rs")
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
  1094
  apply simp             
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
  1095
                      apply(subgoal_tac "\<forall>r \<in>  {r1, r2}. r \<notin> set rs")
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
  1096
  apply (metis distinct_not_exist rdistinct_on_distinct)
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
  1097
  
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
  1098
                      apply blast
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
  1099
                      apply (meson map_idI)
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
  1100
                      apply (metis good.simps(6) insert_iff list.simps(15))
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
  1101
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
  1102
  apply (meson distinct.simps(2))
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
  1103
                      apply (simp add: distinct.simps(2) distinct_length_2_or_more)
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
  1104
                      apply simp+
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
  1105
  done
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
  1106
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
  1107
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
  1108
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
  1109
lemma rsimp_idem:
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
  1110
  shows "rsimp (rsimp r) = rsimp r"
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
  1111
  using test good1
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
  1112
  by force
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
  1113
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
  1114
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
  1115
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
  1116
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
  1117
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
  1118
corollary rsimp_inner_idem1:
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
  1119
  shows "rsimp r = RSEQ r1 r2 \<Longrightarrow> rsimp r1 = r1 \<and> rsimp r2 = r2"
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
  1120
  by (metis bsimp_ASEQ0 good.simps(7) good.simps(8) good1 good_SEQ rrexp.distinct(5) rsimp.simps(1) rsimp.simps(3) test)
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
  1121
  
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
  1122
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
  1123
corollary rsimp_inner_idem2:
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
  1124
  shows "rsimp r = RALTS rs \<Longrightarrow> \<forall>r' \<in> (set rs). rsimp r' = r'"
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
  1125
  by (metis flts2 good1 k0a rrexp.simps(12) test)
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
  1126
  
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
  1127
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
  1128
corollary rsimp_inner_idem3:
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
  1129
  shows "rsimp r = RALTS rs \<Longrightarrow> map rsimp rs = rs"
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
  1130
  by (meson map_idI rsimp_inner_idem2)
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
  1131
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
  1132
corollary rsimp_inner_idem4:
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
  1133
  shows "rsimp r = RALTS rs \<Longrightarrow> rflts rs = rs"
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
  1134
  by (metis good1 goodalts_nonalt rrexp.simps(12))
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
  1135
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
  1136
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
  1137
lemma head_one_more_simp:
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
  1138
  shows "map rsimp (r # rs) = map rsimp (( rsimp r) # rs)"
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
  1139
  by (simp add: rsimp_idem)
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
  1140
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
  1141
lemma head_one_more_dersimp:
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
  1142
  shows "map rsimp ((rder x (rders_simp r s) # rs)) = map rsimp ((rders_simp r (s@[x]) ) # rs)"
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
  1143
  using head_one_more_simp rders_simp_append rders_simp_one_char by presburger
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
  1144
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
  1145
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
  1146
488
370dae790b30 more sorrys fileld
Chengsong
parents: 486
diff changeset
  1147
lemma der_simp_nullability:
370dae790b30 more sorrys fileld
Chengsong
parents: 486
diff changeset
  1148
  shows "rnullable r = rnullable (rsimp r)"
370dae790b30 more sorrys fileld
Chengsong
parents: 486
diff changeset
  1149
  using RL_rnullable RL_rsimp by auto
370dae790b30 more sorrys fileld
Chengsong
parents: 486
diff changeset
  1150
  
444
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
  1151
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
  1152
lemma ders_simp_nullability:
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
  1153
  shows "rnullable (rders r s) = rnullable (rders_simp r s)"
488
370dae790b30 more sorrys fileld
Chengsong
parents: 486
diff changeset
  1154
  apply(induct s arbitrary: r rule: rev_induct)
370dae790b30 more sorrys fileld
Chengsong
parents: 486
diff changeset
  1155
   apply(simp)
370dae790b30 more sorrys fileld
Chengsong
parents: 486
diff changeset
  1156
  apply(simp add: rders_append rders_simp_append)
370dae790b30 more sorrys fileld
Chengsong
parents: 486
diff changeset
  1157
  apply(simp only: RL_rnullable)
370dae790b30 more sorrys fileld
Chengsong
parents: 486
diff changeset
  1158
  apply(simp only: RL_rder)
370dae790b30 more sorrys fileld
Chengsong
parents: 486
diff changeset
  1159
  apply(subst RL_rsimp[symmetric])
370dae790b30 more sorrys fileld
Chengsong
parents: 486
diff changeset
  1160
  apply(simp only: RL_rder)
370dae790b30 more sorrys fileld
Chengsong
parents: 486
diff changeset
  1161
  by (simp add: RL_rders)
444
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
  1162
488
370dae790b30 more sorrys fileld
Chengsong
parents: 486
diff changeset
  1163
370dae790b30 more sorrys fileld
Chengsong
parents: 486
diff changeset
  1164
370dae790b30 more sorrys fileld
Chengsong
parents: 486
diff changeset
  1165
480
574749f5190b a few more
Chengsong
parents: 478
diff changeset
  1166
574749f5190b a few more
Chengsong
parents: 478
diff changeset
  1167
444
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
  1168
lemma  first_elem_seqder:
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
  1169
  shows "\<not>rnullable r1p \<Longrightarrow> map rsimp (rder x (RSEQ r1p r2)
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
  1170
                   # rs) = map rsimp ((RSEQ (rder x r1p) r2) # rs) "
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
  1171
  by auto
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
  1172
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
  1173
lemma first_elem_seqder1:
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
  1174
  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
  1175
                                          map rsimp ( (RSEQ (rsimp (rder x (rders_simp r xs))) r2) # rs)"
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
  1176
  by (simp add: rsimp_idem)
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
  1177
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
  1178
lemma first_elem_seqdersimps:
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
  1179
  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
  1180
                                          map rsimp ( (RSEQ (rders_simp r (xs @ [x])) r2) # rs)"
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
  1181
  using first_elem_seqder1 rders_simp_append by auto
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
  1182
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
  1183
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
  1184
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
  1185
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
  1186
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
  1187
489
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
  1188
lemma no_alt_short_list_after_simp:
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
  1189
  shows "RALTS rs = rsimp r \<Longrightarrow> rsimp_ALTs rs = RALTS rs"
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
  1190
  by (metis bbbbs good1 k0a rrexp.simps(12))
444
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
  1191
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
  1192
489
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
  1193
lemma no_further_dB_after_simp:
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
  1194
  shows "RALTS rs = rsimp r \<Longrightarrow> rdistinct rs {} = rs"
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
  1195
  apply(subgoal_tac "good (RALTS rs)")
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
  1196
  apply(subgoal_tac "distinct rs")
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
  1197
  using rdistinct_on_distinct apply blast
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
  1198
  apply (metis distinct.simps(1) distinct.simps(2) empty_iff good.simps(6) list.exhaust set_empty2)
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
  1199
  using good1 by fastforce
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
  1200
444
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
  1201
478
Chengsong
parents: 476
diff changeset
  1202
lemma idem_after_simp1:
Chengsong
parents: 476
diff changeset
  1203
  shows "rsimp_ALTs (rdistinct (rflts [rsimp aa]) {}) = rsimp aa"
Chengsong
parents: 476
diff changeset
  1204
  apply(case_tac "rsimp aa")
Chengsong
parents: 476
diff changeset
  1205
  apply simp+
Chengsong
parents: 476
diff changeset
  1206
  apply (metis no_alt_short_list_after_simp no_further_dB_after_simp)
Chengsong
parents: 476
diff changeset
  1207
  by simp
Chengsong
parents: 476
diff changeset
  1208
Chengsong
parents: 476
diff changeset
  1209
lemma identity_wwo0:
Chengsong
parents: 476
diff changeset
  1210
  shows "rsimp (rsimp_ALTs (RZERO # rs)) = rsimp (rsimp_ALTs rs)"
Chengsong
parents: 476
diff changeset
  1211
  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
  1212
Chengsong
parents: 476
diff changeset
  1213
Chengsong
parents: 476
diff changeset
  1214
lemma distinct_removes_last:
Chengsong
parents: 476
diff changeset
  1215
  shows "\<lbrakk>a \<in> set as\<rbrakk>
Chengsong
parents: 476
diff changeset
  1216
    \<Longrightarrow> rdistinct as rset = rdistinct (as @ [a]) rset"
Chengsong
parents: 476
diff changeset
  1217
and "rdistinct (ab # as @ [ab]) rset1 = rdistinct (ab # as) rset1"
Chengsong
parents: 476
diff changeset
  1218
  apply(induct as arbitrary: rset ab rset1 a)
Chengsong
parents: 476
diff changeset
  1219
     apply simp
Chengsong
parents: 476
diff changeset
  1220
    apply simp
Chengsong
parents: 476
diff changeset
  1221
  apply(case_tac "aa \<in> rset")
Chengsong
parents: 476
diff changeset
  1222
   apply(case_tac "a = aa")
Chengsong
parents: 476
diff changeset
  1223
  apply (metis append_Cons)
Chengsong
parents: 476
diff changeset
  1224
    apply simp
Chengsong
parents: 476
diff changeset
  1225
   apply(case_tac "a \<in> set as")
Chengsong
parents: 476
diff changeset
  1226
  apply (metis append_Cons rdistinct.simps(2) set_ConsD)
Chengsong
parents: 476
diff changeset
  1227
   apply(case_tac "a = aa")
Chengsong
parents: 476
diff changeset
  1228
    prefer 2
Chengsong
parents: 476
diff changeset
  1229
    apply simp
Chengsong
parents: 476
diff changeset
  1230
   apply (metis append_Cons)
Chengsong
parents: 476
diff changeset
  1231
  apply(case_tac "ab \<in> rset1")
Chengsong
parents: 476
diff changeset
  1232
  prefer 2
Chengsong
parents: 476
diff changeset
  1233
   apply(subgoal_tac "rdistinct (ab # (a # as) @ [ab]) rset1 = 
Chengsong
parents: 476
diff changeset
  1234
               ab # (rdistinct ((a # as) @ [ab]) (insert ab rset1))")
Chengsong
parents: 476
diff changeset
  1235
  prefer 2
Chengsong
parents: 476
diff changeset
  1236
  apply force
Chengsong
parents: 476
diff changeset
  1237
  apply(simp only:)
Chengsong
parents: 476
diff changeset
  1238
     apply(subgoal_tac "rdistinct (ab # a # as) rset1 = ab # (rdistinct (a # as) (insert ab rset1))")
Chengsong
parents: 476
diff changeset
  1239
    apply(simp only:)
Chengsong
parents: 476
diff changeset
  1240
    apply(subgoal_tac "rdistinct ((a # as) @ [ab]) (insert ab rset1) = rdistinct (a # as) (insert ab rset1)")
Chengsong
parents: 476
diff changeset
  1241
     apply blast
Chengsong
parents: 476
diff changeset
  1242
    apply(case_tac "a \<in> insert ab rset1")
Chengsong
parents: 476
diff changeset
  1243
     apply simp
Chengsong
parents: 476
diff changeset
  1244
     apply (metis insertI1)
Chengsong
parents: 476
diff changeset
  1245
    apply simp
Chengsong
parents: 476
diff changeset
  1246
    apply (meson insertI1)
Chengsong
parents: 476
diff changeset
  1247
   apply simp
Chengsong
parents: 476
diff changeset
  1248
  apply(subgoal_tac "rdistinct ((a # as) @ [ab]) rset1 = rdistinct (a # as) rset1")
Chengsong
parents: 476
diff changeset
  1249
   apply simp
Chengsong
parents: 476
diff changeset
  1250
  by (metis append_Cons insert_iff insert_is_Un rdistinct.simps(2))
Chengsong
parents: 476
diff changeset
  1251
Chengsong
parents: 476
diff changeset
  1252
Chengsong
parents: 476
diff changeset
  1253
lemma distinct_removes_middle:
Chengsong
parents: 476
diff changeset
  1254
  shows  "\<lbrakk>a \<in> set as\<rbrakk>
Chengsong
parents: 476
diff changeset
  1255
    \<Longrightarrow> rdistinct (as @ as2) rset = rdistinct (as @ [a] @ as2) rset"
Chengsong
parents: 476
diff changeset
  1256
and "rdistinct (ab # as @ [ab] @ as3) rset1 = rdistinct (ab # as @ as3) rset1"
Chengsong
parents: 476
diff changeset
  1257
   apply(induct as arbitrary: rset rset1 ab as2 as3 a)
Chengsong
parents: 476
diff changeset
  1258
     apply simp
Chengsong
parents: 476
diff changeset
  1259
    apply simp
Chengsong
parents: 476
diff changeset
  1260
   apply(case_tac "a \<in> rset")
Chengsong
parents: 476
diff changeset
  1261
    apply simp
Chengsong
parents: 476
diff changeset
  1262
    apply metis
Chengsong
parents: 476
diff changeset
  1263
   apply simp
Chengsong
parents: 476
diff changeset
  1264
   apply (metis insertI1)
Chengsong
parents: 476
diff changeset
  1265
  apply(case_tac "a = ab")
Chengsong
parents: 476
diff changeset
  1266
   apply simp
Chengsong
parents: 476
diff changeset
  1267
   apply(case_tac "ab \<in> rset")
Chengsong
parents: 476
diff changeset
  1268
    apply simp
Chengsong
parents: 476
diff changeset
  1269
    apply presburger
Chengsong
parents: 476
diff changeset
  1270
   apply (meson insertI1)
Chengsong
parents: 476
diff changeset
  1271
  apply(case_tac "a \<in> rset")
Chengsong
parents: 476
diff changeset
  1272
  apply (metis (no_types, opaque_lifting) Un_insert_left append_Cons insert_iff rdistinct.simps(2) sup_bot_left)
Chengsong
parents: 476
diff changeset
  1273
  apply(case_tac "ab \<in> rset")
Chengsong
parents: 476
diff changeset
  1274
  apply simp
Chengsong
parents: 476
diff changeset
  1275
   apply (meson insert_iff)
Chengsong
parents: 476
diff changeset
  1276
  apply simp
Chengsong
parents: 476
diff changeset
  1277
  by (metis insertI1)
Chengsong
parents: 476
diff changeset
  1278
Chengsong
parents: 476
diff changeset
  1279
Chengsong
parents: 476
diff changeset
  1280
lemma distinct_removes_middle3:
Chengsong
parents: 476
diff changeset
  1281
  shows  "\<lbrakk>a \<in> set as\<rbrakk>
Chengsong
parents: 476
diff changeset
  1282
    \<Longrightarrow> rdistinct (as @ a #as2) rset = rdistinct (as @ as2) rset"
Chengsong
parents: 476
diff changeset
  1283
  using distinct_removes_middle(1) by fastforce
Chengsong
parents: 476
diff changeset
  1284
Chengsong
parents: 476
diff changeset
  1285
lemma distinct_removes_last2:
Chengsong
parents: 476
diff changeset
  1286
  shows "\<lbrakk>a \<in> set as\<rbrakk>
Chengsong
parents: 476
diff changeset
  1287
    \<Longrightarrow> rdistinct as rset = rdistinct (as @ [a]) rset"
Chengsong
parents: 476
diff changeset
  1288
  by (simp add: distinct_removes_last(1))
Chengsong
parents: 476
diff changeset
  1289
Chengsong
parents: 476
diff changeset
  1290
lemma distinct_removes_middle2:
Chengsong
parents: 476
diff changeset
  1291
  shows "a \<in> set as \<Longrightarrow> rdistinct (as @ [a] @ rs) {} = rdistinct (as @ rs) {}"
Chengsong
parents: 476
diff changeset
  1292
  by (metis distinct_removes_middle(1))
Chengsong
parents: 476
diff changeset
  1293
Chengsong
parents: 476
diff changeset
  1294
lemma distinct_removes_list:
Chengsong
parents: 476
diff changeset
  1295
  shows "\<lbrakk> \<forall>r \<in> set rs. r \<in> set as\<rbrakk> \<Longrightarrow> rdistinct (as @ rs) {} = rdistinct as {}"
Chengsong
parents: 476
diff changeset
  1296
  apply(induct rs)
Chengsong
parents: 476
diff changeset
  1297
   apply simp+
Chengsong
parents: 476
diff changeset
  1298
  apply(subgoal_tac "rdistinct (as @ a # rs) {} = rdistinct (as @ rs) {}")
Chengsong
parents: 476
diff changeset
  1299
   prefer 2
Chengsong
parents: 476
diff changeset
  1300
  apply (metis append_Cons append_Nil distinct_removes_middle(1))
Chengsong
parents: 476
diff changeset
  1301
  by presburger
Chengsong
parents: 476
diff changeset
  1302
Chengsong
parents: 476
diff changeset
  1303
Chengsong
parents: 476
diff changeset
  1304
lemma spawn_simp_rsimpalts:
Chengsong
parents: 476
diff changeset
  1305
  shows "rsimp (rsimp_ALTs rs) = rsimp (rsimp_ALTs (map rsimp rs))"
Chengsong
parents: 476
diff changeset
  1306
  apply(cases rs)
Chengsong
parents: 476
diff changeset
  1307
   apply simp
Chengsong
parents: 476
diff changeset
  1308
  apply(case_tac list)
Chengsong
parents: 476
diff changeset
  1309
   apply simp
Chengsong
parents: 476
diff changeset
  1310
   apply(subst rsimp_idem[symmetric])
Chengsong
parents: 476
diff changeset
  1311
   apply simp
Chengsong
parents: 476
diff changeset
  1312
  apply(subgoal_tac "rsimp_ALTs rs = RALTS rs")
Chengsong
parents: 476
diff changeset
  1313
   apply(simp only:)
Chengsong
parents: 476
diff changeset
  1314
   apply(subgoal_tac "rsimp_ALTs (map rsimp rs) = RALTS (map rsimp rs)")
Chengsong
parents: 476
diff changeset
  1315
    apply(simp only:)
Chengsong
parents: 476
diff changeset
  1316
  prefer 2
Chengsong
parents: 476
diff changeset
  1317
  apply simp
Chengsong
parents: 476
diff changeset
  1318
   prefer 2
Chengsong
parents: 476
diff changeset
  1319
  using rsimp_ALTs.simps(3) apply presburger
Chengsong
parents: 476
diff changeset
  1320
  apply auto
Chengsong
parents: 476
diff changeset
  1321
  apply(subst rsimp_idem)+
Chengsong
parents: 476
diff changeset
  1322
  by (metis comp_apply rsimp_idem)
444
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
  1323
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
  1324
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
  1325
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
  1326
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
  1327
478
Chengsong
parents: 476
diff changeset
  1328
Chengsong
parents: 476
diff changeset
  1329
lemma rsimp_no_dup:
Chengsong
parents: 476
diff changeset
  1330
  shows "rsimp r = RALTS rs \<Longrightarrow> distinct rs"
489
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
  1331
  by (metis no_further_dB_after_simp rdistinct_does_the_job)
478
Chengsong
parents: 476
diff changeset
  1332
Chengsong
parents: 476
diff changeset
  1333
Chengsong
parents: 476
diff changeset
  1334
Chengsong
parents: 476
diff changeset
  1335
Chengsong
parents: 476
diff changeset
  1336
lemma simp_singlealt_flatten:
Chengsong
parents: 476
diff changeset
  1337
  shows "rsimp (RALTS [RALTS rsa]) = rsimp (RALTS (rsa @ []))"
Chengsong
parents: 476
diff changeset
  1338
  apply(induct rsa)
Chengsong
parents: 476
diff changeset
  1339
   apply simp
Chengsong
parents: 476
diff changeset
  1340
  apply simp
Chengsong
parents: 476
diff changeset
  1341
  by (metis idem_after_simp1 list.simps(9) rsimp.simps(2))
Chengsong
parents: 476
diff changeset
  1342
Chengsong
parents: 476
diff changeset
  1343
Chengsong
parents: 476
diff changeset
  1344
lemma good1_rsimpalts:
Chengsong
parents: 476
diff changeset
  1345
  shows "rsimp r = RALTS rs \<Longrightarrow> rsimp_ALTs rs = RALTS rs"
Chengsong
parents: 476
diff changeset
  1346
  by (metis no_alt_short_list_after_simp) 
Chengsong
parents: 476
diff changeset
  1347
  
Chengsong
parents: 476
diff changeset
  1348
Chengsong
parents: 476
diff changeset
  1349
Chengsong
parents: 476
diff changeset
  1350
Chengsong
parents: 476
diff changeset
  1351
lemma good1_flatten:
Chengsong
parents: 476
diff changeset
  1352
  shows "\<lbrakk> rsimp r =  (RALTS rs1)\<rbrakk>
Chengsong
parents: 476
diff changeset
  1353
       \<Longrightarrow> rflts (rsimp_ALTs rs1 # map rsimp rsb) = rflts (rs1 @ map rsimp rsb)"
Chengsong
parents: 476
diff changeset
  1354
  apply(subst good1_rsimpalts)
Chengsong
parents: 476
diff changeset
  1355
   apply simp+
Chengsong
parents: 476
diff changeset
  1356
  apply(subgoal_tac "rflts (rs1 @ map rsimp rsb) = rs1 @ rflts (map rsimp rsb)")
Chengsong
parents: 476
diff changeset
  1357
   apply simp
489
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
  1358
  using flts_append rsimp_inner_idem4 by presburger
478
Chengsong
parents: 476
diff changeset
  1359
489
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
  1360
  
478
Chengsong
parents: 476
diff changeset
  1361
lemma flatten_rsimpalts:
Chengsong
parents: 476
diff changeset
  1362
  shows "rflts (rsimp_ALTs (rdistinct (rflts (map rsimp rsa)) {}) # map rsimp rsb) = 
Chengsong
parents: 476
diff changeset
  1363
         rflts ( (rdistinct (rflts (map rsimp rsa)) {}) @ map rsimp rsb)"
Chengsong
parents: 476
diff changeset
  1364
  apply(case_tac "map rsimp rsa")
Chengsong
parents: 476
diff changeset
  1365
   apply simp
Chengsong
parents: 476
diff changeset
  1366
  apply(case_tac "list")
Chengsong
parents: 476
diff changeset
  1367
   apply simp
Chengsong
parents: 476
diff changeset
  1368
   apply(case_tac a)
Chengsong
parents: 476
diff changeset
  1369
        apply simp+
Chengsong
parents: 476
diff changeset
  1370
    apply(rename_tac rs1)
489
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
  1371
    apply (metis good1_flatten map_eq_Cons_D no_further_dB_after_simp)
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
  1372
  
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
  1373
  apply simp
478
Chengsong
parents: 476
diff changeset
  1374
  
489
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
  1375
  apply(subgoal_tac "\<forall>r \<in> set( rflts (map rsimp rsa)). good r")
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
  1376
   apply(case_tac "rdistinct (rflts (map rsimp rsa)) {}")
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
  1377
    apply simp
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
  1378
   apply(case_tac "listb")
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
  1379
    apply simp+
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
  1380
  apply (metis Cons_eq_appendI good1_flatten rflts.simps(3) rsimp.simps(2) rsimp_ALTs.simps(3))
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
  1381
  by (metis (mono_tags, lifting) flts3 good1 image_iff list.set_map)
478
Chengsong
parents: 476
diff changeset
  1382
Chengsong
parents: 476
diff changeset
  1383
489
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
  1384
lemma last_elem_out:
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
  1385
  shows "\<lbrakk>x \<notin> set xs; x \<notin> rset \<rbrakk> \<Longrightarrow> rdistinct (xs @ [x]) rset = rdistinct xs rset @ [x]"
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
  1386
  apply(induct xs arbitrary: rset)
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
  1387
  apply simp+
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
  1388
  done
478
Chengsong
parents: 476
diff changeset
  1389
Chengsong
parents: 476
diff changeset
  1390
444
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
  1391
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
  1392
488
370dae790b30 more sorrys fileld
Chengsong
parents: 486
diff changeset
  1393
lemma rdistinct_concat_general:
370dae790b30 more sorrys fileld
Chengsong
parents: 486
diff changeset
  1394
  shows "rdistinct (rs1 @ rs2) {} = (rdistinct rs1 {}) @ (rdistinct rs2 (set rs1))"
489
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
  1395
  apply(induct rs1 arbitrary: rs2 rule: rev_induct)
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
  1396
   apply simp
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
  1397
  apply(drule_tac x = "x # rs2" in meta_spec)
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
  1398
  apply simp
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
  1399
  apply(case_tac "x \<in> set xs")
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
  1400
   apply simp
488
370dae790b30 more sorrys fileld
Chengsong
parents: 486
diff changeset
  1401
  
489
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
  1402
   apply (simp add: distinct_removes_middle3 insert_absorb)
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
  1403
  apply simp
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
  1404
  by (simp add: last_elem_out)
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
  1405
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
  1406
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
  1407
  
488
370dae790b30 more sorrys fileld
Chengsong
parents: 486
diff changeset
  1408
370dae790b30 more sorrys fileld
Chengsong
parents: 486
diff changeset
  1409
lemma distinct_once_enough:
370dae790b30 more sorrys fileld
Chengsong
parents: 486
diff changeset
  1410
  shows "rdistinct (rs @ rsa) {} = rdistinct (rdistinct rs {} @ rsa) {}"
370dae790b30 more sorrys fileld
Chengsong
parents: 486
diff changeset
  1411
  apply(subgoal_tac "distinct (rdistinct rs {})")
370dae790b30 more sorrys fileld
Chengsong
parents: 486
diff changeset
  1412
   apply(subgoal_tac 
370dae790b30 more sorrys fileld
Chengsong
parents: 486
diff changeset
  1413
" rdistinct (rdistinct rs {} @ rsa) {} = rdistinct rs {} @ (rdistinct rsa (set rs))")
370dae790b30 more sorrys fileld
Chengsong
parents: 486
diff changeset
  1414
  apply(simp only:)
370dae790b30 more sorrys fileld
Chengsong
parents: 486
diff changeset
  1415
  using rdistinct_concat_general apply blast
370dae790b30 more sorrys fileld
Chengsong
parents: 486
diff changeset
  1416
  apply (simp add: distinct_rdistinct_append rdistinct_set_equality)
370dae790b30 more sorrys fileld
Chengsong
parents: 486
diff changeset
  1417
  by (simp add: rdistinct_does_the_job)
370dae790b30 more sorrys fileld
Chengsong
parents: 486
diff changeset
  1418
  
370dae790b30 more sorrys fileld
Chengsong
parents: 486
diff changeset
  1419
444
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
  1420
lemma simp_flatten:
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
  1421
  shows "rsimp (RALTS ((RALTS rsa) # rsb)) = rsimp (RALTS (rsa @ rsb))"
478
Chengsong
parents: 476
diff changeset
  1422
  apply simp
Chengsong
parents: 476
diff changeset
  1423
  apply(subst flatten_rsimpalts)
Chengsong
parents: 476
diff changeset
  1424
  apply(simp add: flts_append)
489
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
  1425
  by (metis distinct_once_enough nonalt0_fltseq nonalt_flts_rd qqq1 rdistinct_set_equality)
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
  1426
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
  1427
lemma basic_rsimp_SEQ_property1:
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
  1428
  shows "rsimp_SEQ RONE r = r"
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
  1429
  by (simp add: idiot)
444
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
  1430
489
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
  1431
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
  1432
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
  1433
lemma basic_rsimp_SEQ_property3:
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
  1434
  shows "rsimp_SEQ r RZERO = RZERO"  
2b5b3f83e2b6 1sorry left
Chengsong
parents: 488
diff changeset
  1435
  using rsimp_SEQ.elims by blast
444
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
  1436
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
  1437
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
  1438
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
  1439
fun vsuf :: "char list \<Rightarrow> rrexp \<Rightarrow> char list list" where
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
  1440
"vsuf [] _ = []"
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
  1441
|"vsuf (c#cs) r1 = (if (rnullable r1) then  (vsuf cs (rder c r1)) @ [c # cs]
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
  1442
                                      else  (vsuf cs (rder c r1))
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
  1443
                   ) "
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
  1444
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
  1445
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
  1446
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
  1447
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
  1448
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
  1449
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
  1450
fun star_update :: "char \<Rightarrow> rrexp \<Rightarrow> char list list \<Rightarrow> char list list" where
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
  1451
"star_update c r [] = []"
486
f5b96a532c85 starclosed
Chengsong
parents: 481
diff changeset
  1452
|"star_update c r (s # Ss) = (if (rnullable (rders r s)) 
444
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
  1453
                                then (s@[c]) # [c] # (star_update c r Ss) 
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
  1454
                               else   (s@[c]) # (star_update c r Ss) )"
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
  1455
486
f5b96a532c85 starclosed
Chengsong
parents: 481
diff changeset
  1456
444
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
  1457
fun star_updates :: "char list \<Rightarrow> rrexp \<Rightarrow> char list list \<Rightarrow> char list list"
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
  1458
  where
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
  1459
"star_updates [] r Ss = Ss"
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
  1460
| "star_updates (c # cs) r Ss = star_updates cs r (star_update c r Ss)"
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
  1461
486
f5b96a532c85 starclosed
Chengsong
parents: 481
diff changeset
  1462
lemma stupdates_append: shows 
f5b96a532c85 starclosed
Chengsong
parents: 481
diff changeset
  1463
"star_updates (s @ [c]) r Ss = star_update c r (star_updates s r Ss)"
f5b96a532c85 starclosed
Chengsong
parents: 481
diff changeset
  1464
  apply(induct s arbitrary: Ss)
f5b96a532c85 starclosed
Chengsong
parents: 481
diff changeset
  1465
   apply simp
f5b96a532c85 starclosed
Chengsong
parents: 481
diff changeset
  1466
  apply simp
f5b96a532c85 starclosed
Chengsong
parents: 481
diff changeset
  1467
  done
f5b96a532c85 starclosed
Chengsong
parents: 481
diff changeset
  1468
444
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
  1469
478
Chengsong
parents: 476
diff changeset
  1470
lemma distinct_flts_no0:
Chengsong
parents: 476
diff changeset
  1471
  shows "  rflts (map rsimp (rdistinct rs (insert RZERO rset)))  =
Chengsong
parents: 476
diff changeset
  1472
           rflts (map rsimp (rdistinct rs rset))  "
Chengsong
parents: 476
diff changeset
  1473
  
Chengsong
parents: 476
diff changeset
  1474
  apply(induct rs arbitrary: rset)
Chengsong
parents: 476
diff changeset
  1475
   apply simp
Chengsong
parents: 476
diff changeset
  1476
  apply(case_tac a)
Chengsong
parents: 476
diff changeset
  1477
  apply simp+
Chengsong
parents: 476
diff changeset
  1478
    apply (smt (verit, ccfv_SIG) rflts.simps(2) rflts.simps(3) rflts_def_idiot)
Chengsong
parents: 476
diff changeset
  1479
  prefer 2
Chengsong
parents: 476
diff changeset
  1480
  apply simp  
Chengsong
parents: 476
diff changeset
  1481
  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
  1482
478
Chengsong
parents: 476
diff changeset
  1483
lemma flts_removes0:
Chengsong
parents: 476
diff changeset
  1484
  shows "  rflts (rs @ [RZERO])  =
Chengsong
parents: 476
diff changeset
  1485
           rflts rs"
Chengsong
parents: 476
diff changeset
  1486
  apply(induct rs)
Chengsong
parents: 476
diff changeset
  1487
   apply simp
Chengsong
parents: 476
diff changeset
  1488
  by (metis append_Cons rflts.simps(2) rflts.simps(3) rflts_def_idiot)
Chengsong
parents: 476
diff changeset
  1489
  
Chengsong
parents: 476
diff changeset
  1490
Chengsong
parents: 476
diff changeset
  1491
lemma rflts_spills_last:
Chengsong
parents: 476
diff changeset
  1492
  shows "a = RALTS rs \<Longrightarrow> rflts (rs1 @ [a]) = rflts rs1 @ rs"
Chengsong
parents: 476
diff changeset
  1493
  apply (induct rs1)
Chengsong
parents: 476
diff changeset
  1494
  apply simp
Chengsong
parents: 476
diff changeset
  1495
  by (metis append.assoc append_Cons rflts.simps(2) rflts.simps(3) rflts_def_idiot)
Chengsong
parents: 476
diff changeset
  1496
Chengsong
parents: 476
diff changeset
  1497
lemma flts_keeps1:
Chengsong
parents: 476
diff changeset
  1498
  shows " rflts (rs @ [RONE]) = 
Chengsong
parents: 476
diff changeset
  1499
          rflts  rs @ [RONE] "
Chengsong
parents: 476
diff changeset
  1500
  apply (induct rs)
Chengsong
parents: 476
diff changeset
  1501
   apply simp
Chengsong
parents: 476
diff changeset
  1502
  by (metis append.assoc append_Cons rflts.simps(2) rflts.simps(3) rflts_def_idiot)
Chengsong
parents: 476
diff changeset
  1503
Chengsong
parents: 476
diff changeset
  1504
lemma flts_keeps_others:
Chengsong
parents: 476
diff changeset
  1505
  shows "\<lbrakk>a \<noteq> RZERO; \<nexists>rs1. a = RALTS rs1\<rbrakk> \<Longrightarrow>rflts (rs @ [a]) = rflts rs @ [a]"
Chengsong
parents: 476
diff changeset
  1506
  apply(induct rs)
Chengsong
parents: 476
diff changeset
  1507
   apply simp
Chengsong
parents: 476
diff changeset
  1508
  apply (simp add: rflts_def_idiot)
Chengsong
parents: 476
diff changeset
  1509
  apply(case_tac a)
Chengsong
parents: 476
diff changeset
  1510
       apply simp
Chengsong
parents: 476
diff changeset
  1511
  using flts_keeps1 apply blast
Chengsong
parents: 476
diff changeset
  1512
     apply (metis append.assoc append_Cons rflts.simps(2) rflts.simps(3) rflts_def_idiot)
Chengsong
parents: 476
diff changeset
  1513
  apply (metis append.assoc append_Cons rflts.simps(2) rflts.simps(3) rflts_def_idiot)
Chengsong
parents: 476
diff changeset
  1514
  apply blast
Chengsong
parents: 476
diff changeset
  1515
  by (metis append.assoc append_Cons rflts.simps(2) rflts.simps(3) rflts_def_idiot)
Chengsong
parents: 476
diff changeset
  1516
Chengsong
parents: 476
diff changeset
  1517
lemma spilled_alts_contained:
Chengsong
parents: 476
diff changeset
  1518
  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
  1519
  apply(induct rs1)
Chengsong
parents: 476
diff changeset
  1520
   apply simp 
Chengsong
parents: 476
diff changeset
  1521
  apply(case_tac "a = aa")
Chengsong
parents: 476
diff changeset
  1522
   apply simp
Chengsong
parents: 476
diff changeset
  1523
  apply(subgoal_tac " a \<in> set rs1")
Chengsong
parents: 476
diff changeset
  1524
  prefer 2
Chengsong
parents: 476
diff changeset
  1525
   apply (meson set_ConsD)
Chengsong
parents: 476
diff changeset
  1526
  apply(case_tac aa)
Chengsong
parents: 476
diff changeset
  1527
  using rflts.simps(2) apply presburger
Chengsong
parents: 476
diff changeset
  1528
      apply fastforce
Chengsong
parents: 476
diff changeset
  1529
  apply fastforce
Chengsong
parents: 476
diff changeset
  1530
  apply fastforce
Chengsong
parents: 476
diff changeset
  1531
  apply fastforce
Chengsong
parents: 476
diff changeset
  1532
  by fastforce
Chengsong
parents: 476
diff changeset
  1533
Chengsong
parents: 476
diff changeset
  1534
Chengsong
parents: 476
diff changeset
  1535
lemma distinct_removes_duplicate_flts:
Chengsong
parents: 476
diff changeset
  1536
  shows " a \<in> set rsa
Chengsong
parents: 476
diff changeset
  1537
       \<Longrightarrow> rdistinct (rflts (map rsimp rsa @ [rsimp a])) {} =
Chengsong
parents: 476
diff changeset
  1538
           rdistinct (rflts (map rsimp rsa)) {}"
Chengsong
parents: 476
diff changeset
  1539
  apply(subgoal_tac "rsimp a \<in> set (map rsimp rsa)")
Chengsong
parents: 476
diff changeset
  1540
  prefer 2
Chengsong
parents: 476
diff changeset
  1541
  apply simp
Chengsong
parents: 476
diff changeset
  1542
  apply(induct "rsimp a")
Chengsong
parents: 476
diff changeset
  1543
       apply simp
Chengsong
parents: 476
diff changeset
  1544
  using flts_removes0 apply presburger
Chengsong
parents: 476
diff changeset
  1545
      apply(subgoal_tac " rdistinct (rflts (map rsimp rsa @ [rsimp a])) {} =  
Chengsong
parents: 476
diff changeset
  1546
                          rdistinct (rflts (map rsimp rsa @ [RONE])) {}")
Chengsong
parents: 476
diff changeset
  1547
      apply (simp only:)
Chengsong
parents: 476
diff changeset
  1548
       apply(subst flts_keeps1)
Chengsong
parents: 476
diff changeset
  1549
  apply (metis distinct_removes_last2 rflts_def_idiot2 rrexp.simps(20) rrexp.simps(6))
Chengsong
parents: 476
diff changeset
  1550
      apply presburger
Chengsong
parents: 476
diff changeset
  1551
        apply(subgoal_tac " rdistinct (rflts (map rsimp rsa @ [rsimp a]))    {} =  
Chengsong
parents: 476
diff changeset
  1552
                            rdistinct ((rflts (map rsimp rsa)) @ [RCHAR x]) {}")
Chengsong
parents: 476
diff changeset
  1553
      apply (simp only:)
Chengsong
parents: 476
diff changeset
  1554
      prefer 2
Chengsong
parents: 476
diff changeset
  1555
      apply (metis flts_keeps_others rrexp.distinct(21) rrexp.distinct(3))
Chengsong
parents: 476
diff changeset
  1556
  apply (metis distinct_removes_last2 rflts_def_idiot2 rrexp.distinct(21) rrexp.distinct(3))
Chengsong
parents: 476
diff changeset
  1557
Chengsong
parents: 476
diff changeset
  1558
    apply (metis distinct_removes_last2 flts_keeps_others rflts_def_idiot2 rrexp.distinct(25) rrexp.distinct(5))
Chengsong
parents: 476
diff changeset
  1559
   prefer 2
Chengsong
parents: 476
diff changeset
  1560
   apply (metis distinct_removes_last2 flts_keeps_others flts_removes0 rflts_def_idiot2 rrexp.distinct(29))
Chengsong
parents: 476
diff changeset
  1561
  apply(subgoal_tac "rflts (map rsimp rsa @ [rsimp a]) = rflts (map rsimp rsa) @ x")
Chengsong
parents: 476
diff changeset
  1562
  prefer 2
Chengsong
parents: 476
diff changeset
  1563
  apply (simp add: rflts_spills_last)
Chengsong
parents: 476
diff changeset
  1564
  apply(simp only:)
Chengsong
parents: 476
diff changeset
  1565
  apply(subgoal_tac "\<forall> r \<in> set x. r \<in> set (rflts (map rsimp rsa))")
Chengsong
parents: 476
diff changeset
  1566
  prefer 2
Chengsong
parents: 476
diff changeset
  1567
  using spilled_alts_contained apply presburger
Chengsong
parents: 476
diff changeset
  1568
  using distinct_removes_list by blast
444
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
  1569
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
  1570
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
  1571
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
  1572
(*some basic facts about rsimp*)
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
  1573
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
  1574
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
  1575
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
  1576
a7e98deebb5c restructured sizebound proof
Chengsong
parents:
diff changeset
  1577
end