Dom::Multiset -- multisets
IntroductionDom::Multiset is the domain of multisets, i.e., sets
with possibly multiple identical elements.
Detailssolve. For example, the input
solve(x^3 - 4*x^2 + 5*x - 2, x, Multiple) gives all roots
of the polynomial x^3 - 4*x^2 + 5*x - 2 in form of the
multiset {[1, 2], [2, 1]}.These operations can handle different types of sets, such as sets of
type DOM_SET and
multisets. One may, for example, compute the union of the multiset
{[a, 2], [b, 1]} and the set {c}, which
results in the multiset {[a, 2], [b, 1], [c, 1]}.
sort is used in order to guarantee that
exactly one representation exists for a multiset, independent of the
sequence in which the arguments appear.
Creating
ElementsDom::Multiset( <s1, s2...>)
Parameterss1, s2... |
- | objects of any type |
Cat::Set
Related
Domains
DetailsDom::Multiset(s1, s2...) creates the
multiset consisting of the elements s1, s2...s1, s2... are
collected. For example, the call Dom::Multiset(a, b,
a, c) creates a multiset with the elements a, b, c.
The element a has multiplicity two, the other two elements
b and c both have multiplicity one.is TRUE because Dom::Multiset represents
finite sets.
a table of the form T = Proc(multiset, setoftypeT).
This entry is used internally by the implementation, and thus should
not be touched.
a table of the form T = Proc(multiset, setoftypeT).
This entry is used internally by the implementation, and thus should
not be touched.
normal(dom set)set using the
system function normal.normal for
multisets, i.e., one may use it in the form
normal(set).powerset(dom set)set, i.e., all sub-multisets of set.set is returned as a set of multisets.random()random to
create the elements of the random multiset. Therefore, the elements of
the returned multiset will be integers._index(dom set, index
i)set and its multiplicity m in form of the list
[s, m].
Note that the elements of the multiset are sorted with the use of
the system function sort,
and thus the order of a multiset depends on the sorting criteria
specified by this function.
"op"._index for multisets, i.e., one may
use it in the form set[i], or in functional notation:
_index(set, i).contains(dom set, any
s)TRUE if set does
contain s (i.e., if s is an element of
set), otherwise FALSE is returned. For the
comparison of two elements, the system function _equal is used, which only tests for
syntactical equivalence.contains for multisets, i.e., one
may use it in the form contains(set, s).expand(dom set)"_exprseq") of all elements in set,
appearing in correspondence to their multiplicity. For example, for the
multiset {[1, 1], [2, 2], [3, 1]}. the expression sequence
3, 2, 2, 1 is returned.expand for multisets, i.e., one may
use it in the form expand(set).getElement(dom set)set.sort,
and thus the order of a multiset depends on the sorting criteria
specified by this function.solvelib::getElement, i.e., one
may use it in the form solvelib::getElement(set).has(dom set, any
expr)TRUE if the multiset
set has a subexpression equal to expr, and
FALSE otherwise.expr is contained as an element of
set and not as a subexpression of the elements of
set, the function contains must be used.has for multisets, i.e., one may use it
in the form has(set, expr).map(dom set, function
func <, any expr...>)func onto the elements
(not onto their multiplicities) of the multiset set, with
the additional function parameters expr... passed to
func, if given.
See the system function map for details.
map for multisets, i.e., one
may use it in the form map(set, func...).multiplicity(dom set, any s)s
in the multiset set.set have
multiplicity zero.nops(dom set)set.nops for multisets, i.e., one may use
it in the form nops(set).op(dom set, positive
integer i)set and its multiplicity m in form of the list
[s,m]."_index".sort,
and thus the order of a multiset depends on the sorting criteria
specified by this function.op for multisets, i.e., one may use it in
the form op(s, i).select(dom set, function func <, any
expr...>)func onto the elements
(not onto their multiplicities) of the multiset set, with
the additional function parameters expr... passed on to
func, if given, and returns a multiset with those elements
for which the function call returned TRUE.select for multisets, i.e., one may
use it in the form select(set, func...). See select for details.split(dom set, function func <, any
expr...>)func onto the elements
(not onto their multiplicities) of the multiset set, with
the additional function parameters, if given, expr...
passed to func and returns a list of three multisets with
those elements for which the function call returned TRUE,
FALSE, and UNKNOWN respectively.split for multisets, i.e., one may use
it in the form split(set, func...). See split for details.subs(dom set...)convert(any x)x into a multiset of
domain type Dom::Multiset.FAIL is returned if the conversion fails.DOM_SET can be converted into
multisets.convert_to(dom set, any T)set into an
element of domain type T.FAIL is returned if the conversion fails.T may either be DOM_SET to convert the multiset
set into a set (loosing the multiplicities and the order
of the elements of set), or DOM_EXPR or "_exprseq"
to convert set into an expression sequence (see the method
"expand" for details)."expr".bin_intersect(dom set1, dom set2)set1 and
set2.Cat::Set, which implements
among others the overloading of the function _intersect for multisets. One may
intersect two multisets directly by set1 intersect set2,
or in functional notation by _intersect(set1, set2).bin_minus(dom set1, dom set2)homog_union(dom set...)Cat::Set, which implements
among others the overloading of the function _union for multisets. One may compute
the union of two multisets directly by set1 union set2, or
in functional notation by _union(set1, set2).nested_union(set setofsets)setofsets. The contained sets may be multisets or sets of
type DOM_SET.Cat::Set, which implements
among others the overloading of the function _union for multisets and sets. One
may compute the union of multisets and sets directly by set1
union set2, or in functional notation by _union(set1,
set2).
Example
1The multiset {a, a, b} consists of the two different elements a and b, where a has multiplicity two and b has multiplicity one:
>> delete a, b, c: set1 := Dom::Multiset(a, a, b)
{[a, 2], [b, 1]}
We create another multiset:
>> set2 := Dom::Multiset(a, c, c)
{[a, 1], [c, 2]}
Standard set operations such as union, intersection or subtraction are implemented for multisets and can be performed using the standard set operators of MuPAD:
>> set1 union set2
{[b, 1], [a, 3], [c, 2]}
>> set1 intersect set2
{[a, 1]}
>> contains(set1, a), contains(set1, d)
TRUE, FALSE
Example
2Some system functions were overloaded for multisets,
such as expand,
normal or split.
If we apply expand to a multiset, for example, we get
an expression sequence of all elements of the multiset (appearing in
correspondence to their multiplicity):
>> delete a, b, c, d, e: set := Dom::Multiset(a, b, c, a, c, d, c, e, c)
{[a, 2], [b, 1], [d, 1], [e, 1], [c, 4]}
>> expand(set)
e, d, c, c, c, c, b, a, a
If you want to convert a multiset into an ordinary set
of the domain type DOM_SET, use coerce:
>> coerce(set, DOM_SET)
{a, b, c, d, e}
Note: The system function coerce uses the
methods "convert" and "convert_to" of the
domain Dom::Multiset.
Compare the last result with the return value of the function
expr, when it is applied
for multisets:
>> expr(set)
{[a, 2], [b, 1], [d, 1], [e, 1], [c, 4]}
The result is a set of the domain type
DOM_SET, consisting of lists of the domain type DOM_LIST with two entries, an
element of the multiset and the corresponding multiplicity of that
element.
Super-Domaincontains now returns either TRUE
or FALSE instead of an integer.convert expects exactly one argument only and
was extended to deal with sets of type DOM_SET."isFinite",
"convert_to", "equal",
"getElement", "powerset",
"random"."_intersect", "_subtract" and
"_union" were removed and replaced by the following new
entries and methods: "bin_intersect",
"bin_minus", "inhomog_intersect",
"inhomog_union", "homog_union" and
"nested_union"."has", "map",
"select", and "subs" now work on the elements
only, but not on the multiplicities.Dom::Multiset is of the new category Cat::Set, and therefore offers the new
features provided by this category.