# HG changeset patch # User haftmann # Date 1613980188 0 # Node ID e2d03448d5b5ab07d4fe162b5f0c4d73c8dd03e6 # Parent f5a77ee9106cd14a0c5992aa10bf7ab50c16cbbf get rid of traditional predicate diff -r f5a77ee9106c -r e2d03448d5b5 NEWS --- a/NEWS Sun Feb 21 13:33:05 2021 +0100 +++ b/NEWS Mon Feb 22 07:49:48 2021 +0000 @@ -3,6 +3,10 @@ (Note: Isabelle/jEdit shows a tree-view of the NEWS file in Sidekick.) +*** HOL *** + +* Theory Multiset: dedicated predicate "multiset" is gone, use +explict expression instead. Minor INCOMPATIBILITY. New in this Isabelle version ---------------------------- diff -r f5a77ee9106c -r e2d03448d5b5 src/HOL/Algebra/Polynomial_Divisibility.thy --- a/src/HOL/Algebra/Polynomial_Divisibility.thy Sun Feb 21 13:33:05 2021 +0100 +++ b/src/HOL/Algebra/Polynomial_Divisibility.thy Mon Feb 22 07:49:48 2021 +0000 @@ -1507,7 +1507,7 @@ assumes "p \ carrier (poly_ring R)" shows "alg_mult p = count (roots p)" using finite_number_of_roots[OF assms] unfolding sym[OF alg_mult_gt_zero_iff_is_root[OF assms]] - by (simp add: multiset_def roots_def) + by (simp add: roots_def) lemma (in domain) roots_mem_iff_is_root: assumes "p \ carrier (poly_ring R)" shows "x \# roots p \ is_root p x" diff -r f5a77ee9106c -r e2d03448d5b5 src/HOL/Computational_Algebra/Factorial_Ring.thy --- a/src/HOL/Computational_Algebra/Factorial_Ring.thy Sun Feb 21 13:33:05 2021 +0100 +++ b/src/HOL/Computational_Algebra/Factorial_Ring.thy Mon Feb 22 07:49:48 2021 +0000 @@ -1208,8 +1208,7 @@ lift_definition prime_factorization :: "'a \ 'a multiset" is "\x p. if prime p then multiplicity p x else 0" - unfolding multiset_def -proof clarify +proof - fix x :: 'a show "finite {p. 0 < (if prime p then multiplicity p x else 0)}" (is "finite ?A") proof (cases "x = 0") @@ -2097,7 +2096,7 @@ from \finite S\ S(1) have "(\p\S. p ^ f p) \ 0" by auto with S(2) have nz: "n \ 0" by auto from S_eq \finite S\ have count_A: "count A = f" - unfolding A_def by (subst multiset.Abs_multiset_inverse) (simp_all add: multiset_def) + unfolding A_def by (subst multiset.Abs_multiset_inverse) simp_all from S_eq count_A have set_mset_A: "set_mset A = S" by (simp only: set_mset_def) from S(2) have "normalize n = (\p\S. p ^ f p)" . diff -r f5a77ee9106c -r e2d03448d5b5 src/HOL/Computational_Algebra/Primes.thy --- a/src/HOL/Computational_Algebra/Primes.thy Sun Feb 21 13:33:05 2021 +0100 +++ b/src/HOL/Computational_Algebra/Primes.thy Mon Feb 22 07:49:48 2021 +0000 @@ -728,8 +728,8 @@ define g where "g = (\x. if x \ S then f x else 0)" define A where "A = Abs_multiset g" have "{x. g x > 0} \ S" by (auto simp: g_def) - from finite_subset[OF this assms(1)] have [simp]: "g \ multiset" - by (simp add: multiset_def) + from finite_subset[OF this assms(1)] have [simp]: "finite {x. 0 < g x}" + by simp from assms have count_A: "count A x = g x" for x unfolding A_def by simp have set_mset_A: "set_mset A = {x\S. f x > 0}" diff -r f5a77ee9106c -r e2d03448d5b5 src/HOL/Library/DAList_Multiset.thy --- a/src/HOL/Library/DAList_Multiset.thy Sun Feb 21 13:33:05 2021 +0100 +++ b/src/HOL/Library/DAList_Multiset.thy Mon Feb 22 07:49:48 2021 +0000 @@ -100,7 +100,7 @@ definition count_of :: "('a \ nat) list \ 'a \ nat" where "count_of xs x = (case map_of xs x of None \ 0 | Some n \ n)" -lemma count_of_multiset: "count_of xs \ multiset" +lemma count_of_multiset: "finite {x. 0 < count_of xs x}" proof - let ?A = "{x::'a. 0 < (case map_of xs x of None \ 0::nat | Some n \ n)}" have "?A \ dom (map_of xs)" @@ -117,7 +117,7 @@ with finite_dom_map_of [of xs] have "finite ?A" by (auto intro: finite_subset) then show ?thesis - by (simp add: count_of_def fun_eq_iff multiset_def) + by (simp add: count_of_def fun_eq_iff) qed lemma count_simps [simp]: @@ -291,7 +291,7 @@ let ?inv = "{xs :: ('a \ nat) list. (distinct \ map fst) xs}" note cs[simp del] = count_simps have count[simp]: "\x. count (Abs_multiset (count_of x)) = count_of x" - by (rule Abs_multiset_inverse[OF count_of_multiset]) + by (rule Abs_multiset_inverse) (simp add: count_of_multiset) assume ys: "ys \ ?inv" then show "fold_mset f e (Bag (Alist ys)) = fold_impl fn e (DAList.impl_of (Alist ys))" unfolding Bag_def unfolding Alist_inverse[OF ys] diff -r f5a77ee9106c -r e2d03448d5b5 src/HOL/Library/Multiset.thy --- a/src/HOL/Library/Multiset.thy Sun Feb 21 13:33:05 2021 +0100 +++ b/src/HOL/Library/Multiset.thy Mon Feb 22 07:49:48 2021 +0000 @@ -14,17 +14,19 @@ subsection \The type of multisets\ -definition "multiset = {f :: 'a \ nat. finite {x. f x > 0}}" - -typedef 'a multiset = "multiset :: ('a \ nat) set" +typedef 'a multiset = \{f :: 'a \ nat. finite {x. f x > 0}}\ morphisms count Abs_multiset - unfolding multiset_def proof - show "(\x. 0::nat) \ {f. finite {x. f x > 0}}" by simp + show \(\x. 0::nat) \ {f. finite {x. f x > 0}}\ + by simp qed setup_lifting type_definition_multiset +lemma count_Abs_multiset: + \count (Abs_multiset f) = f\ if \finite {x. f x > 0}\ + by (rule Abs_multiset_inverse) (simp add: that) + lemma multiset_eq_iff: "M = N \ (\a. count M a = count N a)" by (simp only: count_inject [symmetric] fun_eq_iff) @@ -33,37 +35,15 @@ text \Preservation of the representing set \<^term>\multiset\.\ -lemma const0_in_multiset: "(\a. 0) \ multiset" - by (simp add: multiset_def) - -lemma only1_in_multiset: "(\b. if b = a then n else 0) \ multiset" - by (simp add: multiset_def) - -lemma union_preserves_multiset: "M \ multiset \ N \ multiset \ (\a. M a + N a) \ multiset" - by (simp add: multiset_def) - lemma diff_preserves_multiset: - assumes "M \ multiset" - shows "(\a. M a - N a) \ multiset" -proof - - have "{x. N x < M x} \ {x. 0 < M x}" - by auto - with assms show ?thesis - by (auto simp add: multiset_def intro: finite_subset) -qed + \finite {x. 0 < M x - N x}\ if \finite {x. 0 < M x}\ for M N :: \'a \ nat\ + using that by (rule rev_finite_subset) auto lemma filter_preserves_multiset: - assumes "M \ multiset" - shows "(\x. if P x then M x else 0) \ multiset" -proof - - have "{x. (P x \ 0 < M x) \ P x} \ {x. 0 < M x}" - by auto - with assms show ?thesis - by (auto simp add: multiset_def intro: finite_subset) -qed - -lemmas in_multiset = const0_in_multiset only1_in_multiset - union_preserves_multiset diff_preserves_multiset filter_preserves_multiset + \finite {x. 0 < (if P x then M x else 0)}\ if \finite {x. 0 < M x}\ for M N :: \'a \ nat\ + using that by (rule rev_finite_subset) auto + +lemmas in_multiset = diff_preserves_multiset filter_preserves_multiset subsection \Representing multisets\ @@ -74,19 +54,19 @@ begin lift_definition zero_multiset :: "'a multiset" is "\a. 0" -by (rule const0_in_multiset) + by simp abbreviation Mempty :: "'a multiset" ("{#}") where "Mempty \ 0" lift_definition plus_multiset :: "'a multiset \ 'a multiset \ 'a multiset" is "\M N. (\a. M a + N a)" -by (rule union_preserves_multiset) + by simp lift_definition minus_multiset :: "'a multiset \ 'a multiset \ 'a multiset" is "\ M N. \a. M a - N a" -by (rule diff_preserves_multiset) + by (rule diff_preserves_multiset) instance - by (standard; transfer; simp add: fun_eq_iff) + by (standard; transfer) (simp_all add: fun_eq_iff) end @@ -99,9 +79,9 @@ end lemma add_mset_in_multiset: - assumes M: \M \ multiset\ - shows \(\b. if b = a then Suc (M b) else M b) \ multiset\ - using assms by (simp add: multiset_def flip: insert_Collect) + \finite {x. 0 < (if x = a then Suc (M x) else M x)}\ + if \finite {x. 0 < M x}\ + using that by (simp add: flip: insert_Collect) lift_definition add_mset :: "'a \ 'a multiset \ 'a multiset" is "\a M b. if b = a then Suc (M b) else M b" @@ -246,7 +226,7 @@ lemma finite_set_mset [iff]: "finite (set_mset M)" - using count [of M] by (simp add: multiset_def) + using count [of M] by simp lemma set_mset_add_mset_insert [simp]: \set_mset (add_mset a A) = insert a (set_mset A)\ by (auto simp flip: count_greater_eq_Suc_zero_iff split: if_splits) @@ -1029,18 +1009,18 @@ lift_definition Inf_multiset :: "'a multiset set \ 'a multiset" is "\A i. if A = {} then 0 else Inf ((\f. f i) ` A)" proof - - fix A :: "('a \ nat) set" assume *: "\x. x \ A \ x \ multiset" - have "finite {i. (if A = {} then 0 else Inf ((\f. f i) ` A)) > 0}" unfolding multiset_def + fix A :: "('a \ nat) set" + assume *: "\f. f \ A \ finite {x. 0 < f x}" + show \finite {i. 0 < (if A = {} then 0 else INF f\A. f i)}\ proof (cases "A = {}") case False then obtain f where "f \ A" by blast hence "{i. Inf ((\f. f i) ` A) > 0} \ {i. f i > 0}" by (auto intro: less_le_trans[OF _ cInf_lower]) - moreover from \f \ A\ * have "finite \" by (simp add: multiset_def) + moreover from \f \ A\ * have "finite \" by simp ultimately have "finite {i. Inf ((\f. f i) ` A) > 0}" by (rule finite_subset) with False show ?thesis by simp qed simp_all - thus "(\i. if A = {} then 0 else INF f\A. f i) \ multiset" by (simp add: multiset_def) qed instance .. @@ -1098,10 +1078,9 @@ 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 + \finite {i. 0 < (SUP M\A. count M i)}\ + if \A \ {}\ \subset_mset.bdd_above A\ +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" @@ -1109,20 +1088,21 @@ 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" + with that 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) + moreover from that 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)" - using assms by (simp add: Sup_multiset_def Abs_multiset_inverse Sup_multiset_in_multiset) - + \count (Sup A) x = (SUP X\A. count X x)\ + if \A \ {}\ \subset_mset.bdd_above A\ + using that by (simp add: Sup_multiset_def Sup_multiset_in_multiset count_Abs_multiset) interpretation subset_mset: conditionally_complete_lattice Inf Sup "(\#)" "(\#)" "(\#)" "(\#)" proof @@ -3700,7 +3680,7 @@ by (rule natLeq_cinfinite) show "ordLeq3 (card_of (set_mset X)) natLeq" for X by transfer - (auto intro!: ordLess_imp_ordLeq simp: finite_iff_ordLess_natLeq[symmetric] multiset_def) + (auto intro!: ordLess_imp_ordLeq simp: finite_iff_ordLess_natLeq[symmetric]) show "rel_mset R OO rel_mset S \ rel_mset (R OO S)" for R S unfolding rel_mset_def[abs_def] OO_def apply clarify @@ -3749,9 +3729,8 @@ unfolding rel_mset_def Grp_def by auto declare multiset.count[simp] -declare Abs_multiset_inverse[simp] +declare count_Abs_multiset[simp] declare multiset.count_inverse[simp] -declare union_preserves_multiset[simp] lemma rel_mset_Plus: assumes ab: "R a b"