2084
+ − 1
(* Title: HOL/Quotient_Examples/FSet.thy
+ − 2
Author: Cezary Kaliszyk, TU Munich
+ − 3
Author: Christian Urban, TU Munich
1823
+ − 4
2533
+ − 5
Type of finite sets.
1823
+ − 6
*)
2084
+ − 7
1518
+ − 8
theory FSet
2528
+ − 9
imports Quotient_List
1518
+ − 10
begin
+ − 11
2533
+ − 12
text {* Definiton of the list equivalence relation *}
1909
+ − 13
1518
+ − 14
fun
+ − 15
list_eq :: "'a list \<Rightarrow> 'a list \<Rightarrow> bool" (infix "\<approx>" 50)
+ − 16
where
2524
693562f03eee
major reorganisation of fset (renamed fset_to_set to fset, changed the definition of list_eq and fcard_raw)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 17
"list_eq xs ys = (set xs = set ys)"
1518
+ − 18
+ − 19
lemma list_eq_equivp:
+ − 20
shows "equivp list_eq"
1909
+ − 21
unfolding equivp_reflp_symp_transp
1889
+ − 22
unfolding reflp_def symp_def transp_def
+ − 23
by auto
+ − 24
2533
+ − 25
text {* Fset type *}
+ − 26
1909
+ − 27
quotient_type
+ − 28
'a fset = "'a list" / "list_eq"
+ − 29
by (rule list_eq_equivp)
+ − 30
2533
+ − 31
text {*
2538
+ − 32
Definitions of membership, sublist, cardinality, intersection,
+ − 33
difference and respectful fold over lists
2372
+ − 34
*}
1909
+ − 35
1889
+ − 36
definition
+ − 37
"memb x xs \<equiv> x \<in> set xs"
+ − 38
+ − 39
definition
2524
693562f03eee
major reorganisation of fset (renamed fset_to_set to fset, changed the definition of list_eq and fcard_raw)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 40
"sub_list xs ys \<equiv> set xs \<subseteq> set ys"
1889
+ − 41
2524
693562f03eee
major reorganisation of fset (renamed fset_to_set to fset, changed the definition of list_eq and fcard_raw)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 42
definition
2536
+ − 43
"card_list xs = card (set xs)"
1518
+ − 44
2538
+ − 45
definition
+ − 46
"inter_list xs ys = [x \<leftarrow> xs. x \<in> set xs \<and> x \<in> set ys]"
2534
+ − 47
+ − 48
definition
2537
+ − 49
"diff_list xs ys \<equiv> [x \<leftarrow> xs. x\<notin>set ys]"
2534
+ − 50
1909
+ − 51
definition
+ − 52
rsp_fold
+ − 53
where
2538
+ − 54
"rsp_fold f \<equiv> \<forall>u v w. (f u (f v w) = f v (f u w))"
1893
+ − 55
1909
+ − 56
primrec
+ − 57
ffold_raw :: "('a \<Rightarrow> 'b \<Rightarrow> 'b) \<Rightarrow> 'b \<Rightarrow> 'a list \<Rightarrow> 'b"
+ − 58
where
+ − 59
"ffold_raw f z [] = z"
2084
+ − 60
| "ffold_raw f z (a # xs) =
1909
+ − 61
(if (rsp_fold f) then
2524
693562f03eee
major reorganisation of fset (renamed fset_to_set to fset, changed the definition of list_eq and fcard_raw)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 62
if a \<in> set xs then ffold_raw f z xs
2084
+ − 63
else f a (ffold_raw f z xs)
1909
+ − 64
else z)"
+ − 65
2533
+ − 66
+ − 67
section {* Quotient composition lemmas *}
1935
+ − 68
2326
+ − 69
lemma list_all2_refl1:
+ − 70
shows "(list_all2 op \<approx>) r r"
+ − 71
by (rule list_all2_refl) (metis equivp_def fset_equivp)
1938
+ − 72
1935
+ − 73
lemma compose_list_refl:
2326
+ − 74
shows "(list_all2 op \<approx> OOO op \<approx>) r r"
1935
+ − 75
proof
2084
+ − 76
have *: "r \<approx> r" by (rule equivp_reflp[OF fset_equivp])
2326
+ − 77
show "list_all2 op \<approx> r r" by (rule list_all2_refl1)
+ − 78
with * show "(op \<approx> OO list_all2 op \<approx>) r r" ..
1935
+ − 79
qed
+ − 80
+ − 81
lemma Quotient_fset_list:
2326
+ − 82
shows "Quotient (list_all2 op \<approx>) (map abs_fset) (map rep_fset)"
1935
+ − 83
by (fact list_quotient[OF Quotient_fset])
+ − 84
+ − 85
lemma map_rel_cong: "b \<approx> ba \<Longrightarrow> map f b \<approx> map f ba"
+ − 86
unfolding list_eq.simps
2524
693562f03eee
major reorganisation of fset (renamed fset_to_set to fset, changed the definition of list_eq and fcard_raw)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 87
by (simp only: set_map)
1935
+ − 88
+ − 89
lemma quotient_compose_list[quot_thm]:
2326
+ − 90
shows "Quotient ((list_all2 op \<approx>) OOO (op \<approx>))
1935
+ − 91
(abs_fset \<circ> (map abs_fset)) ((map rep_fset) \<circ> rep_fset)"
+ − 92
unfolding Quotient_def comp_def
+ − 93
proof (intro conjI allI)
+ − 94
fix a r s
+ − 95
show "abs_fset (map abs_fset (map rep_fset (rep_fset a))) = a"
+ − 96
by (simp add: abs_o_rep[OF Quotient_fset] Quotient_abs_rep[OF Quotient_fset] map_id)
2326
+ − 97
have b: "list_all2 op \<approx> (map rep_fset (rep_fset a)) (map rep_fset (rep_fset a))"
+ − 98
by (rule list_all2_refl1)
+ − 99
have c: "(op \<approx> OO list_all2 op \<approx>) (map rep_fset (rep_fset a)) (map rep_fset (rep_fset a))"
1935
+ − 100
by (rule, rule equivp_reflp[OF fset_equivp]) (rule b)
2326
+ − 101
show "(list_all2 op \<approx> OOO op \<approx>) (map rep_fset (rep_fset a)) (map rep_fset (rep_fset a))"
+ − 102
by (rule, rule list_all2_refl1) (rule c)
+ − 103
show "(list_all2 op \<approx> OOO op \<approx>) r s = ((list_all2 op \<approx> OOO op \<approx>) r r \<and>
+ − 104
(list_all2 op \<approx> OOO op \<approx>) s s \<and> abs_fset (map abs_fset r) = abs_fset (map abs_fset s))"
1935
+ − 105
proof (intro iffI conjI)
2326
+ − 106
show "(list_all2 op \<approx> OOO op \<approx>) r r" by (rule compose_list_refl)
+ − 107
show "(list_all2 op \<approx> OOO op \<approx>) s s" by (rule compose_list_refl)
1935
+ − 108
next
2326
+ − 109
assume a: "(list_all2 op \<approx> OOO op \<approx>) r s"
2084
+ − 110
then have b: "map abs_fset r \<approx> map abs_fset s"
+ − 111
proof (elim pred_compE)
1935
+ − 112
fix b ba
2326
+ − 113
assume c: "list_all2 op \<approx> r b"
1935
+ − 114
assume d: "b \<approx> ba"
2326
+ − 115
assume e: "list_all2 op \<approx> ba s"
1935
+ − 116
have f: "map abs_fset r = map abs_fset b"
1938
+ − 117
using Quotient_rel[OF Quotient_fset_list] c by blast
+ − 118
have "map abs_fset ba = map abs_fset s"
+ − 119
using Quotient_rel[OF Quotient_fset_list] e by blast
+ − 120
then have g: "map abs_fset s = map abs_fset ba" by simp
+ − 121
then show "map abs_fset r \<approx> map abs_fset s" using d f map_rel_cong by simp
1935
+ − 122
qed
+ − 123
then show "abs_fset (map abs_fset r) = abs_fset (map abs_fset s)"
1938
+ − 124
using Quotient_rel[OF Quotient_fset] by blast
1935
+ − 125
next
2326
+ − 126
assume a: "(list_all2 op \<approx> OOO op \<approx>) r r \<and> (list_all2 op \<approx> OOO op \<approx>) s s
1935
+ − 127
\<and> abs_fset (map abs_fset r) = abs_fset (map abs_fset s)"
2326
+ − 128
then have s: "(list_all2 op \<approx> OOO op \<approx>) s s" by simp
1935
+ − 129
have d: "map abs_fset r \<approx> map abs_fset s"
+ − 130
by (subst Quotient_rel[OF Quotient_fset]) (simp add: a)
+ − 131
have b: "map rep_fset (map abs_fset r) \<approx> map rep_fset (map abs_fset s)"
+ − 132
by (rule map_rel_cong[OF d])
2326
+ − 133
have y: "list_all2 op \<approx> (map rep_fset (map abs_fset s)) s"
+ − 134
by (fact rep_abs_rsp_left[OF Quotient_fset_list, OF list_all2_refl1[of s]])
+ − 135
have c: "(op \<approx> OO list_all2 op \<approx>) (map rep_fset (map abs_fset r)) s"
1935
+ − 136
by (rule pred_compI) (rule b, rule y)
2326
+ − 137
have z: "list_all2 op \<approx> r (map rep_fset (map abs_fset r))"
+ − 138
by (fact rep_abs_rsp[OF Quotient_fset_list, OF list_all2_refl1[of r]])
+ − 139
then show "(list_all2 op \<approx> OOO op \<approx>) r s"
1935
+ − 140
using a c pred_compI by simp
+ − 141
qed
+ − 142
qed
+ − 143
2525
+ − 144
2538
+ − 145
subsection {* Respectfulness lemmas for list operations *}
1893
+ − 146
2538
+ − 147
lemma list_equiv_rsp [quot_respect]:
+ − 148
shows "(op \<approx> ===> op \<approx> ===> op =) op \<approx> op \<approx>"
+ − 149
by auto
+ − 150
+ − 151
lemma append_rsp [quot_respect]:
2524
693562f03eee
major reorganisation of fset (renamed fset_to_set to fset, changed the definition of list_eq and fcard_raw)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 152
shows "(op \<approx> ===> op \<approx> ===> op \<approx>) append append"
2533
+ − 153
by simp
1895
+ − 154
2538
+ − 155
lemma sub_list_rsp [quot_respect]:
1909
+ − 156
shows "(op \<approx> ===> op \<approx> ===> op =) sub_list sub_list"
+ − 157
by (auto simp add: sub_list_def)
+ − 158
2538
+ − 159
lemma memb_rsp [quot_respect]:
1909
+ − 160
shows "(op = ===> op \<approx> ===> op =) memb memb"
+ − 161
by (auto simp add: memb_def)
+ − 162
2538
+ − 163
lemma nil_rsp [quot_respect]:
2525
+ − 164
shows "(op \<approx>) Nil Nil"
1909
+ − 165
by simp
+ − 166
2538
+ − 167
lemma cons_rsp [quot_respect]:
2524
693562f03eee
major reorganisation of fset (renamed fset_to_set to fset, changed the definition of list_eq and fcard_raw)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 168
shows "(op = ===> op \<approx> ===> op \<approx>) Cons Cons"
1909
+ − 169
by simp
+ − 170
2538
+ − 171
lemma map_rsp [quot_respect]:
1909
+ − 172
shows "(op = ===> op \<approx> ===> op \<approx>) map map"
+ − 173
by auto
+ − 174
2538
+ − 175
lemma set_rsp [quot_respect]:
1909
+ − 176
"(op \<approx> ===> op =) set set"
+ − 177
by auto
+ − 178
2538
+ − 179
lemma inter_list_rsp [quot_respect]:
+ − 180
shows "(op \<approx> ===> op \<approx> ===> op \<approx>) inter_list inter_list"
+ − 181
by (simp add: inter_list_def)
1909
+ − 182
2538
+ − 183
lemma removeAll_rsp [quot_respect]:
2525
+ − 184
shows "(op = ===> op \<approx> ===> op \<approx>) removeAll removeAll"
+ − 185
by simp
+ − 186
2538
+ − 187
lemma diff_list_rsp [quot_respect]:
2537
+ − 188
shows "(op \<approx> ===> op \<approx> ===> op \<approx>) diff_list diff_list"
2538
+ − 189
by (simp add: diff_list_def)
2525
+ − 190
2538
+ − 191
lemma card_list_rsp [quot_respect]:
2536
+ − 192
shows "(op \<approx> ===> op =) card_list card_list"
+ − 193
by (simp add: card_list_def)
2525
+ − 194
2538
+ − 195
lemma filter_rsp [quot_respect]:
+ − 196
shows "(op = ===> op \<approx> ===> op \<approx>) filter filter"
+ − 197
by simp
2525
+ − 198
1909
+ − 199
lemma memb_commute_ffold_raw:
2524
693562f03eee
major reorganisation of fset (renamed fset_to_set to fset, changed the definition of list_eq and fcard_raw)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 200
"rsp_fold f \<Longrightarrow> h \<in> set b \<Longrightarrow> ffold_raw f z b = f h (ffold_raw f z (removeAll h b))"
1909
+ − 201
apply (induct b)
2524
693562f03eee
major reorganisation of fset (renamed fset_to_set to fset, changed the definition of list_eq and fcard_raw)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 202
apply (auto simp add: rsp_fold_def)
1909
+ − 203
done
+ − 204
+ − 205
lemma ffold_raw_rsp_pre:
2524
693562f03eee
major reorganisation of fset (renamed fset_to_set to fset, changed the definition of list_eq and fcard_raw)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 206
"set a = set b \<Longrightarrow> ffold_raw f z a = ffold_raw f z b"
1909
+ − 207
apply (induct a arbitrary: b)
+ − 208
apply (simp)
2524
693562f03eee
major reorganisation of fset (renamed fset_to_set to fset, changed the definition of list_eq and fcard_raw)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 209
apply (simp (no_asm_use))
1909
+ − 210
apply (rule conjI)
+ − 211
apply (rule_tac [!] impI)
+ − 212
apply (rule_tac [!] conjI)
+ − 213
apply (rule_tac [!] impI)
2524
693562f03eee
major reorganisation of fset (renamed fset_to_set to fset, changed the definition of list_eq and fcard_raw)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 214
apply (metis insert_absorb)
693562f03eee
major reorganisation of fset (renamed fset_to_set to fset, changed the definition of list_eq and fcard_raw)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 215
apply (metis List.insert_def List.set.simps(2) List.set_insert ffold_raw.simps(2))
693562f03eee
major reorganisation of fset (renamed fset_to_set to fset, changed the definition of list_eq and fcard_raw)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 216
apply (metis Diff_insert_absorb insertI1 memb_commute_ffold_raw set_removeAll)
693562f03eee
major reorganisation of fset (renamed fset_to_set to fset, changed the definition of list_eq and fcard_raw)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 217
apply(drule_tac x="removeAll a1 b" in meta_spec)
693562f03eee
major reorganisation of fset (renamed fset_to_set to fset, changed the definition of list_eq and fcard_raw)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 218
apply(auto)
693562f03eee
major reorganisation of fset (renamed fset_to_set to fset, changed the definition of list_eq and fcard_raw)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 219
apply(drule meta_mp)
693562f03eee
major reorganisation of fset (renamed fset_to_set to fset, changed the definition of list_eq and fcard_raw)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 220
apply(blast)
693562f03eee
major reorganisation of fset (renamed fset_to_set to fset, changed the definition of list_eq and fcard_raw)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 221
by (metis List.set.simps(2) emptyE ffold_raw.simps(2) in_listsp_conv_set listsp.simps mem_def)
1909
+ − 222
2538
+ − 223
lemma ffold_raw_rsp [quot_respect]:
2524
693562f03eee
major reorganisation of fset (renamed fset_to_set to fset, changed the definition of list_eq and fcard_raw)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 224
shows "(op = ===> op = ===> op \<approx> ===> op =) ffold_raw ffold_raw"
693562f03eee
major reorganisation of fset (renamed fset_to_set to fset, changed the definition of list_eq and fcard_raw)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 225
unfolding fun_rel_def
2529
+ − 226
by(auto intro: ffold_raw_rsp_pre)
1909
+ − 227
1935
+ − 228
lemma concat_rsp_pre:
2326
+ − 229
assumes a: "list_all2 op \<approx> x x'"
1935
+ − 230
and b: "x' \<approx> y'"
2326
+ − 231
and c: "list_all2 op \<approx> y' y"
1935
+ − 232
and d: "\<exists>x\<in>set x. xa \<in> set x"
+ − 233
shows "\<exists>x\<in>set y. xa \<in> set x"
+ − 234
proof -
+ − 235
obtain xb where e: "xb \<in> set x" and f: "xa \<in> set xb" using d by auto
2326
+ − 236
have "\<exists>y. y \<in> set x' \<and> xb \<approx> y" by (rule list_all2_find_element[OF e a])
1935
+ − 237
then obtain ya where h: "ya \<in> set x'" and i: "xb \<approx> ya" by auto
2084
+ − 238
have "ya \<in> set y'" using b h by simp
2326
+ − 239
then have "\<exists>yb. yb \<in> set y \<and> ya \<approx> yb" using c by (rule list_all2_find_element)
1935
+ − 240
then show ?thesis using f i by auto
+ − 241
qed
+ − 242
2538
+ − 243
lemma concat_rsp [quot_respect]:
2326
+ − 244
shows "(list_all2 op \<approx> OOO op \<approx> ===> op \<approx>) concat concat"
1935
+ − 245
proof (rule fun_relI, elim pred_compE)
+ − 246
fix a b ba bb
2326
+ − 247
assume a: "list_all2 op \<approx> a ba"
1935
+ − 248
assume b: "ba \<approx> bb"
2326
+ − 249
assume c: "list_all2 op \<approx> bb b"
2524
693562f03eee
major reorganisation of fset (renamed fset_to_set to fset, changed the definition of list_eq and fcard_raw)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 250
have "\<forall>x. (\<exists>xa\<in>set a. x \<in> set xa) = (\<exists>xa\<in>set b. x \<in> set xa)"
693562f03eee
major reorganisation of fset (renamed fset_to_set to fset, changed the definition of list_eq and fcard_raw)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 251
proof
1935
+ − 252
fix x
2524
693562f03eee
major reorganisation of fset (renamed fset_to_set to fset, changed the definition of list_eq and fcard_raw)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 253
show "(\<exists>xa\<in>set a. x \<in> set xa) = (\<exists>xa\<in>set b. x \<in> set xa)"
693562f03eee
major reorganisation of fset (renamed fset_to_set to fset, changed the definition of list_eq and fcard_raw)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 254
proof
1935
+ − 255
assume d: "\<exists>xa\<in>set a. x \<in> set xa"
+ − 256
show "\<exists>xa\<in>set b. x \<in> set xa" by (rule concat_rsp_pre[OF a b c d])
+ − 257
next
+ − 258
assume e: "\<exists>xa\<in>set b. x \<in> set xa"
2326
+ − 259
have a': "list_all2 op \<approx> ba a" by (rule list_all2_symp[OF list_eq_equivp, OF a])
1935
+ − 260
have b': "bb \<approx> ba" by (rule equivp_symp[OF list_eq_equivp, OF b])
2326
+ − 261
have c': "list_all2 op \<approx> b bb" by (rule list_all2_symp[OF list_eq_equivp, OF c])
1935
+ − 262
show "\<exists>xa\<in>set a. x \<in> set xa" by (rule concat_rsp_pre[OF c' b' a' e])
+ − 263
qed
+ − 264
qed
2524
693562f03eee
major reorganisation of fset (renamed fset_to_set to fset, changed the definition of list_eq and fcard_raw)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 265
then show "concat a \<approx> concat b" by auto
1935
+ − 266
qed
+ − 267
2084
+ − 268
2538
+ − 269
subsection {* Finite sets are a bounded, distributive lattice with minus *}
1905
+ − 270
2528
+ − 271
instantiation fset :: (type) "{bounded_lattice_bot, distrib_lattice, minus}"
1893
+ − 272
begin
+ − 273
+ − 274
quotient_definition
2538
+ − 275
"bot :: 'a fset"
+ − 276
is "Nil :: 'a list"
1893
+ − 277
+ − 278
abbreviation
+ − 279
fempty ("{||}")
+ − 280
where
+ − 281
"{||} \<equiv> bot :: 'a fset"
+ − 282
+ − 283
quotient_definition
2538
+ − 284
"less_eq_fset :: ('a fset \<Rightarrow> 'a fset \<Rightarrow> bool)"
+ − 285
is "sub_list :: ('a list \<Rightarrow> 'a list \<Rightarrow> bool)"
1893
+ − 286
+ − 287
abbreviation
+ − 288
f_subset_eq :: "'a fset \<Rightarrow> 'a fset \<Rightarrow> bool" (infix "|\<subseteq>|" 50)
+ − 289
where
+ − 290
"xs |\<subseteq>| ys \<equiv> xs \<le> ys"
+ − 291
+ − 292
definition
2524
693562f03eee
major reorganisation of fset (renamed fset_to_set to fset, changed the definition of list_eq and fcard_raw)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 293
less_fset :: "'a fset \<Rightarrow> 'a fset \<Rightarrow> bool"
693562f03eee
major reorganisation of fset (renamed fset_to_set to fset, changed the definition of list_eq and fcard_raw)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 294
where
693562f03eee
major reorganisation of fset (renamed fset_to_set to fset, changed the definition of list_eq and fcard_raw)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 295
"xs < ys \<equiv> xs \<le> ys \<and> xs \<noteq> (ys::'a fset)"
1893
+ − 296
+ − 297
abbreviation
2524
693562f03eee
major reorganisation of fset (renamed fset_to_set to fset, changed the definition of list_eq and fcard_raw)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 298
fsubset :: "'a fset \<Rightarrow> 'a fset \<Rightarrow> bool" (infix "|\<subset>|" 50)
1893
+ − 299
where
+ − 300
"xs |\<subset>| ys \<equiv> xs < ys"
+ − 301
1895
+ − 302
quotient_definition
2524
693562f03eee
major reorganisation of fset (renamed fset_to_set to fset, changed the definition of list_eq and fcard_raw)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 303
"sup :: 'a fset \<Rightarrow> 'a fset \<Rightarrow> 'a fset"
2538
+ − 304
is "append :: 'a list \<Rightarrow> 'a list \<Rightarrow> 'a list"
1895
+ − 305
+ − 306
abbreviation
2084
+ − 307
funion (infixl "|\<union>|" 65)
1895
+ − 308
where
2524
693562f03eee
major reorganisation of fset (renamed fset_to_set to fset, changed the definition of list_eq and fcard_raw)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 309
"xs |\<union>| ys \<equiv> sup xs (ys::'a fset)"
1895
+ − 310
1905
+ − 311
quotient_definition
2524
693562f03eee
major reorganisation of fset (renamed fset_to_set to fset, changed the definition of list_eq and fcard_raw)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 312
"inf :: 'a fset \<Rightarrow> 'a fset \<Rightarrow> 'a fset"
2538
+ − 313
is "inter_list :: 'a list \<Rightarrow> 'a list \<Rightarrow> 'a list"
1905
+ − 314
+ − 315
abbreviation
+ − 316
finter (infixl "|\<inter>|" 65)
+ − 317
where
2524
693562f03eee
major reorganisation of fset (renamed fset_to_set to fset, changed the definition of list_eq and fcard_raw)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 318
"xs |\<inter>| ys \<equiv> inf xs (ys::'a fset)"
1905
+ − 319
2084
+ − 320
quotient_definition
2524
693562f03eee
major reorganisation of fset (renamed fset_to_set to fset, changed the definition of list_eq and fcard_raw)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 321
"minus :: 'a fset \<Rightarrow> 'a fset \<Rightarrow> 'a fset"
2538
+ − 322
is "diff_list :: 'a list \<Rightarrow> 'a list \<Rightarrow> 'a list"
2084
+ − 323
2533
+ − 324
1895
+ − 325
instance
+ − 326
proof
1905
+ − 327
fix x y z :: "'a fset"
2528
+ − 328
show "x |\<subset>| y \<longleftrightarrow> x |\<subseteq>| y \<and> \<not> y |\<subseteq>| x"
2530
+ − 329
unfolding less_fset_def
+ − 330
by (descending) (auto simp add: sub_list_def)
2528
+ − 331
show "x |\<subseteq>| x" by (descending) (simp add: sub_list_def)
+ − 332
show "{||} |\<subseteq>| x" by (descending) (simp add: sub_list_def)
+ − 333
show "x |\<subseteq>| x |\<union>| y" by (descending) (simp add: sub_list_def)
+ − 334
show "y |\<subseteq>| x |\<union>| y" by (descending) (simp add: sub_list_def)
+ − 335
show "x |\<inter>| y |\<subseteq>| x"
2538
+ − 336
by (descending) (auto simp add: inter_list_def sub_list_def memb_def)
2528
+ − 337
show "x |\<inter>| y |\<subseteq>| y"
2538
+ − 338
by (descending) (auto simp add: inter_list_def sub_list_def memb_def)
2528
+ − 339
show "x |\<union>| (y |\<inter>| z) = x |\<union>| y |\<inter>| (x |\<union>| z)"
2538
+ − 340
by (descending) (auto simp add: inter_list_def)
1905
+ − 341
next
+ − 342
fix x y z :: "'a fset"
+ − 343
assume a: "x |\<subseteq>| y"
+ − 344
assume b: "y |\<subseteq>| z"
2528
+ − 345
show "x |\<subseteq>| z" using a b
+ − 346
by (descending) (simp add: sub_list_def)
1895
+ − 347
next
+ − 348
fix x y :: "'a fset"
+ − 349
assume a: "x |\<subseteq>| y"
+ − 350
assume b: "y |\<subseteq>| x"
2528
+ − 351
show "x = y" using a b
+ − 352
by (descending) (unfold sub_list_def list_eq.simps, blast)
1895
+ − 353
next
+ − 354
fix x y z :: "'a fset"
+ − 355
assume a: "y |\<subseteq>| x"
+ − 356
assume b: "z |\<subseteq>| x"
2528
+ − 357
show "y |\<union>| z |\<subseteq>| x" using a b
+ − 358
by (descending) (simp add: sub_list_def)
1905
+ − 359
next
+ − 360
fix x y z :: "'a fset"
+ − 361
assume a: "x |\<subseteq>| y"
+ − 362
assume b: "x |\<subseteq>| z"
2528
+ − 363
show "x |\<subseteq>| y |\<inter>| z" using a b
2538
+ − 364
by (descending) (auto simp add: inter_list_def sub_list_def memb_def)
1895
+ − 365
qed
1905
+ − 366
1893
+ − 367
end
+ − 368
2534
+ − 369
2538
+ − 370
section {* Quotient definitions for fsets *}
2534
+ − 371
1518
+ − 372
+ − 373
quotient_definition
1893
+ − 374
"finsert :: 'a \<Rightarrow> 'a fset \<Rightarrow> 'a fset"
2534
+ − 375
is "Cons"
1518
+ − 376
+ − 377
syntax
+ − 378
"@Finset" :: "args => 'a fset" ("{|(_)|}")
+ − 379
+ − 380
translations
+ − 381
"{|x, xs|}" == "CONST finsert x {|xs|}"
+ − 382
"{|x|}" == "CONST finsert x {||}"
+ − 383
+ − 384
quotient_definition
1938
+ − 385
fin (infix "|\<in>|" 50)
1518
+ − 386
where
1816
+ − 387
"fin :: 'a \<Rightarrow> 'a fset \<Rightarrow> bool" is "memb"
1518
+ − 388
+ − 389
abbreviation
1938
+ − 390
fnotin :: "'a \<Rightarrow> 'a fset \<Rightarrow> bool" (infix "|\<notin>|" 50)
1518
+ − 391
where
1860
+ − 392
"x |\<notin>| S \<equiv> \<not> (x |\<in>| S)"
1518
+ − 393
2084
+ − 394
section {* Other constants on the Quotient Type *}
1935
+ − 395
+ − 396
quotient_definition
2084
+ − 397
"fcard :: 'a fset \<Rightarrow> nat"
2536
+ − 398
is card_list
1935
+ − 399
+ − 400
quotient_definition
+ − 401
"fmap :: ('a \<Rightarrow> 'b) \<Rightarrow> 'a fset \<Rightarrow> 'b fset"
2534
+ − 402
is map
1935
+ − 403
+ − 404
quotient_definition
2524
693562f03eee
major reorganisation of fset (renamed fset_to_set to fset, changed the definition of list_eq and fcard_raw)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 405
"fdelete :: 'a \<Rightarrow> 'a fset \<Rightarrow> 'a fset"
693562f03eee
major reorganisation of fset (renamed fset_to_set to fset, changed the definition of list_eq and fcard_raw)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 406
is removeAll
1935
+ − 407
+ − 408
quotient_definition
2524
693562f03eee
major reorganisation of fset (renamed fset_to_set to fset, changed the definition of list_eq and fcard_raw)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 409
"fset :: 'a fset \<Rightarrow> 'a set"
1935
+ − 410
is "set"
+ − 411
+ − 412
quotient_definition
+ − 413
"ffold :: ('a \<Rightarrow> 'b \<Rightarrow> 'b) \<Rightarrow> 'b \<Rightarrow> 'a fset \<Rightarrow> 'b"
2534
+ − 414
is ffold_raw
1935
+ − 415
+ − 416
quotient_definition
+ − 417
"fconcat :: ('a fset) fset \<Rightarrow> 'a fset"
2534
+ − 418
is concat
1935
+ − 419
2084
+ − 420
quotient_definition
+ − 421
"ffilter :: ('a \<Rightarrow> bool) \<Rightarrow> 'a fset \<Rightarrow> 'a fset"
2534
+ − 422
is filter
2084
+ − 423
2534
+ − 424
+ − 425
subsection {* Compositional Respectfulness and Preservation *}
1935
+ − 426
2326
+ − 427
lemma [quot_respect]: "(list_all2 op \<approx> OOO op \<approx>) [] []"
1938
+ − 428
by (fact compose_list_refl)
1935
+ − 429
2538
+ − 430
lemma [quot_preserve]: "(abs_fset \<circ> map f) [] = abs_fset []"
1935
+ − 431
by simp
+ − 432
+ − 433
lemma [quot_respect]:
2524
693562f03eee
major reorganisation of fset (renamed fset_to_set to fset, changed the definition of list_eq and fcard_raw)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 434
shows "(op \<approx> ===> list_all2 op \<approx> OOO op \<approx> ===> list_all2 op \<approx> OOO op \<approx>) Cons Cons"
1935
+ − 435
apply auto
+ − 436
apply (rule_tac b="x # b" in pred_compI)
+ − 437
apply auto
+ − 438
apply (rule_tac b="x # ba" in pred_compI)
+ − 439
apply auto
+ − 440
done
+ − 441
+ − 442
lemma [quot_preserve]:
+ − 443
"(rep_fset ---> (map rep_fset \<circ> rep_fset) ---> (abs_fset \<circ> map abs_fset)) op # = finsert"
2479
+ − 444
by (simp add: fun_eq_iff Quotient_abs_rep[OF Quotient_fset]
1935
+ − 445
abs_o_rep[OF Quotient_fset] map_id finsert_def)
+ − 446
+ − 447
lemma [quot_preserve]:
1938
+ − 448
"((map rep_fset \<circ> rep_fset) ---> (map rep_fset \<circ> rep_fset) ---> (abs_fset \<circ> map abs_fset)) op @ = funion"
2479
+ − 449
by (simp add: fun_eq_iff Quotient_abs_rep[OF Quotient_fset]
1935
+ − 450
abs_o_rep[OF Quotient_fset] map_id sup_fset_def)
+ − 451
2326
+ − 452
lemma list_all2_app_l:
1935
+ − 453
assumes a: "reflp R"
2326
+ − 454
and b: "list_all2 R l r"
+ − 455
shows "list_all2 R (z @ l) (z @ r)"
1938
+ − 456
by (induct z) (simp_all add: b rev_iffD1[OF a meta_eq_to_obj_eq[OF reflp_def]])
1935
+ − 457
+ − 458
lemma append_rsp2_pre0:
2326
+ − 459
assumes a:"list_all2 op \<approx> x x'"
+ − 460
shows "list_all2 op \<approx> (x @ z) (x' @ z)"
1935
+ − 461
using a apply (induct x x' rule: list_induct2')
2326
+ − 462
by simp_all (rule list_all2_refl1)
1935
+ − 463
+ − 464
lemma append_rsp2_pre1:
2326
+ − 465
assumes a:"list_all2 op \<approx> x x'"
+ − 466
shows "list_all2 op \<approx> (z @ x) (z @ x')"
1935
+ − 467
using a apply (induct x x' arbitrary: z rule: list_induct2')
2326
+ − 468
apply (rule list_all2_refl1)
1935
+ − 469
apply (simp_all del: list_eq.simps)
2326
+ − 470
apply (rule list_all2_app_l)
1935
+ − 471
apply (simp_all add: reflp_def)
+ − 472
done
+ − 473
+ − 474
lemma append_rsp2_pre:
2326
+ − 475
assumes a:"list_all2 op \<approx> x x'"
+ − 476
and b: "list_all2 op \<approx> z z'"
+ − 477
shows "list_all2 op \<approx> (x @ z) (x' @ z')"
+ − 478
apply (rule list_all2_transp[OF fset_equivp])
1935
+ − 479
apply (rule append_rsp2_pre0)
+ − 480
apply (rule a)
+ − 481
using b apply (induct z z' rule: list_induct2')
+ − 482
apply (simp_all only: append_Nil2)
2326
+ − 483
apply (rule list_all2_refl1)
1935
+ − 484
apply simp_all
+ − 485
apply (rule append_rsp2_pre1)
+ − 486
apply simp
+ − 487
done
+ − 488
+ − 489
lemma [quot_respect]:
2326
+ − 490
"(list_all2 op \<approx> OOO op \<approx> ===> list_all2 op \<approx> OOO op \<approx> ===> list_all2 op \<approx> OOO op \<approx>) op @ op @"
1935
+ − 491
proof (intro fun_relI, elim pred_compE)
+ − 492
fix x y z w x' z' y' w' :: "'a list list"
2326
+ − 493
assume a:"list_all2 op \<approx> x x'"
1935
+ − 494
and b: "x' \<approx> y'"
2326
+ − 495
and c: "list_all2 op \<approx> y' y"
+ − 496
assume aa: "list_all2 op \<approx> z z'"
1935
+ − 497
and bb: "z' \<approx> w'"
2326
+ − 498
and cc: "list_all2 op \<approx> w' w"
+ − 499
have a': "list_all2 op \<approx> (x @ z) (x' @ z')" using a aa append_rsp2_pre by auto
1935
+ − 500
have b': "x' @ z' \<approx> y' @ w'" using b bb by simp
2326
+ − 501
have c': "list_all2 op \<approx> (y' @ w') (y @ w)" using c cc append_rsp2_pre by auto
+ − 502
have d': "(op \<approx> OO list_all2 op \<approx>) (x' @ z') (y @ w)"
1935
+ − 503
by (rule pred_compI) (rule b', rule c')
2326
+ − 504
show "(list_all2 op \<approx> OOO op \<approx>) (x @ z) (y @ w)"
1935
+ − 505
by (rule pred_compI) (rule a', rule d')
+ − 506
qed
+ − 507
1878
+ − 508
2524
693562f03eee
major reorganisation of fset (renamed fset_to_set to fset, changed the definition of list_eq and fcard_raw)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 509
2534
+ − 510
section {* Cases *}
1518
+ − 511
1819
+ − 512
+ − 513
lemma fset_raw_strong_cases:
2084
+ − 514
obtains "xs = []"
+ − 515
| x ys where "\<not> memb x ys" and "xs \<approx> x # ys"
+ − 516
proof (induct xs arbitrary: x ys)
+ − 517
case Nil
+ − 518
then show thesis by simp
+ − 519
next
+ − 520
case (Cons a xs)
+ − 521
have a: "\<lbrakk>xs = [] \<Longrightarrow> thesis; \<And>x ys. \<lbrakk>\<not> memb x ys; xs \<approx> x # ys\<rbrakk> \<Longrightarrow> thesis\<rbrakk> \<Longrightarrow> thesis" by fact
+ − 522
have b: "\<And>x' ys'. \<lbrakk>\<not> memb x' ys'; a # xs \<approx> x' # ys'\<rbrakk> \<Longrightarrow> thesis" by fact
2534
+ − 523
have c: "xs = [] \<Longrightarrow> thesis" using b unfolding memb_def
+ − 524
by (metis in_set_conv_nth less_zeroE list.size(3) list_eq.simps member_set)
2084
+ − 525
have "\<And>x ys. \<lbrakk>\<not> memb x ys; xs \<approx> x # ys\<rbrakk> \<Longrightarrow> thesis"
+ − 526
proof -
+ − 527
fix x :: 'a
+ − 528
fix ys :: "'a list"
+ − 529
assume d:"\<not> memb x ys"
+ − 530
assume e:"xs \<approx> x # ys"
+ − 531
show thesis
+ − 532
proof (cases "x = a")
+ − 533
assume h: "x = a"
+ − 534
then have f: "\<not> memb a ys" using d by simp
+ − 535
have g: "a # xs \<approx> a # ys" using e h by auto
+ − 536
show thesis using b f g by simp
+ − 537
next
+ − 538
assume h: "x \<noteq> a"
+ − 539
then have f: "\<not> memb x (a # ys)" using d unfolding memb_def by auto
+ − 540
have g: "a # xs \<approx> x # (a # ys)" using e h by auto
+ − 541
show thesis using b f g by simp
+ − 542
qed
+ − 543
qed
+ − 544
then show thesis using a c by blast
+ − 545
qed
1518
+ − 546
1533
+ − 547
1888
+ − 548
text {* alternate formulation with a different decomposition principle
+ − 549
and a proof of equivalence *}
+ − 550
+ − 551
inductive
+ − 552
list_eq2
+ − 553
where
+ − 554
"list_eq2 (a # b # xs) (b # a # xs)"
+ − 555
| "list_eq2 [] []"
+ − 556
| "list_eq2 xs ys \<Longrightarrow> list_eq2 ys xs"
+ − 557
| "list_eq2 (a # a # xs) (a # xs)"
+ − 558
| "list_eq2 xs ys \<Longrightarrow> list_eq2 (a # xs) (a # ys)"
+ − 559
| "\<lbrakk>list_eq2 xs1 xs2; list_eq2 xs2 xs3\<rbrakk> \<Longrightarrow> list_eq2 xs1 xs3"
+ − 560
+ − 561
lemma list_eq2_refl:
+ − 562
shows "list_eq2 xs xs"
+ − 563
by (induct xs) (auto intro: list_eq2.intros)
+ − 564
+ − 565
lemma cons_delete_list_eq2:
2524
693562f03eee
major reorganisation of fset (renamed fset_to_set to fset, changed the definition of list_eq and fcard_raw)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 566
shows "list_eq2 (a # (removeAll a A)) (if memb a A then A else a # A)"
1888
+ − 567
apply (induct A)
+ − 568
apply (simp add: memb_def list_eq2_refl)
+ − 569
apply (case_tac "memb a (aa # A)")
2533
+ − 570
apply (simp_all only: memb_def)
1888
+ − 571
apply (case_tac [!] "a = aa")
1909
+ − 572
apply (simp_all)
1888
+ − 573
apply (case_tac "memb a A")
+ − 574
apply (auto simp add: memb_def)[2]
+ − 575
apply (metis list_eq2.intros(3) list_eq2.intros(4) list_eq2.intros(5) list_eq2.intros(6))
1895
+ − 576
apply (metis list_eq2.intros(1) list_eq2.intros(5) list_eq2.intros(6))
2525
+ − 577
apply (auto simp add: list_eq2_refl memb_def)
1888
+ − 578
done
+ − 579
+ − 580
lemma memb_delete_list_eq2:
+ − 581
assumes a: "memb e r"
2524
693562f03eee
major reorganisation of fset (renamed fset_to_set to fset, changed the definition of list_eq and fcard_raw)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 582
shows "list_eq2 (e # removeAll e r) r"
1888
+ − 583
using a cons_delete_list_eq2[of e r]
+ − 584
by simp
+ − 585
+ − 586
lemma list_eq2_equiv:
+ − 587
"(l \<approx> r) \<longleftrightarrow> (list_eq2 l r)"
+ − 588
proof
+ − 589
show "list_eq2 l r \<Longrightarrow> l \<approx> r" by (induct rule: list_eq2.induct) auto
1938
+ − 590
next
+ − 591
{
+ − 592
fix n
2536
+ − 593
assume a: "card_list l = n" and b: "l \<approx> r"
1938
+ − 594
have "list_eq2 l r"
+ − 595
using a b
+ − 596
proof (induct n arbitrary: l r)
+ − 597
case 0
2536
+ − 598
have "card_list l = 0" by fact
+ − 599
then have "\<forall>x. \<not> memb x l" unfolding card_list_def memb_def by auto
2534
+ − 600
then have z: "l = []" unfolding memb_def by auto
1938
+ − 601
then have "r = []" using `l \<approx> r` by simp
+ − 602
then show ?case using z list_eq2_refl by simp
+ − 603
next
+ − 604
case (Suc m)
+ − 605
have b: "l \<approx> r" by fact
2536
+ − 606
have d: "card_list l = Suc m" by fact
2524
693562f03eee
major reorganisation of fset (renamed fset_to_set to fset, changed the definition of list_eq and fcard_raw)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 607
then have "\<exists>a. memb a l"
2536
+ − 608
apply(simp add: card_list_def memb_def)
2524
693562f03eee
major reorganisation of fset (renamed fset_to_set to fset, changed the definition of list_eq and fcard_raw)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 609
apply(drule card_eq_SucD)
693562f03eee
major reorganisation of fset (renamed fset_to_set to fset, changed the definition of list_eq and fcard_raw)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 610
apply(blast)
693562f03eee
major reorganisation of fset (renamed fset_to_set to fset, changed the definition of list_eq and fcard_raw)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 611
done
1938
+ − 612
then obtain a where e: "memb a l" by auto
2524
693562f03eee
major reorganisation of fset (renamed fset_to_set to fset, changed the definition of list_eq and fcard_raw)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 613
then have e': "memb a r" using list_eq.simps[simplified memb_def[symmetric], of l r] b
693562f03eee
major reorganisation of fset (renamed fset_to_set to fset, changed the definition of list_eq and fcard_raw)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 614
unfolding memb_def by auto
2536
+ − 615
have f: "card_list (removeAll a l) = m" using e d by (simp add: card_list_def memb_def)
2525
+ − 616
have g: "removeAll a l \<approx> removeAll a r" using removeAll_rsp b by simp
2524
693562f03eee
major reorganisation of fset (renamed fset_to_set to fset, changed the definition of list_eq and fcard_raw)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 617
have "list_eq2 (removeAll a l) (removeAll a r)" by (rule Suc.hyps[OF f g])
693562f03eee
major reorganisation of fset (renamed fset_to_set to fset, changed the definition of list_eq and fcard_raw)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 618
then have h: "list_eq2 (a # removeAll a l) (a # removeAll a r)" by (rule list_eq2.intros(5))
693562f03eee
major reorganisation of fset (renamed fset_to_set to fset, changed the definition of list_eq and fcard_raw)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 619
have i: "list_eq2 l (a # removeAll a l)"
1938
+ − 620
by (rule list_eq2.intros(3)[OF memb_delete_list_eq2[OF e]])
2524
693562f03eee
major reorganisation of fset (renamed fset_to_set to fset, changed the definition of list_eq and fcard_raw)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 621
have "list_eq2 l (a # removeAll a r)" by (rule list_eq2.intros(6)[OF i h])
1938
+ − 622
then show ?case using list_eq2.intros(6)[OF _ memb_delete_list_eq2[OF e']] by simp
+ − 623
qed
+ − 624
}
+ − 625
then show "l \<approx> r \<Longrightarrow> list_eq2 l r" by blast
1888
+ − 626
qed
+ − 627
2534
+ − 628
+ − 629
section {* Lifted theorems *}
+ − 630
+ − 631
+ − 632
subsection {* fin *}
1518
+ − 633
2534
+ − 634
lemma not_fin_fnil:
+ − 635
shows "x |\<notin>| {||}"
+ − 636
by (descending) (simp add: memb_def)
+ − 637
+ − 638
lemma fin_set:
+ − 639
shows "x |\<in>| S \<longleftrightarrow> x \<in> fset S"
2529
+ − 640
by (descending) (simp add: memb_def)
1518
+ − 641
2534
+ − 642
lemma fnotin_set:
+ − 643
shows "x |\<notin>| S \<longleftrightarrow> x \<notin> fset S"
+ − 644
by (descending) (simp add: memb_def)
+ − 645
+ − 646
lemma fset_eq_iff:
+ − 647
shows "S = T \<longleftrightarrow> (\<forall>x. (x |\<in>| S) = (x |\<in>| T))"
+ − 648
by (descending) (auto simp add: memb_def)
+ − 649
+ − 650
lemma none_fin_fempty:
+ − 651
shows "(\<forall>x. x |\<notin>| S) \<longleftrightarrow> S = {||}"
+ − 652
by (descending) (simp add: memb_def)
+ − 653
+ − 654
+ − 655
subsection {* finsert *}
+ − 656
1518
+ − 657
lemma fin_finsert_iff[simp]:
2534
+ − 658
shows "x |\<in>| finsert y S \<longleftrightarrow> x = y \<or> x |\<in>| S"
2528
+ − 659
by (descending) (simp add: memb_def)
1518
+ − 660
+ − 661
lemma
+ − 662
shows finsertI1: "x |\<in>| finsert x S"
+ − 663
and finsertI2: "x |\<in>| S \<Longrightarrow> x |\<in>| finsert y S"
2534
+ − 664
by (descending, simp add: memb_def)+
1518
+ − 665
+ − 666
lemma finsert_absorb[simp]:
+ − 667
shows "x |\<in>| S \<Longrightarrow> finsert x S = S"
2528
+ − 668
by (descending) (auto simp add: memb_def)
1518
+ − 669
+ − 670
lemma fempty_not_finsert[simp]:
2534
+ − 671
shows "{||} \<noteq> finsert x S"
+ − 672
and "finsert x S \<noteq> {||}"
+ − 673
by (descending, simp)+
1518
+ − 674
+ − 675
lemma finsert_left_comm:
2534
+ − 676
shows "finsert x (finsert y S) = finsert y (finsert x S)"
2528
+ − 677
by (descending) (auto)
1518
+ − 678
+ − 679
lemma finsert_left_idem:
2534
+ − 680
shows "finsert x (finsert x S) = finsert x S"
2528
+ − 681
by (descending) (auto)
1518
+ − 682
+ − 683
lemma fsingleton_eq[simp]:
+ − 684
shows "{|x|} = {|y|} \<longleftrightarrow> x = y"
2528
+ − 685
by (descending) (auto)
1518
+ − 686
2524
693562f03eee
major reorganisation of fset (renamed fset_to_set to fset, changed the definition of list_eq and fcard_raw)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 687
2534
+ − 688
(* FIXME: is this in any case a useful lemma *)
+ − 689
lemma fin_mdef:
+ − 690
shows "x |\<in>| F \<longleftrightarrow> x |\<notin>| (F - {|x|}) \<and> F = finsert x (F - {|x|})"
2537
+ − 691
by (descending) (auto simp add: memb_def diff_list_def)
2534
+ − 692
+ − 693
+ − 694
subsection {* fset *}
1518
+ − 695
2524
693562f03eee
major reorganisation of fset (renamed fset_to_set to fset, changed the definition of list_eq and fcard_raw)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 696
lemma fset_simps[simp]:
693562f03eee
major reorganisation of fset (renamed fset_to_set to fset, changed the definition of list_eq and fcard_raw)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 697
"fset {||} = ({} :: 'a set)"
2533
+ − 698
"fset (finsert (x :: 'a) S) = insert x (fset S)"
1819
+ − 699
by (lifting set.simps)
1518
+ − 700
2534
+ − 701
lemma finite_fset [simp]:
+ − 702
shows "finite (fset S)"
+ − 703
by (descending) (simp)
+ − 704
+ − 705
lemma fset_cong:
+ − 706
shows "fset S = fset T \<longleftrightarrow> S = T"
+ − 707
by (descending) (simp)
+ − 708
+ − 709
lemma ffilter_set [simp]:
+ − 710
shows "fset (ffilter P xs) = P \<inter> fset xs"
+ − 711
by (descending) (auto simp add: mem_def)
+ − 712
+ − 713
lemma fdelete_set [simp]:
+ − 714
shows "fset (fdelete x xs) = fset xs - {x}"
+ − 715
by (descending) (simp)
+ − 716
+ − 717
lemma finter_set [simp]:
+ − 718
shows "fset (xs |\<inter>| ys) = fset xs \<inter> fset ys"
2538
+ − 719
by (descending) (auto simp add: inter_list_def)
2534
+ − 720
+ − 721
lemma funion_set [simp]:
+ − 722
shows "fset (xs |\<union>| ys) = fset xs \<union> fset ys"
+ − 723
by (lifting set_append)
+ − 724
+ − 725
lemma fminus_set [simp]:
+ − 726
shows "fset (xs - ys) = fset xs - fset ys"
2538
+ − 727
by (descending) (auto simp add: diff_list_def)
2534
+ − 728
+ − 729
+ − 730
subsection {* funion *}
+ − 731
+ − 732
lemmas [simp] =
+ − 733
sup_bot_left[where 'a="'a fset", standard]
+ − 734
sup_bot_right[where 'a="'a fset", standard]
+ − 735
+ − 736
lemma funion_finsert[simp]:
+ − 737
shows "finsert x S |\<union>| T = finsert x (S |\<union>| T)"
+ − 738
by (lifting append.simps(2))
+ − 739
+ − 740
lemma singleton_funion_left:
+ − 741
shows "{|a|} |\<union>| S = finsert a S"
+ − 742
by simp
1518
+ − 743
2534
+ − 744
lemma singleton_funion_right:
+ − 745
shows "S |\<union>| {|a|} = finsert a S"
+ − 746
by (subst sup.commute) simp
+ − 747
+ − 748
lemma fin_funion:
+ − 749
shows "x |\<in>| S |\<union>| T \<longleftrightarrow> x |\<in>| S \<or> x |\<in>| T"
+ − 750
by (descending) (simp add: memb_def)
+ − 751
+ − 752
+ − 753
subsection {* fminus *}
+ − 754
+ − 755
lemma fminus_fin:
+ − 756
shows "x |\<in>| (xs - ys) \<longleftrightarrow> x |\<in>| xs \<and> x |\<notin>| ys"
2538
+ − 757
by (descending) (simp add: diff_list_def memb_def)
2534
+ − 758
+ − 759
lemma fminus_red:
+ − 760
shows "finsert x xs - ys = (if x |\<in>| ys then xs - ys else finsert x (xs - ys))"
2538
+ − 761
by (descending) (auto simp add: diff_list_def memb_def)
2534
+ − 762
+ − 763
lemma fminus_red_fin[simp]:
+ − 764
shows "x |\<in>| ys \<Longrightarrow> finsert x xs - ys = xs - ys"
+ − 765
by (simp add: fminus_red)
+ − 766
+ − 767
lemma fminus_red_fnotin[simp]:
+ − 768
shows "x |\<notin>| ys \<Longrightarrow> finsert x xs - ys = finsert x (xs - ys)"
+ − 769
by (simp add: fminus_red)
+ − 770
+ − 771
lemma fin_fminus_fnotin:
+ − 772
shows "x |\<in>| F - S \<Longrightarrow> x |\<notin>| S"
+ − 773
unfolding fin_set fminus_set
+ − 774
by blast
+ − 775
+ − 776
lemma fin_fnotin_fminus:
+ − 777
shows "x |\<in>| S \<Longrightarrow> x |\<notin>| F - S"
+ − 778
unfolding fin_set fminus_set
+ − 779
by blast
+ − 780
+ − 781
+ − 782
section {* fdelete *}
+ − 783
+ − 784
lemma fin_fdelete:
+ − 785
shows "x |\<in>| fdelete y S \<longleftrightarrow> x |\<in>| S \<and> x \<noteq> y"
2533
+ − 786
by (descending) (simp add: memb_def)
1518
+ − 787
2534
+ − 788
lemma fnotin_fdelete:
+ − 789
shows "x |\<notin>| fdelete x S"
+ − 790
by (descending) (simp add: memb_def)
+ − 791
+ − 792
lemma fnotin_fdelete_ident:
+ − 793
shows "x |\<notin>| S \<Longrightarrow> fdelete x S = S"
+ − 794
by (descending) (simp add: memb_def)
+ − 795
+ − 796
lemma fset_fdelete_cases:
+ − 797
shows "S = {||} \<or> (\<exists>x. x |\<in>| S \<and> S = finsert x (fdelete x S))"
+ − 798
by (descending) (auto simp add: memb_def insert_absorb)
+ − 799
+ − 800
+ − 801
section {* finter *}
+ − 802
+ − 803
lemma finter_empty_l:
+ − 804
shows "{||} |\<inter>| S = {||}"
+ − 805
by simp
+ − 806
+ − 807
lemma finter_empty_r:
+ − 808
shows "S |\<inter>| {||} = {||}"
+ − 809
by simp
+ − 810
+ − 811
lemma finter_finsert:
+ − 812
shows "finsert x S |\<inter>| T = (if x |\<in>| T then finsert x (S |\<inter>| T) else S |\<inter>| T)"
2538
+ − 813
by (descending) (auto simp add: inter_list_def memb_def)
2534
+ − 814
+ − 815
lemma fin_finter:
+ − 816
shows "x |\<in>| (S |\<inter>| T) \<longleftrightarrow> x |\<in>| S \<and> x |\<in>| T"
2538
+ − 817
by (descending) (simp add: inter_list_def memb_def)
1533
+ − 818
1518
+ − 819
2534
+ − 820
subsection {* fsubset *}
+ − 821
+ − 822
lemma fsubseteq_set:
+ − 823
shows "xs |\<subseteq>| ys \<longleftrightarrow> fset xs \<subseteq> fset ys"
+ − 824
by (descending) (simp add: sub_list_def)
+ − 825
+ − 826
lemma fsubset_set:
+ − 827
shows "xs |\<subset>| ys \<longleftrightarrow> fset xs \<subset> fset ys"
+ − 828
unfolding less_fset_def
+ − 829
by (descending) (auto simp add: sub_list_def)
+ − 830
+ − 831
lemma fsubseteq_finsert:
+ − 832
shows "(finsert x xs) |\<subseteq>| ys \<longleftrightarrow> x |\<in>| ys \<and> xs |\<subseteq>| ys"
+ − 833
by (descending) (simp add: sub_list_def memb_def)
+ − 834
+ − 835
lemma fsubset_fin:
+ − 836
shows "xs |\<subseteq>| ys = (\<forall>x. x |\<in>| xs \<longrightarrow> x |\<in>| ys)"
+ − 837
by (descending) (auto simp add: sub_list_def memb_def)
+ − 838
+ − 839
(* FIXME: no type ord *)
+ − 840
(*
+ − 841
lemma fsubset_finsert:
+ − 842
shows "(finsert x xs) |\<subset>| ys \<longleftrightarrow> x |\<in>| ys \<and> xs |\<subset>| ys"
+ − 843
by (descending) (simp add: sub_list_def memb_def)
+ − 844
*)
+ − 845
+ − 846
lemma fsubseteq_fempty:
+ − 847
shows "xs |\<subseteq>| {||} \<longleftrightarrow> xs = {||}"
+ − 848
by (descending) (simp add: sub_list_def)
+ − 849
+ − 850
(* also problem with ord *)
+ − 851
lemma not_fsubset_fnil:
+ − 852
shows "\<not> xs |\<subset>| {||}"
+ − 853
by (metis fset_simps(1) fsubset_set not_psubset_empty)
+ − 854
+ − 855
+ − 856
section {* fmap *}
+ − 857
+ − 858
lemma fmap_simps [simp]:
+ − 859
shows "fmap f {||} = {||}"
+ − 860
and "fmap f (finsert x S) = finsert (f x) (fmap f S)"
+ − 861
by (descending, simp)+
+ − 862
+ − 863
lemma fmap_set_image [simp]:
+ − 864
shows "fset (fmap f S) = f ` (fset S)"
+ − 865
by (descending) (simp)
+ − 866
+ − 867
lemma inj_fmap_eq_iff:
+ − 868
shows "inj f \<Longrightarrow> fmap f S = fmap f T \<longleftrightarrow> S = T"
+ − 869
by (descending) (metis inj_vimage_image_eq list_eq.simps set_map)
+ − 870
+ − 871
lemma fmap_funion:
+ − 872
shows "fmap f (S |\<union>| T) = fmap f S |\<union>| fmap f T"
+ − 873
by (descending) (simp)
+ − 874
+ − 875
+ − 876
subsection {* fcard *}
+ − 877
+ − 878
lemma fcard_set:
+ − 879
shows "fcard xs = card (fset xs)"
2536
+ − 880
by (lifting card_list_def)
1518
+ − 881
+ − 882
lemma fcard_finsert_if [simp]:
+ − 883
shows "fcard (finsert x S) = (if x |\<in>| S then fcard S else Suc (fcard S))"
2536
+ − 884
by (descending) (auto simp add: card_list_def memb_def insert_absorb)
1518
+ − 885
2530
+ − 886
lemma fcard_0[simp]:
2524
693562f03eee
major reorganisation of fset (renamed fset_to_set to fset, changed the definition of list_eq and fcard_raw)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 887
shows "fcard S = 0 \<longleftrightarrow> S = {||}"
2536
+ − 888
by (descending) (simp add: card_list_def)
2524
693562f03eee
major reorganisation of fset (renamed fset_to_set to fset, changed the definition of list_eq and fcard_raw)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 889
693562f03eee
major reorganisation of fset (renamed fset_to_set to fset, changed the definition of list_eq and fcard_raw)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 890
lemma fcard_fempty[simp]:
693562f03eee
major reorganisation of fset (renamed fset_to_set to fset, changed the definition of list_eq and fcard_raw)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 891
shows "fcard {||} = 0"
693562f03eee
major reorganisation of fset (renamed fset_to_set to fset, changed the definition of list_eq and fcard_raw)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 892
by (simp add: fcard_0)
1813
+ − 893
1821
+ − 894
lemma fcard_1:
2524
693562f03eee
major reorganisation of fset (renamed fset_to_set to fset, changed the definition of list_eq and fcard_raw)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 895
shows "fcard S = 1 \<longleftrightarrow> (\<exists>x. S = {|x|})"
2536
+ − 896
by (descending) (auto simp add: card_list_def card_Suc_eq)
1819
+ − 897
2084
+ − 898
lemma fcard_gt_0:
2524
693562f03eee
major reorganisation of fset (renamed fset_to_set to fset, changed the definition of list_eq and fcard_raw)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 899
shows "x \<in> fset S \<Longrightarrow> 0 < fcard S"
2536
+ − 900
by (descending) (auto simp add: card_list_def card_gt_0_iff)
2524
693562f03eee
major reorganisation of fset (renamed fset_to_set to fset, changed the definition of list_eq and fcard_raw)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 901
2084
+ − 902
lemma fcard_not_fin:
2531
+ − 903
shows "(x |\<notin>| S) = (fcard (finsert x S) = Suc (fcard S))"
2536
+ − 904
by (descending) (auto simp add: memb_def card_list_def insert_absorb)
1813
+ − 905
2524
693562f03eee
major reorganisation of fset (renamed fset_to_set to fset, changed the definition of list_eq and fcard_raw)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 906
lemma fcard_suc:
693562f03eee
major reorganisation of fset (renamed fset_to_set to fset, changed the definition of list_eq and fcard_raw)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 907
shows "fcard S = Suc n \<Longrightarrow> \<exists>x T. x |\<notin>| T \<and> S = finsert x T \<and> fcard T = n"
693562f03eee
major reorganisation of fset (renamed fset_to_set to fset, changed the definition of list_eq and fcard_raw)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 908
apply(descending)
2536
+ − 909
apply(auto simp add: card_list_def memb_def)
2524
693562f03eee
major reorganisation of fset (renamed fset_to_set to fset, changed the definition of list_eq and fcard_raw)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 910
apply(drule card_eq_SucD)
693562f03eee
major reorganisation of fset (renamed fset_to_set to fset, changed the definition of list_eq and fcard_raw)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 911
apply(auto)
693562f03eee
major reorganisation of fset (renamed fset_to_set to fset, changed the definition of list_eq and fcard_raw)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 912
apply(rule_tac x="b" in exI)
693562f03eee
major reorganisation of fset (renamed fset_to_set to fset, changed the definition of list_eq and fcard_raw)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 913
apply(rule_tac x="removeAll b S" in exI)
693562f03eee
major reorganisation of fset (renamed fset_to_set to fset, changed the definition of list_eq and fcard_raw)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 914
apply(auto)
693562f03eee
major reorganisation of fset (renamed fset_to_set to fset, changed the definition of list_eq and fcard_raw)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 915
done
1813
+ − 916
1819
+ − 917
lemma fcard_delete:
2534
+ − 918
shows "fcard (fdelete y S) = (if y |\<in>| S then fcard S - 1 else fcard S)"
2536
+ − 919
by (descending) (simp add: card_list_def memb_def)
1819
+ − 920
2524
693562f03eee
major reorganisation of fset (renamed fset_to_set to fset, changed the definition of list_eq and fcard_raw)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 921
lemma fcard_suc_memb:
693562f03eee
major reorganisation of fset (renamed fset_to_set to fset, changed the definition of list_eq and fcard_raw)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 922
shows "fcard A = Suc n \<Longrightarrow> \<exists>a. a |\<in>| A"
693562f03eee
major reorganisation of fset (renamed fset_to_set to fset, changed the definition of list_eq and fcard_raw)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 923
apply(descending)
2536
+ − 924
apply(simp add: card_list_def memb_def)
2524
693562f03eee
major reorganisation of fset (renamed fset_to_set to fset, changed the definition of list_eq and fcard_raw)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 925
apply(drule card_eq_SucD)
693562f03eee
major reorganisation of fset (renamed fset_to_set to fset, changed the definition of list_eq and fcard_raw)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 926
apply(auto)
693562f03eee
major reorganisation of fset (renamed fset_to_set to fset, changed the definition of list_eq and fcard_raw)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 927
done
1878
+ − 928
2524
693562f03eee
major reorganisation of fset (renamed fset_to_set to fset, changed the definition of list_eq and fcard_raw)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 929
lemma fin_fcard_not_0:
693562f03eee
major reorganisation of fset (renamed fset_to_set to fset, changed the definition of list_eq and fcard_raw)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 930
shows "a |\<in>| A \<Longrightarrow> fcard A \<noteq> 0"
2536
+ − 931
by (descending) (auto simp add: card_list_def memb_def)
1878
+ − 932
2534
+ − 933
lemma fcard_mono:
+ − 934
shows "xs |\<subseteq>| ys \<Longrightarrow> fcard xs \<le> fcard ys"
+ − 935
unfolding fcard_set fsubseteq_set
+ − 936
by (simp add: card_mono[OF finite_fset])
2524
693562f03eee
major reorganisation of fset (renamed fset_to_set to fset, changed the definition of list_eq and fcard_raw)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 937
2534
+ − 938
lemma fcard_fsubset_eq:
+ − 939
shows "xs |\<subseteq>| ys \<Longrightarrow> fcard ys \<le> fcard xs \<Longrightarrow> xs = ys"
+ − 940
unfolding fcard_set fsubseteq_set
+ − 941
by (auto dest: card_seteq[OF finite_fset] simp add: fset_cong)
+ − 942
+ − 943
lemma psubset_fcard_mono:
+ − 944
shows "xs |\<subset>| ys \<Longrightarrow> fcard xs < fcard ys"
+ − 945
unfolding fcard_set fsubset_set
+ − 946
by (rule psubset_card_mono[OF finite_fset])
+ − 947
+ − 948
lemma fcard_funion_finter:
+ − 949
shows "fcard xs + fcard ys = fcard (xs |\<union>| ys) + fcard (xs |\<inter>| ys)"
+ − 950
unfolding fcard_set funion_set finter_set
+ − 951
by (rule card_Un_Int[OF finite_fset finite_fset])
+ − 952
+ − 953
lemma fcard_funion_disjoint:
+ − 954
shows "xs |\<inter>| ys = {||} \<Longrightarrow> fcard (xs |\<union>| ys) = fcard xs + fcard ys"
+ − 955
unfolding fcard_set funion_set
+ − 956
apply (rule card_Un_disjoint[OF finite_fset finite_fset])
+ − 957
by (metis finter_set fset_simps(1))
+ − 958
+ − 959
lemma fcard_delete1_less:
+ − 960
shows "x |\<in>| xs \<Longrightarrow> fcard (fdelete x xs) < fcard xs"
+ − 961
unfolding fcard_set fin_set fdelete_set
+ − 962
by (rule card_Diff1_less[OF finite_fset])
1518
+ − 963
2534
+ − 964
lemma fcard_delete2_less:
+ − 965
shows "x |\<in>| xs \<Longrightarrow> y |\<in>| xs \<Longrightarrow> fcard (fdelete y (fdelete x xs)) < fcard xs"
+ − 966
unfolding fcard_set fdelete_set fin_set
+ − 967
by (rule card_Diff2_less[OF finite_fset])
+ − 968
+ − 969
lemma fcard_delete1_le:
+ − 970
shows "fcard (fdelete x xs) \<le> fcard xs"
+ − 971
unfolding fdelete_set fcard_set
+ − 972
by (rule card_Diff1_le[OF finite_fset])
+ − 973
+ − 974
lemma fcard_psubset:
+ − 975
shows "ys |\<subseteq>| xs \<Longrightarrow> fcard ys < fcard xs \<Longrightarrow> ys |\<subset>| xs"
+ − 976
unfolding fcard_set fsubseteq_set fsubset_set
+ − 977
by (rule card_psubset[OF finite_fset])
+ − 978
+ − 979
lemma fcard_fmap_le:
+ − 980
shows "fcard (fmap f xs) \<le> fcard xs"
+ − 981
unfolding fcard_set fmap_set_image
+ − 982
by (rule card_image_le[OF finite_fset])
+ − 983
+ − 984
lemma fcard_fminus_finsert[simp]:
+ − 985
assumes "a |\<in>| A" and "a |\<notin>| B"
+ − 986
shows "fcard (A - finsert a B) = fcard (A - B) - 1"
+ − 987
using assms
+ − 988
unfolding fin_set fcard_set fminus_set
+ − 989
by (simp add: card_Diff_insert[OF finite_fset])
+ − 990
+ − 991
lemma fcard_fminus_fsubset:
+ − 992
assumes "B |\<subseteq>| A"
+ − 993
shows "fcard (A - B) = fcard A - fcard B"
+ − 994
using assms
+ − 995
unfolding fsubseteq_set fcard_set fminus_set
+ − 996
by (rule card_Diff_subset[OF finite_fset])
1518
+ − 997
2534
+ − 998
lemma fcard_fminus_subset_finter:
+ − 999
shows "fcard (A - B) = fcard A - fcard (A |\<inter>| B)"
+ − 1000
unfolding finter_set fcard_set fminus_set
+ − 1001
by (rule card_Diff_subset_Int) (simp)
+ − 1002
+ − 1003
+ − 1004
section {* fconcat *}
+ − 1005
+ − 1006
lemma fconcat_fempty:
+ − 1007
shows "fconcat {||} = {||}"
+ − 1008
by (lifting concat.simps(1))
+ − 1009
+ − 1010
lemma fconcat_finsert:
+ − 1011
shows "fconcat (finsert x S) = x |\<union>| fconcat S"
+ − 1012
by (lifting concat.simps(2))
+ − 1013
+ − 1014
lemma fconcat_finter:
+ − 1015
shows "fconcat (xs |\<union>| ys) = fconcat xs |\<union>| fconcat ys"
+ − 1016
by (lifting concat_append)
+ − 1017
+ − 1018
+ − 1019
section {* ffilter *}
+ − 1020
+ − 1021
lemma subseteq_filter:
+ − 1022
shows "ffilter P xs <= ffilter Q xs = (\<forall> x. x |\<in>| xs \<longrightarrow> P x \<longrightarrow> Q x)"
+ − 1023
by (descending) (auto simp add: memb_def sub_list_def)
+ − 1024
+ − 1025
lemma eq_ffilter:
+ − 1026
shows "(ffilter P xs = ffilter Q xs) = (\<forall>x. x |\<in>| xs \<longrightarrow> P x = Q x)"
+ − 1027
by (descending) (auto simp add: memb_def)
1887
+ − 1028
2534
+ − 1029
lemma subset_ffilter:
+ − 1030
shows "(\<And>x. x |\<in>| xs \<Longrightarrow> P x \<Longrightarrow> Q x) \<Longrightarrow> (x |\<in>| xs & \<not> P x & Q x) \<Longrightarrow> ffilter P xs < ffilter Q xs"
+ − 1031
unfolding less_fset_def by (auto simp add: subseteq_filter eq_ffilter)
+ − 1032
+ − 1033
+ − 1034
subsection {* ffold *}
+ − 1035
+ − 1036
lemma ffold_nil:
+ − 1037
shows "ffold f z {||} = z"
+ − 1038
by (descending) (simp)
+ − 1039
+ − 1040
lemma ffold_finsert: "ffold f z (finsert a A) =
+ − 1041
(if rsp_fold f then if a |\<in>| A then ffold f z A else f a (ffold f z A) else z)"
+ − 1042
by (descending) (simp add: memb_def)
1887
+ − 1043
2534
+ − 1044
lemma fin_commute_ffold:
+ − 1045
"\<lbrakk>rsp_fold f; h |\<in>| b\<rbrakk> \<Longrightarrow> ffold f z b = f h (ffold f z (fdelete h b))"
+ − 1046
by (descending) (simp add: memb_def memb_commute_ffold_raw)
+ − 1047
+ − 1048
+ − 1049
subsection {* Choice in fsets *}
+ − 1050
+ − 1051
lemma fset_choice:
+ − 1052
assumes a: "\<forall>x. x |\<in>| A \<longrightarrow> (\<exists>y. P x y)"
+ − 1053
shows "\<exists>f. \<forall>x. x |\<in>| A \<longrightarrow> P x (f x)"
+ − 1054
using a
+ − 1055
apply(descending)
+ − 1056
using finite_set_choice
+ − 1057
by (auto simp add: memb_def Ball_def)
+ − 1058
+ − 1059
+ − 1060
(* FIXME: is that in any way useful *)
+ − 1061
1887
+ − 1062
2524
693562f03eee
major reorganisation of fset (renamed fset_to_set to fset, changed the definition of list_eq and fcard_raw)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 1063
693562f03eee
major reorganisation of fset (renamed fset_to_set to fset, changed the definition of list_eq and fcard_raw)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 1064
section {* Induction and Cases rules for fsets *}
1518
+ − 1065
+ − 1066
lemma fset_strong_cases:
2084
+ − 1067
obtains "xs = {||}"
+ − 1068
| x ys where "x |\<notin>| ys" and "xs = finsert x ys"
1819
+ − 1069
by (lifting fset_raw_strong_cases)
1518
+ − 1070
+ − 1071
lemma fset_exhaust[case_names fempty finsert, cases type: fset]:
+ − 1072
shows "\<lbrakk>S = {||} \<Longrightarrow> P; \<And>x S'. S = finsert x S' \<Longrightarrow> P\<rbrakk> \<Longrightarrow> P"
+ − 1073
by (lifting list.exhaust)
+ − 1074
1533
+ − 1075
lemma fset_induct_weak[case_names fempty finsert]:
1518
+ − 1076
shows "\<lbrakk>P {||}; \<And>x S. P S \<Longrightarrow> P (finsert x S)\<rbrakk> \<Longrightarrow> P S"
+ − 1077
by (lifting list.induct)
+ − 1078
1533
+ − 1079
lemma fset_induct[case_names fempty finsert, induct type: fset]:
2084
+ − 1080
assumes prem1: "P {||}"
1518
+ − 1081
and prem2: "\<And>x S. \<lbrakk>x |\<notin>| S; P S\<rbrakk> \<Longrightarrow> P (finsert x S)"
+ − 1082
shows "P S"
1533
+ − 1083
proof(induct S rule: fset_induct_weak)
1518
+ − 1084
case fempty
+ − 1085
show "P {||}" by (rule prem1)
+ − 1086
next
+ − 1087
case (finsert x S)
+ − 1088
have asm: "P S" by fact
+ − 1089
show "P (finsert x S)"
1938
+ − 1090
by (cases "x |\<in>| S") (simp_all add: asm prem2)
1518
+ − 1091
qed
+ − 1092
1533
+ − 1093
lemma fset_induct2:
+ − 1094
"P {||} {||} \<Longrightarrow>
+ − 1095
(\<And>x xs. x |\<notin>| xs \<Longrightarrow> P (finsert x xs) {||}) \<Longrightarrow>
+ − 1096
(\<And>y ys. y |\<notin>| ys \<Longrightarrow> P {||} (finsert y ys)) \<Longrightarrow>
+ − 1097
(\<And>x xs y ys. \<lbrakk>P xs ys; x |\<notin>| xs; y |\<notin>| ys\<rbrakk> \<Longrightarrow> P (finsert x xs) (finsert y ys)) \<Longrightarrow>
+ − 1098
P xsa ysa"
+ − 1099
apply (induct xsa arbitrary: ysa)
+ − 1100
apply (induct_tac x rule: fset_induct)
+ − 1101
apply simp_all
+ − 1102
apply (induct_tac xa rule: fset_induct)
+ − 1103
apply simp_all
+ − 1104
done
1518
+ − 1105
2084
+ − 1106
lemma fset_fcard_induct:
+ − 1107
assumes a: "P {||}"
+ − 1108
and b: "\<And>xs ys. Suc (fcard xs) = (fcard ys) \<Longrightarrow> P xs \<Longrightarrow> P ys"
+ − 1109
shows "P zs"
+ − 1110
proof (induct zs)
+ − 1111
show "P {||}" by (rule a)
+ − 1112
next
+ − 1113
fix x :: 'a and zs :: "'a fset"
+ − 1114
assume h: "P zs"
+ − 1115
assume "x |\<notin>| zs"
+ − 1116
then have H1: "Suc (fcard zs) = fcard (finsert x zs)" using fcard_suc by auto
+ − 1117
then show "P (finsert x zs)" using b h by simp
+ − 1118
qed
+ − 1119
2524
693562f03eee
major reorganisation of fset (renamed fset_to_set to fset, changed the definition of list_eq and fcard_raw)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 1120
1888
+ − 1121
(* We cannot write it as "assumes .. shows" since Isabelle changes
+ − 1122
the quantifiers to schematic variables and reintroduces them in
+ − 1123
a different order *)
+ − 1124
lemma fset_eq_cases:
+ − 1125
"\<lbrakk>a1 = a2;
+ − 1126
\<And>a b xs. \<lbrakk>a1 = finsert a (finsert b xs); a2 = finsert b (finsert a xs)\<rbrakk> \<Longrightarrow> P;
+ − 1127
\<lbrakk>a1 = {||}; a2 = {||}\<rbrakk> \<Longrightarrow> P; \<And>xs ys. \<lbrakk>a1 = ys; a2 = xs; xs = ys\<rbrakk> \<Longrightarrow> P;
+ − 1128
\<And>a xs. \<lbrakk>a1 = finsert a (finsert a xs); a2 = finsert a xs\<rbrakk> \<Longrightarrow> P;
+ − 1129
\<And>xs ys a. \<lbrakk>a1 = finsert a xs; a2 = finsert a ys; xs = ys\<rbrakk> \<Longrightarrow> P;
+ − 1130
\<And>xs1 xs2 xs3. \<lbrakk>a1 = xs1; a2 = xs3; xs1 = xs2; xs2 = xs3\<rbrakk> \<Longrightarrow> P\<rbrakk>
+ − 1131
\<Longrightarrow> P"
+ − 1132
by (lifting list_eq2.cases[simplified list_eq2_equiv[symmetric]])
+ − 1133
+ − 1134
lemma fset_eq_induct:
+ − 1135
assumes "x1 = x2"
+ − 1136
and "\<And>a b xs. P (finsert a (finsert b xs)) (finsert b (finsert a xs))"
+ − 1137
and "P {||} {||}"
+ − 1138
and "\<And>xs ys. \<lbrakk>xs = ys; P xs ys\<rbrakk> \<Longrightarrow> P ys xs"
+ − 1139
and "\<And>a xs. P (finsert a (finsert a xs)) (finsert a xs)"
+ − 1140
and "\<And>xs ys a. \<lbrakk>xs = ys; P xs ys\<rbrakk> \<Longrightarrow> P (finsert a xs) (finsert a ys)"
+ − 1141
and "\<And>xs1 xs2 xs3. \<lbrakk>xs1 = xs2; P xs1 xs2; xs2 = xs3; P xs2 xs3\<rbrakk> \<Longrightarrow> P xs1 xs3"
+ − 1142
shows "P x1 x2"
+ − 1143
using assms
+ − 1144
by (lifting list_eq2.induct[simplified list_eq2_equiv[symmetric]])
1820
+ − 1145
2524
693562f03eee
major reorganisation of fset (renamed fset_to_set to fset, changed the definition of list_eq and fcard_raw)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 1146
2084
+ − 1147
+ − 1148
section {* lemmas transferred from Finite_Set theory *}
+ − 1149
+ − 1150
text {* finiteness for finite sets holds *}
+ − 1151
+ − 1152
+ − 1153
2234
+ − 1154
2326
+ − 1155
lemma list_all2_refl:
2266
dcffc2f132c9
Qpaper / Clarify the typing system and composition of quotients issue.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 1156
assumes q: "equivp R"
2326
+ − 1157
shows "(list_all2 R) r r"
2378
+ − 1158
by (rule list_all2_refl) (metis equivp_def q)
2266
dcffc2f132c9
Qpaper / Clarify the typing system and composition of quotients issue.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 1159
dcffc2f132c9
Qpaper / Clarify the typing system and composition of quotients issue.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 1160
lemma compose_list_refl2:
dcffc2f132c9
Qpaper / Clarify the typing system and composition of quotients issue.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 1161
assumes q: "equivp R"
2326
+ − 1162
shows "(list_all2 R OOO op \<approx>) r r"
2266
dcffc2f132c9
Qpaper / Clarify the typing system and composition of quotients issue.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 1163
proof
dcffc2f132c9
Qpaper / Clarify the typing system and composition of quotients issue.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 1164
have *: "r \<approx> r" by (rule equivp_reflp[OF fset_equivp])
2326
+ − 1165
show "list_all2 R r r" by (rule list_all2_refl[OF q])
+ − 1166
with * show "(op \<approx> OO list_all2 R) r r" ..
2266
dcffc2f132c9
Qpaper / Clarify the typing system and composition of quotients issue.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 1167
qed
dcffc2f132c9
Qpaper / Clarify the typing system and composition of quotients issue.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 1168
2285
+ − 1169
lemma quotient_compose_list_g:
2266
dcffc2f132c9
Qpaper / Clarify the typing system and composition of quotients issue.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 1170
assumes q: "Quotient R Abs Rep"
dcffc2f132c9
Qpaper / Clarify the typing system and composition of quotients issue.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 1171
and e: "equivp R"
2326
+ − 1172
shows "Quotient ((list_all2 R) OOO (op \<approx>))
2266
dcffc2f132c9
Qpaper / Clarify the typing system and composition of quotients issue.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 1173
(abs_fset \<circ> (map Abs)) ((map Rep) \<circ> rep_fset)"
dcffc2f132c9
Qpaper / Clarify the typing system and composition of quotients issue.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 1174
unfolding Quotient_def comp_def
dcffc2f132c9
Qpaper / Clarify the typing system and composition of quotients issue.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 1175
proof (intro conjI allI)
dcffc2f132c9
Qpaper / Clarify the typing system and composition of quotients issue.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 1176
fix a r s
dcffc2f132c9
Qpaper / Clarify the typing system and composition of quotients issue.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 1177
show "abs_fset (map Abs (map Rep (rep_fset a))) = a"
dcffc2f132c9
Qpaper / Clarify the typing system and composition of quotients issue.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 1178
by (simp add: abs_o_rep[OF q] Quotient_abs_rep[OF Quotient_fset] map_id)
2326
+ − 1179
have b: "list_all2 R (map Rep (rep_fset a)) (map Rep (rep_fset a))"
+ − 1180
by (rule list_all2_refl[OF e])
+ − 1181
have c: "(op \<approx> OO list_all2 R) (map Rep (rep_fset a)) (map Rep (rep_fset a))"
2266
dcffc2f132c9
Qpaper / Clarify the typing system and composition of quotients issue.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 1182
by (rule, rule equivp_reflp[OF fset_equivp]) (rule b)
2326
+ − 1183
show "(list_all2 R OOO op \<approx>) (map Rep (rep_fset a)) (map Rep (rep_fset a))"
+ − 1184
by (rule, rule list_all2_refl[OF e]) (rule c)
+ − 1185
show "(list_all2 R OOO op \<approx>) r s = ((list_all2 R OOO op \<approx>) r r \<and>
+ − 1186
(list_all2 R OOO op \<approx>) s s \<and> abs_fset (map Abs r) = abs_fset (map Abs s))"
2266
dcffc2f132c9
Qpaper / Clarify the typing system and composition of quotients issue.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 1187
proof (intro iffI conjI)
2326
+ − 1188
show "(list_all2 R OOO op \<approx>) r r" by (rule compose_list_refl2[OF e])
+ − 1189
show "(list_all2 R OOO op \<approx>) s s" by (rule compose_list_refl2[OF e])
2266
dcffc2f132c9
Qpaper / Clarify the typing system and composition of quotients issue.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 1190
next
2326
+ − 1191
assume a: "(list_all2 R OOO op \<approx>) r s"
2266
dcffc2f132c9
Qpaper / Clarify the typing system and composition of quotients issue.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 1192
then have b: "map Abs r \<approx> map Abs s"
dcffc2f132c9
Qpaper / Clarify the typing system and composition of quotients issue.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 1193
proof (elim pred_compE)
dcffc2f132c9
Qpaper / Clarify the typing system and composition of quotients issue.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 1194
fix b ba
2326
+ − 1195
assume c: "list_all2 R r b"
2266
dcffc2f132c9
Qpaper / Clarify the typing system and composition of quotients issue.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 1196
assume d: "b \<approx> ba"
2326
+ − 1197
assume e: "list_all2 R ba s"
2266
dcffc2f132c9
Qpaper / Clarify the typing system and composition of quotients issue.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 1198
have f: "map Abs r = map Abs b"
dcffc2f132c9
Qpaper / Clarify the typing system and composition of quotients issue.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 1199
using Quotient_rel[OF list_quotient[OF q]] c by blast
dcffc2f132c9
Qpaper / Clarify the typing system and composition of quotients issue.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 1200
have "map Abs ba = map Abs s"
dcffc2f132c9
Qpaper / Clarify the typing system and composition of quotients issue.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 1201
using Quotient_rel[OF list_quotient[OF q]] e by blast
dcffc2f132c9
Qpaper / Clarify the typing system and composition of quotients issue.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 1202
then have g: "map Abs s = map Abs ba" by simp
dcffc2f132c9
Qpaper / Clarify the typing system and composition of quotients issue.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 1203
then show "map Abs r \<approx> map Abs s" using d f map_rel_cong by simp
dcffc2f132c9
Qpaper / Clarify the typing system and composition of quotients issue.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 1204
qed
dcffc2f132c9
Qpaper / Clarify the typing system and composition of quotients issue.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 1205
then show "abs_fset (map Abs r) = abs_fset (map Abs s)"
dcffc2f132c9
Qpaper / Clarify the typing system and composition of quotients issue.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 1206
using Quotient_rel[OF Quotient_fset] by blast
dcffc2f132c9
Qpaper / Clarify the typing system and composition of quotients issue.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 1207
next
2326
+ − 1208
assume a: "(list_all2 R OOO op \<approx>) r r \<and> (list_all2 R OOO op \<approx>) s s
2266
dcffc2f132c9
Qpaper / Clarify the typing system and composition of quotients issue.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 1209
\<and> abs_fset (map Abs r) = abs_fset (map Abs s)"
2326
+ − 1210
then have s: "(list_all2 R OOO op \<approx>) s s" by simp
2266
dcffc2f132c9
Qpaper / Clarify the typing system and composition of quotients issue.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 1211
have d: "map Abs r \<approx> map Abs s"
dcffc2f132c9
Qpaper / Clarify the typing system and composition of quotients issue.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 1212
by (subst Quotient_rel[OF Quotient_fset]) (simp add: a)
dcffc2f132c9
Qpaper / Clarify the typing system and composition of quotients issue.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 1213
have b: "map Rep (map Abs r) \<approx> map Rep (map Abs s)"
dcffc2f132c9
Qpaper / Clarify the typing system and composition of quotients issue.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 1214
by (rule map_rel_cong[OF d])
2326
+ − 1215
have y: "list_all2 R (map Rep (map Abs s)) s"
+ − 1216
by (fact rep_abs_rsp_left[OF list_quotient[OF q], OF list_all2_refl[OF e, of s]])
+ − 1217
have c: "(op \<approx> OO list_all2 R) (map Rep (map Abs r)) s"
2266
dcffc2f132c9
Qpaper / Clarify the typing system and composition of quotients issue.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 1218
by (rule pred_compI) (rule b, rule y)
2326
+ − 1219
have z: "list_all2 R r (map Rep (map Abs r))"
+ − 1220
by (fact rep_abs_rsp[OF list_quotient[OF q], OF list_all2_refl[OF e, of r]])
+ − 1221
then show "(list_all2 R OOO op \<approx>) r s"
2266
dcffc2f132c9
Qpaper / Clarify the typing system and composition of quotients issue.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 1222
using a c pred_compI by simp
dcffc2f132c9
Qpaper / Clarify the typing system and composition of quotients issue.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 1223
qed
dcffc2f132c9
Qpaper / Clarify the typing system and composition of quotients issue.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 1224
qed
dcffc2f132c9
Qpaper / Clarify the typing system and composition of quotients issue.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 1225
2528
+ − 1226
+ − 1227
ML {*
+ − 1228
fun dest_fsetT (Type (@{type_name fset}, [T])) = T
+ − 1229
| dest_fsetT T = raise TYPE ("dest_fsetT: fset type expected", [T], []);
+ − 1230
*}
+ − 1231
2266
dcffc2f132c9
Qpaper / Clarify the typing system and composition of quotients issue.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 1232
no_notation
dcffc2f132c9
Qpaper / Clarify the typing system and composition of quotients issue.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 1233
list_eq (infix "\<approx>" 50)
dcffc2f132c9
Qpaper / Clarify the typing system and composition of quotients issue.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 1234
2234
+ − 1235
end