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