# HG changeset patch # User haftmann # Date 1615056130 0 # Node ID 716d256259d5c99ee73f0ac570bafc0be559cbf5 # Parent 24f0df084aad5fd6e07c16a1ca28a007f658f5c6 consolidated names diff -r 24f0df084aad -r 716d256259d5 NEWS --- a/NEWS Sat Mar 06 18:42:10 2021 +0000 +++ b/NEWS Sat Mar 06 18:42:10 2021 +0000 @@ -22,6 +22,18 @@ * Theory Multiset: dedicated predicate "multiset" is gone, use explict expression instead. Minor INCOMPATIBILITY. +* Theory Multiset: consolidated abbreviations Mempty, Melem, not_Melem +to empty_mset, member_mset, not_member_mset respectively. Minor +INCOMPATIBILITY. + +* Theory Multiset: consolidated operation and fact names: + inf_subset_mset ~> inter_mset + sup_subset_mset ~> union_mset + multiset_inter_def ~> inter_mset_def + sup_subset_mset_def ~> union_mset_def + multiset_inter_count ~> count_inter_mset + sup_subset_mset_count ~> count_union_mset + * HOL-Analysis/HOL-Probability: indexed products of discrete distributions, negative binomial distribution, Hoeffding's inequality, Chernoff bounds, Cauchy–Schwarz inequality for nn_integral, and some diff -r 24f0df084aad -r 716d256259d5 src/HOL/Algebra/Divisibility.thy --- a/src/HOL/Algebra/Divisibility.thy Sat Mar 06 18:42:10 2021 +0000 +++ b/src/HOL/Algebra/Divisibility.thy Sat Mar 06 18:42:10 2021 +0000 @@ -2128,11 +2128,11 @@ proof (simp add: isgcd_def, safe) from csmset have "fmset G cs \# fmset G as" - by (simp add: multiset_inter_def subset_mset_def) + by simp then show "c divides a" by (rule fmsubset_divides) fact+ next from csmset have "fmset G cs \# fmset G bs" - by (simp add: multiset_inter_def subseteq_mset_def, force) + by simp then show "c divides b" by (rule fmsubset_divides) fact+ next diff -r 24f0df084aad -r 716d256259d5 src/HOL/Library/DAList_Multiset.thy --- a/src/HOL/Library/DAList_Multiset.thy Sat Mar 06 18:42:10 2021 +0000 +++ b/src/HOL/Library/DAList_Multiset.thy Sat Mar 06 18:42:10 2021 +0000 @@ -12,7 +12,7 @@ declare [[code drop: "{#}" Multiset.is_empty add_mset "plus :: 'a multiset \ _" "minus :: 'a multiset \ _" - inf_subset_mset sup_subset_mset image_mset filter_mset count + inter_mset union_mset image_mset filter_mset count "size :: _ multiset \ nat" sum_mset prod_mset set_mset sorted_list_of_multiset subset_mset subseteq_mset equal_multiset_inst.equal_multiset]] @@ -261,8 +261,8 @@ unfolding mset_less_eq_Bag0 by auto qed -declare multiset_inter_def [code] -declare sup_subset_mset_def [code] +declare inter_mset_def [code] +declare union_mset_def [code] declare mset.simps [code] diff -r 24f0df084aad -r 716d256259d5 src/HOL/Library/Multiset.thy --- a/src/HOL/Library/Multiset.thy Sat Mar 06 18:42:10 2021 +0000 +++ b/src/HOL/Library/Multiset.thy Sat Mar 06 18:42:10 2021 +0000 @@ -53,16 +53,19 @@ instantiation multiset :: (type) cancel_comm_monoid_add begin -lift_definition zero_multiset :: "'a multiset" is "\a. 0" +lift_definition zero_multiset :: \'a multiset\ + is \\a. 0\ 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)" +abbreviation empty_mset :: \'a multiset\ (\{#}\) + where \empty_mset \ 0\ + +lift_definition plus_multiset :: \'a multiset \ 'a multiset \ 'a multiset\ + is \\M N a. M a + N a\ by simp -lift_definition minus_multiset :: "'a multiset \ 'a multiset \ 'a multiset" is "\ M N. \a. M a - N a" +lift_definition minus_multiset :: \'a multiset \ 'a multiset \ 'a multiset\ + is \\M N a. M a - N a\ by (rule diff_preserves_multiset) instance @@ -121,30 +124,30 @@ subsubsection \Conversion to set and membership\ -definition set_mset :: "'a multiset \ 'a set" - where "set_mset M = {x. count M x > 0}" - -abbreviation Melem :: "'a \ 'a multiset \ bool" - where "Melem a M \ a \ set_mset M" +definition set_mset :: \'a multiset \ 'a set\ + where \set_mset M = {x. count M x > 0}\ + +abbreviation member_mset :: \'a \ 'a multiset \ bool\ + where \member_mset a M \ a \ set_mset M\ notation - Melem ("'(\#')") and - Melem ("(_/ \# _)" [51, 51] 50) + member_mset (\'(\#')\) and + member_mset (\(_/ \# _)\ [51, 51] 50) notation (ASCII) - Melem ("'(:#')") and - Melem ("(_/ :# _)" [51, 51] 50) - -abbreviation not_Melem :: "'a \ 'a multiset \ bool" - where "not_Melem a M \ a \ set_mset M" + member_mset (\'(:#')\) and + member_mset (\(_/ :# _)\ [51, 51] 50) + +abbreviation not_member_mset :: \'a \ 'a multiset \ bool\ + where \not_member_mset a M \ a \ set_mset M\ notation - not_Melem ("'(\#')") and - not_Melem ("(_/ \# _)" [51, 51] 50) + not_member_mset (\'(\#')\) and + not_member_mset (\(_/ \# _)\ [51, 51] 50) notation (ASCII) - not_Melem ("'(~:#')") and - not_Melem ("(_/ ~:# _)" [51, 51] 50) + not_member_mset (\'(~:#')\) and + not_member_mset (\(_/ ~:# _)\ [51, 51] 50) context begin @@ -671,26 +674,26 @@ subsubsection \Intersection and bounded union\ -definition inf_subset_mset :: "'a multiset \ 'a multiset \ 'a multiset" (infixl "\#" 70) where - multiset_inter_def: "inf_subset_mset A B = A - (A - B)" - -interpretation subset_mset: semilattice_inf inf_subset_mset "(\#)" "(\#)" +definition inter_mset :: \'a multiset \ 'a multiset \ 'a multiset\ (infixl \\#\ 70) + where \A \# B = A - (A - B)\ + +interpretation subset_mset: semilattice_inf \(\#)\ \(\#)\ \(\#)\ proof - have [simp]: "m \ n \ m \ q \ m \ n - (n - q)" for m n q :: nat by arith show "class.semilattice_inf (\#) (\#) (\#)" - by standard (auto simp add: multiset_inter_def subseteq_mset_def) + by standard (auto simp add: inter_mset_def subseteq_mset_def) qed \ \FIXME: avoid junk stemming from type class interpretation\ -definition sup_subset_mset :: "'a multiset \ 'a multiset \ 'a multiset"(infixl "\#" 70) - where "sup_subset_mset A B = A + (B - A)" \ \FIXME irregular fact name\ - -interpretation subset_mset: semilattice_sup sup_subset_mset "(\#)" "(\#)" +definition union_mset :: \'a multiset \ 'a multiset \ 'a multiset\ (infixl \\#\ 70) + where \A \# B = A + (B - A)\ + +interpretation subset_mset: semilattice_sup \(\#)\ \(\#)\ \(\#)\ proof - have [simp]: "m \ n \ q \ n \ m + (q - m) \ n" for m n q :: nat by arith show "class.semilattice_sup (\#) (\#) (\#)" - by standard (auto simp add: sup_subset_mset_def subseteq_mset_def) + by standard (auto simp add: union_mset_def subseteq_mset_def) qed \ \FIXME: avoid junk stemming from type class interpretation\ interpretation subset_mset: bounded_lattice_bot "(\#)" "(\#)" "(\#)" @@ -701,14 +704,13 @@ subsubsection \Additional intersection facts\ -lemma multiset_inter_count [simp]: - fixes A B :: "'a multiset" - shows "count (A \# B) x = min (count A x) (count B x)" - by (simp add: multiset_inter_def) +lemma count_inter_mset [simp]: + \count (A \# B) x = min (count A x) (count B x)\ + by (simp add: inter_mset_def) lemma set_mset_inter [simp]: "set_mset (A \# B) = set_mset A \ set_mset B" - by (simp only: set_eq_iff count_greater_zero_iff [symmetric] multiset_inter_count) simp + by (simp only: set_mset_def) auto lemma diff_intersect_left_idem [simp]: "M - M \# N = M - N" @@ -766,10 +768,9 @@ lemma inter_mset_empty_distrib_left: "(A + B) \# C = {#} \ A \# C = {#} \ B \# C = {#}" by (meson disjunct_not_in union_iff) -lemma add_mset_inter_add_mset[simp]: +lemma add_mset_inter_add_mset [simp]: "add_mset a A \# add_mset a B = add_mset a (A \# B)" - by (metis add_mset_add_single add_mset_diff_bothsides diff_subset_eq_self multiset_inter_def - subset_mset.diff_add_assoc2) + by (rule multiset_eqI) simp lemma add_mset_disjoint [simp]: "add_mset a A \# B = {#} \ a \# B \ A \# B = {#}" @@ -838,14 +839,13 @@ subsubsection \Additional bounded union facts\ -lemma sup_subset_mset_count [simp]: \ \FIXME irregular fact name\ - "count (A \# B) x = max (count A x) (count B x)" - by (simp add: sup_subset_mset_def) +lemma count_union_mset [simp]: + \count (A \# B) x = max (count A x) (count B x)\ + by (simp add: union_mset_def) lemma set_mset_sup [simp]: - "set_mset (A \# B) = set_mset A \ set_mset B" - by (simp only: set_eq_iff count_greater_zero_iff [symmetric] sup_subset_mset_count) - (auto simp add: not_in_iff elim: mset_add) + \set_mset (A \# B) = set_mset A \ set_mset B\ + by (simp only: set_mset_def) (auto simp add: less_max_iff_disj) lemma sup_union_left1 [simp]: "\ x \# N \ (add_mset x M) \# N = add_mset x (M \# N)" by (simp add: multiset_eq_iff not_in_iff) @@ -894,12 +894,19 @@ lemma count_replicate_mset[simp]: "count (replicate_mset n x) y = (if y = x then n else 0)" unfolding replicate_mset_def by (induct n) auto -fun repeat_mset :: "nat \ 'a multiset \ 'a multiset" where - "repeat_mset 0 _ = {#}" | - "repeat_mset (Suc n) A = A + repeat_mset n A" +lift_definition repeat_mset :: \nat \ 'a multiset \ 'a multiset\ + is \\n M a. n * M a\ by simp lemma count_repeat_mset [simp]: "count (repeat_mset i A) a = i * count A a" - by (induction i) auto + by transfer rule + +lemma repeat_mset_0 [simp]: + \repeat_mset 0 M = {#}\ + by transfer simp + +lemma repeat_mset_Suc [simp]: + \repeat_mset (Suc n) M = M + repeat_mset n M\ + by transfer simp lemma repeat_mset_right [simp]: "repeat_mset a (repeat_mset b A) = repeat_mset (a * b) A" by (auto simp: multiset_eq_iff left_diff_distrib') @@ -928,7 +935,7 @@ by (auto simp: multiset_eq_iff) lemma repeat_mset_empty[simp]: "repeat_mset n {#} = {#}" - by (induction n) simp_all + by transfer simp subsubsection \Simprocs\ @@ -3254,10 +3261,10 @@ let fun msetT T = Type (\<^type_name>\multiset\, [T]); - fun mk_mset T [] = Const (\<^const_abbrev>\Mempty\, msetT T) + fun mk_mset T [] = Const (\<^const_abbrev>\empty_mset\, msetT T) | mk_mset T [x] = Const (\<^const_name>\add_mset\, T --> msetT T --> msetT T) $ x $ - Const (\<^const_abbrev>\Mempty\, msetT T) + Const (\<^const_abbrev>\empty_mset\, msetT T) | mk_mset T (x :: xs) = Const (\<^const_name>\plus\, msetT T --> msetT T --> msetT T) $ mk_mset T [x] $ mk_mset T xs @@ -3274,7 +3281,7 @@ resolve_tac ctxt @{thms nonempty_single} fun regroup_munion_conv ctxt = - Function_Lib.regroup_conv ctxt \<^const_abbrev>\Mempty\ \<^const_name>\plus\ + Function_Lib.regroup_conv ctxt \<^const_abbrev>\empty_mset\ \<^const_name>\plus\ (map (fn t => t RS eq_reflection) (@{thms ac_simps} @ @{thms empty_neutral})) fun unfold_pwleq_tac ctxt i =