# HG changeset patch # User Manuel Eberl # Date 1467363414 -7200 # Node ID 65a9eb946ff2e854178becdad46b37aa481904a8 # Parent 99b51ba8da1c000aba5042e87f016f04860ecf51 Tuned multiset lattice diff -r 99b51ba8da1c -r 65a9eb946ff2 src/HOL/Library/Multiset.thy --- a/src/HOL/Library/Multiset.thy Fri Jul 01 08:35:15 2016 +0200 +++ b/src/HOL/Library/Multiset.thy Fri Jul 01 10:56:54 2016 +0200 @@ -815,40 +815,20 @@ instantiation multiset :: (type) Sup begin -lift_definition Sup_multiset :: "'a multiset set \ 'a multiset" is - "\A i. if A \ {} \ (\i. bdd_above ((\f. f i) ` A)) \ finite (\f\A. {i. f i > 0}) then - Sup ((\f. f i) ` A) else 0" -proof - - fix A :: "('a \ nat) set" assume *: "\x. x \ A \ x \ multiset" - show "(\i. if A \ {} \ (\i. bdd_above ((\f. f i) ` A)) \ finite (\f\A. {i. 0 < f i}) - then SUP f:A. f i else 0) \ multiset" - proof (cases "A \ {} \ (\i. bdd_above ((\f. f i) ` A)) \ finite (\f\A. {i. 0 < f i})") - case True - have "{i. Sup ((\f. f i) ` A) > 0} \ (\f\A. {i. 0 < f i})" - proof safe - fix i assume pos: "(SUP f:A. f i) > 0" - show "i \ (\f\A. {i. 0 < f i})" - proof (rule ccontr) - assume "i \ (\f\A. {i. 0 < f i})" - hence "\f\A. f i \ 0" by auto - with True have "(SUP f:A. f i) \ 0" - by (intro cSup_least) auto - with pos show False by simp - qed - qed - moreover from True have "finite \" by blast - ultimately have "finite {i. Sup ((\f. f i) ` A) > 0}" by (rule finite_subset) - with True show ?thesis by (simp add: multiset_def) - qed (simp_all add: multiset_def) -qed +definition Sup_multiset :: "'a multiset set \ 'a multiset" where + "Sup_multiset A = (if A \ {} \ subset_mset.bdd_above A then + Abs_multiset (\i. Sup ((\X. count X i) ` A)) else {#})" + +lemma Sup_multiset_empty: "Sup {} = {#}" + by (simp add: Sup_multiset_def) + +lemma Sup_multiset_unbounded: "\subset_mset.bdd_above A \ Sup A = {#}" + by (simp add: Sup_multiset_def) instance .. end -lemma Sup_multiset_empty: "Sup {} = {#}" - by transfer simp_all - lemma bdd_below_multiset [simp]: "subset_mset.bdd_below A" by (intro subset_mset.bdd_belowI[of _ "{#}"]) simp_all @@ -877,16 +857,31 @@ ultimately show ?thesis by (rule finite_subset) qed +lemma Sup_multiset_in_multiset: + assumes "A \ {}" "subset_mset.bdd_above A" + shows "(\i. SUP X:A. count X i) \ multiset" + unfolding multiset_def +proof + have "{i. Sup ((\X. count X i) ` A) > 0} \ (\X\A. {i. 0 < count X i})" + proof safe + fix i assume pos: "(SUP X:A. count X i) > 0" + show "i \ (\X\A. {i. 0 < count X i})" + proof (rule ccontr) + assume "i \ (\X\A. {i. 0 < count X i})" + hence "\X\A. count X i \ 0" by (auto simp: count_eq_zero_iff) + with assms have "(SUP X:A. count X i) \ 0" + by (intro cSup_least bdd_above_multiset_imp_bdd_above_count) auto + with pos show False by simp + qed + qed + moreover from assms have "finite \" by (rule bdd_above_multiset_imp_finite_support) + ultimately show "finite {i. Sup ((\X. count X i) ` A) > 0}" by (rule finite_subset) +qed + lemma count_Sup_multiset_nonempty: assumes "A \ {}" "subset_mset.bdd_above A" shows "count (Sup A) x = (SUP X:A. count X x)" -proof - - from bdd_above_multiset_imp_bdd_above_count[OF assms(2)] - have "\x. bdd_above ((\X. count X x) ` A)" .. - moreover from bdd_above_multiset_imp_finite_support[OF assms] - have "finite (\X\A. {x. count X x > 0})" . - ultimately show ?thesis using assms(1) by transfer simp -qed + using assms by (simp add: Sup_multiset_def Abs_multiset_inverse Sup_multiset_in_multiset) interpretation subset_mset: conditionally_complete_lattice Inf Sup "op #\" "op \#" "op \#" "op #\" @@ -967,6 +962,9 @@ finally show ?thesis . qed +lemma in_Inf_multisetD: "x \# Inf A \ X \ A \ x \# X" + by (subst (asm) in_Inf_multiset_iff) auto + lemma set_mset_Sup: assumes "subset_mset.bdd_above A" shows "set_mset (Sup A) = (\X\A. set_mset X)" @@ -1001,6 +999,15 @@ finally show ?thesis . qed +lemma in_Sup_multisetD: + assumes "x \# Sup A" + shows "\X\A. x \# X" +proof - + have "subset_mset.bdd_above A" + by (rule ccontr) (insert assms, simp_all add: Sup_multiset_unbounded) + with assms show ?thesis by (simp add: in_Sup_multiset_iff) +qed + subsubsection \Filter (with comprehension syntax)\