Multi-sets
CPN ML


Multi-set Creation

The back-quote (`) operator is the multi-set constructor. For example, 3`7 is the multi-set with three appearances of the colour 7.

Syntax

i`c

The integer i must be non-negative. If this is not the case then the empty multi-set will be returned.

Example

The multi-set operator combined with multi-set addition and subtraction (described below) provide a succinct method for specifying multi-sets. For example,

3`true++2`false

is an boolean multi-set consisting of 5 boolean values: 3 instances of true and 2 instances of false.

Constants, Operations, and Functions

empty the empty constant constructs an empty multi-set that is identical for all kinds of multi-sets
ms1 == ms2 multi-set equality
ms1 <><> ms2 multi-set inequality
ms1 >> ms2 multi-set greater than
ms1 >>= ms2 multi-set greater than or equal to
ms1 << ms2 multi-set less than
ms1 <<= ms2 multi-set less than or equal to
ms1 ++ ms2 multi-set addition
ms1 -- ms2 multi-set subtraction (ms2 must be less than or equal to ms1), raises Subtract exception if ms2 is not less than or equal to ms1.
i ** ms scalar multiplication
size ms size of multi-set ms
random ms returns a pseudo-random colour from ms
cf(c,ms) returns the number of appearances of colour c in ms
filter p ms takes a predicate p and a multi-set ms and produces the multi-set
of all the appearances in ms satisfying the predicate
ext_col f ms takes a function f and a multi-set c1`s1++c2`s2++...++cn`sn
and produces the multi-set c1`f(s1)++c2`f(s2)++...++cn`f(sn)
ext_ms f ms takes a function f and a multi-set c1`s1++c2`s2++...++cn`sn
and produces the multi-set c1*f(s1)++c2*f(s2)++...++cn*f(sn)
ms_to_col ms converts a multi-set of size 1 into the single element in the multi-set, raises no_singleton exception if (size ms) is not equal to 1.