thys3/RfltsRdistinctProps.thy
author Chengsong
Mon, 10 Jul 2023 00:44:45 +0100
changeset 659 2e05f04ed6b3
parent 556 c27f04bb2262
permissions -rw-r--r--
Addressed Gerog "can't understand 'erase messes with structure'" comment
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
556
Chengsong
parents:
diff changeset
     1
theory RfltsRdistinctProps imports "Rsimp"
Chengsong
parents:
diff changeset
     2
begin
Chengsong
parents:
diff changeset
     3
Chengsong
parents:
diff changeset
     4
Chengsong
parents:
diff changeset
     5
Chengsong
parents:
diff changeset
     6
lemma all_that_same_elem:
Chengsong
parents:
diff changeset
     7
  shows "\<lbrakk> a \<in> rset; rdistinct rs {a} = []\<rbrakk>
Chengsong
parents:
diff changeset
     8
       \<Longrightarrow> rdistinct (rs @ rsb) rset = rdistinct rsb rset"
Chengsong
parents:
diff changeset
     9
  apply(induct rs)
Chengsong
parents:
diff changeset
    10
   apply simp
Chengsong
parents:
diff changeset
    11
  apply(subgoal_tac "aa = a")
Chengsong
parents:
diff changeset
    12
   apply simp
Chengsong
parents:
diff changeset
    13
  by (metis empty_iff insert_iff list.discI rdistinct.simps(2))
Chengsong
parents:
diff changeset
    14
Chengsong
parents:
diff changeset
    15
Chengsong
parents:
diff changeset
    16
lemma rdistinct1:
Chengsong
parents:
diff changeset
    17
  assumes "a \<in> acc"
Chengsong
parents:
diff changeset
    18
  shows "a \<notin> set (rdistinct rs acc)"
Chengsong
parents:
diff changeset
    19
  using assms
Chengsong
parents:
diff changeset
    20
  apply(induct rs arbitrary: acc a)
Chengsong
parents:
diff changeset
    21
   apply(auto)
Chengsong
parents:
diff changeset
    22
  done
Chengsong
parents:
diff changeset
    23
Chengsong
parents:
diff changeset
    24
Chengsong
parents:
diff changeset
    25
lemma rdistinct_does_the_job:
Chengsong
parents:
diff changeset
    26
  shows "distinct (rdistinct rs s)"
Chengsong
parents:
diff changeset
    27
  apply(induct rs s rule: rdistinct.induct)
Chengsong
parents:
diff changeset
    28
  apply(auto simp add: rdistinct1)
Chengsong
parents:
diff changeset
    29
  done
Chengsong
parents:
diff changeset
    30
Chengsong
parents:
diff changeset
    31
Chengsong
parents:
diff changeset
    32
Chengsong
parents:
diff changeset
    33
lemma rdistinct_concat:
Chengsong
parents:
diff changeset
    34
  assumes "set rs \<subseteq> rset"
Chengsong
parents:
diff changeset
    35
  shows "rdistinct (rs @ rsa) rset = rdistinct rsa rset"
Chengsong
parents:
diff changeset
    36
  using assms
Chengsong
parents:
diff changeset
    37
  apply(induct rs)
Chengsong
parents:
diff changeset
    38
  apply simp+
Chengsong
parents:
diff changeset
    39
  done
Chengsong
parents:
diff changeset
    40
Chengsong
parents:
diff changeset
    41
lemma distinct_not_exist:
Chengsong
parents:
diff changeset
    42
  assumes "a \<notin> set rs"
Chengsong
parents:
diff changeset
    43
  shows "rdistinct rs rset = rdistinct rs (insert a rset)"
Chengsong
parents:
diff changeset
    44
  using assms
Chengsong
parents:
diff changeset
    45
  apply(induct rs arbitrary: rset)
Chengsong
parents:
diff changeset
    46
  apply(auto)
Chengsong
parents:
diff changeset
    47
  done
Chengsong
parents:
diff changeset
    48
Chengsong
parents:
diff changeset
    49
lemma rdistinct_on_distinct:
Chengsong
parents:
diff changeset
    50
  shows "distinct rs \<Longrightarrow> rdistinct rs {} = rs"
Chengsong
parents:
diff changeset
    51
  apply(induct rs)
Chengsong
parents:
diff changeset
    52
  apply simp
Chengsong
parents:
diff changeset
    53
  using distinct_not_exist by fastforce
Chengsong
parents:
diff changeset
    54
Chengsong
parents:
diff changeset
    55
lemma distinct_rdistinct_append:
Chengsong
parents:
diff changeset
    56
  assumes "distinct rs1" "\<forall>r \<in> set rs1. r \<notin> acc"
Chengsong
parents:
diff changeset
    57
  shows "rdistinct (rs1 @ rsa) acc = rs1 @ (rdistinct rsa (acc \<union> set rs1))"
Chengsong
parents:
diff changeset
    58
  using assms
Chengsong
parents:
diff changeset
    59
  apply(induct rs1 arbitrary: rsa acc)
Chengsong
parents:
diff changeset
    60
   apply(auto)[1]
Chengsong
parents:
diff changeset
    61
  apply(auto)[1]
Chengsong
parents:
diff changeset
    62
  apply(drule_tac x="rsa" in meta_spec)
Chengsong
parents:
diff changeset
    63
  apply(drule_tac x="{a} \<union> acc" in meta_spec)
Chengsong
parents:
diff changeset
    64
  apply(simp)
Chengsong
parents:
diff changeset
    65
  apply(drule meta_mp)
Chengsong
parents:
diff changeset
    66
   apply(auto)[1]
Chengsong
parents:
diff changeset
    67
  apply(simp)
Chengsong
parents:
diff changeset
    68
  done
Chengsong
parents:
diff changeset
    69
  
Chengsong
parents:
diff changeset
    70
Chengsong
parents:
diff changeset
    71
lemma rdistinct_set_equality1:
Chengsong
parents:
diff changeset
    72
  shows "set (rdistinct rs acc) = set rs - acc"
Chengsong
parents:
diff changeset
    73
  apply(induct rs acc rule: rdistinct.induct)
Chengsong
parents:
diff changeset
    74
  apply(auto)
Chengsong
parents:
diff changeset
    75
  done
Chengsong
parents:
diff changeset
    76
Chengsong
parents:
diff changeset
    77
Chengsong
parents:
diff changeset
    78
lemma rdistinct_set_equality:
Chengsong
parents:
diff changeset
    79
  shows "set (rdistinct rs {}) = set rs"
Chengsong
parents:
diff changeset
    80
  by (simp add: rdistinct_set_equality1)
Chengsong
parents:
diff changeset
    81
Chengsong
parents:
diff changeset
    82
Chengsong
parents:
diff changeset
    83
Chengsong
parents:
diff changeset
    84
lemma distinct_removes_last:
Chengsong
parents:
diff changeset
    85
  shows "\<lbrakk>a \<in> set as\<rbrakk>
Chengsong
parents:
diff changeset
    86
    \<Longrightarrow> rdistinct as rset = rdistinct (as @ [a]) rset"
Chengsong
parents:
diff changeset
    87
and "rdistinct (ab # as @ [ab]) rset1 = rdistinct (ab # as) rset1"
Chengsong
parents:
diff changeset
    88
   apply(induct as arbitrary: rset ab rset1 a)
Chengsong
parents:
diff changeset
    89
     apply simp
Chengsong
parents:
diff changeset
    90
    apply simp
Chengsong
parents:
diff changeset
    91
  apply(case_tac "aa \<in> rset")
Chengsong
parents:
diff changeset
    92
   apply(case_tac "a = aa")
Chengsong
parents:
diff changeset
    93
  apply (metis append_Cons)
Chengsong
parents:
diff changeset
    94
    apply simp
Chengsong
parents:
diff changeset
    95
   apply(case_tac "a \<in> set as")
Chengsong
parents:
diff changeset
    96
  apply (metis append_Cons rdistinct.simps(2) set_ConsD)
Chengsong
parents:
diff changeset
    97
   apply(case_tac "a = aa")
Chengsong
parents:
diff changeset
    98
    prefer 2
Chengsong
parents:
diff changeset
    99
    apply simp
Chengsong
parents:
diff changeset
   100
   apply (metis append_Cons)
Chengsong
parents:
diff changeset
   101
  apply(case_tac "ab \<in> rset1")
Chengsong
parents:
diff changeset
   102
  prefer 2
Chengsong
parents:
diff changeset
   103
   apply(subgoal_tac "rdistinct (ab # (a # as) @ [ab]) rset1 = 
Chengsong
parents:
diff changeset
   104
               ab # (rdistinct ((a # as) @ [ab]) (insert ab rset1))")
Chengsong
parents:
diff changeset
   105
  prefer 2
Chengsong
parents:
diff changeset
   106
  apply force
Chengsong
parents:
diff changeset
   107
  apply(simp only:)
Chengsong
parents:
diff changeset
   108
     apply(subgoal_tac "rdistinct (ab # a # as) rset1 = ab # (rdistinct (a # as) (insert ab rset1))")
Chengsong
parents:
diff changeset
   109
    apply(simp only:)
Chengsong
parents:
diff changeset
   110
    apply(subgoal_tac "rdistinct ((a # as) @ [ab]) (insert ab rset1) = rdistinct (a # as) (insert ab rset1)")
Chengsong
parents:
diff changeset
   111
     apply blast
Chengsong
parents:
diff changeset
   112
    apply(case_tac "a \<in> insert ab rset1")
Chengsong
parents:
diff changeset
   113
     apply simp
Chengsong
parents:
diff changeset
   114
     apply (metis insertI1)
Chengsong
parents:
diff changeset
   115
    apply simp
Chengsong
parents:
diff changeset
   116
    apply (meson insertI1)
Chengsong
parents:
diff changeset
   117
   apply simp
Chengsong
parents:
diff changeset
   118
  apply(subgoal_tac "rdistinct ((a # as) @ [ab]) rset1 = rdistinct (a # as) rset1")
Chengsong
parents:
diff changeset
   119
   apply simp
Chengsong
parents:
diff changeset
   120
  by (metis append_Cons insert_iff insert_is_Un rdistinct.simps(2))
Chengsong
parents:
diff changeset
   121
Chengsong
parents:
diff changeset
   122
Chengsong
parents:
diff changeset
   123
lemma distinct_removes_middle:
Chengsong
parents:
diff changeset
   124
  shows  "\<lbrakk>a \<in> set as\<rbrakk>
Chengsong
parents:
diff changeset
   125
    \<Longrightarrow> rdistinct (as @ as2) rset = rdistinct (as @ [a] @ as2) rset"
Chengsong
parents:
diff changeset
   126
and "rdistinct (ab # as @ [ab] @ as3) rset1 = rdistinct (ab # as @ as3) rset1"
Chengsong
parents:
diff changeset
   127
   apply(induct as arbitrary: rset rset1 ab as2 as3 a)
Chengsong
parents:
diff changeset
   128
     apply simp
Chengsong
parents:
diff changeset
   129
    apply simp
Chengsong
parents:
diff changeset
   130
   apply(case_tac "a \<in> rset")
Chengsong
parents:
diff changeset
   131
    apply simp
Chengsong
parents:
diff changeset
   132
    apply metis
Chengsong
parents:
diff changeset
   133
   apply simp
Chengsong
parents:
diff changeset
   134
   apply (metis insertI1)
Chengsong
parents:
diff changeset
   135
  apply(case_tac "a = ab")
Chengsong
parents:
diff changeset
   136
   apply simp
Chengsong
parents:
diff changeset
   137
   apply(case_tac "ab \<in> rset")
Chengsong
parents:
diff changeset
   138
    apply simp
Chengsong
parents:
diff changeset
   139
    apply presburger
Chengsong
parents:
diff changeset
   140
   apply (meson insertI1)
Chengsong
parents:
diff changeset
   141
  apply(case_tac "a \<in> rset")
Chengsong
parents:
diff changeset
   142
  apply (metis (no_types, opaque_lifting) Un_insert_left append_Cons insert_iff rdistinct.simps(2) sup_bot_left)
Chengsong
parents:
diff changeset
   143
  apply(case_tac "ab \<in> rset")
Chengsong
parents:
diff changeset
   144
  apply simp
Chengsong
parents:
diff changeset
   145
   apply (meson insert_iff)
Chengsong
parents:
diff changeset
   146
  apply simp
Chengsong
parents:
diff changeset
   147
  by (metis insertI1)
Chengsong
parents:
diff changeset
   148
Chengsong
parents:
diff changeset
   149
Chengsong
parents:
diff changeset
   150
lemma k0b:
Chengsong
parents:
diff changeset
   151
  assumes "nonalt r" "r \<noteq> RZERO"
Chengsong
parents:
diff changeset
   152
  shows "rflts [r] = [r]"
Chengsong
parents:
diff changeset
   153
  using assms
Chengsong
parents:
diff changeset
   154
  apply(case_tac  r)
Chengsong
parents:
diff changeset
   155
       apply(simp_all)
Chengsong
parents:
diff changeset
   156
  done
Chengsong
parents:
diff changeset
   157
Chengsong
parents:
diff changeset
   158
lemma rflts_def_idiot:
Chengsong
parents:
diff changeset
   159
  shows "\<lbrakk> a \<noteq> RZERO; \<nexists>rs1. a = RALTS rs1\<rbrakk> \<Longrightarrow> rflts (a # rs) = a # rflts rs"
Chengsong
parents:
diff changeset
   160
  apply(case_tac a)
Chengsong
parents:
diff changeset
   161
  apply simp_all
Chengsong
parents:
diff changeset
   162
  done
Chengsong
parents:
diff changeset
   163
Chengsong
parents:
diff changeset
   164
lemma flts_middle0:
Chengsong
parents:
diff changeset
   165
  shows "rflts (rsa @ RZERO # rsb) = rflts (rsa @ rsb)"
Chengsong
parents:
diff changeset
   166
  apply(induct rsa)
Chengsong
parents:
diff changeset
   167
  apply simp
Chengsong
parents:
diff changeset
   168
  by (metis append_Cons rflts.simps(2) rflts.simps(3) rflts_def_idiot)
Chengsong
parents:
diff changeset
   169
Chengsong
parents:
diff changeset
   170
Chengsong
parents:
diff changeset
   171
lemma flts_removes0:
Chengsong
parents:
diff changeset
   172
  shows "  rflts (rs @ [RZERO])  =
Chengsong
parents:
diff changeset
   173
           rflts rs"
Chengsong
parents:
diff changeset
   174
  apply(induct rs)
Chengsong
parents:
diff changeset
   175
   apply simp
Chengsong
parents:
diff changeset
   176
  by (metis append_Cons rflts.simps(2) rflts.simps(3) rflts_def_idiot)
Chengsong
parents:
diff changeset
   177
Chengsong
parents:
diff changeset
   178
lemma rflts_spills_last:
Chengsong
parents:
diff changeset
   179
  shows "rflts (rs1 @ [RALTS rs]) = rflts rs1 @ rs"
Chengsong
parents:
diff changeset
   180
  apply (induct rs1 rule: rflts.induct)
Chengsong
parents:
diff changeset
   181
  apply(auto)
Chengsong
parents:
diff changeset
   182
  done
Chengsong
parents:
diff changeset
   183
Chengsong
parents:
diff changeset
   184
lemma flts_keeps1:
Chengsong
parents:
diff changeset
   185
  shows "rflts (rs @ [RONE]) = rflts rs @ [RONE]"
Chengsong
parents:
diff changeset
   186
  apply (induct rs rule: rflts.induct)
Chengsong
parents:
diff changeset
   187
  apply(auto)
Chengsong
parents:
diff changeset
   188
  done
Chengsong
parents:
diff changeset
   189
Chengsong
parents:
diff changeset
   190
lemma flts_keeps_others:
Chengsong
parents:
diff changeset
   191
  shows "\<lbrakk>a \<noteq> RZERO; \<nexists>rs1. a = RALTS rs1\<rbrakk> \<Longrightarrow>rflts (rs @ [a]) = rflts rs @ [a]"
Chengsong
parents:
diff changeset
   192
  apply(induct rs rule: rflts.induct)
Chengsong
parents:
diff changeset
   193
  apply(auto)
Chengsong
parents:
diff changeset
   194
  by (meson k0b nonalt.elims(3))
Chengsong
parents:
diff changeset
   195
Chengsong
parents:
diff changeset
   196
lemma spilled_alts_contained:
Chengsong
parents:
diff changeset
   197
  shows "\<lbrakk>a = RALTS rs ; a \<in> set rs1\<rbrakk> \<Longrightarrow> \<forall>r \<in> set rs. r \<in> set (rflts rs1)"
Chengsong
parents:
diff changeset
   198
  apply(induct rs1)
Chengsong
parents:
diff changeset
   199
   apply simp 
Chengsong
parents:
diff changeset
   200
  apply(case_tac "a = aa")
Chengsong
parents:
diff changeset
   201
   apply simp
Chengsong
parents:
diff changeset
   202
  apply(subgoal_tac " a \<in> set rs1")
Chengsong
parents:
diff changeset
   203
  prefer 2
Chengsong
parents:
diff changeset
   204
   apply (meson set_ConsD)
Chengsong
parents:
diff changeset
   205
  apply(case_tac aa)
Chengsong
parents:
diff changeset
   206
  using rflts.simps(2) apply presburger
Chengsong
parents:
diff changeset
   207
      apply fastforce
Chengsong
parents:
diff changeset
   208
  apply fastforce
Chengsong
parents:
diff changeset
   209
  apply fastforce
Chengsong
parents:
diff changeset
   210
  apply fastforce
Chengsong
parents:
diff changeset
   211
  by fastforce
Chengsong
parents:
diff changeset
   212
Chengsong
parents:
diff changeset
   213
Chengsong
parents:
diff changeset
   214
lemma rflts_def_idiot2:
Chengsong
parents:
diff changeset
   215
  shows "\<lbrakk>a \<noteq> RZERO; \<nexists>rs1. a = RALTS rs1; a \<in> set rs\<rbrakk> \<Longrightarrow> a \<in> set (rflts rs)"
Chengsong
parents:
diff changeset
   216
  apply(induct rs rule: rflts.induct)
Chengsong
parents:
diff changeset
   217
  apply(auto)
Chengsong
parents:
diff changeset
   218
  done
Chengsong
parents:
diff changeset
   219
Chengsong
parents:
diff changeset
   220
lemma flts_append:
Chengsong
parents:
diff changeset
   221
  shows "rflts (rs1 @ rs2) = rflts rs1 @ rflts rs2"
Chengsong
parents:
diff changeset
   222
  apply(induct rs1)
Chengsong
parents:
diff changeset
   223
   apply simp
Chengsong
parents:
diff changeset
   224
  apply(case_tac a)
Chengsong
parents:
diff changeset
   225
       apply simp+
Chengsong
parents:
diff changeset
   226
  done
Chengsong
parents:
diff changeset
   227
lemma distinct_removes_middle3:
Chengsong
parents:
diff changeset
   228
  shows  "\<lbrakk>a \<in> set as\<rbrakk>
Chengsong
parents:
diff changeset
   229
    \<Longrightarrow> rdistinct (as @ a #as2) rset = rdistinct (as @ as2) rset"
Chengsong
parents:
diff changeset
   230
  using distinct_removes_middle(1) by fastforce
Chengsong
parents:
diff changeset
   231
Chengsong
parents:
diff changeset
   232
Chengsong
parents:
diff changeset
   233
lemma distinct_removes_list:
Chengsong
parents:
diff changeset
   234
  shows "\<lbrakk> \<forall>r \<in> set rs. r \<in> set as\<rbrakk> \<Longrightarrow> rdistinct (as @ rs) {} = rdistinct as {}"
Chengsong
parents:
diff changeset
   235
  apply(induct rs)
Chengsong
parents:
diff changeset
   236
   apply simp+
Chengsong
parents:
diff changeset
   237
  apply(subgoal_tac "rdistinct (as @ a # rs) {} = rdistinct (as @ rs) {}")
Chengsong
parents:
diff changeset
   238
   prefer 2
Chengsong
parents:
diff changeset
   239
  apply (metis append_Cons append_Nil distinct_removes_middle(1))
Chengsong
parents:
diff changeset
   240
  by presburger
Chengsong
parents:
diff changeset
   241
Chengsong
parents:
diff changeset
   242
lemma last_elem_out:
Chengsong
parents:
diff changeset
   243
  shows "\<lbrakk>x \<notin> set xs; x \<notin> rset \<rbrakk> \<Longrightarrow> rdistinct (xs @ [x]) rset = rdistinct xs rset @ [x]"
Chengsong
parents:
diff changeset
   244
  apply(induct xs arbitrary: rset)
Chengsong
parents:
diff changeset
   245
  apply simp+
Chengsong
parents:
diff changeset
   246
  done
Chengsong
parents:
diff changeset
   247
Chengsong
parents:
diff changeset
   248
Chengsong
parents:
diff changeset
   249
lemma rdistinct_concat_general:
Chengsong
parents:
diff changeset
   250
  shows "rdistinct (rs1 @ rs2) {} = (rdistinct rs1 {}) @ (rdistinct rs2 (set rs1))"
Chengsong
parents:
diff changeset
   251
  apply(induct rs1 arbitrary: rs2 rule: rev_induct)
Chengsong
parents:
diff changeset
   252
   apply simp
Chengsong
parents:
diff changeset
   253
  apply(drule_tac x = "x # rs2" in meta_spec)
Chengsong
parents:
diff changeset
   254
  apply simp
Chengsong
parents:
diff changeset
   255
  apply(case_tac "x \<in> set xs")
Chengsong
parents:
diff changeset
   256
   apply simp
Chengsong
parents:
diff changeset
   257
  
Chengsong
parents:
diff changeset
   258
   apply (simp add: distinct_removes_middle3 insert_absorb)
Chengsong
parents:
diff changeset
   259
  apply simp
Chengsong
parents:
diff changeset
   260
  by (simp add: last_elem_out)
Chengsong
parents:
diff changeset
   261
Chengsong
parents:
diff changeset
   262
Chengsong
parents:
diff changeset
   263
Chengsong
parents:
diff changeset
   264
  
Chengsong
parents:
diff changeset
   265
lemma distinct_once_enough:
Chengsong
parents:
diff changeset
   266
  shows "rdistinct (rs @ rsa) {} = rdistinct (rdistinct rs {} @ rsa) {}"
Chengsong
parents:
diff changeset
   267
  apply(subgoal_tac "distinct (rdistinct rs {})")
Chengsong
parents:
diff changeset
   268
   apply(subgoal_tac 
Chengsong
parents:
diff changeset
   269
" rdistinct (rdistinct rs {} @ rsa) {} = rdistinct rs {} @ (rdistinct rsa (set rs))")
Chengsong
parents:
diff changeset
   270
  apply(simp only:)
Chengsong
parents:
diff changeset
   271
  using rdistinct_concat_general apply blast
Chengsong
parents:
diff changeset
   272
  apply (simp add: distinct_rdistinct_append rdistinct_set_equality1)
Chengsong
parents:
diff changeset
   273
  by (simp add: rdistinct_does_the_job)
Chengsong
parents:
diff changeset
   274
  
Chengsong
parents:
diff changeset
   275
Chengsong
parents:
diff changeset
   276
Chengsong
parents:
diff changeset
   277
Chengsong
parents:
diff changeset
   278
lemma distinct_removes_duplicate_flts:
Chengsong
parents:
diff changeset
   279
  shows " a \<in> set rsa
Chengsong
parents:
diff changeset
   280
       \<Longrightarrow> rdistinct (rflts (map rsimp rsa @ [rsimp a])) {} =
Chengsong
parents:
diff changeset
   281
           rdistinct (rflts (map rsimp rsa)) {}"
Chengsong
parents:
diff changeset
   282
  apply(subgoal_tac "rsimp a \<in> set (map rsimp rsa)")
Chengsong
parents:
diff changeset
   283
  prefer 2
Chengsong
parents:
diff changeset
   284
   apply simp
Chengsong
parents:
diff changeset
   285
  apply(induct "rsimp a")
Chengsong
parents:
diff changeset
   286
       apply simp
Chengsong
parents:
diff changeset
   287
  using flts_removes0 apply presburger
Chengsong
parents:
diff changeset
   288
      apply(subgoal_tac " rdistinct (rflts (map rsimp rsa @ [rsimp a])) {} =  
Chengsong
parents:
diff changeset
   289
                          rdistinct (rflts (map rsimp rsa @ [RONE])) {}")
Chengsong
parents:
diff changeset
   290
      apply (simp only:)
Chengsong
parents:
diff changeset
   291
       apply(subst flts_keeps1)
Chengsong
parents:
diff changeset
   292
  apply (metis distinct_removes_last(1) rflts_def_idiot2 rrexp.simps(20) rrexp.simps(6))
Chengsong
parents:
diff changeset
   293
      apply presburger
Chengsong
parents:
diff changeset
   294
        apply(subgoal_tac " rdistinct (rflts (map rsimp rsa @ [rsimp a]))    {} =  
Chengsong
parents:
diff changeset
   295
                            rdistinct ((rflts (map rsimp rsa)) @ [RCHAR x]) {}")
Chengsong
parents:
diff changeset
   296
      apply (simp only:)
Chengsong
parents:
diff changeset
   297
      prefer 2
Chengsong
parents:
diff changeset
   298
      apply (metis flts_keeps_others rrexp.distinct(21) rrexp.distinct(3))
Chengsong
parents:
diff changeset
   299
  apply (metis distinct_removes_last(1) rflts_def_idiot2 rrexp.distinct(21) rrexp.distinct(3))
Chengsong
parents:
diff changeset
   300
Chengsong
parents:
diff changeset
   301
    apply (metis distinct_removes_last(1) flts_keeps_others rflts_def_idiot2 rrexp.distinct(25) rrexp.distinct(5))
Chengsong
parents:
diff changeset
   302
   prefer 2
Chengsong
parents:
diff changeset
   303
   apply (metis distinct_removes_last(1) flts_keeps_others flts_removes0 rflts_def_idiot2 rrexp.distinct(29))
Chengsong
parents:
diff changeset
   304
  apply(subgoal_tac "rflts (map rsimp rsa @ [rsimp a]) = rflts (map rsimp rsa) @ x")
Chengsong
parents:
diff changeset
   305
  prefer 2
Chengsong
parents:
diff changeset
   306
  apply (simp add: rflts_spills_last)
Chengsong
parents:
diff changeset
   307
  apply(subgoal_tac "\<forall> r \<in> set x. r \<in> set (rflts (map rsimp rsa))")
Chengsong
parents:
diff changeset
   308
    prefer 2
Chengsong
parents:
diff changeset
   309
  apply (metis (mono_tags, lifting) image_iff image_set spilled_alts_contained)
Chengsong
parents:
diff changeset
   310
  apply (metis rflts_spills_last)
Chengsong
parents:
diff changeset
   311
  by (metis distinct_removes_list spilled_alts_contained)
Chengsong
parents:
diff changeset
   312
Chengsong
parents:
diff changeset
   313
Chengsong
parents:
diff changeset
   314
Chengsong
parents:
diff changeset
   315
Chengsong
parents:
diff changeset
   316
Chengsong
parents:
diff changeset
   317
lemma distinct_early_app1:
Chengsong
parents:
diff changeset
   318
  shows "rset1 \<subseteq> rset \<Longrightarrow> rdistinct rs rset = rdistinct (rdistinct rs rset1) rset"
Chengsong
parents:
diff changeset
   319
  apply(induct rs arbitrary: rset rset1)
Chengsong
parents:
diff changeset
   320
   apply simp
Chengsong
parents:
diff changeset
   321
  apply simp
Chengsong
parents:
diff changeset
   322
  apply(case_tac "a \<in> rset1")
Chengsong
parents:
diff changeset
   323
   apply simp
Chengsong
parents:
diff changeset
   324
   apply(case_tac "a \<in> rset")
Chengsong
parents:
diff changeset
   325
    apply simp+
Chengsong
parents:
diff changeset
   326
  
Chengsong
parents:
diff changeset
   327
   apply blast
Chengsong
parents:
diff changeset
   328
  apply(case_tac "a \<in> rset1")
Chengsong
parents:
diff changeset
   329
   apply simp+
Chengsong
parents:
diff changeset
   330
  apply(case_tac "a \<in> rset")
Chengsong
parents:
diff changeset
   331
   apply simp
Chengsong
parents:
diff changeset
   332
   apply (metis insert_subsetI)
Chengsong
parents:
diff changeset
   333
  apply simp
Chengsong
parents:
diff changeset
   334
  by (meson insert_mono)
Chengsong
parents:
diff changeset
   335
Chengsong
parents:
diff changeset
   336
Chengsong
parents:
diff changeset
   337
lemma distinct_early_app:
Chengsong
parents:
diff changeset
   338
  shows " rdistinct (rs @ rsb) rset = rdistinct (rdistinct rs {} @ rsb) rset"
Chengsong
parents:
diff changeset
   339
  apply(induct rsb)
Chengsong
parents:
diff changeset
   340
   apply simp
Chengsong
parents:
diff changeset
   341
  using distinct_early_app1 apply blast
Chengsong
parents:
diff changeset
   342
  by (metis distinct_early_app1 distinct_once_enough empty_subsetI)
Chengsong
parents:
diff changeset
   343
Chengsong
parents:
diff changeset
   344
Chengsong
parents:
diff changeset
   345
lemma distinct_eq_interesting1:
Chengsong
parents:
diff changeset
   346
  shows "a \<in> rset \<Longrightarrow> rdistinct (rs @ rsb) rset = rdistinct (rdistinct (a # rs) {} @ rsb) rset"
Chengsong
parents:
diff changeset
   347
  apply(subgoal_tac "rdistinct (rdistinct (a # rs) {} @ rsb) rset = rdistinct (rdistinct rs {} @ rsb) rset")
Chengsong
parents:
diff changeset
   348
   apply(simp only:)
Chengsong
parents:
diff changeset
   349
  using distinct_early_app apply blast 
Chengsong
parents:
diff changeset
   350
  by (metis append_Cons distinct_early_app rdistinct.simps(2))
Chengsong
parents:
diff changeset
   351
Chengsong
parents:
diff changeset
   352
Chengsong
parents:
diff changeset
   353
Chengsong
parents:
diff changeset
   354
Chengsong
parents:
diff changeset
   355
end