thys3/BasicIdentities.thy
author Christian Urban <christian.urban@kcl.ac.uk>
Thu, 16 Feb 2023 23:23:22 +0000
changeset 642 6c13f76c070b
parent 556 c27f04bb2262
permissions -rw-r--r--
updated
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
556
Chengsong
parents:
diff changeset
     1
theory BasicIdentities 
642
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
     2
  imports "Lexer" 
556
Chengsong
parents:
diff changeset
     3
begin
Chengsong
parents:
diff changeset
     4
642
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
     5
datatype rrexp = 
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
     6
  RZERO
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
     7
| RONE 
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
     8
| RCHAR char
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
     9
| RSEQ rrexp rrexp
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
    10
| RALTS "rrexp list"
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
    11
| RSTAR rrexp
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
    12
| RNTIMES rrexp nat
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
    13
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
    14
abbreviation
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
    15
  "RALT r1 r2 \<equiv> RALTS [r1, r2]"
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
    16
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
    17
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
    18
fun
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
    19
 rnullable :: "rrexp \<Rightarrow> bool"
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
    20
where
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
    21
  "rnullable (RZERO) = False"
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
    22
| "rnullable (RONE) = True"
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
    23
| "rnullable (RCHAR c) = False"
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
    24
| "rnullable (RALTS rs) = (\<exists>r \<in> set rs. rnullable r)"
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
    25
| "rnullable (RSEQ r1 r2) = (rnullable r1 \<and> rnullable r2)"
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
    26
| "rnullable (RSTAR r) = True"
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
    27
| "rnullable (RNTIMES r n) = (if n = 0 then True else rnullable r)"
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
    28
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
    29
fun
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
    30
 rder :: "char \<Rightarrow> rrexp \<Rightarrow> rrexp"
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
    31
where
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
    32
  "rder c (RZERO) = RZERO"
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
    33
| "rder c (RONE) = RZERO"
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
    34
| "rder c (RCHAR d) = (if c = d then RONE else RZERO)"
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
    35
| "rder c (RALTS rs) = RALTS (map (rder c) rs)"
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
    36
| "rder c (RSEQ r1 r2) = 
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
    37
     (if rnullable r1
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
    38
      then RALT   (RSEQ (rder c r1) r2) (rder c r2)
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
    39
      else RSEQ   (rder c r1) r2)"
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
    40
| "rder c (RSTAR r) = RSEQ  (rder c r) (RSTAR r)"   
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
    41
| "rder c (RNTIMES r n) = (if n = 0 then RZERO else RSEQ (rder c r) (RNTIMES r (n - 1)))"
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
    42
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
    43
fun 
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
    44
  rders :: "rrexp \<Rightarrow> string \<Rightarrow> rrexp"
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
    45
where
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
    46
  "rders r [] = r"
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
    47
| "rders r (c#s) = rders (rder c r) s"
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
    48
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
    49
fun rdistinct :: "'a list \<Rightarrow>'a set \<Rightarrow> 'a list"
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
    50
  where
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
    51
  "rdistinct [] acc = []"
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
    52
| "rdistinct (x#xs)  acc = 
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
    53
     (if x \<in> acc then rdistinct xs  acc 
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
    54
      else x # (rdistinct xs  ({x} \<union> acc)))"
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
    55
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
    56
lemma rdistinct1:
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
    57
  assumes "a \<in> acc"
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
    58
  shows "a \<notin> set (rdistinct rs acc)"
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
    59
  using assms
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
    60
  apply(induct rs arbitrary: acc a)
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
    61
   apply(auto)
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
    62
  done
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
    63
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
    64
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
    65
lemma rdistinct_does_the_job:
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
    66
  shows "distinct (rdistinct rs s)"
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
    67
  apply(induct rs s rule: rdistinct.induct)
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
    68
  apply(auto simp add: rdistinct1)
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
    69
  done
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
    70
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
    71
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
    72
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
    73
lemma rdistinct_concat:
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
    74
  assumes "set rs \<subseteq> rset"
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
    75
  shows "rdistinct (rs @ rsa) rset = rdistinct rsa rset"
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
    76
  using assms
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
    77
  apply(induct rs)
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
    78
  apply simp+
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
    79
  done
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
    80
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
    81
lemma distinct_not_exist:
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
    82
  assumes "a \<notin> set rs"
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
    83
  shows "rdistinct rs rset = rdistinct rs (insert a rset)"
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
    84
  using assms
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
    85
  apply(induct rs arbitrary: rset)
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
    86
  apply(auto)
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
    87
  done
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
    88
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
    89
lemma rdistinct_on_distinct:
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
    90
  shows "distinct rs \<Longrightarrow> rdistinct rs {} = rs"
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
    91
  apply(induct rs)
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
    92
  apply simp
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
    93
  using distinct_not_exist by fastforce
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
    94
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
    95
lemma distinct_rdistinct_append:
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
    96
  assumes "distinct rs1" "\<forall>r \<in> set rs1. r \<notin> acc"
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
    97
  shows "rdistinct (rs1 @ rsa) acc = rs1 @ (rdistinct rsa (acc \<union> set rs1))"
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
    98
  using assms
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
    99
  apply(induct rs1 arbitrary: rsa acc)
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   100
   apply(auto)[1]
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   101
  apply(auto)[1]
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   102
  apply(drule_tac x="rsa" in meta_spec)
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   103
  apply(drule_tac x="{a} \<union> acc" in meta_spec)
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   104
  apply(simp)
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   105
  apply(drule meta_mp)
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   106
   apply(auto)[1]
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   107
  apply(simp)
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   108
  done
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   109
  
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   110
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   111
lemma rdistinct_set_equality1:
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   112
  shows "set (rdistinct rs acc) = set rs - acc"
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   113
  apply(induct rs acc rule: rdistinct.induct)
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   114
  apply(auto)
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   115
  done
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   116
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   117
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   118
lemma rdistinct_set_equality:
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   119
  shows "set (rdistinct rs {}) = set rs"
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   120
  by (simp add: rdistinct_set_equality1)
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   121
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   122
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   123
fun rflts :: "rrexp list \<Rightarrow> rrexp list"
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   124
  where 
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   125
  "rflts [] = []"
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   126
| "rflts (RZERO # rs) = rflts rs"
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   127
| "rflts ((RALTS rs1) # rs) = rs1 @ rflts rs"
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   128
| "rflts (r1 # rs) = r1 # rflts rs"
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   129
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   130
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   131
lemma rflts_def_idiot:
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   132
  shows "\<lbrakk> a \<noteq> RZERO; \<nexists>rs1. a = RALTS rs1\<rbrakk> \<Longrightarrow> rflts (a # rs) = a # rflts rs"
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   133
  apply(case_tac a)
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   134
  apply simp_all
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   135
  done
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   136
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   137
lemma rflts_def_idiot2:
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   138
  shows "\<lbrakk>a \<noteq> RZERO; \<nexists>rs1. a = RALTS rs1; a \<in> set rs\<rbrakk> \<Longrightarrow> a \<in> set (rflts rs)"
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   139
  apply(induct rs rule: rflts.induct)
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   140
  apply(auto)
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   141
  done
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   142
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   143
lemma flts_append:
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   144
  shows "rflts (rs1 @ rs2) = rflts rs1 @ rflts rs2"
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   145
  apply(induct rs1)
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   146
   apply simp
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   147
  apply(case_tac a)
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   148
       apply simp+
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   149
  done
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   150
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   151
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   152
fun rsimp_ALTs :: " rrexp list \<Rightarrow> rrexp"
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   153
  where
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   154
  "rsimp_ALTs  [] = RZERO"
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   155
| "rsimp_ALTs [r] =  r"
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   156
| "rsimp_ALTs rs = RALTS rs"
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   157
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   158
lemma rsimpalts_conscons:
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   159
  shows "rsimp_ALTs (r1 # rsa @ r2 # rsb) = RALTS (r1 # rsa @ r2 # rsb)"
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   160
  by (metis Nil_is_append_conv list.exhaust rsimp_ALTs.simps(3))
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   161
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   162
lemma rsimp_alts_equal:
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   163
  shows "rsimp_ALTs (rsa @ a # rsb @ a # rsc) = RALTS (rsa @ a # rsb @ a # rsc) "
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   164
  by (metis append_Cons append_Nil neq_Nil_conv rsimpalts_conscons)
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   165
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   166
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   167
fun rsimp_SEQ :: " rrexp \<Rightarrow> rrexp \<Rightarrow> rrexp"
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   168
  where
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   169
  "rsimp_SEQ  RZERO _ = RZERO"
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   170
| "rsimp_SEQ  _ RZERO = RZERO"
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   171
| "rsimp_SEQ RONE r2 = r2"
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   172
| "rsimp_SEQ r1 r2 = RSEQ r1 r2"
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   173
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   174
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   175
fun rsimp :: "rrexp \<Rightarrow> rrexp" 
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   176
  where
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   177
  "rsimp (RSEQ r1 r2) = rsimp_SEQ  (rsimp r1) (rsimp r2)"
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   178
| "rsimp (RALTS rs) = rsimp_ALTs  (rdistinct (rflts (map rsimp rs))  {}) "
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   179
| "rsimp r = r"
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   180
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   181
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   182
fun 
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   183
  rders_simp :: "rrexp \<Rightarrow> string \<Rightarrow> rrexp"
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   184
where
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   185
  "rders_simp r [] = r"
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   186
| "rders_simp r (c#s) = rders_simp (rsimp (rder c r)) s"
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   187
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   188
fun rsize :: "rrexp \<Rightarrow> nat" where
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   189
  "rsize RZERO = 1"
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   190
| "rsize (RONE) = 1" 
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   191
| "rsize (RCHAR  c) = 1"
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   192
| "rsize (RALTS  rs) = Suc (sum_list (map rsize rs))"
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   193
| "rsize (RSEQ  r1 r2) = Suc (rsize r1 + rsize r2)"
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   194
| "rsize (RSTAR  r) = Suc (rsize r)"
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   195
| "rsize (RNTIMES  r n) = Suc (rsize r) + n"
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   196
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   197
abbreviation rsizes where
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   198
  "rsizes rs \<equiv> sum_list (map rsize rs)"
556
Chengsong
parents:
diff changeset
   199
Chengsong
parents:
diff changeset
   200
Chengsong
parents:
diff changeset
   201
lemma rder_rsimp_ALTs_commute:
Chengsong
parents:
diff changeset
   202
  shows "  (rder x (rsimp_ALTs rs)) = rsimp_ALTs (map (rder x) rs)"
Chengsong
parents:
diff changeset
   203
  apply(induct rs)
Chengsong
parents:
diff changeset
   204
   apply simp
Chengsong
parents:
diff changeset
   205
  apply(case_tac rs)
Chengsong
parents:
diff changeset
   206
   apply simp
Chengsong
parents:
diff changeset
   207
  apply auto
Chengsong
parents:
diff changeset
   208
  done
Chengsong
parents:
diff changeset
   209
Chengsong
parents:
diff changeset
   210
Chengsong
parents:
diff changeset
   211
lemma rsimp_aalts_smaller:
Chengsong
parents:
diff changeset
   212
  shows "rsize (rsimp_ALTs  rs) \<le> rsize (RALTS rs)"
Chengsong
parents:
diff changeset
   213
  apply(induct rs)
Chengsong
parents:
diff changeset
   214
   apply simp
Chengsong
parents:
diff changeset
   215
  apply simp
Chengsong
parents:
diff changeset
   216
  apply(case_tac "rs = []")
Chengsong
parents:
diff changeset
   217
   apply simp
Chengsong
parents:
diff changeset
   218
  apply(subgoal_tac "\<exists>rsp ap. rs = ap # rsp")
Chengsong
parents:
diff changeset
   219
   apply(erule exE)+
Chengsong
parents:
diff changeset
   220
   apply simp
Chengsong
parents:
diff changeset
   221
  apply simp
Chengsong
parents:
diff changeset
   222
  by(meson neq_Nil_conv)
Chengsong
parents:
diff changeset
   223
  
Chengsong
parents:
diff changeset
   224
Chengsong
parents:
diff changeset
   225
Chengsong
parents:
diff changeset
   226
Chengsong
parents:
diff changeset
   227
Chengsong
parents:
diff changeset
   228
lemma rSEQ_mono:
Chengsong
parents:
diff changeset
   229
  shows "rsize (rsimp_SEQ r1 r2) \<le>rsize (RSEQ r1 r2)"
Chengsong
parents:
diff changeset
   230
  apply auto
Chengsong
parents:
diff changeset
   231
  apply(induct r1)
Chengsong
parents:
diff changeset
   232
       apply auto
Chengsong
parents:
diff changeset
   233
      apply(case_tac "r2")
Chengsong
parents:
diff changeset
   234
       apply simp_all
Chengsong
parents:
diff changeset
   235
     apply(case_tac r2)
Chengsong
parents:
diff changeset
   236
          apply simp_all
Chengsong
parents:
diff changeset
   237
     apply(case_tac r2)
Chengsong
parents:
diff changeset
   238
         apply simp_all
Chengsong
parents:
diff changeset
   239
     apply(case_tac r2)
Chengsong
parents:
diff changeset
   240
        apply simp_all
Chengsong
parents:
diff changeset
   241
     apply(case_tac r2)
642
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   242
         apply simp_all
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   243
  apply(case_tac r2)
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   244
         apply simp_all
556
Chengsong
parents:
diff changeset
   245
  done
Chengsong
parents:
diff changeset
   246
Chengsong
parents:
diff changeset
   247
lemma ralts_cap_mono:
Chengsong
parents:
diff changeset
   248
  shows "rsize (RALTS rs) \<le> Suc (rsizes rs)"
Chengsong
parents:
diff changeset
   249
  by simp
Chengsong
parents:
diff changeset
   250
Chengsong
parents:
diff changeset
   251
Chengsong
parents:
diff changeset
   252
Chengsong
parents:
diff changeset
   253
Chengsong
parents:
diff changeset
   254
lemma rflts_mono:
Chengsong
parents:
diff changeset
   255
  shows "rsizes (rflts rs) \<le> rsizes rs"
Chengsong
parents:
diff changeset
   256
  apply(induct rs)
Chengsong
parents:
diff changeset
   257
  apply simp
Chengsong
parents:
diff changeset
   258
  apply(case_tac "a = RZERO")
Chengsong
parents:
diff changeset
   259
   apply simp
Chengsong
parents:
diff changeset
   260
  apply(case_tac "\<exists>rs1. a = RALTS rs1")
Chengsong
parents:
diff changeset
   261
  apply(erule exE)
Chengsong
parents:
diff changeset
   262
   apply simp
Chengsong
parents:
diff changeset
   263
  apply(subgoal_tac "rflts (a # rs) = a # (rflts rs)")
Chengsong
parents:
diff changeset
   264
   prefer 2
Chengsong
parents:
diff changeset
   265
  
Chengsong
parents:
diff changeset
   266
  using rflts_def_idiot apply blast
Chengsong
parents:
diff changeset
   267
  apply simp
Chengsong
parents:
diff changeset
   268
  done
Chengsong
parents:
diff changeset
   269
Chengsong
parents:
diff changeset
   270
lemma rdistinct_smaller: 
Chengsong
parents:
diff changeset
   271
  shows "rsizes (rdistinct rs ss) \<le> rsizes rs"
Chengsong
parents:
diff changeset
   272
  apply (induct rs arbitrary: ss)
Chengsong
parents:
diff changeset
   273
   apply simp
Chengsong
parents:
diff changeset
   274
  by (simp add: trans_le_add2)
Chengsong
parents:
diff changeset
   275
Chengsong
parents:
diff changeset
   276
Chengsong
parents:
diff changeset
   277
lemma rsimp_alts_mono :
Chengsong
parents:
diff changeset
   278
  shows "\<And>x. (\<And>xa. xa \<in> set x \<Longrightarrow> rsize (rsimp xa) \<le> rsize xa)  \<Longrightarrow>
Chengsong
parents:
diff changeset
   279
      rsize (rsimp_ALTs (rdistinct (rflts (map rsimp x)) {})) \<le> Suc (rsizes x)"
Chengsong
parents:
diff changeset
   280
  apply(subgoal_tac "rsize (rsimp_ALTs (rdistinct (rflts (map rsimp x)) {} )) 
Chengsong
parents:
diff changeset
   281
                    \<le> rsize (RALTS (rdistinct (rflts (map rsimp x)) {} ))")
Chengsong
parents:
diff changeset
   282
  prefer 2
Chengsong
parents:
diff changeset
   283
  using rsimp_aalts_smaller apply auto[1]
Chengsong
parents:
diff changeset
   284
  apply(subgoal_tac "rsize (RALTS (rdistinct (rflts (map rsimp x)) {})) \<le>Suc (rsizes (rdistinct (rflts (map rsimp x)) {}))")
Chengsong
parents:
diff changeset
   285
  prefer 2
Chengsong
parents:
diff changeset
   286
  using ralts_cap_mono apply blast
Chengsong
parents:
diff changeset
   287
  apply(subgoal_tac "rsizes (rdistinct (rflts (map rsimp x)) {}) \<le> rsizes (rflts (map rsimp x))")
Chengsong
parents:
diff changeset
   288
  prefer 2
Chengsong
parents:
diff changeset
   289
  using rdistinct_smaller apply presburger
Chengsong
parents:
diff changeset
   290
  apply(subgoal_tac "rsizes (rflts (map rsimp x)) \<le> rsizes (map rsimp x)")
Chengsong
parents:
diff changeset
   291
  prefer 2
Chengsong
parents:
diff changeset
   292
  using rflts_mono apply blast
Chengsong
parents:
diff changeset
   293
  apply(subgoal_tac "rsizes (map rsimp x) \<le> rsizes x")
Chengsong
parents:
diff changeset
   294
  prefer 2
Chengsong
parents:
diff changeset
   295
  
Chengsong
parents:
diff changeset
   296
  apply (simp add: sum_list_mono)
Chengsong
parents:
diff changeset
   297
  by linarith
Chengsong
parents:
diff changeset
   298
Chengsong
parents:
diff changeset
   299
Chengsong
parents:
diff changeset
   300
Chengsong
parents:
diff changeset
   301
Chengsong
parents:
diff changeset
   302
Chengsong
parents:
diff changeset
   303
lemma rsimp_mono:
Chengsong
parents:
diff changeset
   304
  shows "rsize (rsimp r) \<le> rsize r"
Chengsong
parents:
diff changeset
   305
  apply(induct r)
Chengsong
parents:
diff changeset
   306
  apply simp_all
Chengsong
parents:
diff changeset
   307
  apply(subgoal_tac "rsize (rsimp_SEQ (rsimp r1) (rsimp r2)) \<le> rsize (RSEQ (rsimp r1) (rsimp r2))")
Chengsong
parents:
diff changeset
   308
    apply force
Chengsong
parents:
diff changeset
   309
  using rSEQ_mono
Chengsong
parents:
diff changeset
   310
   apply presburger
Chengsong
parents:
diff changeset
   311
  using rsimp_alts_mono by auto
Chengsong
parents:
diff changeset
   312
Chengsong
parents:
diff changeset
   313
lemma idiot:
Chengsong
parents:
diff changeset
   314
  shows "rsimp_SEQ RONE r = r"
Chengsong
parents:
diff changeset
   315
  apply(case_tac r)
Chengsong
parents:
diff changeset
   316
       apply simp_all
Chengsong
parents:
diff changeset
   317
  done
Chengsong
parents:
diff changeset
   318
Chengsong
parents:
diff changeset
   319
Chengsong
parents:
diff changeset
   320
Chengsong
parents:
diff changeset
   321
Chengsong
parents:
diff changeset
   322
Chengsong
parents:
diff changeset
   323
lemma idiot2:
Chengsong
parents:
diff changeset
   324
  shows " \<lbrakk>r1 \<noteq> RZERO; r1 \<noteq> RONE;r2 \<noteq> RZERO\<rbrakk>
Chengsong
parents:
diff changeset
   325
    \<Longrightarrow> rsimp_SEQ r1 r2 = RSEQ r1 r2"
Chengsong
parents:
diff changeset
   326
  apply(case_tac r1)
Chengsong
parents:
diff changeset
   327
       apply(case_tac r2)
Chengsong
parents:
diff changeset
   328
  apply simp_all
Chengsong
parents:
diff changeset
   329
     apply(case_tac r2)
Chengsong
parents:
diff changeset
   330
  apply simp_all
Chengsong
parents:
diff changeset
   331
     apply(case_tac r2)
Chengsong
parents:
diff changeset
   332
  apply simp_all
Chengsong
parents:
diff changeset
   333
   apply(case_tac r2)
Chengsong
parents:
diff changeset
   334
  apply simp_all
Chengsong
parents:
diff changeset
   335
  apply(case_tac r2)
642
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   336
         apply simp_all
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   337
apply(case_tac r2)
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   338
         apply simp_all
556
Chengsong
parents:
diff changeset
   339
  done
Chengsong
parents:
diff changeset
   340
Chengsong
parents:
diff changeset
   341
lemma rders__onechar:
Chengsong
parents:
diff changeset
   342
  shows " (rders_simp r [c]) =  (rsimp (rders r [c]))"
Chengsong
parents:
diff changeset
   343
  by simp
Chengsong
parents:
diff changeset
   344
Chengsong
parents:
diff changeset
   345
lemma rders_append:
Chengsong
parents:
diff changeset
   346
  "rders c (s1 @ s2) = rders (rders c s1) s2"
Chengsong
parents:
diff changeset
   347
  apply(induct s1 arbitrary: c s2)
Chengsong
parents:
diff changeset
   348
  apply(simp_all)
Chengsong
parents:
diff changeset
   349
  done
Chengsong
parents:
diff changeset
   350
Chengsong
parents:
diff changeset
   351
lemma rders_simp_append:
Chengsong
parents:
diff changeset
   352
  "rders_simp c (s1 @ s2) = rders_simp (rders_simp c s1) s2"
Chengsong
parents:
diff changeset
   353
  apply(induct s1 arbitrary: c s2)
Chengsong
parents:
diff changeset
   354
   apply(simp_all)
Chengsong
parents:
diff changeset
   355
  done
Chengsong
parents:
diff changeset
   356
Chengsong
parents:
diff changeset
   357
Chengsong
parents:
diff changeset
   358
lemma rders_simp_one_char:
Chengsong
parents:
diff changeset
   359
  shows "rders_simp r [c] = rsimp (rder c r)"
Chengsong
parents:
diff changeset
   360
  apply auto
Chengsong
parents:
diff changeset
   361
  done
Chengsong
parents:
diff changeset
   362
Chengsong
parents:
diff changeset
   363
Chengsong
parents:
diff changeset
   364
642
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   365
fun nonalt :: "rrexp \<Rightarrow> bool"
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   366
  where
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   367
  "nonalt (RALTS  rs) = False"
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   368
| "nonalt r = True"
556
Chengsong
parents:
diff changeset
   369
Chengsong
parents:
diff changeset
   370
642
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   371
fun good :: "rrexp \<Rightarrow> bool" where
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   372
  "good RZERO = False"
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   373
| "good (RONE) = True" 
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   374
| "good (RCHAR c) = True"
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   375
| "good (RALTS []) = False"
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   376
| "good (RALTS [r]) = False"
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   377
| "good (RALTS (r1 # r2 # rs)) = ((distinct ( (r1 # r2 # rs))) \<and>(\<forall>r' \<in> set (r1 # r2 # rs). good r' \<and> nonalt r'))"
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   378
| "good (RSEQ RZERO _) = False"
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   379
| "good (RSEQ RONE _) = False"
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   380
| "good (RSEQ  _ RZERO) = False"
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   381
| "good (RSEQ r1 r2) = (good r1 \<and> good r2)"
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   382
| "good (RSTAR r) = True"
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   383
| "good (RNTIMES r n) = True"
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   384
556
Chengsong
parents:
diff changeset
   385
lemma  k0a:
Chengsong
parents:
diff changeset
   386
  shows "rflts [RALTS rs] =   rs"
Chengsong
parents:
diff changeset
   387
  apply(simp)
Chengsong
parents:
diff changeset
   388
  done
Chengsong
parents:
diff changeset
   389
Chengsong
parents:
diff changeset
   390
lemma bbbbs:
Chengsong
parents:
diff changeset
   391
  assumes "good r" "r = RALTS rs"
Chengsong
parents:
diff changeset
   392
  shows "rsimp_ALTs  (rflts [r]) = RALTS rs"
Chengsong
parents:
diff changeset
   393
  using  assms
Chengsong
parents:
diff changeset
   394
  by (metis good.simps(4) good.simps(5) k0a rsimp_ALTs.elims)
Chengsong
parents:
diff changeset
   395
Chengsong
parents:
diff changeset
   396
lemma bbbbs1:
Chengsong
parents:
diff changeset
   397
  shows "nonalt r \<or> (\<exists> rs. r  = RALTS  rs)"
Chengsong
parents:
diff changeset
   398
  by (meson nonalt.elims(3))
Chengsong
parents:
diff changeset
   399
Chengsong
parents:
diff changeset
   400
Chengsong
parents:
diff changeset
   401
Chengsong
parents:
diff changeset
   402
lemma good0:
Chengsong
parents:
diff changeset
   403
  assumes "rs \<noteq> Nil" "\<forall>r \<in> set rs. nonalt r" "distinct rs"
Chengsong
parents:
diff changeset
   404
  shows "good (rsimp_ALTs rs) \<longleftrightarrow> (\<forall>r \<in> set rs. good r)"
Chengsong
parents:
diff changeset
   405
  using  assms
Chengsong
parents:
diff changeset
   406
  apply(induct  rs rule: rsimp_ALTs.induct)
Chengsong
parents:
diff changeset
   407
  apply(auto)
Chengsong
parents:
diff changeset
   408
  done
Chengsong
parents:
diff changeset
   409
Chengsong
parents:
diff changeset
   410
lemma flts1:
Chengsong
parents:
diff changeset
   411
  assumes "good r" 
Chengsong
parents:
diff changeset
   412
  shows "rflts [r] \<noteq> []"
Chengsong
parents:
diff changeset
   413
  using  assms
Chengsong
parents:
diff changeset
   414
  apply(induct r)
Chengsong
parents:
diff changeset
   415
       apply(simp_all)
Chengsong
parents:
diff changeset
   416
  using good.simps(4) by blast
Chengsong
parents:
diff changeset
   417
Chengsong
parents:
diff changeset
   418
lemma flts2:
Chengsong
parents:
diff changeset
   419
  assumes "good r" 
Chengsong
parents:
diff changeset
   420
  shows "\<forall>r' \<in> set (rflts [r]). good r' \<and> nonalt r'"
Chengsong
parents:
diff changeset
   421
  using  assms
Chengsong
parents:
diff changeset
   422
  apply(induct r)
Chengsong
parents:
diff changeset
   423
       apply(simp)
Chengsong
parents:
diff changeset
   424
      apply(simp)
Chengsong
parents:
diff changeset
   425
     apply(simp)
Chengsong
parents:
diff changeset
   426
    prefer 2
Chengsong
parents:
diff changeset
   427
    apply(simp)
Chengsong
parents:
diff changeset
   428
    apply(auto)[1]
Chengsong
parents:
diff changeset
   429
  
Chengsong
parents:
diff changeset
   430
     apply (metis flts1 good.simps(5) good.simps(6) k0a neq_Nil_conv)
Chengsong
parents:
diff changeset
   431
    apply (metis flts1 good.simps(5) good.simps(6) k0a neq_Nil_conv)
Chengsong
parents:
diff changeset
   432
   apply fastforce
642
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   433
   apply(simp)
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   434
  by simp
556
Chengsong
parents:
diff changeset
   435
Chengsong
parents:
diff changeset
   436
Chengsong
parents:
diff changeset
   437
lemma flts3:
Chengsong
parents:
diff changeset
   438
  assumes "\<forall>r \<in> set rs. good r \<or> r = RZERO" 
Chengsong
parents:
diff changeset
   439
  shows "\<forall>r \<in> set (rflts rs). good r"
Chengsong
parents:
diff changeset
   440
  using  assms
642
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   441
  apply(induct rs arbitrary: rule: rflts.induct)
556
Chengsong
parents:
diff changeset
   442
        apply(simp_all)
Chengsong
parents:
diff changeset
   443
  by (metis UnE flts2 k0a)
Chengsong
parents:
diff changeset
   444
Chengsong
parents:
diff changeset
   445
Chengsong
parents:
diff changeset
   446
lemma  k0:
Chengsong
parents:
diff changeset
   447
  shows "rflts (r # rs1) = rflts [r] @ rflts rs1"
Chengsong
parents:
diff changeset
   448
  apply(induct r arbitrary: rs1)
Chengsong
parents:
diff changeset
   449
   apply(auto)
Chengsong
parents:
diff changeset
   450
  done
Chengsong
parents:
diff changeset
   451
Chengsong
parents:
diff changeset
   452
Chengsong
parents:
diff changeset
   453
lemma good_SEQ:
Chengsong
parents:
diff changeset
   454
  assumes "r1 \<noteq> RZERO" "r2 \<noteq> RZERO" " r1 \<noteq> RONE"
Chengsong
parents:
diff changeset
   455
  shows "good (RSEQ r1 r2) = (good r1 \<and> good r2)"
Chengsong
parents:
diff changeset
   456
  using assms
Chengsong
parents:
diff changeset
   457
  apply(case_tac r1)
Chengsong
parents:
diff changeset
   458
       apply(simp_all)
Chengsong
parents:
diff changeset
   459
  apply(case_tac r2)
Chengsong
parents:
diff changeset
   460
          apply(simp_all)
Chengsong
parents:
diff changeset
   461
  apply(case_tac r2)
Chengsong
parents:
diff changeset
   462
         apply(simp_all)
Chengsong
parents:
diff changeset
   463
  apply(case_tac r2)
Chengsong
parents:
diff changeset
   464
        apply(simp_all)
Chengsong
parents:
diff changeset
   465
  apply(case_tac r2)
642
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   466
         apply(simp_all)
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   467
apply(case_tac r2)
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   468
         apply(simp_all)
556
Chengsong
parents:
diff changeset
   469
  done
Chengsong
parents:
diff changeset
   470
Chengsong
parents:
diff changeset
   471
lemma rsize0:
Chengsong
parents:
diff changeset
   472
  shows "0 < rsize r"
Chengsong
parents:
diff changeset
   473
  apply(induct  r)
Chengsong
parents:
diff changeset
   474
       apply(auto)
Chengsong
parents:
diff changeset
   475
  done
Chengsong
parents:
diff changeset
   476
Chengsong
parents:
diff changeset
   477
642
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   478
fun nonnested :: "rrexp \<Rightarrow> bool"
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   479
  where
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   480
  "nonnested (RALTS []) = True"
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   481
| "nonnested (RALTS ((RALTS rs1) # rs2)) = False"
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   482
| "nonnested (RALTS (r # rs2)) = nonnested (RALTS rs2)"
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   483
| "nonnested r = True"
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   484
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   485
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   486
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   487
lemma  k00:
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   488
  shows "rflts (rs1 @ rs2) = rflts rs1 @ rflts rs2"
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   489
  apply(induct rs1 arbitrary: rs2)
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   490
   apply(auto)
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   491
  by (metis append.assoc k0)
556
Chengsong
parents:
diff changeset
   492
Chengsong
parents:
diff changeset
   493
Chengsong
parents:
diff changeset
   494
Chengsong
parents:
diff changeset
   495
642
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   496
lemma k0b:
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   497
  assumes "nonalt r" "r \<noteq> RZERO"
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   498
  shows "rflts [r] = [r]"
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   499
  using assms
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   500
  apply(case_tac  r)
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   501
  apply(simp_all)
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   502
  done
556
Chengsong
parents:
diff changeset
   503
Chengsong
parents:
diff changeset
   504
lemma nn1qq:
Chengsong
parents:
diff changeset
   505
  assumes "nonnested (RALTS rs)"
Chengsong
parents:
diff changeset
   506
  shows "\<nexists> rs1. RALTS rs1 \<in> set rs"
Chengsong
parents:
diff changeset
   507
  using assms
Chengsong
parents:
diff changeset
   508
  apply(induct rs rule: rflts.induct)
Chengsong
parents:
diff changeset
   509
  apply(auto)
Chengsong
parents:
diff changeset
   510
  done
Chengsong
parents:
diff changeset
   511
Chengsong
parents:
diff changeset
   512
 
Chengsong
parents:
diff changeset
   513
Chengsong
parents:
diff changeset
   514
lemma n0:
Chengsong
parents:
diff changeset
   515
  shows "nonnested (RALTS rs) \<longleftrightarrow> (\<forall>r \<in> set rs. nonalt r)"
Chengsong
parents:
diff changeset
   516
  apply(induct rs )
Chengsong
parents:
diff changeset
   517
   apply(auto)
Chengsong
parents:
diff changeset
   518
    apply (metis list.set_intros(1) nn1qq nonalt.elims(3))
642
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   519
  apply (metis nonalt.elims(2) nonnested.simps(3) nonnested.simps(4) nonnested.simps(5) nonnested.simps(6) nonnested.simps(7) nonnested.simps(8))
556
Chengsong
parents:
diff changeset
   520
  using bbbbs1 apply fastforce
Chengsong
parents:
diff changeset
   521
  by (metis bbbbs1 list.set_intros(2) nn1qq)
Chengsong
parents:
diff changeset
   522
Chengsong
parents:
diff changeset
   523
  
Chengsong
parents:
diff changeset
   524
  
Chengsong
parents:
diff changeset
   525
Chengsong
parents:
diff changeset
   526
lemma nn1c:
Chengsong
parents:
diff changeset
   527
  assumes "\<forall>r \<in> set rs. nonnested r"
Chengsong
parents:
diff changeset
   528
  shows "\<forall>r \<in> set (rflts rs). nonalt r"
Chengsong
parents:
diff changeset
   529
  using assms
Chengsong
parents:
diff changeset
   530
  apply(induct rs rule: rflts.induct)
Chengsong
parents:
diff changeset
   531
        apply(auto)
Chengsong
parents:
diff changeset
   532
  using n0 by blast
Chengsong
parents:
diff changeset
   533
Chengsong
parents:
diff changeset
   534
lemma nn1bb:
Chengsong
parents:
diff changeset
   535
  assumes "\<forall>r \<in> set rs. nonalt r"
Chengsong
parents:
diff changeset
   536
  shows "nonnested (rsimp_ALTs  rs)"
Chengsong
parents:
diff changeset
   537
  using assms
Chengsong
parents:
diff changeset
   538
  apply(induct  rs rule: rsimp_ALTs.induct)
Chengsong
parents:
diff changeset
   539
    apply(auto)
Chengsong
parents:
diff changeset
   540
  using nonalt.simps(1) nonnested.elims(3) apply blast
Chengsong
parents:
diff changeset
   541
  using n0 by auto
Chengsong
parents:
diff changeset
   542
Chengsong
parents:
diff changeset
   543
lemma bsimp_ASEQ0:
Chengsong
parents:
diff changeset
   544
  shows "rsimp_SEQ  r1 RZERO = RZERO"
Chengsong
parents:
diff changeset
   545
  apply(induct r1)
Chengsong
parents:
diff changeset
   546
  apply(auto)
Chengsong
parents:
diff changeset
   547
  done
Chengsong
parents:
diff changeset
   548
Chengsong
parents:
diff changeset
   549
lemma nn1b:
Chengsong
parents:
diff changeset
   550
  shows "nonnested (rsimp r)"
Chengsong
parents:
diff changeset
   551
  apply(induct r)
Chengsong
parents:
diff changeset
   552
       apply(simp_all)
Chengsong
parents:
diff changeset
   553
  apply(case_tac "rsimp r1 = RZERO")
Chengsong
parents:
diff changeset
   554
    apply(simp)
Chengsong
parents:
diff changeset
   555
 apply(case_tac "rsimp r2 = RZERO")
Chengsong
parents:
diff changeset
   556
   apply(simp)
Chengsong
parents:
diff changeset
   557
    apply(subst bsimp_ASEQ0)
Chengsong
parents:
diff changeset
   558
  apply(simp)
Chengsong
parents:
diff changeset
   559
  apply(case_tac "\<exists>bs. rsimp r1 = RONE")
Chengsong
parents:
diff changeset
   560
    apply(auto)[1]
Chengsong
parents:
diff changeset
   561
  using idiot apply fastforce
642
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   562
  apply (simp add: idiot2)
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   563
  by (metis (mono_tags, lifting) image_iff list.set_map nn1bb nn1c rdistinct_set_equality)
556
Chengsong
parents:
diff changeset
   564
Chengsong
parents:
diff changeset
   565
lemma nonalt_flts_rd:
Chengsong
parents:
diff changeset
   566
  shows "\<lbrakk>xa \<in> set (rdistinct (rflts (map rsimp rs)) {})\<rbrakk>
Chengsong
parents:
diff changeset
   567
       \<Longrightarrow> nonalt xa"
Chengsong
parents:
diff changeset
   568
  by (metis Diff_empty ex_map_conv nn1b nn1c rdistinct_set_equality1)
Chengsong
parents:
diff changeset
   569
Chengsong
parents:
diff changeset
   570
642
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   571
lemma rsimpalts_implies1:
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   572
  shows " rsimp_ALTs (a # rdistinct rs {a}) = RZERO \<Longrightarrow> a = RZERO"
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   573
  using rsimp_ALTs.elims by auto
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   574
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   575
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   576
lemma rsimpalts_implies2:
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   577
  shows "rsimp_ALTs (a # rdistinct rs rset) = RZERO \<Longrightarrow> rdistinct rs rset = []"
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   578
  by (metis append_butlast_last_id rrexp.distinct(7) rsimpalts_conscons)
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   579
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   580
lemma rsimpalts_implies21:
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   581
  shows "rsimp_ALTs (a # rdistinct rs {a}) = RZERO \<Longrightarrow> rdistinct rs {a} = []"
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   582
  using rsimpalts_implies2 by blast
556
Chengsong
parents:
diff changeset
   583
Chengsong
parents:
diff changeset
   584
Chengsong
parents:
diff changeset
   585
lemma bsimp_ASEQ2:
Chengsong
parents:
diff changeset
   586
  shows "rsimp_SEQ RONE r2 =  r2"
Chengsong
parents:
diff changeset
   587
  apply(induct r2)
Chengsong
parents:
diff changeset
   588
  apply(auto)
Chengsong
parents:
diff changeset
   589
  done
Chengsong
parents:
diff changeset
   590
Chengsong
parents:
diff changeset
   591
lemma elem_smaller_than_set:
Chengsong
parents:
diff changeset
   592
  shows "xa \<in> set  list \<Longrightarrow> rsize xa < Suc (rsizes list)"
Chengsong
parents:
diff changeset
   593
  apply(induct list)
Chengsong
parents:
diff changeset
   594
   apply simp
Chengsong
parents:
diff changeset
   595
  by (metis image_eqI le_imp_less_Suc list.set_map member_le_sum_list)
Chengsong
parents:
diff changeset
   596
Chengsong
parents:
diff changeset
   597
lemma rsimp_list_mono:
Chengsong
parents:
diff changeset
   598
  shows "rsizes (map rsimp rs) \<le> rsizes rs"
Chengsong
parents:
diff changeset
   599
  apply(induct rs)
Chengsong
parents:
diff changeset
   600
   apply simp+
Chengsong
parents:
diff changeset
   601
  by (simp add: add_mono_thms_linordered_semiring(1) rsimp_mono)
Chengsong
parents:
diff changeset
   602
Chengsong
parents:
diff changeset
   603
Chengsong
parents:
diff changeset
   604
(*says anything coming out of simp+flts+db will be good*)
Chengsong
parents:
diff changeset
   605
lemma good2_obv_simplified:
Chengsong
parents:
diff changeset
   606
  shows " \<lbrakk>\<forall>y. rsize y < Suc (rsizes rs) \<longrightarrow> good (rsimp y) \<or> rsimp y = RZERO;
642
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   607
           xa \<in> set (rdistinct (rflts (map rsimp rs)) {}); good (rsimp xa) \<or> rsimp xa = RZERO\<rbrakk> \<Longrightarrow> good xa"
556
Chengsong
parents:
diff changeset
   608
  apply(subgoal_tac " \<forall>xa' \<in> set (map rsimp rs). good xa' \<or> xa' = RZERO")
Chengsong
parents:
diff changeset
   609
  prefer 2
Chengsong
parents:
diff changeset
   610
   apply (simp add: elem_smaller_than_set)
Chengsong
parents:
diff changeset
   611
  by (metis Diff_empty flts3 rdistinct_set_equality1)
Chengsong
parents:
diff changeset
   612
642
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   613
thm Diff_empty flts3 rdistinct_set_equality1
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   614
  
556
Chengsong
parents:
diff changeset
   615
lemma good1:
Chengsong
parents:
diff changeset
   616
  shows "good (rsimp a) \<or> rsimp a = RZERO"
Chengsong
parents:
diff changeset
   617
  apply(induct a taking: rsize rule: measure_induct)
Chengsong
parents:
diff changeset
   618
  apply(case_tac x)
Chengsong
parents:
diff changeset
   619
  apply(simp)
Chengsong
parents:
diff changeset
   620
  apply(simp)
Chengsong
parents:
diff changeset
   621
  apply(simp)
Chengsong
parents:
diff changeset
   622
  prefer 3
Chengsong
parents:
diff changeset
   623
    apply(simp)
Chengsong
parents:
diff changeset
   624
   prefer 2
Chengsong
parents:
diff changeset
   625
   apply(simp only:)
Chengsong
parents:
diff changeset
   626
   apply simp
Chengsong
parents:
diff changeset
   627
  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_smaller rflts_mono rsimp_ALTs.simps(1) rsimp_list_mono)
Chengsong
parents:
diff changeset
   628
  apply simp
Chengsong
parents:
diff changeset
   629
  apply(subgoal_tac "good (rsimp x41) \<or> rsimp x41 = RZERO")
Chengsong
parents:
diff changeset
   630
   apply(subgoal_tac "good (rsimp x42) \<or> rsimp x42 = RZERO")
Chengsong
parents:
diff changeset
   631
    apply(case_tac "rsimp x41 = RZERO")
Chengsong
parents:
diff changeset
   632
     apply simp
Chengsong
parents:
diff changeset
   633
    apply(case_tac "rsimp x42 = RZERO")
Chengsong
parents:
diff changeset
   634
     apply simp
Chengsong
parents:
diff changeset
   635
  using bsimp_ASEQ0 apply blast
Chengsong
parents:
diff changeset
   636
    apply(subgoal_tac "good (rsimp x41)")
Chengsong
parents:
diff changeset
   637
     apply(subgoal_tac "good (rsimp x42)")
Chengsong
parents:
diff changeset
   638
      apply simp
Chengsong
parents:
diff changeset
   639
  apply (metis bsimp_ASEQ2 good_SEQ idiot2)
Chengsong
parents:
diff changeset
   640
  apply blast
Chengsong
parents:
diff changeset
   641
  apply fastforce
Chengsong
parents:
diff changeset
   642
  using less_add_Suc2 apply blast  
642
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   643
  using less_iff_Suc_add apply blast
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   644
  using good.simps(45) rsimp.simps(7) by presburger
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   645
  
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   646
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   647
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   648
fun
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   649
  RL :: "rrexp \<Rightarrow> string set"
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   650
where
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   651
  "RL (RZERO) = {}"
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   652
| "RL (RONE) = {[]}"
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   653
| "RL (RCHAR c) = {[c]}"
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   654
| "RL (RSEQ r1 r2) = (RL r1) ;; (RL r2)"
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   655
| "RL (RALTS rs) = (\<Union> (set (map RL rs)))"
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   656
| "RL (RSTAR r) = (RL r)\<star>"
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   657
| "RL (RNTIMES r n) = (RL r) ^^ n"
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   658
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   659
lemma pow_rempty_iff:
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   660
  shows "[] \<in> (RL r) ^^ n \<longleftrightarrow> (if n = 0 then True else [] \<in> (RL r))"
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   661
  by (induct n) (auto simp add: Sequ_def)
556
Chengsong
parents:
diff changeset
   662
Chengsong
parents:
diff changeset
   663
lemma RL_rnullable:
Chengsong
parents:
diff changeset
   664
  shows "rnullable r = ([] \<in> RL r)"
Chengsong
parents:
diff changeset
   665
  apply(induct r)
642
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   666
        apply(auto simp add: Sequ_def pow_rempty_iff)
556
Chengsong
parents:
diff changeset
   667
  done
Chengsong
parents:
diff changeset
   668
642
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   669
lemma concI_if_Nil1: "[] \<in> A \<Longrightarrow> xs : B \<Longrightarrow> xs \<in> A ;; B"
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   670
by (metis append_Nil concI)
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   671
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   672
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   673
lemma empty_pow_add:
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   674
  fixes A::"string set"
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   675
  assumes "[] \<in> A" "s \<in> A ^^ n"
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   676
  shows "s \<in> A ^^ (n + m)"
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   677
  using assms
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   678
  apply(induct m arbitrary: n)
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   679
   apply(auto simp add: Sequ_def)
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   680
  done
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   681
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   682
(*
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   683
lemma der_pow:
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   684
  shows "Der c (A ^^ n) = (if n = 0 then {} else (Der c A) ;; (A ^^ (n - 1)))"
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   685
  apply(induct n arbitrary: A)
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   686
   apply(auto)
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   687
  by (smt (verit, best) Suc_pred concE concI concI_if_Nil2 conc_pow_comm lang_pow.simps(2))
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   688
*)
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   689
556
Chengsong
parents:
diff changeset
   690
lemma RL_rder:
Chengsong
parents:
diff changeset
   691
  shows "RL (rder c r) = Der c (RL r)"
Chengsong
parents:
diff changeset
   692
  apply(induct r)
642
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   693
  apply(auto simp add: Sequ_def Der_def)[5]
556
Chengsong
parents:
diff changeset
   694
        apply (metis append_Cons)
Chengsong
parents:
diff changeset
   695
  using RL_rnullable apply blast
Chengsong
parents:
diff changeset
   696
  apply (metis append_eq_Cons_conv)
Chengsong
parents:
diff changeset
   697
  apply (metis append_Cons)
642
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   698
    apply (metis RL_rnullable append_eq_Cons_conv)
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   699
  apply simp
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   700
  apply(simp)
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   701
  done
556
Chengsong
parents:
diff changeset
   702
Chengsong
parents:
diff changeset
   703
lemma RL_rsimp_RSEQ:
Chengsong
parents:
diff changeset
   704
  shows "RL (rsimp_SEQ r1 r2) = (RL r1 ;; RL r2)"
Chengsong
parents:
diff changeset
   705
  apply(induct r1 r2 rule: rsimp_SEQ.induct)
Chengsong
parents:
diff changeset
   706
  apply(simp_all)
Chengsong
parents:
diff changeset
   707
  done
Chengsong
parents:
diff changeset
   708
Chengsong
parents:
diff changeset
   709
lemma RL_rsimp_RALTS:
Chengsong
parents:
diff changeset
   710
  shows "RL (rsimp_ALTs rs) = (\<Union> (set (map RL rs)))"
Chengsong
parents:
diff changeset
   711
  apply(induct rs rule: rsimp_ALTs.induct)
Chengsong
parents:
diff changeset
   712
  apply(simp_all)
Chengsong
parents:
diff changeset
   713
  done
Chengsong
parents:
diff changeset
   714
Chengsong
parents:
diff changeset
   715
lemma RL_rsimp_rdistinct:
Chengsong
parents:
diff changeset
   716
  shows "(\<Union> (set (map RL (rdistinct rs {})))) = (\<Union> (set (map RL rs)))"
Chengsong
parents:
diff changeset
   717
  apply(auto)
Chengsong
parents:
diff changeset
   718
  apply (metis Diff_iff rdistinct_set_equality1)
Chengsong
parents:
diff changeset
   719
  by (metis Diff_empty rdistinct_set_equality1)
Chengsong
parents:
diff changeset
   720
Chengsong
parents:
diff changeset
   721
lemma RL_rsimp_rflts:
Chengsong
parents:
diff changeset
   722
  shows "(\<Union> (set (map RL (rflts rs)))) = (\<Union> (set (map RL rs)))"
Chengsong
parents:
diff changeset
   723
  apply(induct rs rule: rflts.induct)
Chengsong
parents:
diff changeset
   724
  apply(simp_all)
Chengsong
parents:
diff changeset
   725
  done
Chengsong
parents:
diff changeset
   726
Chengsong
parents:
diff changeset
   727
lemma RL_rsimp:
Chengsong
parents:
diff changeset
   728
  shows "RL r = RL (rsimp r)"
Chengsong
parents:
diff changeset
   729
  apply(induct r rule: rsimp.induct)
Chengsong
parents:
diff changeset
   730
       apply(auto simp add: Sequ_def RL_rsimp_RSEQ)
Chengsong
parents:
diff changeset
   731
  using RL_rsimp_RALTS RL_rsimp_rdistinct RL_rsimp_rflts apply auto[1]
Chengsong
parents:
diff changeset
   732
  by (smt (verit, del_insts) RL_rsimp_RALTS RL_rsimp_rdistinct RL_rsimp_rflts UN_E image_iff list.set_map)
Chengsong
parents:
diff changeset
   733
Chengsong
parents:
diff changeset
   734
  
Chengsong
parents:
diff changeset
   735
lemma qqq1:
Chengsong
parents:
diff changeset
   736
  shows "RZERO \<notin> set (rflts (map rsimp rs))"
Chengsong
parents:
diff changeset
   737
  by (metis ex_map_conv flts3 good.simps(1) good1)
Chengsong
parents:
diff changeset
   738
Chengsong
parents:
diff changeset
   739
642
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   740
fun nonazero :: "rrexp \<Rightarrow> bool"
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   741
  where
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   742
  "nonazero RZERO = False"
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   743
| "nonazero r = True"
556
Chengsong
parents:
diff changeset
   744
Chengsong
parents:
diff changeset
   745
Chengsong
parents:
diff changeset
   746
lemma flts_single1:
Chengsong
parents:
diff changeset
   747
  assumes "nonalt r" "nonazero r"
Chengsong
parents:
diff changeset
   748
  shows "rflts [r] = [r]"
Chengsong
parents:
diff changeset
   749
  using assms
Chengsong
parents:
diff changeset
   750
  apply(induct r)
Chengsong
parents:
diff changeset
   751
  apply(auto)
Chengsong
parents:
diff changeset
   752
  done
Chengsong
parents:
diff changeset
   753
Chengsong
parents:
diff changeset
   754
lemma nonalt0_flts_keeps:
Chengsong
parents:
diff changeset
   755
  shows "(a \<noteq> RZERO) \<and> (\<forall>rs. a \<noteq> RALTS rs) \<Longrightarrow> rflts (a # xs) = a # rflts xs"
Chengsong
parents:
diff changeset
   756
  apply(case_tac a)
Chengsong
parents:
diff changeset
   757
       apply simp+
Chengsong
parents:
diff changeset
   758
  done
Chengsong
parents:
diff changeset
   759
Chengsong
parents:
diff changeset
   760
Chengsong
parents:
diff changeset
   761
lemma nonalt0_fltseq:
Chengsong
parents:
diff changeset
   762
  shows "\<forall>r \<in> set rs. r \<noteq> RZERO \<and> nonalt r \<Longrightarrow> rflts rs = rs"
Chengsong
parents:
diff changeset
   763
  apply(induct rs)
Chengsong
parents:
diff changeset
   764
   apply simp
Chengsong
parents:
diff changeset
   765
  apply(case_tac "a = RZERO")
Chengsong
parents:
diff changeset
   766
   apply fastforce
Chengsong
parents:
diff changeset
   767
  apply(case_tac "\<exists>rs1. a = RALTS rs1")
Chengsong
parents:
diff changeset
   768
   apply(erule exE)
Chengsong
parents:
diff changeset
   769
   apply simp+
Chengsong
parents:
diff changeset
   770
  using nonalt0_flts_keeps by presburger
Chengsong
parents:
diff changeset
   771
Chengsong
parents:
diff changeset
   772
  
Chengsong
parents:
diff changeset
   773
Chengsong
parents:
diff changeset
   774
Chengsong
parents:
diff changeset
   775
lemma goodalts_nonalt:
Chengsong
parents:
diff changeset
   776
  shows "good (RALTS rs) \<Longrightarrow> rflts rs = rs"
Chengsong
parents:
diff changeset
   777
  apply(induct x == "RALTS rs" arbitrary: rs rule: good.induct)
Chengsong
parents:
diff changeset
   778
    apply simp
Chengsong
parents:
diff changeset
   779
  
Chengsong
parents:
diff changeset
   780
  using good.simps(5) apply blast
Chengsong
parents:
diff changeset
   781
  apply simp
Chengsong
parents:
diff changeset
   782
  apply(case_tac "r1 = RZERO")
Chengsong
parents:
diff changeset
   783
  using good.simps(1) apply force
Chengsong
parents:
diff changeset
   784
  apply(case_tac "r2 = RZERO")
Chengsong
parents:
diff changeset
   785
  using good.simps(1) apply force
Chengsong
parents:
diff changeset
   786
  apply(subgoal_tac "rflts (r1 # r2 # rs) = r1 # r2 # rflts rs")
Chengsong
parents:
diff changeset
   787
  prefer 2
Chengsong
parents:
diff changeset
   788
   apply (metis nonalt.simps(1) rflts_def_idiot)
Chengsong
parents:
diff changeset
   789
  apply(subgoal_tac "\<forall>r \<in> set rs. r \<noteq> RZERO \<and> nonalt r")
Chengsong
parents:
diff changeset
   790
   apply(subgoal_tac "rflts rs = rs")
Chengsong
parents:
diff changeset
   791
    apply presburger
Chengsong
parents:
diff changeset
   792
  using nonalt0_fltseq apply presburger
Chengsong
parents:
diff changeset
   793
  using good.simps(1) by blast
Chengsong
parents:
diff changeset
   794
  
Chengsong
parents:
diff changeset
   795
Chengsong
parents:
diff changeset
   796
  
Chengsong
parents:
diff changeset
   797
Chengsong
parents:
diff changeset
   798
Chengsong
parents:
diff changeset
   799
lemma test:
Chengsong
parents:
diff changeset
   800
  assumes "good r"
Chengsong
parents:
diff changeset
   801
  shows "rsimp r = r"
Chengsong
parents:
diff changeset
   802
Chengsong
parents:
diff changeset
   803
  using assms
Chengsong
parents:
diff changeset
   804
  apply(induct rule: good.induct)
Chengsong
parents:
diff changeset
   805
                      apply simp
Chengsong
parents:
diff changeset
   806
                      apply simp
Chengsong
parents:
diff changeset
   807
                      apply simp
Chengsong
parents:
diff changeset
   808
                      apply simp
Chengsong
parents:
diff changeset
   809
                      apply simp
Chengsong
parents:
diff changeset
   810
                      apply(subgoal_tac "distinct (r1 # r2 # rs)")
Chengsong
parents:
diff changeset
   811
  prefer 2
Chengsong
parents:
diff changeset
   812
  using good.simps(6) apply blast
Chengsong
parents:
diff changeset
   813
  apply(subgoal_tac "rflts (r1 # r2 # rs ) = r1 # r2 # rs")
Chengsong
parents:
diff changeset
   814
  prefer 2
Chengsong
parents:
diff changeset
   815
  using goodalts_nonalt apply blast
Chengsong
parents:
diff changeset
   816
Chengsong
parents:
diff changeset
   817
                      apply(subgoal_tac "r1 \<noteq> r2")
Chengsong
parents:
diff changeset
   818
  prefer 2
Chengsong
parents:
diff changeset
   819
                      apply (meson distinct_length_2_or_more)
Chengsong
parents:
diff changeset
   820
                      apply(subgoal_tac "r1 \<notin> set rs")
Chengsong
parents:
diff changeset
   821
                      apply(subgoal_tac "r2 \<notin> set rs")
Chengsong
parents:
diff changeset
   822
                      apply(subgoal_tac "\<forall>r \<in> set rs. rsimp r = r")
Chengsong
parents:
diff changeset
   823
                      apply(subgoal_tac "map rsimp rs = rs")
Chengsong
parents:
diff changeset
   824
  apply simp             
Chengsong
parents:
diff changeset
   825
                      apply(subgoal_tac "\<forall>r \<in>  {r1, r2}. r \<notin> set rs")
Chengsong
parents:
diff changeset
   826
  apply (metis distinct_not_exist rdistinct_on_distinct)
Chengsong
parents:
diff changeset
   827
  
Chengsong
parents:
diff changeset
   828
                      apply blast
Chengsong
parents:
diff changeset
   829
                      apply (meson map_idI)
Chengsong
parents:
diff changeset
   830
                      apply (metis good.simps(6) insert_iff list.simps(15))
Chengsong
parents:
diff changeset
   831
Chengsong
parents:
diff changeset
   832
  apply (meson distinct.simps(2))
Chengsong
parents:
diff changeset
   833
                      apply (simp add: distinct_length_2_or_more)
Chengsong
parents:
diff changeset
   834
                      apply simp+
Chengsong
parents:
diff changeset
   835
  done
Chengsong
parents:
diff changeset
   836
Chengsong
parents:
diff changeset
   837
Chengsong
parents:
diff changeset
   838
Chengsong
parents:
diff changeset
   839
lemma rsimp_idem:
Chengsong
parents:
diff changeset
   840
  shows "rsimp (rsimp r) = rsimp r"
Chengsong
parents:
diff changeset
   841
  using test good1
Chengsong
parents:
diff changeset
   842
  by force
Chengsong
parents:
diff changeset
   843
Chengsong
parents:
diff changeset
   844
corollary rsimp_inner_idem4:
Chengsong
parents:
diff changeset
   845
  shows "rsimp r = RALTS rs \<Longrightarrow> rflts rs = rs"
Chengsong
parents:
diff changeset
   846
  by (metis good1 goodalts_nonalt rrexp.simps(12))
Chengsong
parents:
diff changeset
   847
Chengsong
parents:
diff changeset
   848
642
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   849
lemma head_one_more_simp:
556
Chengsong
parents:
diff changeset
   850
  shows "map rsimp (r # rs) = map rsimp (( rsimp r) # rs)"
Chengsong
parents:
diff changeset
   851
  by (simp add: rsimp_idem)
Chengsong
parents:
diff changeset
   852
Chengsong
parents:
diff changeset
   853
642
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   854
lemma der_simp_nullability:
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   855
  shows "rnullable r = rnullable (rsimp r)"
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   856
  using RL_rnullable RL_rsimp by auto
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   857
  
556
Chengsong
parents:
diff changeset
   858
Chengsong
parents:
diff changeset
   859
lemma no_alt_short_list_after_simp:
Chengsong
parents:
diff changeset
   860
  shows "RALTS rs = rsimp r \<Longrightarrow> rsimp_ALTs rs = RALTS rs"
Chengsong
parents:
diff changeset
   861
  by (metis bbbbs good1 k0a rrexp.simps(12))
Chengsong
parents:
diff changeset
   862
Chengsong
parents:
diff changeset
   863
Chengsong
parents:
diff changeset
   864
lemma no_further_dB_after_simp:
Chengsong
parents:
diff changeset
   865
  shows "RALTS rs = rsimp r \<Longrightarrow> rdistinct rs {} = rs"
Chengsong
parents:
diff changeset
   866
  apply(subgoal_tac "good (RALTS rs)")
Chengsong
parents:
diff changeset
   867
  apply(subgoal_tac "distinct rs")
Chengsong
parents:
diff changeset
   868
  using rdistinct_on_distinct apply blast
Chengsong
parents:
diff changeset
   869
  apply (metis distinct.simps(1) distinct.simps(2) empty_iff good.simps(6) list.exhaust set_empty2)
Chengsong
parents:
diff changeset
   870
  using good1 by fastforce
Chengsong
parents:
diff changeset
   871
Chengsong
parents:
diff changeset
   872
Chengsong
parents:
diff changeset
   873
lemma idem_after_simp1:
Chengsong
parents:
diff changeset
   874
  shows "rsimp_ALTs (rdistinct (rflts [rsimp aa]) {}) = rsimp aa"
Chengsong
parents:
diff changeset
   875
  apply(case_tac "rsimp aa")
Chengsong
parents:
diff changeset
   876
  apply simp+
Chengsong
parents:
diff changeset
   877
  apply (metis no_alt_short_list_after_simp no_further_dB_after_simp)
642
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   878
   apply(simp)
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   879
  apply(simp)
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   880
  done
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   881
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   882
lemma identity_wwo0:
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   883
  shows "rsimp (rsimp_ALTs (RZERO # rs)) = rsimp (rsimp_ALTs rs)"
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   884
  apply (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))
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   885
  done
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   886
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   887
lemma distinct_removes_last:
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   888
  shows "\<lbrakk>a \<in> set as\<rbrakk>
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   889
    \<Longrightarrow> rdistinct as rset = rdistinct (as @ [a]) rset"
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   890
and "rdistinct (ab # as @ [ab]) rset1 = rdistinct (ab # as) rset1"
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   891
  apply(induct as arbitrary: rset ab rset1 a)
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   892
     apply simp
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   893
    apply simp
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   894
  apply(case_tac "aa \<in> rset")
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   895
   apply(case_tac "a = aa")
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   896
  apply (metis append_Cons)
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   897
    apply simp
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   898
   apply(case_tac "a \<in> set as")
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   899
  apply (metis append_Cons rdistinct.simps(2) set_ConsD)
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   900
   apply(case_tac "a = aa")
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   901
    prefer 2
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   902
    apply simp
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   903
   apply (metis append_Cons)
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   904
  apply(case_tac "ab \<in> rset1")
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   905
  prefer 2
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   906
   apply(subgoal_tac "rdistinct (ab # (a # as) @ [ab]) rset1 = 
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   907
               ab # (rdistinct ((a # as) @ [ab]) (insert ab rset1))")
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   908
  prefer 2
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   909
  apply force
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   910
  apply(simp only:)
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   911
     apply(subgoal_tac "rdistinct (ab # a # as) rset1 = ab # (rdistinct (a # as) (insert ab rset1))")
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   912
    apply(simp only:)
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   913
    apply(subgoal_tac "rdistinct ((a # as) @ [ab]) (insert ab rset1) = rdistinct (a # as) (insert ab rset1)")
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   914
     apply blast
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   915
    apply(case_tac "a \<in> insert ab rset1")
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   916
     apply simp
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   917
     apply (metis insertI1)
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   918
    apply simp
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   919
    apply (meson insertI1)
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   920
   apply simp
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   921
  apply(subgoal_tac "rdistinct ((a # as) @ [ab]) rset1 = rdistinct (a # as) rset1")
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   922
   apply simp
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   923
  by (metis append_Cons insert_iff insert_is_Un rdistinct.simps(2))
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   924
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   925
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   926
lemma distinct_removes_middle:
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   927
  shows  "\<lbrakk>a \<in> set as\<rbrakk>
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   928
    \<Longrightarrow> rdistinct (as @ as2) rset = rdistinct (as @ [a] @ as2) rset"
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   929
and "rdistinct (ab # as @ [ab] @ as3) rset1 = rdistinct (ab # as @ as3) rset1"
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   930
   apply(induct as arbitrary: rset rset1 ab as2 as3 a)
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   931
     apply simp
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   932
    apply simp
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   933
   apply(case_tac "a \<in> rset")
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   934
    apply simp
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   935
    apply metis
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   936
   apply simp
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   937
   apply (metis insertI1)
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   938
  apply(case_tac "a = ab")
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   939
   apply simp
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   940
   apply(case_tac "ab \<in> rset")
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   941
    apply simp
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   942
    apply presburger
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   943
   apply (meson insertI1)
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   944
  apply(case_tac "a \<in> rset")
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   945
  apply (metis (no_types, opaque_lifting) Un_insert_left append_Cons insert_iff rdistinct.simps(2) sup_bot_left)
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   946
  apply(case_tac "ab \<in> rset")
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   947
  apply simp
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   948
   apply (meson insert_iff)
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   949
  apply simp
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   950
  by (metis insertI1)
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   951
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   952
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   953
lemma distinct_removes_middle3:
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   954
  shows  "\<lbrakk>a \<in> set as\<rbrakk>
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   955
    \<Longrightarrow> rdistinct (as @ a #as2) rset = rdistinct (as @ as2) rset"
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   956
  using distinct_removes_middle(1) by fastforce
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   957
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   958
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   959
lemma distinct_removes_list:
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   960
  shows "\<lbrakk> \<forall>r \<in> set rs. r \<in> set as\<rbrakk> \<Longrightarrow> rdistinct (as @ rs) {} = rdistinct as {}"
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   961
  apply(induct rs)
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   962
   apply simp+
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   963
  apply(subgoal_tac "rdistinct (as @ a # rs) {} = rdistinct (as @ rs) {}")
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   964
   prefer 2
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   965
  apply (metis append_Cons append_Nil distinct_removes_middle(1))
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   966
  by presburger
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   967
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   968
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   969
lemma spawn_simp_rsimpalts:
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   970
  shows "rsimp (rsimp_ALTs rs) = rsimp (rsimp_ALTs (map rsimp rs))"
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   971
  apply(cases rs)
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   972
   apply simp
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   973
  apply(case_tac list)
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   974
   apply simp
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   975
   apply(subst rsimp_idem[symmetric])
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   976
   apply simp
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   977
  apply(subgoal_tac "rsimp_ALTs rs = RALTS rs")
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   978
   apply(simp only:)
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   979
   apply(subgoal_tac "rsimp_ALTs (map rsimp rs) = RALTS (map rsimp rs)")
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   980
    apply(simp only:)
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   981
  prefer 2
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   982
  apply simp
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   983
   prefer 2
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   984
  using rsimp_ALTs.simps(3) apply presburger
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   985
  apply auto
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   986
  apply(subst rsimp_idem)+
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   987
  by (metis comp_apply rsimp_idem)
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   988
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   989
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   990
lemma simp_singlealt_flatten:
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   991
  shows "rsimp (RALTS [RALTS rsa]) = rsimp (RALTS (rsa @ []))"
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   992
  apply(induct rsa)
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   993
   apply simp
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   994
  apply simp
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   995
  by (metis idem_after_simp1 list.simps(9) rsimp.simps(2))
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   996
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   997
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   998
lemma good1_rsimpalts:
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
   999
  shows "rsimp r = RALTS rs \<Longrightarrow> rsimp_ALTs rs = RALTS rs"
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
  1000
  by (metis no_alt_short_list_after_simp) 
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
  1001
  
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
  1002
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
  1003
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
  1004
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
  1005
lemma good1_flatten:
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
  1006
  shows "\<lbrakk> rsimp r =  (RALTS rs1)\<rbrakk>
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
  1007
       \<Longrightarrow> rflts (rsimp_ALTs rs1 # map rsimp rsb) = rflts (rs1 @ map rsimp rsb)"
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
  1008
  apply(subst good1_rsimpalts)
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
  1009
   apply simp+
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
  1010
  apply(subgoal_tac "rflts (rs1 @ map rsimp rsb) = rs1 @ rflts (map rsimp rsb)")
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
  1011
   apply simp
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
  1012
  using flts_append rsimp_inner_idem4 by presburger
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
  1013
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
  1014
  
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
  1015
lemma flatten_rsimpalts:
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
  1016
  shows "rflts (rsimp_ALTs (rdistinct (rflts (map rsimp rsa)) {}) # map rsimp rsb) = 
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
  1017
         rflts ( (rdistinct (rflts (map rsimp rsa)) {}) @ map rsimp rsb)"
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
  1018
  apply(case_tac "map rsimp rsa")
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
  1019
   apply simp
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
  1020
  apply(case_tac "list")
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
  1021
   apply simp
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
  1022
   apply(case_tac a)
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
  1023
        apply simp+
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
  1024
    apply(rename_tac rs1)
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
  1025
    apply (metis good1_flatten map_eq_Cons_D no_further_dB_after_simp)
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
  1026
  
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
  1027
  apply simp
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
  1028
  
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
  1029
  apply(subgoal_tac "\<forall>r \<in> set( rflts (map rsimp rsa)). good r")
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
  1030
   apply(case_tac "rdistinct (rflts (map rsimp rsa)) {}")
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
  1031
     apply simp
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
  1032
  apply auto[1]
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
  1033
  apply simp
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
  1034
  apply(simp)
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
  1035
   apply(case_tac "lista")
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
  1036
  apply simp_all
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
  1037
 
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
  1038
   apply (metis append_Cons append_Nil good1_flatten rflts.simps(2) rsimp.simps(2) rsimp_ALTs.elims)
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
  1039
   by (metis (no_types, opaque_lifting) append_Cons append_Nil good1_flatten rflts.simps(2) rsimp.simps(2) rsimp_ALTs.elims)
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
  1040
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
  1041
lemma last_elem_out:
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
  1042
  shows "\<lbrakk>x \<notin> set xs; x \<notin> rset \<rbrakk> \<Longrightarrow> rdistinct (xs @ [x]) rset = rdistinct xs rset @ [x]"
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
  1043
  apply(induct xs arbitrary: rset)
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
  1044
  apply simp+
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
  1045
  done
556
Chengsong
parents:
diff changeset
  1046
Chengsong
parents:
diff changeset
  1047
Chengsong
parents:
diff changeset
  1048
Chengsong
parents:
diff changeset
  1049
642
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
  1050
lemma rdistinct_concat_general:
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
  1051
  shows "rdistinct (rs1 @ rs2) {} = (rdistinct rs1 {}) @ (rdistinct rs2 (set rs1))"
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
  1052
  apply(induct rs1 arbitrary: rs2 rule: rev_induct)
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
  1053
   apply simp
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
  1054
  apply(drule_tac x = "x # rs2" in meta_spec)
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
  1055
  apply simp
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
  1056
  apply(case_tac "x \<in> set xs")
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
  1057
   apply simp
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
  1058
  
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
  1059
   apply (simp add: distinct_removes_middle3 insert_absorb)
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
  1060
  apply simp
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
  1061
  by (simp add: last_elem_out)
556
Chengsong
parents:
diff changeset
  1062
642
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
  1063
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
  1064
  
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
  1065
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
  1066
lemma distinct_once_enough:
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
  1067
  shows "rdistinct (rs @ rsa) {} = rdistinct (rdistinct rs {} @ rsa) {}"
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
  1068
  apply(subgoal_tac "distinct (rdistinct rs {})")
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
  1069
   apply(subgoal_tac 
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
  1070
" rdistinct (rdistinct rs {} @ rsa) {} = rdistinct rs {} @ (rdistinct rsa (set rs))")
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
  1071
  apply(simp only:)
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
  1072
  using rdistinct_concat_general apply blast
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
  1073
  apply (simp add: distinct_rdistinct_append rdistinct_set_equality1)
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
  1074
  by (simp add: rdistinct_does_the_job)
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
  1075
  
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
  1076
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
  1077
lemma simp_flatten:
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
  1078
  shows "rsimp (RALTS ((RALTS rsa) # rsb)) = rsimp (RALTS (rsa @ rsb))"
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
  1079
  apply simp
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
  1080
  apply(subst flatten_rsimpalts)
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
  1081
  apply(simp add: flts_append)
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
  1082
  by (metis Diff_empty distinct_once_enough flts_append nonalt0_fltseq nonalt_flts_rd qqq1 rdistinct_set_equality1)
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
  1083
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
  1084
lemma basic_rsimp_SEQ_property1:
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
  1085
  shows "rsimp_SEQ RONE r = r"
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
  1086
  by (simp add: idiot)
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
  1087
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
  1088
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
  1089
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
  1090
lemma basic_rsimp_SEQ_property3:
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
  1091
  shows "rsimp_SEQ r RZERO = RZERO"  
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
  1092
  using rsimp_SEQ.elims by blast
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
  1093
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
  1094
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
  1095
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
  1096
fun vsuf :: "char list \<Rightarrow> rrexp \<Rightarrow> char list list" where
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
  1097
"vsuf [] _ = []"
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
  1098
|"vsuf (c#cs) r1 = (if (rnullable r1) then  (vsuf cs (rder c r1)) @ [c # cs]
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
  1099
                                      else  (vsuf cs (rder c r1))
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
  1100
                   ) "
556
Chengsong
parents:
diff changeset
  1101
Chengsong
parents:
diff changeset
  1102
Chengsong
parents:
diff changeset
  1103
Chengsong
parents:
diff changeset
  1104
Chengsong
parents:
diff changeset
  1105
Chengsong
parents:
diff changeset
  1106
642
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
  1107
fun star_update :: "char \<Rightarrow> rrexp \<Rightarrow> char list list \<Rightarrow> char list list" where
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
  1108
"star_update c r [] = []"
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
  1109
|"star_update c r (s # Ss) = (if (rnullable (rders r s)) 
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
  1110
                                then (s@[c]) # [c] # (star_update c r Ss) 
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
  1111
                               else   (s@[c]) # (star_update c r Ss) )"
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
  1112
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
  1113
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
  1114
fun star_updates :: "char list \<Rightarrow> rrexp \<Rightarrow> char list list \<Rightarrow> char list list"
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
  1115
  where
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
  1116
"star_updates [] r Ss = Ss"
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
  1117
| "star_updates (c # cs) r Ss = star_updates cs r (star_update c r Ss)"
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
  1118
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
  1119
lemma stupdates_append: shows 
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
  1120
"star_updates (s @ [c]) r Ss = star_update c r (star_updates s r Ss)"
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
  1121
  apply(induct s arbitrary: Ss)
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
  1122
   apply simp
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
  1123
  apply simp
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
  1124
  done
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
  1125
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
  1126
lemma flts_removes0:
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
  1127
  shows "  rflts (rs @ [RZERO])  =
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
  1128
           rflts rs"
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
  1129
  apply(induct rs)
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
  1130
   apply simp
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
  1131
  by (metis append_Cons rflts.simps(2) rflts.simps(3) rflts_def_idiot)
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
  1132
  
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
  1133
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
  1134
lemma rflts_spills_last:
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
  1135
  shows "rflts (rs1 @ [RALTS rs]) = rflts rs1 @ rs"
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
  1136
  apply (induct rs1 rule: rflts.induct)
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
  1137
  apply(auto)
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
  1138
  done
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
  1139
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
  1140
lemma flts_keeps1:
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
  1141
  shows "rflts (rs @ [RONE]) = rflts rs @ [RONE]"
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
  1142
  apply (induct rs rule: rflts.induct)
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
  1143
  apply(auto)
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
  1144
  done
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
  1145
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
  1146
lemma flts_keeps_others:
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
  1147
  shows "\<lbrakk>a \<noteq> RZERO; \<nexists>rs1. a = RALTS rs1\<rbrakk> \<Longrightarrow>rflts (rs @ [a]) = rflts rs @ [a]"
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
  1148
  apply(induct rs rule: rflts.induct)
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
  1149
  apply(auto)
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
  1150
  by (meson k0b nonalt.elims(3))
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
  1151
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
  1152
lemma spilled_alts_contained:
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
  1153
  shows "\<lbrakk>a = RALTS rs ; a \<in> set rs1\<rbrakk> \<Longrightarrow> \<forall>r \<in> set rs. r \<in> set (rflts rs1)"
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
  1154
  apply(induct rs1)
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
  1155
   apply simp 
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
  1156
  apply(case_tac "a = aa")
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
  1157
   apply simp
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
  1158
  apply(subgoal_tac " a \<in> set rs1")
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
  1159
  prefer 2
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
  1160
   apply (meson set_ConsD)
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
  1161
  apply(case_tac aa)
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
  1162
  using rflts.simps(2) apply presburger
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
  1163
      apply fastforce
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
  1164
  apply fastforce
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
  1165
  apply fastforce
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
  1166
  apply fastforce
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
  1167
  apply fastforce
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
  1168
  by simp
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
  1169
  
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
  1170
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
  1171
lemma distinct_removes_duplicate_flts:
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
  1172
  shows " a \<in> set rsa
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
  1173
       \<Longrightarrow> rdistinct (rflts (map rsimp rsa @ [rsimp a])) {} =
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
  1174
           rdistinct (rflts (map rsimp rsa)) {}"
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
  1175
  apply(subgoal_tac "rsimp a \<in> set (map rsimp rsa)")
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
  1176
  prefer 2
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
  1177
   apply simp
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
  1178
  apply(induct "rsimp a")
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
  1179
       apply simp
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
  1180
  using flts_removes0 apply presburger
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
  1181
      apply(subgoal_tac " rdistinct (rflts (map rsimp rsa @ [rsimp a])) {} =  
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
  1182
                          rdistinct (rflts (map rsimp rsa @ [RONE])) {}")
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
  1183
      apply (simp only:)
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
  1184
        apply(subst flts_keeps1)
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
  1185
  apply (metis distinct_removes_last(1) flts_append in_set_conv_decomp rflts.simps(4))
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
  1186
      apply presburger
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
  1187
        apply(subgoal_tac " rdistinct (rflts (map rsimp rsa @ [rsimp a]))    {} =  
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
  1188
                            rdistinct ((rflts (map rsimp rsa)) @ [RCHAR x]) {}")
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
  1189
      apply (simp only:)
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
  1190
       prefer 2
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
  1191
       apply (metis flts_append rflts.simps(1) rflts.simps(5))
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
  1192
  apply (metis distinct_removes_last(1) rflts_def_idiot2 rrexp.distinct(25) rrexp.distinct(3))
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
  1193
  apply (metis distinct_removes_last(1) flts_append rflts.simps(1) rflts.simps(6) rflts_def_idiot2 rrexp.distinct(31) rrexp.distinct(5))
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
  1194
  apply (metis distinct_removes_list rflts_spills_last spilled_alts_contained)
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
  1195
  apply (metis distinct_removes_last(1) flts_append good.simps(1) good.simps(44) rflts.simps(1) rflts.simps(7) rflts_def_idiot2 rrexp.distinct(37))
6c13f76c070b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 556
diff changeset
  1196
  by (metis distinct_removes_last(1) flts_append rflts.simps(1) rflts.simps(8) rflts_def_idiot2 rrexp.distinct(11) rrexp.distinct(39))
556
Chengsong
parents:
diff changeset
  1197
Chengsong
parents:
diff changeset
  1198
(*some basic facts about rsimp*)
Chengsong
parents:
diff changeset
  1199
Chengsong
parents:
diff changeset
  1200
unused_thms
Chengsong
parents:
diff changeset
  1201
Chengsong
parents:
diff changeset
  1202
Chengsong
parents:
diff changeset
  1203
end