Multiset creation
The back-quote (`
) operator is the multiset constructor. For example, 3`7
is the multiset with three appearances of the color 7
.
Syntax
i`c
The integer i
must be non-negative. If this is not the case then the empty
multiset will be returned.
Example
The multiset operator combined with multiset addition and subtraction (described below) provide a succinct method for specifying multisets. For example,
3`true++2`false
is a Boolean multiset consisting of 5 Boolean values: 3 instances of true
and 2 instances of false
.
Constants, operations, and functions
Empty
empty
The empty
constant constructs an empty multiset that is identical for all kinds of multisets
Multiset equality
ms1 == ms2
Multiset inequality
ms1 <><> ms2
Multiset greater than
ms1 >> ms2
Multiset greater than or equal to
ms1 >>= ms2
Multiset less than
ms1 << ms2
Multiset less than or equal to
ms1 <<= ms2
Multiset addition
ms1 ++ ms2
Multiset subtraction
ms1 — ms2
ms2
must be less than or equal to ms1
, raises Subtract
exception if ms2
is not less than or equal to ms1
.
Scalar multiplication
i ** ms
Size of multiset
size ms
Pseudo-random color
random ms
Number of appearances
cf(c,ms)
Multiset and predicate
filter p ms
Takes a predicate p
and a multiset ms
and produces the multiset of all the appearances in ms
satisfying the predicate p
.
Multiset and function
ext_col f ms
Takes a function f
and a multiset c1`s1++c2`s2++...++cn`sn
and produces the multiset c1`f(s1)++c2`f(s2)++...++cn`f(sn)
.
ext_ms f ms
Takes a function f
and a multiset c1`s1++c2`s2++...++cn`sn
and produces the multiset c1*f(s1)++c2*f(s2)++...++cn*f(sn)
.
Single element
ms_to_col ms
Converts a multiset of size 1 into the single element in the multiset, raises no_singleton
exception if (size ms)
is not equal to 1.
You must be logged in to post a comment.