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