equal
deleted
inserted
replaced
493 then have "add_mset b A = add_mset b (add_mset c A) - {#c#}" |
493 then have "add_mset b A = add_mset b (add_mset c A) - {#c#}" |
494 by (simp add: \<open>b \<noteq> c\<close>) |
494 by (simp add: \<open>b \<noteq> c\<close>) |
495 then show ?thesis using B by simp |
495 then show ?thesis using B by simp |
496 qed |
496 qed |
497 |
497 |
|
498 lemma add_mset_eq_singleton_iff[iff]: |
|
499 "add_mset x M = {#y#} \<longleftrightarrow> M = {#} \<and> x = y" |
|
500 by auto |
|
501 |
498 |
502 |
499 subsubsection \<open>Pointwise ordering induced by count\<close> |
503 subsubsection \<open>Pointwise ordering induced by count\<close> |
500 |
504 |
501 definition subseteq_mset :: "'a multiset \<Rightarrow> 'a multiset \<Rightarrow> bool" (infix "\<subseteq>#" 50) |
505 definition subseteq_mset :: "'a multiset \<Rightarrow> 'a multiset \<Rightarrow> bool" (infix "\<subseteq>#" 50) |
502 where "A \<subseteq># B = (\<forall>a. count A a \<le> count B a)" |
506 where "A \<subseteq># B = (\<forall>a. count A a \<le> count B a)" |
656 lemma mset_subset_diff_self: "c \<in># B \<Longrightarrow> B - {#c#} \<subset># B" |
660 lemma mset_subset_diff_self: "c \<in># B \<Longrightarrow> B - {#c#} \<subset># B" |
657 by (auto simp: subset_mset_def elim: mset_add) |
661 by (auto simp: subset_mset_def elim: mset_add) |
658 |
662 |
659 lemma Diff_eq_empty_iff_mset: "A - B = {#} \<longleftrightarrow> A \<subseteq># B" |
663 lemma Diff_eq_empty_iff_mset: "A - B = {#} \<longleftrightarrow> A \<subseteq># B" |
660 by (auto simp: multiset_eq_iff subseteq_mset_def) |
664 by (auto simp: multiset_eq_iff subseteq_mset_def) |
|
665 |
|
666 lemma add_mset_subseteq_single_iff[iff]: "add_mset a M \<subseteq># {#b#} \<longleftrightarrow> M = {#} \<and> a = b" |
|
667 proof |
|
668 assume A: "add_mset a M \<subseteq># {#b#}" |
|
669 then have \<open>a = b\<close> |
|
670 by (auto dest: mset_subset_eq_insertD) |
|
671 then show "M={#} \<and> a=b" |
|
672 using A by (simp add: mset_subset_eq_add_mset_cancel) |
|
673 qed simp |
661 |
674 |
662 |
675 |
663 subsubsection \<open>Intersection and bounded union\<close> |
676 subsubsection \<open>Intersection and bounded union\<close> |
664 |
677 |
665 definition inf_subset_mset :: "'a multiset \<Rightarrow> 'a multiset \<Rightarrow> 'a multiset" (infixl "\<inter>#" 70) where |
678 definition inf_subset_mset :: "'a multiset \<Rightarrow> 'a multiset \<Rightarrow> 'a multiset" (infixl "\<inter>#" 70) where |
1315 qed |
1328 qed |
1316 |
1329 |
1317 lemma filter_filter_mset: "filter_mset P (filter_mset Q M) = {#x \<in># M. Q x \<and> P x#}" |
1330 lemma filter_filter_mset: "filter_mset P (filter_mset Q M) = {#x \<in># M. Q x \<and> P x#}" |
1318 by (auto simp: multiset_eq_iff) |
1331 by (auto simp: multiset_eq_iff) |
1319 |
1332 |
|
1333 lemma |
|
1334 filter_mset_True[simp]: "{#y \<in># M. True#} = M" and |
|
1335 filter_mset_False[simp]: "{#y \<in># M. False#} = {#}" |
|
1336 by (auto simp: multiset_eq_iff) |
|
1337 |
1320 |
1338 |
1321 subsubsection \<open>Size\<close> |
1339 subsubsection \<open>Size\<close> |
1322 |
1340 |
1323 definition wcount where "wcount f M = (\<lambda>x. count M x * Suc (f x))" |
1341 definition wcount where "wcount f M = (\<lambda>x. count M x * Suc (f x))" |
1324 |
1342 |
2171 by (induction M) auto |
2189 by (induction M) auto |
2172 |
2190 |
2173 lemma sum_mset_0_iff [simp]: |
2191 lemma sum_mset_0_iff [simp]: |
2174 "sum_mset M = (0::'a::canonically_ordered_monoid_add) |
2192 "sum_mset M = (0::'a::canonically_ordered_monoid_add) |
2175 \<longleftrightarrow> (\<forall>x \<in> set_mset M. x = 0)" |
2193 \<longleftrightarrow> (\<forall>x \<in> set_mset M. x = 0)" |
2176 by(induction M) (auto simp: add_eq_0_iff_both_eq_0) |
2194 by(induction M) auto |
2177 |
2195 |
2178 lemma sum_mset_diff: |
2196 lemma sum_mset_diff: |
2179 fixes M N :: "('a :: ordered_cancel_comm_monoid_diff) multiset" |
2197 fixes M N :: "('a :: ordered_cancel_comm_monoid_diff) multiset" |
2180 shows "N \<subseteq># M \<Longrightarrow> sum_mset (M - N) = sum_mset M - sum_mset N" |
2198 shows "N \<subseteq># M \<Longrightarrow> sum_mset (M - N) = sum_mset M - sum_mset N" |
2181 by (metis add_diff_cancel_right' sum_mset.union subset_mset.diff_add) |
2199 by (metis add_diff_cancel_right' sum_mset.union subset_mset.diff_add) |
2191 qed |
2209 qed |
2192 |
2210 |
2193 lemma size_mset_set [simp]: "size (mset_set A) = card A" |
2211 lemma size_mset_set [simp]: "size (mset_set A) = card A" |
2194 by (simp only: size_eq_sum_mset card_eq_sum sum_unfold_sum_mset) |
2212 by (simp only: size_eq_sum_mset card_eq_sum sum_unfold_sum_mset) |
2195 |
2213 |
|
2214 lemma sum_mset_sum_list: "sum_mset (mset xs) = sum_list xs" |
|
2215 by (induction xs) auto |
|
2216 |
2196 syntax (ASCII) |
2217 syntax (ASCII) |
2197 "_sum_mset_image" :: "pttrn \<Rightarrow> 'b set \<Rightarrow> 'a \<Rightarrow> 'a::comm_monoid_add" ("(3SUM _:#_. _)" [0, 51, 10] 10) |
2218 "_sum_mset_image" :: "pttrn \<Rightarrow> 'b set \<Rightarrow> 'a \<Rightarrow> 'a::comm_monoid_add" ("(3SUM _:#_. _)" [0, 51, 10] 10) |
2198 syntax |
2219 syntax |
2199 "_sum_mset_image" :: "pttrn \<Rightarrow> 'b set \<Rightarrow> 'a \<Rightarrow> 'a::comm_monoid_add" ("(3\<Sum>_\<in>#_. _)" [0, 51, 10] 10) |
2220 "_sum_mset_image" :: "pttrn \<Rightarrow> 'b set \<Rightarrow> 'a \<Rightarrow> 'a::comm_monoid_add" ("(3\<Sum>_\<in>#_. _)" [0, 51, 10] 10) |
2200 translations |
2221 translations |
2339 proof - |
2360 proof - |
2340 from assms have "image_mset normalize A = A" |
2361 from assms have "image_mset normalize A = A" |
2341 by (induct A) simp_all |
2362 by (induct A) simp_all |
2342 then show ?thesis by (simp add: normalize_prod_mset) |
2363 then show ?thesis by (simp add: normalize_prod_mset) |
2343 qed |
2364 qed |
|
2365 |
|
2366 lemma prod_mset_prod_list: "prod_mset (mset xs) = prod_list xs" |
|
2367 by (induct xs) auto |
2344 |
2368 |
2345 |
2369 |
2346 subsection \<open>Alternative representations\<close> |
2370 subsection \<open>Alternative representations\<close> |
2347 |
2371 |
2348 subsubsection \<open>Lists\<close> |
2372 subsubsection \<open>Lists\<close> |