A general Multiset object for mathematical Multisets, inheriting from Set.

Details

Multisets are generalisations of sets that allow an element to be repeated. They can be thought of as Tuples without ordering.

See also

Super class

set6::Set -> Multiset

Methods

Public methods

Inherited methods

Method equals()

Tests if two sets are equal.

Usage

Multiset$equals(x, all = FALSE)

Arguments

x

Set or vector of Sets.

all

logical. If FALSE tests each x separately. Otherwise returns TRUE only if all x pass test.

Details

An object is equal to a Multiset if it contains all the same elements, and in the same order. Infix operators can be used for:

Equal==
Not equal!=

Returns

If all is TRUE then returns TRUE if all x are equal to the Set, otherwise FALSE. If all is FALSE then returns a vector of logicals corresponding to each individual element of x.

Examples

Multiset$new(1,2) ==  Multiset$new(1,2)
Multiset$new(1,2) != Multiset$new(1,2)
Multiset$new(1,1) != Set$new(1,1)


Method isSubset()

Test if one set is a (proper) subset of another

Usage

Multiset$isSubset(x, proper = FALSE, all = FALSE)

Arguments

x

any. Object or vector of objects to test.

proper

logical. If TRUE tests for proper subsets.

all

logical. If FALSE tests each x separately. Otherwise returns TRUE only if all x pass test.

Details

If using the method directly, and not via one of the operators then the additional boolean argument proper can be used to specify testing of subsets or proper subsets. A Set is a proper subset of another if it is fully contained by the other Set (i.e. not equal to) whereas a Set is a (non-proper) subset if it is fully contained by, or equal to, the other Set.

When calling $isSubset on objects inheriting from Interval, the method treats the interval as if it is a Set, i.e. ordering and class are ignored. Use $isSubinterval to test if one interval is a subinterval of another.

Infix operators can be used for:

Subset<
Proper Subset<=
Superset>
Proper Superset>=

An object is a (proper) subset of a Multiset if it contains all (some) of the same elements, and in the same order.

Returns

If all is TRUE then returns TRUE if all x are subsets of the Set, otherwise FALSE. If all is FALSE then returns a vector of logicals corresponding to each individual element of x.

Examples

Multiset$new(1,2,3) < Multiset$new(1,2,3,4)
Multiset$new(1,3,2) < Multiset$new(1,2,3,4)
Multiset$new(1,3,2,4) <= Multiset$new(1,2,3,4)


Method clone()

The objects of this class are cloneable with this method.

Usage

Multiset$clone(deep = FALSE)

Arguments

deep

Whether to make a deep clone.

Examples

# Multiset of integers
Multiset$new(1:5)
#> {1, 2,...,4, 5} 

# Multiset of multiple types
Multiset$new("a", 5, Set$new(1), Multiset$new(2))
#> {{1}, {2}, 5, a} 

# Each Multiset has properties and traits
t <- Multiset$new(1, 2, 3)
t$traits
#> $crisp
#> [1] TRUE
#> 
t$properties
#> $empty
#> [1] FALSE
#> 
#> $singleton
#> [1] FALSE
#> 
#> $cardinality
#> [1] 3
#> 
#> $countability
#> [1] "countably finite"
#> 
#> $closure
#> [1] "closed"
#> 

# Elements can be duplicated
Multiset$new(2, 2) != Multiset$new(2)
#> [1] TRUE

# Ordering does not matter
Multiset$new(1, 2) == Multiset$new(2, 1)
#> [1] TRUE

## ------------------------------------------------
## Method `Multiset$equals`
## ------------------------------------------------

Multiset$new(1,2) ==  Multiset$new(1,2)
#> [1] TRUE
Multiset$new(1,2) != Multiset$new(1,2)
#> [1] FALSE
Multiset$new(1,1) != Set$new(1,1)
#> [1] TRUE

## ------------------------------------------------
## Method `Multiset$isSubset`
## ------------------------------------------------

Multiset$new(1,2,3) < Multiset$new(1,2,3,4)
#> [1] TRUE
Multiset$new(1,3,2) < Multiset$new(1,2,3,4)
#> [1] TRUE
Multiset$new(1,3,2,4) <= Multiset$new(1,2,3,4)
#> [1] TRUE