# Multisets

## 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 `
the `empty` constant constructs an empty multiset that is identical for all kinds of multisets
`ms1 == ms2`
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`
`ms1 -``- ms2`
multiset 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 multiset `ms`
`random ms`
returns a pseudo-random color from ms
` cf(c,ms) `
returns the number of appearances of color c in ms
` filter p ms `
takes a predicate `p` and a multiset `ms` and produces the multiset of all the appearances in ms satisfying the predicate
` 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)`
` 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.