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
2190
+ − 301
2529
+ − 302
2190
+ − 303
2084
+ − 304
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
+ − 305
shows "((op =) ===> op \<approx> ===> op \<approx>) filter filter"
2084
+ − 306
by auto
+ − 307
1909
+ − 308
text {* Distributive lattice with bot *}
+ − 309
1893
+ − 310
lemma sub_list_not_eq:
+ − 311
"(sub_list x y \<and> \<not> list_eq x y) = (sub_list x y \<and> \<not> sub_list y x)"
+ − 312
by (auto simp add: sub_list_def)
+ − 313
+ − 314
lemma sub_list_refl:
+ − 315
"sub_list x x"
+ − 316
by (simp add: sub_list_def)
+ − 317
+ − 318
lemma sub_list_trans:
+ − 319
"sub_list x y \<Longrightarrow> sub_list y z \<Longrightarrow> sub_list x z"
+ − 320
by (simp add: sub_list_def)
+ − 321
+ − 322
lemma sub_list_empty:
+ − 323
"sub_list [] x"
+ − 324
by (simp add: sub_list_def)
+ − 325
1905
+ − 326
lemma sub_list_append_left:
+ − 327
"sub_list x (x @ y)"
+ − 328
by (simp add: sub_list_def)
+ − 329
+ − 330
lemma sub_list_append_right:
+ − 331
"sub_list y (x @ y)"
+ − 332
by (simp add: sub_list_def)
+ − 333
+ − 334
lemma sub_list_inter_left:
+ − 335
shows "sub_list (finter_raw x y) 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
+ − 336
by (simp add: sub_list_def)
1905
+ − 337
+ − 338
lemma sub_list_inter_right:
+ − 339
shows "sub_list (finter_raw x y) 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
+ − 340
by (simp add: sub_list_def)
1905
+ − 341
+ − 342
lemma sub_list_list_eq:
+ − 343
"sub_list x y \<Longrightarrow> sub_list y x \<Longrightarrow> list_eq x y"
+ − 344
unfolding sub_list_def list_eq.simps by blast
+ − 345
+ − 346
lemma sub_list_append:
+ − 347
"sub_list y x \<Longrightarrow> sub_list z x \<Longrightarrow> sub_list (y @ z) x"
+ − 348
unfolding sub_list_def by auto
+ − 349
+ − 350
lemma sub_list_inter:
+ − 351
"sub_list x y \<Longrightarrow> sub_list x z \<Longrightarrow> sub_list x (finter_raw y 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
+ − 352
by (simp add: sub_list_def)
1905
+ − 353
+ − 354
lemma append_inter_distrib:
+ − 355
"x @ (finter_raw y z) \<approx> finter_raw (x @ y) (x @ z)"
+ − 356
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
+ − 357
apply (auto)
2084
+ − 358
done
1905
+ − 359
2528
+ − 360
instantiation fset :: (type) "{bounded_lattice_bot, distrib_lattice, minus}"
1893
+ − 361
begin
+ − 362
+ − 363
quotient_definition
+ − 364
"bot :: 'a fset" is "[] :: 'a list"
+ − 365
+ − 366
abbreviation
+ − 367
fempty ("{||}")
+ − 368
where
+ − 369
"{||} \<equiv> bot :: 'a fset"
+ − 370
+ − 371
quotient_definition
+ − 372
"less_eq_fset \<Colon> ('a fset \<Rightarrow> 'a fset \<Rightarrow> bool)"
+ − 373
is
+ − 374
"sub_list \<Colon> ('a list \<Rightarrow> 'a list \<Rightarrow> bool)"
+ − 375
+ − 376
abbreviation
+ − 377
f_subset_eq :: "'a fset \<Rightarrow> 'a fset \<Rightarrow> bool" (infix "|\<subseteq>|" 50)
+ − 378
where
+ − 379
"xs |\<subseteq>| ys \<equiv> xs \<le> ys"
+ − 380
+ − 381
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
+ − 382
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
+ − 383
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
+ − 384
"xs < ys \<equiv> xs \<le> ys \<and> xs \<noteq> (ys::'a fset)"
1893
+ − 385
+ − 386
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
+ − 387
fsubset :: "'a fset \<Rightarrow> 'a fset \<Rightarrow> bool" (infix "|\<subset>|" 50)
1893
+ − 388
where
+ − 389
"xs |\<subset>| ys \<equiv> xs < ys"
+ − 390
1895
+ − 391
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
+ − 392
"sup :: 'a fset \<Rightarrow> 'a fset \<Rightarrow> 'a fset"
1895
+ − 393
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
+ − 394
"append :: 'a list \<Rightarrow> 'a list \<Rightarrow> 'a list"
1895
+ − 395
+ − 396
abbreviation
2084
+ − 397
funion (infixl "|\<union>|" 65)
1895
+ − 398
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
+ − 399
"xs |\<union>| ys \<equiv> sup xs (ys::'a fset)"
1895
+ − 400
1905
+ − 401
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
+ − 402
"inf :: 'a fset \<Rightarrow> 'a fset \<Rightarrow> 'a fset"
1905
+ − 403
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
+ − 404
"finter_raw :: 'a list \<Rightarrow> 'a list \<Rightarrow> 'a list"
1905
+ − 405
+ − 406
abbreviation
+ − 407
finter (infixl "|\<inter>|" 65)
+ − 408
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
+ − 409
"xs |\<inter>| ys \<equiv> inf xs (ys::'a fset)"
1905
+ − 410
2084
+ − 411
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
+ − 412
"minus :: 'a fset \<Rightarrow> 'a fset \<Rightarrow> 'a fset"
2084
+ − 413
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
+ − 414
"fminus_raw :: 'a list \<Rightarrow> 'a list \<Rightarrow> 'a list"
2084
+ − 415
1895
+ − 416
instance
+ − 417
proof
1905
+ − 418
fix x y z :: "'a fset"
2528
+ − 419
show "x |\<subset>| y \<longleftrightarrow> x |\<subseteq>| y \<and> \<not> y |\<subseteq>| 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
+ − 420
unfolding less_fset_def by (lifting sub_list_not_eq)
2528
+ − 421
show "x |\<subseteq>| x" by (descending) (simp add: sub_list_def)
+ − 422
show "{||} |\<subseteq>| x" by (descending) (simp add: sub_list_def)
+ − 423
show "x |\<subseteq>| x |\<union>| y" by (descending) (simp add: sub_list_def)
+ − 424
show "y |\<subseteq>| x |\<union>| y" by (descending) (simp add: sub_list_def)
+ − 425
show "x |\<inter>| y |\<subseteq>| x"
+ − 426
by (descending) (simp add: sub_list_def memb_def[symmetric])
+ − 427
show "x |\<inter>| y |\<subseteq>| y"
+ − 428
by (descending) (simp add: sub_list_def memb_def[symmetric])
+ − 429
show "x |\<union>| (y |\<inter>| z) = x |\<union>| y |\<inter>| (x |\<union>| z)"
+ − 430
by (descending) (rule append_inter_distrib)
1905
+ − 431
next
+ − 432
fix x y z :: "'a fset"
+ − 433
assume a: "x |\<subseteq>| y"
+ − 434
assume b: "y |\<subseteq>| z"
2528
+ − 435
show "x |\<subseteq>| z" using a b
+ − 436
by (descending) (simp add: sub_list_def)
1895
+ − 437
next
+ − 438
fix x y :: "'a fset"
+ − 439
assume a: "x |\<subseteq>| y"
+ − 440
assume b: "y |\<subseteq>| x"
2528
+ − 441
show "x = y" using a b
+ − 442
by (descending) (unfold sub_list_def list_eq.simps, blast)
1895
+ − 443
next
+ − 444
fix x y z :: "'a fset"
+ − 445
assume a: "y |\<subseteq>| x"
+ − 446
assume b: "z |\<subseteq>| x"
2528
+ − 447
show "y |\<union>| z |\<subseteq>| x" using a b
+ − 448
by (descending) (simp add: sub_list_def)
1905
+ − 449
next
+ − 450
fix x y z :: "'a fset"
+ − 451
assume a: "x |\<subseteq>| y"
+ − 452
assume b: "x |\<subseteq>| z"
2528
+ − 453
show "x |\<subseteq>| y |\<inter>| z" using a b
+ − 454
by (descending) (simp add: sub_list_def memb_def[symmetric])
1895
+ − 455
qed
1905
+ − 456
1893
+ − 457
end
+ − 458
1909
+ − 459
section {* Finsert and Membership *}
1518
+ − 460
+ − 461
quotient_definition
1893
+ − 462
"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
+ − 463
is "Cons"
1518
+ − 464
+ − 465
syntax
+ − 466
"@Finset" :: "args => 'a fset" ("{|(_)|}")
+ − 467
+ − 468
translations
+ − 469
"{|x, xs|}" == "CONST finsert x {|xs|}"
+ − 470
"{|x|}" == "CONST finsert x {||}"
+ − 471
+ − 472
quotient_definition
1938
+ − 473
fin (infix "|\<in>|" 50)
1518
+ − 474
where
1816
+ − 475
"fin :: 'a \<Rightarrow> 'a fset \<Rightarrow> bool" is "memb"
1518
+ − 476
+ − 477
abbreviation
1938
+ − 478
fnotin :: "'a \<Rightarrow> 'a fset \<Rightarrow> bool" (infix "|\<notin>|" 50)
1518
+ − 479
where
1860
+ − 480
"x |\<notin>| S \<equiv> \<not> (x |\<in>| S)"
1518
+ − 481
2084
+ − 482
section {* Other constants on the Quotient Type *}
1935
+ − 483
+ − 484
quotient_definition
2084
+ − 485
"fcard :: 'a fset \<Rightarrow> nat"
2529
+ − 486
is
+ − 487
fcard_raw
1935
+ − 488
+ − 489
quotient_definition
+ − 490
"fmap :: ('a \<Rightarrow> 'b) \<Rightarrow> 'a fset \<Rightarrow> 'b fset"
2529
+ − 491
is
+ − 492
map
1935
+ − 493
+ − 494
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
+ − 495
"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
+ − 496
is removeAll
1935
+ − 497
+ − 498
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
+ − 499
"fset :: 'a fset \<Rightarrow> 'a set"
1935
+ − 500
is "set"
+ − 501
+ − 502
quotient_definition
+ − 503
"ffold :: ('a \<Rightarrow> 'b \<Rightarrow> 'b) \<Rightarrow> 'b \<Rightarrow> 'a fset \<Rightarrow> 'b"
+ − 504
is "ffold_raw"
+ − 505
+ − 506
quotient_definition
+ − 507
"fconcat :: ('a fset) fset \<Rightarrow> 'a fset"
+ − 508
is
+ − 509
"concat"
+ − 510
2084
+ − 511
quotient_definition
+ − 512
"ffilter :: ('a \<Rightarrow> bool) \<Rightarrow> 'a fset \<Rightarrow> 'a fset"
+ − 513
is
+ − 514
"filter"
+ − 515
1935
+ − 516
text {* Compositional Respectfullness and Preservation *}
+ − 517
2326
+ − 518
lemma [quot_respect]: "(list_all2 op \<approx> OOO op \<approx>) [] []"
1938
+ − 519
by (fact compose_list_refl)
1935
+ − 520
+ − 521
lemma [quot_preserve]: "(abs_fset \<circ> map f) [] = abs_fset []"
+ − 522
by simp
+ − 523
+ − 524
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
+ − 525
shows "(op \<approx> ===> list_all2 op \<approx> OOO op \<approx> ===> list_all2 op \<approx> OOO op \<approx>) Cons Cons"
1935
+ − 526
apply auto
+ − 527
apply (rule_tac b="x # b" in pred_compI)
+ − 528
apply auto
+ − 529
apply (rule_tac b="x # ba" in pred_compI)
+ − 530
apply auto
+ − 531
done
+ − 532
+ − 533
lemma [quot_preserve]:
+ − 534
"(rep_fset ---> (map rep_fset \<circ> rep_fset) ---> (abs_fset \<circ> map abs_fset)) op # = finsert"
2479
+ − 535
by (simp add: fun_eq_iff Quotient_abs_rep[OF Quotient_fset]
1935
+ − 536
abs_o_rep[OF Quotient_fset] map_id finsert_def)
+ − 537
+ − 538
lemma [quot_preserve]:
1938
+ − 539
"((map rep_fset \<circ> rep_fset) ---> (map rep_fset \<circ> rep_fset) ---> (abs_fset \<circ> map abs_fset)) op @ = funion"
2479
+ − 540
by (simp add: fun_eq_iff Quotient_abs_rep[OF Quotient_fset]
1935
+ − 541
abs_o_rep[OF Quotient_fset] map_id sup_fset_def)
+ − 542
2326
+ − 543
lemma list_all2_app_l:
1935
+ − 544
assumes a: "reflp R"
2326
+ − 545
and b: "list_all2 R l r"
+ − 546
shows "list_all2 R (z @ l) (z @ r)"
1938
+ − 547
by (induct z) (simp_all add: b rev_iffD1[OF a meta_eq_to_obj_eq[OF reflp_def]])
1935
+ − 548
+ − 549
lemma append_rsp2_pre0:
2326
+ − 550
assumes a:"list_all2 op \<approx> x x'"
+ − 551
shows "list_all2 op \<approx> (x @ z) (x' @ z)"
1935
+ − 552
using a apply (induct x x' rule: list_induct2')
2326
+ − 553
by simp_all (rule list_all2_refl1)
1935
+ − 554
+ − 555
lemma append_rsp2_pre1:
2326
+ − 556
assumes a:"list_all2 op \<approx> x x'"
+ − 557
shows "list_all2 op \<approx> (z @ x) (z @ x')"
1935
+ − 558
using a apply (induct x x' arbitrary: z rule: list_induct2')
2326
+ − 559
apply (rule list_all2_refl1)
1935
+ − 560
apply (simp_all del: list_eq.simps)
2326
+ − 561
apply (rule list_all2_app_l)
1935
+ − 562
apply (simp_all add: reflp_def)
+ − 563
done
+ − 564
+ − 565
lemma append_rsp2_pre:
2326
+ − 566
assumes a:"list_all2 op \<approx> x x'"
+ − 567
and b: "list_all2 op \<approx> z z'"
+ − 568
shows "list_all2 op \<approx> (x @ z) (x' @ z')"
+ − 569
apply (rule list_all2_transp[OF fset_equivp])
1935
+ − 570
apply (rule append_rsp2_pre0)
+ − 571
apply (rule a)
+ − 572
using b apply (induct z z' rule: list_induct2')
+ − 573
apply (simp_all only: append_Nil2)
2326
+ − 574
apply (rule list_all2_refl1)
1935
+ − 575
apply simp_all
+ − 576
apply (rule append_rsp2_pre1)
+ − 577
apply simp
+ − 578
done
+ − 579
+ − 580
lemma [quot_respect]:
2326
+ − 581
"(list_all2 op \<approx> OOO op \<approx> ===> list_all2 op \<approx> OOO op \<approx> ===> list_all2 op \<approx> OOO op \<approx>) op @ op @"
1935
+ − 582
proof (intro fun_relI, elim pred_compE)
+ − 583
fix x y z w x' z' y' w' :: "'a list list"
2326
+ − 584
assume a:"list_all2 op \<approx> x x'"
1935
+ − 585
and b: "x' \<approx> y'"
2326
+ − 586
and c: "list_all2 op \<approx> y' y"
+ − 587
assume aa: "list_all2 op \<approx> z z'"
1935
+ − 588
and bb: "z' \<approx> w'"
2326
+ − 589
and cc: "list_all2 op \<approx> w' w"
+ − 590
have a': "list_all2 op \<approx> (x @ z) (x' @ z')" using a aa append_rsp2_pre by auto
1935
+ − 591
have b': "x' @ z' \<approx> y' @ w'" using b bb by simp
2326
+ − 592
have c': "list_all2 op \<approx> (y' @ w') (y @ w)" using c cc append_rsp2_pre by auto
+ − 593
have d': "(op \<approx> OO list_all2 op \<approx>) (x' @ z') (y @ w)"
1935
+ − 594
by (rule pred_compI) (rule b', rule c')
2326
+ − 595
show "(list_all2 op \<approx> OOO op \<approx>) (x @ z) (y @ w)"
1935
+ − 596
by (rule pred_compI) (rule a', rule d')
+ − 597
qed
+ − 598
+ − 599
text {* Raw theorems. Finsert, memb, singleron, sub_list *}
1518
+ − 600
1892
+ − 601
lemma nil_not_cons:
+ − 602
shows "\<not> ([] \<approx> x # xs)"
+ − 603
and "\<not> (x # xs \<approx> [])"
+ − 604
by auto
+ − 605
1878
+ − 606
lemma no_memb_nil:
+ − 607
"(\<forall>x. \<not> memb x xs) = (xs = [])"
+ − 608
by (simp add: memb_def)
+ − 609
1518
+ − 610
lemma memb_consI1:
+ − 611
shows "memb x (x # xs)"
+ − 612
by (simp add: memb_def)
+ − 613
+ − 614
lemma memb_consI2:
+ − 615
shows "memb x xs \<Longrightarrow> memb x (y # xs)"
+ − 616
by (simp add: memb_def)
+ − 617
+ − 618
lemma singleton_list_eq:
+ − 619
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
+ − 620
by (simp)
1518
+ − 621
1892
+ − 622
lemma sub_list_cons:
+ − 623
"sub_list (x # xs) ys = (memb x ys \<and> sub_list xs ys)"
+ − 624
by (auto simp add: memb_def sub_list_def)
+ − 625
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
+ − 626
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
+ − 627
"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
+ − 628
by (induct ys arbitrary: xs x) (simp_all)
2084
+ − 629
1935
+ − 630
text {* Cardinality of finite sets *}
1518
+ − 631
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
+ − 632
(* used in memb_card_not_0 *)
1813
+ − 633
lemma fcard_raw_0:
1860
+ − 634
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
+ − 635
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
+ − 636
by (induct xs) (auto)
1819
+ − 637
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
+ − 638
(* used in list_eq2_equiv *)
1884
+ − 639
lemma memb_card_not_0:
1878
+ − 640
assumes a: "memb a A"
+ − 641
shows "\<not>(fcard_raw A = 0)"
1883
+ − 642
proof -
+ − 643
have "\<not>(\<forall>x. \<not> memb x A)" using a by auto
+ − 644
then have "\<not>A \<approx> []" using none_memb_nil[of A] by simp
+ − 645
then show ?thesis using fcard_raw_0[of A] by simp
+ − 646
qed
1878
+ − 647
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
+ − 648
693562f03eee
major reorganisation of fset (renamed fset_to_set to fset, changed the definition of list_eq and fcard_raw)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 649
693562f03eee
major reorganisation of fset (renamed fset_to_set to fset, changed the definition of list_eq and fcard_raw)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 650
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
+ − 651
693562f03eee
major reorganisation of 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
(* there is another fmap section below *)
1518
+ − 653
1813
+ − 654
lemma map_append:
1821
+ − 655
"map f (xs @ ys) \<approx> (map f xs) @ (map f ys)"
1813
+ − 656
by simp
+ − 657
1819
+ − 658
lemma memb_append:
1823
+ − 659
"memb x (xs @ ys) \<longleftrightarrow> memb x xs \<or> memb x ys"
1821
+ − 660
by (induct xs) (simp_all add: not_memb_nil memb_cons_iff)
1819
+ − 661
+ − 662
lemma fset_raw_strong_cases:
2084
+ − 663
obtains "xs = []"
+ − 664
| x ys where "\<not> memb x ys" and "xs \<approx> x # ys"
+ − 665
proof (induct xs arbitrary: x ys)
+ − 666
case Nil
+ − 667
then show thesis by simp
+ − 668
next
+ − 669
case (Cons a xs)
+ − 670
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
+ − 671
have b: "\<And>x' ys'. \<lbrakk>\<not> memb x' ys'; a # xs \<approx> x' # ys'\<rbrakk> \<Longrightarrow> thesis" by fact
+ − 672
have c: "xs = [] \<Longrightarrow> thesis" by (metis no_memb_nil singleton_list_eq b)
+ − 673
have "\<And>x ys. \<lbrakk>\<not> memb x ys; xs \<approx> x # ys\<rbrakk> \<Longrightarrow> thesis"
+ − 674
proof -
+ − 675
fix x :: 'a
+ − 676
fix ys :: "'a list"
+ − 677
assume d:"\<not> memb x ys"
+ − 678
assume e:"xs \<approx> x # ys"
+ − 679
show thesis
+ − 680
proof (cases "x = a")
+ − 681
assume h: "x = a"
+ − 682
then have f: "\<not> memb a ys" using d by simp
+ − 683
have g: "a # xs \<approx> a # ys" using e h by auto
+ − 684
show thesis using b f g by simp
+ − 685
next
+ − 686
assume h: "x \<noteq> a"
+ − 687
then have f: "\<not> memb x (a # ys)" using d unfolding memb_def by auto
+ − 688
have g: "a # xs \<approx> x # (a # ys)" using e h by auto
+ − 689
show thesis using b f g by simp
+ − 690
qed
+ − 691
qed
+ − 692
then show thesis using a c by blast
+ − 693
qed
1518
+ − 694
1860
+ − 695
section {* deletion *}
+ − 696
1518
+ − 697
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
+ − 698
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
+ − 699
"xs = [] \<or> (\<exists>x. memb x xs \<and> xs \<approx> x # removeAll x xs)"
1821
+ − 700
by (induct xs) (auto simp add: memb_def)
1518
+ − 701
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
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
+ − 703
"removeAll y xs = [x \<leftarrow> xs. x \<noteq> y]"
1819
+ − 704
by (induct xs) simp_all
1518
+ − 705
1819
+ − 706
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
+ − 707
"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
+ − 708
by (auto simp add: fcard_raw_def memb_def)
1518
+ − 709
1819
+ − 710
lemma finter_raw_empty:
+ − 711
"finter_raw l [] = []"
+ − 712
by (induct l) (simp_all add: not_memb_nil)
+ − 713
1533
+ − 714
lemma inj_map_eq_iff:
+ − 715
"inj f \<Longrightarrow> (map f l \<approx> map f m) = (l \<approx> m)"
2479
+ − 716
by (simp add: set_eq_iff[symmetric] inj_image_eq_iff)
1533
+ − 717
1888
+ − 718
text {* alternate formulation with a different decomposition principle
+ − 719
and a proof of equivalence *}
+ − 720
+ − 721
inductive
+ − 722
list_eq2
+ − 723
where
+ − 724
"list_eq2 (a # b # xs) (b # a # xs)"
+ − 725
| "list_eq2 [] []"
+ − 726
| "list_eq2 xs ys \<Longrightarrow> list_eq2 ys xs"
+ − 727
| "list_eq2 (a # a # xs) (a # xs)"
+ − 728
| "list_eq2 xs ys \<Longrightarrow> list_eq2 (a # xs) (a # ys)"
+ − 729
| "\<lbrakk>list_eq2 xs1 xs2; list_eq2 xs2 xs3\<rbrakk> \<Longrightarrow> list_eq2 xs1 xs3"
+ − 730
+ − 731
lemma list_eq2_refl:
+ − 732
shows "list_eq2 xs xs"
+ − 733
by (induct xs) (auto intro: list_eq2.intros)
+ − 734
+ − 735
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
+ − 736
shows "list_eq2 (a # (removeAll a A)) (if memb a A then A else a # A)"
1888
+ − 737
apply (induct A)
+ − 738
apply (simp add: memb_def list_eq2_refl)
+ − 739
apply (case_tac "memb a (aa # A)")
+ − 740
apply (simp_all only: memb_cons_iff)
+ − 741
apply (case_tac [!] "a = aa")
1909
+ − 742
apply (simp_all)
1888
+ − 743
apply (case_tac "memb a A")
+ − 744
apply (auto simp add: memb_def)[2]
+ − 745
apply (metis list_eq2.intros(3) list_eq2.intros(4) list_eq2.intros(5) list_eq2.intros(6))
1895
+ − 746
apply (metis list_eq2.intros(1) list_eq2.intros(5) list_eq2.intros(6))
2525
+ − 747
apply (auto simp add: list_eq2_refl memb_def)
1888
+ − 748
done
+ − 749
+ − 750
lemma memb_delete_list_eq2:
+ − 751
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
+ − 752
shows "list_eq2 (e # removeAll e r) r"
1888
+ − 753
using a cons_delete_list_eq2[of e r]
+ − 754
by simp
+ − 755
+ − 756
lemma list_eq2_equiv:
+ − 757
"(l \<approx> r) \<longleftrightarrow> (list_eq2 l r)"
+ − 758
proof
+ − 759
show "list_eq2 l r \<Longrightarrow> l \<approx> r" by (induct rule: list_eq2.induct) auto
1938
+ − 760
next
+ − 761
{
+ − 762
fix n
+ − 763
assume a: "fcard_raw l = n" and b: "l \<approx> r"
+ − 764
have "list_eq2 l r"
+ − 765
using a b
+ − 766
proof (induct n arbitrary: l r)
+ − 767
case 0
+ − 768
have "fcard_raw l = 0" by fact
+ − 769
then have "\<forall>x. \<not> memb x l" using memb_card_not_0[of _ l] by auto
+ − 770
then have z: "l = []" using no_memb_nil by auto
+ − 771
then have "r = []" using `l \<approx> r` by simp
+ − 772
then show ?case using z list_eq2_refl by simp
+ − 773
next
+ − 774
case (Suc m)
+ − 775
have b: "l \<approx> r" by fact
+ − 776
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
+ − 777
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
+ − 778
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
+ − 779
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
+ − 780
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
+ − 781
done
1938
+ − 782
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
+ − 783
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
+ − 784
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
+ − 785
have f: "fcard_raw (removeAll a l) = m" using fcard_raw_delete[of a l] e d by simp
2525
+ − 786
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
+ − 787
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
+ − 788
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
+ − 789
have i: "list_eq2 l (a # removeAll a l)"
1938
+ − 790
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
+ − 791
have "list_eq2 l (a # removeAll a r)" by (rule list_eq2.intros(6)[OF i h])
1938
+ − 792
then show ?case using list_eq2.intros(6)[OF _ memb_delete_list_eq2[OF e']] by simp
+ − 793
qed
+ − 794
}
+ − 795
then show "l \<approx> r \<Longrightarrow> list_eq2 l r" by blast
1888
+ − 796
qed
+ − 797
1935
+ − 798
text {* Lifted theorems *}
1518
+ − 799
1819
+ − 800
lemma not_fin_fnil: "x |\<notin>| {||}"
2529
+ − 801
by (descending) (simp add: memb_def)
1518
+ − 802
+ − 803
lemma fin_finsert_iff[simp]:
2528
+ − 804
"x |\<in>| finsert y S \<longleftrightarrow> x = y \<or> x |\<in>| S"
+ − 805
by (descending) (simp add: memb_def)
1518
+ − 806
+ − 807
lemma
+ − 808
shows finsertI1: "x |\<in>| finsert x S"
+ − 809
and finsertI2: "x |\<in>| S \<Longrightarrow> x |\<in>| finsert y S"
2528
+ − 810
by (lifting memb_consI1 memb_consI2)
1518
+ − 811
+ − 812
lemma finsert_absorb[simp]:
+ − 813
shows "x |\<in>| S \<Longrightarrow> finsert x S = S"
2528
+ − 814
by (descending) (auto simp add: memb_def)
1518
+ − 815
+ − 816
lemma fempty_not_finsert[simp]:
1533
+ − 817
"{||} \<noteq> finsert x S"
+ − 818
"finsert x S \<noteq> {||}"
1518
+ − 819
by (lifting nil_not_cons)
+ − 820
+ − 821
lemma finsert_left_comm:
1822
+ − 822
"finsert x (finsert y S) = finsert y (finsert x S)"
2528
+ − 823
by (descending) (auto)
1518
+ − 824
+ − 825
lemma finsert_left_idem:
1822
+ − 826
"finsert x (finsert x S) = finsert x S"
2528
+ − 827
by (descending) (auto)
1518
+ − 828
+ − 829
lemma fsingleton_eq[simp]:
+ − 830
shows "{|x|} = {|y|} \<longleftrightarrow> x = y"
2528
+ − 831
by (descending) (auto)
1518
+ − 832
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
+ − 833
693562f03eee
major reorganisation of 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
text {* fset *}
1518
+ − 835
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
+ − 836
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
+ − 837
"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
+ − 838
"fset (finsert (h :: 'a) t) = insert h (fset t)"
1819
+ − 839
by (lifting set.simps)
1518
+ − 840
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
+ − 841
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
+ − 842
"x \<in> fset S \<equiv> x |\<in>| S"
1518
+ − 843
by (lifting memb_def[symmetric])
+ − 844
1819
+ − 845
lemma none_fin_fempty:
1824
+ − 846
"(\<forall>x. x |\<notin>| S) = (S = {||})"
+ − 847
by (lifting none_memb_nil)
1518
+ − 848
1533
+ − 849
lemma fset_cong:
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
+ − 850
"(S = T) = (fset S = fset 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
+ − 851
by (lifting list_eq.simps)
1533
+ − 852
1518
+ − 853
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
+ − 854
section {* fcard *}
1518
+ − 855
+ − 856
lemma fcard_finsert_if [simp]:
+ − 857
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
+ − 858
by (descending) (auto simp add: fcard_raw_def memb_def insert_absorb)
1518
+ − 859
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
+ − 860
lemma fcard_0[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
+ − 861
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
+ − 862
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
+ − 863
693562f03eee
major reorganisation of fset (renamed fset_to_set to fset, changed the definition of list_eq and fcard_raw)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 864
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
+ − 865
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
+ − 866
by (simp add: fcard_0)
1813
+ − 867
1821
+ − 868
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
+ − 869
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
+ − 870
by (descending) (auto simp add: fcard_raw_def card_Suc_eq)
1819
+ − 871
2084
+ − 872
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
+ − 873
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
+ − 874
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
+ − 875
2084
+ − 876
lemma fcard_not_fin:
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
+ − 877
assumes a: "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
+ − 878
shows "fcard (finsert x S) = Suc (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
+ − 879
using 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
+ − 880
by (descending) (simp add: memb_def fcard_raw_def)
1813
+ − 881
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
+ − 882
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
+ − 883
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
+ − 884
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
+ − 885
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
+ − 886
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
+ − 887
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
+ − 888
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
+ − 889
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
+ − 890
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
+ − 891
done
1813
+ − 892
1819
+ − 893
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
+ − 894
"fcard (fdelete y S) = (if y |\<in>| S then fcard S - 1 else fcard S)"
1819
+ − 895
by (lifting fcard_raw_delete)
+ − 896
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
+ − 897
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
+ − 898
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
+ − 899
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
+ − 900
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
+ − 901
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
+ − 902
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
+ − 903
done
1878
+ − 904
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
+ − 905
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
+ − 906
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
+ − 907
by (descending) (auto simp add: fcard_raw_def memb_def)
1878
+ − 908
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
+ − 909
693562f03eee
major reorganisation of fset (renamed fset_to_set to fset, changed the definition of list_eq and fcard_raw)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 910
section {* funion *}
1518
+ − 911
2084
+ − 912
lemmas [simp] =
+ − 913
sup_bot_left[where 'a="'a fset", standard]
+ − 914
sup_bot_right[where 'a="'a fset", standard]
1518
+ − 915
2084
+ − 916
lemma funion_finsert[simp]:
+ − 917
shows "finsert x S |\<union>| T = finsert x (S |\<union>| T)"
+ − 918
by (lifting append.simps(2))
1887
+ − 919
+ − 920
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
+ − 921
shows "{|a|} |\<union>| S = finsert a S"
1887
+ − 922
by simp
+ − 923
+ − 924
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
+ − 925
shows "S |\<union>| {|a|} = finsert a S"
1907
+ − 926
by (subst sup.commute) simp
1887
+ − 927
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
+ − 928
693562f03eee
major reorganisation of fset (renamed fset_to_set to fset, changed the definition of list_eq and fcard_raw)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 929
section {* Induction and Cases rules for fsets *}
1518
+ − 930
+ − 931
lemma fset_strong_cases:
2084
+ − 932
obtains "xs = {||}"
+ − 933
| x ys where "x |\<notin>| ys" and "xs = finsert x ys"
1819
+ − 934
by (lifting fset_raw_strong_cases)
1518
+ − 935
+ − 936
lemma fset_exhaust[case_names fempty finsert, cases type: fset]:
+ − 937
shows "\<lbrakk>S = {||} \<Longrightarrow> P; \<And>x S'. S = finsert x S' \<Longrightarrow> P\<rbrakk> \<Longrightarrow> P"
+ − 938
by (lifting list.exhaust)
+ − 939
1533
+ − 940
lemma fset_induct_weak[case_names fempty finsert]:
1518
+ − 941
shows "\<lbrakk>P {||}; \<And>x S. P S \<Longrightarrow> P (finsert x S)\<rbrakk> \<Longrightarrow> P S"
+ − 942
by (lifting list.induct)
+ − 943
1533
+ − 944
lemma fset_induct[case_names fempty finsert, induct type: fset]:
2084
+ − 945
assumes prem1: "P {||}"
1518
+ − 946
and prem2: "\<And>x S. \<lbrakk>x |\<notin>| S; P S\<rbrakk> \<Longrightarrow> P (finsert x S)"
+ − 947
shows "P S"
1533
+ − 948
proof(induct S rule: fset_induct_weak)
1518
+ − 949
case fempty
+ − 950
show "P {||}" by (rule prem1)
+ − 951
next
+ − 952
case (finsert x S)
+ − 953
have asm: "P S" by fact
+ − 954
show "P (finsert x S)"
1938
+ − 955
by (cases "x |\<in>| S") (simp_all add: asm prem2)
1518
+ − 956
qed
+ − 957
1533
+ − 958
lemma fset_induct2:
+ − 959
"P {||} {||} \<Longrightarrow>
+ − 960
(\<And>x xs. x |\<notin>| xs \<Longrightarrow> P (finsert x xs) {||}) \<Longrightarrow>
+ − 961
(\<And>y ys. y |\<notin>| ys \<Longrightarrow> P {||} (finsert y ys)) \<Longrightarrow>
+ − 962
(\<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>
+ − 963
P xsa ysa"
+ − 964
apply (induct xsa arbitrary: ysa)
+ − 965
apply (induct_tac x rule: fset_induct)
+ − 966
apply simp_all
+ − 967
apply (induct_tac xa rule: fset_induct)
+ − 968
apply simp_all
+ − 969
done
1518
+ − 970
2084
+ − 971
lemma fset_fcard_induct:
+ − 972
assumes a: "P {||}"
+ − 973
and b: "\<And>xs ys. Suc (fcard xs) = (fcard ys) \<Longrightarrow> P xs \<Longrightarrow> P ys"
+ − 974
shows "P zs"
+ − 975
proof (induct zs)
+ − 976
show "P {||}" by (rule a)
+ − 977
next
+ − 978
fix x :: 'a and zs :: "'a fset"
+ − 979
assume h: "P zs"
+ − 980
assume "x |\<notin>| zs"
+ − 981
then have H1: "Suc (fcard zs) = fcard (finsert x zs)" using fcard_suc by auto
+ − 982
then show "P (finsert x zs)" using b h by simp
+ − 983
qed
+ − 984
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
+ − 985
693562f03eee
major reorganisation of 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
section {* fmap *}
1819
+ − 987
1533
+ − 988
lemma fmap_simps[simp]:
2528
+ − 989
fixes f::"'a \<Rightarrow> 'b"
+ − 990
shows "fmap f {||} = {||}"
+ − 991
and "fmap f (finsert x S) = finsert (f x) (fmap f S)"
1533
+ − 992
by (lifting map.simps)
+ − 993
+ − 994
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
+ − 995
"fset (fmap f S) = f ` (fset S)"
2084
+ − 996
by (induct S) simp_all
1533
+ − 997
+ − 998
lemma inj_fmap_eq_iff:
2529
+ − 999
"inj f \<Longrightarrow> fmap f S = fmap f T \<longleftrightarrow> S = T"
1533
+ − 1000
by (lifting inj_map_eq_iff)
+ − 1001
2528
+ − 1002
lemma fmap_funion:
+ − 1003
shows "fmap f (S |\<union>| T) = fmap f S |\<union>| fmap f T"
1813
+ − 1004
by (lifting map_append)
+ − 1005
1819
+ − 1006
lemma fin_funion:
2528
+ − 1007
shows "x |\<in>| S |\<union>| T \<longleftrightarrow> x |\<in>| S \<or> x |\<in>| T"
1819
+ − 1008
by (lifting memb_append)
+ − 1009
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
+ − 1010
693562f03eee
major reorganisation of fset (renamed fset_to_set to fset, changed the definition of list_eq and fcard_raw)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 1011
section {* fset *}
2084
+ − 1012
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
+ − 1013
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
+ − 1014
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
+ − 1015
by (lifting memb_def)
2084
+ − 1016
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
+ − 1017
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
+ − 1018
shows "x |\<notin>| xs \<longleftrightarrow> x \<notin> fset xs"
2084
+ − 1019
by (simp add: fin_set)
+ − 1020
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
+ − 1021
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
+ − 1022
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
+ − 1023
by (lifting fcard_raw_def)
2084
+ − 1024
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
+ − 1025
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
+ − 1026
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
+ − 1027
by (lifting sub_list_def)
2084
+ − 1028
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
+ − 1029
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
+ − 1030
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
+ − 1031
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
+ − 1032
by (descending) (auto simp add: sub_list_def)
2084
+ − 1033
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
+ − 1034
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
+ − 1035
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
+ − 1036
by (descending) (auto simp add: mem_def)
2084
+ − 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
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
+ − 1039
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
+ − 1040
by (lifting set_removeAll)
2084
+ − 1041
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
+ − 1042
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
+ − 1043
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
+ − 1044
by (lifting set_finter_raw)
2084
+ − 1045
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
+ − 1046
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
+ − 1047
shows "fset (xs |\<union>| ys) = fset xs \<union> fset ys"
2084
+ − 1048
by (lifting set_append)
+ − 1049
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
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
+ − 1051
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
+ − 1052
by (lifting set_fminus_raw)
2084
+ − 1053
+ − 1054
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
+ − 1055
693562f03eee
major reorganisation of fset (renamed fset_to_set to fset, changed the definition of list_eq and fcard_raw)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 1056
section {* ffold *}
1819
+ − 1057
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
+ − 1058
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
+ − 1059
shows "ffold f z {||} = z"
1819
+ − 1060
by (lifting ffold_raw.simps(1)[where 'a="'b" and 'b="'a"])
+ − 1061
+ − 1062
lemma ffold_finsert: "ffold f z (finsert a A) =
+ − 1063
(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
+ − 1064
by (descending) (simp add: memb_def)
1819
+ − 1065
+ − 1066
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
+ − 1067
"\<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
+ − 1068
by (descending) (simp add: memb_def memb_commute_ffold_raw)
1819
+ − 1069
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
+ − 1070
693562f03eee
major reorganisation of 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
693562f03eee
major reorganisation of fset (renamed fset_to_set to fset, changed the definition of list_eq and fcard_raw)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 1072
section {* fdelete *}
1819
+ − 1073
2084
+ − 1074
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
+ − 1075
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
+ − 1076
by (descending) (simp add: memb_def)
1819
+ − 1077
2525
+ − 1078
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
+ − 1079
shows "x |\<notin>| fdelete x S"
2525
+ − 1080
by (descending) (simp add: memb_def)
1819
+ − 1081
2525
+ − 1082
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
+ − 1083
shows "x |\<notin>| S \<Longrightarrow> fdelete x S = S"
2525
+ − 1084
by (descending) (simp add: memb_def)
1819
+ − 1085
+ − 1086
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
+ − 1087
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
+ − 1088
by (lifting fset_raw_removeAll_cases)
1819
+ − 1089
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
+ − 1090
693562f03eee
major reorganisation of fset (renamed fset_to_set to fset, changed the definition of list_eq and fcard_raw)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 1091
section {* finter *}
1819
+ − 1092
1822
+ − 1093
lemma finter_empty_l: "({||} |\<inter>| S) = {||}"
1819
+ − 1094
by (lifting finter_raw.simps(1))
+ − 1095
1822
+ − 1096
lemma finter_empty_r: "(S |\<inter>| {||}) = {||}"
1819
+ − 1097
by (lifting finter_raw_empty)
+ − 1098
+ − 1099
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
+ − 1100
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
+ − 1101
by (descending) (simp add: memb_def)
1819
+ − 1102
+ − 1103
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
+ − 1104
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
+ − 1105
by (descending) (simp add: memb_def)
1819
+ − 1106
1893
+ − 1107
lemma fsubset_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
+ − 1108
shows "(finsert x xs |\<subseteq>| ys) = (x |\<in>| ys \<and> xs |\<subseteq>| ys)"
1893
+ − 1109
by (lifting sub_list_cons)
+ − 1110
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
+ − 1111
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
+ − 1112
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
+ − 1113
by (descending) (auto simp add: sub_list_def memb_def)
1893
+ − 1114
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
+ − 1115
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
+ − 1116
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
+ − 1117
by (descending) (auto simp add: sub_list_def memb_def)
1893
+ − 1118
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
+ − 1119
lemma fminus_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
+ − 1120
shows "(x |\<in>| xs - ys) = (x |\<in>| xs \<and> x |\<notin>| 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
+ − 1121
by (descending) (simp add: memb_def)
2084
+ − 1122
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
+ − 1123
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
+ − 1124
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
+ − 1125
by (descending) (auto simp add: memb_def)
2084
+ − 1126
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
+ − 1127
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
+ − 1128
shows "x |\<in>| ys \<Longrightarrow> finsert x xs - ys = xs - ys"
2084
+ − 1129
by (simp add: fminus_red)
+ − 1130
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
+ − 1131
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
+ − 1132
shows "x |\<notin>| ys \<Longrightarrow> finsert x xs - ys = finsert x (xs - ys)"
2084
+ − 1133
by (simp add: fminus_red)
+ − 1134
2479
+ − 1135
lemma fset_eq_iff:
2528
+ − 1136
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
+ − 1137
by (descending) (auto simp add: memb_def)
1820
+ − 1138
1888
+ − 1139
(* We cannot write it as "assumes .. shows" since Isabelle changes
+ − 1140
the quantifiers to schematic variables and reintroduces them in
+ − 1141
a different order *)
+ − 1142
lemma fset_eq_cases:
+ − 1143
"\<lbrakk>a1 = a2;
+ − 1144
\<And>a b xs. \<lbrakk>a1 = finsert a (finsert b xs); a2 = finsert b (finsert a xs)\<rbrakk> \<Longrightarrow> P;
+ − 1145
\<lbrakk>a1 = {||}; a2 = {||}\<rbrakk> \<Longrightarrow> P; \<And>xs ys. \<lbrakk>a1 = ys; a2 = xs; xs = ys\<rbrakk> \<Longrightarrow> P;
+ − 1146
\<And>a xs. \<lbrakk>a1 = finsert a (finsert a xs); a2 = finsert a xs\<rbrakk> \<Longrightarrow> P;
+ − 1147
\<And>xs ys a. \<lbrakk>a1 = finsert a xs; a2 = finsert a ys; xs = ys\<rbrakk> \<Longrightarrow> P;
+ − 1148
\<And>xs1 xs2 xs3. \<lbrakk>a1 = xs1; a2 = xs3; xs1 = xs2; xs2 = xs3\<rbrakk> \<Longrightarrow> P\<rbrakk>
+ − 1149
\<Longrightarrow> P"
+ − 1150
by (lifting list_eq2.cases[simplified list_eq2_equiv[symmetric]])
+ − 1151
+ − 1152
lemma fset_eq_induct:
+ − 1153
assumes "x1 = x2"
+ − 1154
and "\<And>a b xs. P (finsert a (finsert b xs)) (finsert b (finsert a xs))"
+ − 1155
and "P {||} {||}"
+ − 1156
and "\<And>xs ys. \<lbrakk>xs = ys; P xs ys\<rbrakk> \<Longrightarrow> P ys xs"
+ − 1157
and "\<And>a xs. P (finsert a (finsert a xs)) (finsert a xs)"
+ − 1158
and "\<And>xs ys a. \<lbrakk>xs = ys; P xs ys\<rbrakk> \<Longrightarrow> P (finsert a xs) (finsert a ys)"
+ − 1159
and "\<And>xs1 xs2 xs3. \<lbrakk>xs1 = xs2; P xs1 xs2; xs2 = xs3; P xs2 xs3\<rbrakk> \<Longrightarrow> P xs1 xs3"
+ − 1160
shows "P x1 x2"
+ − 1161
using assms
+ − 1162
by (lifting list_eq2.induct[simplified list_eq2_equiv[symmetric]])
1820
+ − 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
693562f03eee
major reorganisation of 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
section {* fconcat *}
1935
+ − 1166
+ − 1167
lemma fconcat_empty:
+ − 1168
shows "fconcat {||} = {||}"
+ − 1169
by (lifting concat.simps(1))
+ − 1170
+ − 1171
lemma fconcat_insert:
+ − 1172
shows "fconcat (finsert x S) = x |\<union>| fconcat S"
+ − 1173
by (lifting concat.simps(2))
+ − 1174
2528
+ − 1175
lemma
+ − 1176
shows "fconcat (xs |\<union>| ys) = fconcat xs |\<union>| fconcat ys"
+ − 1177
by (lifting concat_append)
+ − 1178
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
+ − 1179
693562f03eee
major reorganisation of 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
section {* ffilter *}
2084
+ − 1181
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
+ − 1182
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
+ − 1183
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
+ − 1184
by (descending) (auto simp add: memb_def sub_list_def)
2084
+ − 1185
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
+ − 1186
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
+ − 1187
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
+ − 1188
by (descending) (auto simp add: memb_def)
2529
+ − 1189
+ − 1190
lemma subset_ffilter:
+ − 1191
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"
+ − 1192
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
+ − 1193
2084
+ − 1194
+ − 1195
section {* lemmas transferred from Finite_Set theory *}
+ − 1196
+ − 1197
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
+ − 1198
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
+ − 1199
shows "finite (fset S)"
2084
+ − 1200
by (induct S) auto
+ − 1201
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
+ − 1202
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
+ − 1203
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
+ − 1204
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
+ − 1205
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
+ − 1206
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
+ − 1207
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
+ − 1208
done
2084
+ − 1209
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
+ − 1210
lemma fsubseteq_fempty:
693562f03eee
major reorganisation of 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
shows "xs |\<subseteq>| {||} = (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
+ − 1212
by (metis finter_empty_r le_iff_inf)
2084
+ − 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 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
+ − 1215
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
+ − 1216
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
+ − 1217
693562f03eee
major reorganisation of fset (renamed fset_to_set to fset, changed the definition of list_eq and fcard_raw)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 1218
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
+ − 1219
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
+ − 1220
unfolding fcard_set fsubseteq_set
2084
+ − 1221
by (rule card_mono[OF finite_fset])
+ − 1222
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
+ − 1223
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
+ − 1224
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
+ − 1225
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
+ − 1226
by (simp add: card_seteq[OF finite_fset] fset_cong)
2084
+ − 1227
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
+ − 1228
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
+ − 1229
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
+ − 1230
unfolding fcard_set fsubset_set
2084
+ − 1231
by (rule psubset_card_mono[OF finite_fset])
+ − 1232
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
+ − 1233
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
+ − 1234
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
+ − 1235
unfolding fcard_set funion_set finter_set
2084
+ − 1236
by (rule card_Un_Int[OF finite_fset finite_fset])
+ − 1237
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
+ − 1238
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
+ − 1239
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
+ − 1240
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
+ − 1241
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
+ − 1242
by (metis finter_set fset_simps(1))
2084
+ − 1243
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
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
+ − 1245
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
+ − 1246
unfolding fcard_set fin_set fdelete_set
2084
+ − 1247
by (rule card_Diff1_less[OF finite_fset])
+ − 1248
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
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
+ − 1250
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
+ − 1251
unfolding fcard_set fdelete_set fin_set
2084
+ − 1252
by (rule card_Diff2_less[OF finite_fset])
+ − 1253
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
+ − 1254
lemma fcard_delete1_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
+ − 1255
shows "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
+ − 1256
unfolding fdelete_set fcard_set
2084
+ − 1257
by (rule card_Diff1_le[OF finite_fset])
+ − 1258
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
+ − 1259
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
+ − 1260
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
+ − 1261
unfolding fcard_set fsubseteq_set fsubset_set
2084
+ − 1262
by (rule card_psubset[OF finite_fset])
+ − 1263
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
+ − 1264
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
+ − 1265
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
+ − 1266
unfolding fcard_set fmap_set_image
2084
+ − 1267
by (rule card_image_le[OF finite_fset])
+ − 1268
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
+ − 1269
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
+ − 1270
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
+ − 1271
unfolding fin_set fminus_set
2084
+ − 1272
by blast
+ − 1273
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
+ − 1274
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
+ − 1275
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
+ − 1276
unfolding fin_set fminus_set
2084
+ − 1277
by blast
+ − 1278
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
+ − 1279
lemma fin_mdef:
693562f03eee
major reorganisation of fset (renamed fset_to_set to fset, changed the definition of list_eq and fcard_raw)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 1280
shows "x |\<in>| F = ((x |\<notin>| (F - {|x|})) & (F = finsert 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
+ − 1281
unfolding fin_set fset_simps fset_cong fminus_set
2084
+ − 1282
by blast
+ − 1283
+ − 1284
lemma fcard_fminus_finsert[simp]:
+ − 1285
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
+ − 1286
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
+ − 1287
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
+ − 1288
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
+ − 1289
by (simp add: card_Diff_insert[OF finite_fset])
2084
+ − 1290
+ − 1291
lemma fcard_fminus_fsubset:
+ − 1292
assumes "B |\<subseteq>| A"
+ − 1293
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
+ − 1294
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
+ − 1295
unfolding fsubseteq_set fcard_set fminus_set
2084
+ − 1296
by (rule card_Diff_subset[OF finite_fset])
+ − 1297
+ − 1298
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
+ − 1299
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
+ − 1300
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
+ − 1301
by (rule card_Diff_subset_Int) (simp)
2084
+ − 1302
2234
+ − 1303
2326
+ − 1304
lemma list_all2_refl:
2266
dcffc2f132c9
Qpaper / Clarify the typing system and composition of quotients issue.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 1305
assumes q: "equivp R"
2326
+ − 1306
shows "(list_all2 R) r r"
2378
+ − 1307
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
+ − 1308
dcffc2f132c9
Qpaper / Clarify the typing system and composition of quotients issue.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 1309
lemma compose_list_refl2:
dcffc2f132c9
Qpaper / Clarify the typing system and composition of quotients issue.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 1310
assumes q: "equivp R"
2326
+ − 1311
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
+ − 1312
proof
dcffc2f132c9
Qpaper / Clarify the typing system and composition of quotients issue.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 1313
have *: "r \<approx> r" by (rule equivp_reflp[OF fset_equivp])
2326
+ − 1314
show "list_all2 R r r" by (rule list_all2_refl[OF q])
+ − 1315
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
+ − 1316
qed
dcffc2f132c9
Qpaper / Clarify the typing system and composition of quotients issue.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 1317
2285
+ − 1318
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
+ − 1319
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
+ − 1320
and e: "equivp R"
2326
+ − 1321
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
+ − 1322
(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
+ − 1323
unfolding Quotient_def comp_def
dcffc2f132c9
Qpaper / Clarify the typing system and composition of quotients issue.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 1324
proof (intro conjI allI)
dcffc2f132c9
Qpaper / Clarify the typing system and composition of quotients issue.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 1325
fix a r s
dcffc2f132c9
Qpaper / Clarify the typing system and composition of quotients issue.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 1326
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
+ − 1327
by (simp add: abs_o_rep[OF q] Quotient_abs_rep[OF Quotient_fset] map_id)
2326
+ − 1328
have b: "list_all2 R (map Rep (rep_fset a)) (map Rep (rep_fset a))"
+ − 1329
by (rule list_all2_refl[OF e])
+ − 1330
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
+ − 1331
by (rule, rule equivp_reflp[OF fset_equivp]) (rule b)
2326
+ − 1332
show "(list_all2 R OOO op \<approx>) (map Rep (rep_fset a)) (map Rep (rep_fset a))"
+ − 1333
by (rule, rule list_all2_refl[OF e]) (rule c)
+ − 1334
show "(list_all2 R OOO op \<approx>) r s = ((list_all2 R OOO op \<approx>) r r \<and>
+ − 1335
(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
+ − 1336
proof (intro iffI conjI)
2326
+ − 1337
show "(list_all2 R OOO op \<approx>) r r" by (rule compose_list_refl2[OF e])
+ − 1338
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
+ − 1339
next
2326
+ − 1340
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
+ − 1341
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
+ − 1342
proof (elim pred_compE)
dcffc2f132c9
Qpaper / Clarify the typing system and composition of quotients issue.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 1343
fix b ba
2326
+ − 1344
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
+ − 1345
assume d: "b \<approx> ba"
2326
+ − 1346
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
+ − 1347
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
+ − 1348
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
+ − 1349
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
+ − 1350
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
+ − 1351
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
+ − 1352
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
+ − 1353
qed
dcffc2f132c9
Qpaper / Clarify the typing system and composition of quotients issue.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 1354
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
+ − 1355
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
+ − 1356
next
2326
+ − 1357
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
+ − 1358
\<and> abs_fset (map Abs r) = abs_fset (map Abs s)"
2326
+ − 1359
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
+ − 1360
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
+ − 1361
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
+ − 1362
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
+ − 1363
by (rule map_rel_cong[OF d])
2326
+ − 1364
have y: "list_all2 R (map Rep (map Abs s)) s"
+ − 1365
by (fact rep_abs_rsp_left[OF list_quotient[OF q], OF list_all2_refl[OF e, of s]])
+ − 1366
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
+ − 1367
by (rule pred_compI) (rule b, rule y)
2326
+ − 1368
have z: "list_all2 R r (map Rep (map Abs r))"
+ − 1369
by (fact rep_abs_rsp[OF list_quotient[OF q], OF list_all2_refl[OF e, of r]])
+ − 1370
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
+ − 1371
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
+ − 1372
qed
dcffc2f132c9
Qpaper / Clarify the typing system and composition of quotients issue.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 1373
qed
dcffc2f132c9
Qpaper / Clarify the typing system and composition of quotients issue.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 1374
2528
+ − 1375
+ − 1376
ML {*
+ − 1377
fun dest_fsetT (Type (@{type_name fset}, [T])) = T
+ − 1378
| dest_fsetT T = raise TYPE ("dest_fsetT: fset type expected", [T], []);
+ − 1379
*}
+ − 1380
2266
dcffc2f132c9
Qpaper / Clarify the typing system and composition of quotients issue.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 1381
no_notation
dcffc2f132c9
Qpaper / Clarify the typing system and composition of quotients issue.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 1382
list_eq (infix "\<approx>" 50)
dcffc2f132c9
Qpaper / Clarify the typing system and composition of quotients issue.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 1383
2234
+ − 1384
end