The Universal is defined as the Set containing all possible elements.

Details

The Universal set is the default universe to all sets, and is the largest possible set. The Universal set contains every single possible element. We denote the Universal set with V instead of U to avoid confusion with the union symbol. The Universal set cardinality is set to Inf where we assume Inf is greater than any Aleph or Beth numbers. The Universal set is also responsible for a few set paradoxes, to resolve these we use the following results:

Let \(V\) be the universal set, \(S\) be any non-universal set, and \(0\) the empty set, then

$$V \cup S = V$$ $$V \cap S = S$$ $$S - V = 0$$ $$V^n = V$$ $$P(V) = V$$

See also

Super class

set6::Set -> Universal

Methods

Public methods

Inherited methods

Method new()

Create a new Universal object.

Usage

Universal$new()

Details

The Universal set is the set containing every possible element.

Returns

A new Universal object.


Method equals()

Tests if two sets are equal.

Usage

Universal$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.

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.

Infix operators can be used for:

Equal==
Not equal!=

Examples

# Equals
Set$new(1,2)$equals(Set$new(5,6))
Set$new(1,2)$equals(Interval$new(1,2))
Set$new(1,2) == Interval$new(1,2, class = "integer")

# Not equal
!Set$new(1,2)$equals(Set$new(1,2))
Set$new(1,2) != Set$new(1,5)


Method isSubset()

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

Usage

Universal$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>=

Every Set is a subset of a Universal. No Set is a super set of a Universal, and only a Universal is not a proper subset of a Universal.

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

Set$new(1,2,3)$isSubset(Set$new(1,2), proper = TRUE)
Set$new(1,2) < Set$new(1,2,3) # proper subset

c(Set$new(1,2,3), Set$new(1)) < Set$new(1,2,3) # not proper
Set$new(1,2,3) <= Set$new(1,2,3) # proper


Method contains()

Tests to see if x is contained in the Set.

Usage

Universal$contains(x, all = FALSE, bound = NULL)

Arguments

x

any. Object or vector of objects to test.

all

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

bound

ignored.

Details

x can be of any type, including a Set itself. x should be a tuple if checking to see if it lies within a set of dimension greater than one. To test for multiple x at the same time, then provide these as a list.

If using the method directly, and not via one of the operators then the additional boolean arguments all and bound. If all = TRUE then returns TRUE if all x are contained in the Set, otherwise returns a vector of logicals. For Intervals, bound is used to specify if elements lying on the (possibly open) boundary of the interval are considered contained (bound = TRUE) or not (bound = FALSE).

Returns

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

The infix operator %inset% is available to test if x is an element in the Set, see examples.

Every element is contained within the Universal set.

Examples

s = Set$new(1:5)

# Simplest case
s$contains(4)
8 %inset% s

# Test if multiple elements lie in the set
s$contains(4:6, all = FALSE)
s$contains(4:6, all = TRUE)

# Check if a tuple lies in a Set of higher dimension
s2 = s * s
s2$contains(Tuple$new(2,1))
c(Tuple$new(2,1), Tuple$new(1,7), 2) %inset% s2


Method strprint()

Creates a printable representation of the object.

Usage

Universal$strprint(n = NULL)

Arguments

n

numeric. Number of elements to display on either side of ellipsis when printing.

Returns

A character string representing the object.


Method clone()

The objects of this class are cloneable with this method.

Usage

Universal$clone(deep = FALSE)

Arguments

deep

Whether to make a deep clone.

Examples

u <- Universal$new()
print(u)
#> 𝕍 
u$contains(c(1, letters, TRUE, Set$new()), all = TRUE)
#> [1] TRUE

## ------------------------------------------------
## Method `Universal$equals`
## ------------------------------------------------

# Equals
Set$new(1,2)$equals(Set$new(5,6))
#> Called from: FUN(X[[i]], ...)
#> debug: if (!testSet(y)) {
#>     return(FALSE)
#> }
#> debug: if (testFuzzy(y)) {
#>     if (!all(y$membership() == 1)) {
#>         return(FALSE)
#>     }
#> }
#> debug: if (testConditionalSet(y)) {
#>     return(FALSE)
#> } else if (testInterval(y)) {
#>     if (testCountablyFinite(y)) {
#>         return(all(suppressWarnings(y$elements %in% self$elements & 
#>             self$elements %in% y$elements)))
#>     }
#>     else {
#>         return(FALSE)
#>     }
#> } else if (sum(testEmpty(self), testEmpty(y)) == 1) {
#>     return(FALSE)
#> } else {
#>     comp <- suppressWarnings(y$.__enclos_env__$private$.str_elements %in% 
#>         private$.str_elements & private$.str_elements %in% y$.__enclos_env__$private$.str_elements)
#>     return(all(comp))
#> }
#> debug: if (testInterval(y)) {
#>     if (testCountablyFinite(y)) {
#>         return(all(suppressWarnings(y$elements %in% self$elements & 
#>             self$elements %in% y$elements)))
#>     }
#>     else {
#>         return(FALSE)
#>     }
#> } else if (sum(testEmpty(self), testEmpty(y)) == 1) {
#>     return(FALSE)
#> } else {
#>     comp <- suppressWarnings(y$.__enclos_env__$private$.str_elements %in% 
#>         private$.str_elements & private$.str_elements %in% y$.__enclos_env__$private$.str_elements)
#>     return(all(comp))
#> }
#> debug: if (sum(testEmpty(self), testEmpty(y)) == 1) {
#>     return(FALSE)
#> } else {
#>     comp <- suppressWarnings(y$.__enclos_env__$private$.str_elements %in% 
#>         private$.str_elements & private$.str_elements %in% y$.__enclos_env__$private$.str_elements)
#>     return(all(comp))
#> }
#> debug: comp <- suppressWarnings(y$.__enclos_env__$private$.str_elements %in% 
#>     private$.str_elements & private$.str_elements %in% y$.__enclos_env__$private$.str_elements)
#> debug: return(all(comp))
#> [1] FALSE
Set$new(1,2)$equals(Interval$new(1,2))
#> Called from: FUN(X[[i]], ...)
#> debug: if (!testSet(y)) {
#>     return(FALSE)
#> }
#> debug: if (testFuzzy(y)) {
#>     if (!all(y$membership() == 1)) {
#>         return(FALSE)
#>     }
#> }
#> debug: if (testConditionalSet(y)) {
#>     return(FALSE)
#> } else if (testInterval(y)) {
#>     if (testCountablyFinite(y)) {
#>         return(all(suppressWarnings(y$elements %in% self$elements & 
#>             self$elements %in% y$elements)))
#>     }
#>     else {
#>         return(FALSE)
#>     }
#> } else if (sum(testEmpty(self), testEmpty(y)) == 1) {
#>     return(FALSE)
#> } else {
#>     comp <- suppressWarnings(y$.__enclos_env__$private$.str_elements %in% 
#>         private$.str_elements & private$.str_elements %in% y$.__enclos_env__$private$.str_elements)
#>     return(all(comp))
#> }
#> debug: if (testInterval(y)) {
#>     if (testCountablyFinite(y)) {
#>         return(all(suppressWarnings(y$elements %in% self$elements & 
#>             self$elements %in% y$elements)))
#>     }
#>     else {
#>         return(FALSE)
#>     }
#> } else if (sum(testEmpty(self), testEmpty(y)) == 1) {
#>     return(FALSE)
#> } else {
#>     comp <- suppressWarnings(y$.__enclos_env__$private$.str_elements %in% 
#>         private$.str_elements & private$.str_elements %in% y$.__enclos_env__$private$.str_elements)
#>     return(all(comp))
#> }
#> debug: if (testCountablyFinite(y)) {
#>     return(all(suppressWarnings(y$elements %in% self$elements & 
#>         self$elements %in% y$elements)))
#> } else {
#>     return(FALSE)
#> }
#> debug: return(FALSE)
#> [1] FALSE
Set$new(1,2) == Interval$new(1,2, class = "integer")
#> Called from: FUN(X[[i]], ...)
#> debug: if (!testSet(y)) {
#>     return(FALSE)
#> }
#> debug: if (testFuzzy(y)) {
#>     if (!all(y$membership() == 1)) {
#>         return(FALSE)
#>     }
#> }
#> debug: if (testConditionalSet(y)) {
#>     return(FALSE)
#> } else if (testInterval(y)) {
#>     if (testCountablyFinite(y)) {
#>         return(all(suppressWarnings(y$elements %in% self$elements & 
#>             self$elements %in% y$elements)))
#>     }
#>     else {
#>         return(FALSE)
#>     }
#> } else if (sum(testEmpty(self), testEmpty(y)) == 1) {
#>     return(FALSE)
#> } else {
#>     comp <- suppressWarnings(y$.__enclos_env__$private$.str_elements %in% 
#>         private$.str_elements & private$.str_elements %in% y$.__enclos_env__$private$.str_elements)
#>     return(all(comp))
#> }
#> debug: if (testInterval(y)) {
#>     if (testCountablyFinite(y)) {
#>         return(all(suppressWarnings(y$elements %in% self$elements & 
#>             self$elements %in% y$elements)))
#>     }
#>     else {
#>         return(FALSE)
#>     }
#> } else if (sum(testEmpty(self), testEmpty(y)) == 1) {
#>     return(FALSE)
#> } else {
#>     comp <- suppressWarnings(y$.__enclos_env__$private$.str_elements %in% 
#>         private$.str_elements & private$.str_elements %in% y$.__enclos_env__$private$.str_elements)
#>     return(all(comp))
#> }
#> debug: if (testCountablyFinite(y)) {
#>     return(all(suppressWarnings(y$elements %in% self$elements & 
#>         self$elements %in% y$elements)))
#> } else {
#>     return(FALSE)
#> }
#> debug: return(all(suppressWarnings(y$elements %in% self$elements & self$elements %in% 
#>     y$elements)))
#> [1] TRUE

# Not equal
!Set$new(1,2)$equals(Set$new(1,2))
#> Called from: FUN(X[[i]], ...)
#> debug: if (!testSet(y)) {
#>     return(FALSE)
#> }
#> debug: if (testFuzzy(y)) {
#>     if (!all(y$membership() == 1)) {
#>         return(FALSE)
#>     }
#> }
#> debug: if (testConditionalSet(y)) {
#>     return(FALSE)
#> } else if (testInterval(y)) {
#>     if (testCountablyFinite(y)) {
#>         return(all(suppressWarnings(y$elements %in% self$elements & 
#>             self$elements %in% y$elements)))
#>     }
#>     else {
#>         return(FALSE)
#>     }
#> } else if (sum(testEmpty(self), testEmpty(y)) == 1) {
#>     return(FALSE)
#> } else {
#>     comp <- suppressWarnings(y$.__enclos_env__$private$.str_elements %in% 
#>         private$.str_elements & private$.str_elements %in% y$.__enclos_env__$private$.str_elements)
#>     return(all(comp))
#> }
#> debug: if (testInterval(y)) {
#>     if (testCountablyFinite(y)) {
#>         return(all(suppressWarnings(y$elements %in% self$elements & 
#>             self$elements %in% y$elements)))
#>     }
#>     else {
#>         return(FALSE)
#>     }
#> } else if (sum(testEmpty(self), testEmpty(y)) == 1) {
#>     return(FALSE)
#> } else {
#>     comp <- suppressWarnings(y$.__enclos_env__$private$.str_elements %in% 
#>         private$.str_elements & private$.str_elements %in% y$.__enclos_env__$private$.str_elements)
#>     return(all(comp))
#> }
#> debug: if (sum(testEmpty(self), testEmpty(y)) == 1) {
#>     return(FALSE)
#> } else {
#>     comp <- suppressWarnings(y$.__enclos_env__$private$.str_elements %in% 
#>         private$.str_elements & private$.str_elements %in% y$.__enclos_env__$private$.str_elements)
#>     return(all(comp))
#> }
#> debug: comp <- suppressWarnings(y$.__enclos_env__$private$.str_elements %in% 
#>     private$.str_elements & private$.str_elements %in% y$.__enclos_env__$private$.str_elements)
#> debug: return(all(comp))
#> [1] FALSE
Set$new(1,2) != Set$new(1,5)
#> Called from: FUN(X[[i]], ...)
#> debug: if (!testSet(y)) {
#>     return(FALSE)
#> }
#> debug: if (testFuzzy(y)) {
#>     if (!all(y$membership() == 1)) {
#>         return(FALSE)
#>     }
#> }
#> debug: if (testConditionalSet(y)) {
#>     return(FALSE)
#> } else if (testInterval(y)) {
#>     if (testCountablyFinite(y)) {
#>         return(all(suppressWarnings(y$elements %in% self$elements & 
#>             self$elements %in% y$elements)))
#>     }
#>     else {
#>         return(FALSE)
#>     }
#> } else if (sum(testEmpty(self), testEmpty(y)) == 1) {
#>     return(FALSE)
#> } else {
#>     comp <- suppressWarnings(y$.__enclos_env__$private$.str_elements %in% 
#>         private$.str_elements & private$.str_elements %in% y$.__enclos_env__$private$.str_elements)
#>     return(all(comp))
#> }
#> debug: if (testInterval(y)) {
#>     if (testCountablyFinite(y)) {
#>         return(all(suppressWarnings(y$elements %in% self$elements & 
#>             self$elements %in% y$elements)))
#>     }
#>     else {
#>         return(FALSE)
#>     }
#> } else if (sum(testEmpty(self), testEmpty(y)) == 1) {
#>     return(FALSE)
#> } else {
#>     comp <- suppressWarnings(y$.__enclos_env__$private$.str_elements %in% 
#>         private$.str_elements & private$.str_elements %in% y$.__enclos_env__$private$.str_elements)
#>     return(all(comp))
#> }
#> debug: if (sum(testEmpty(self), testEmpty(y)) == 1) {
#>     return(FALSE)
#> } else {
#>     comp <- suppressWarnings(y$.__enclos_env__$private$.str_elements %in% 
#>         private$.str_elements & private$.str_elements %in% y$.__enclos_env__$private$.str_elements)
#>     return(all(comp))
#> }
#> debug: comp <- suppressWarnings(y$.__enclos_env__$private$.str_elements %in% 
#>     private$.str_elements & private$.str_elements %in% y$.__enclos_env__$private$.str_elements)
#> debug: return(all(comp))
#> [1] TRUE

## ------------------------------------------------
## Method `Universal$isSubset`
## ------------------------------------------------

Set$new(1,2,3)$isSubset(Set$new(1,2), proper = TRUE)
#> [1] TRUE
Set$new(1,2) < Set$new(1,2,3) # proper subset
#> [1] TRUE

c(Set$new(1,2,3), Set$new(1)) < Set$new(1,2,3) # not proper
#> [1] FALSE  TRUE
Set$new(1,2,3) <= Set$new(1,2,3) # proper
#> [1] TRUE

## ------------------------------------------------
## Method `Universal$contains`
## ------------------------------------------------

s = Set$new(1:5)

# Simplest case
s$contains(4)
#> [1] TRUE
8 %inset% s
#> [1] FALSE

# Test if multiple elements lie in the set
s$contains(4:6, all = FALSE)
#> [1]  TRUE  TRUE FALSE
s$contains(4:6, all = TRUE)
#> [1] FALSE

# Check if a tuple lies in a Set of higher dimension
s2 = s * s
s2$contains(Tuple$new(2,1))
#> [1] TRUE
c(Tuple$new(2,1), Tuple$new(1,7), 2) %inset% s2
#> [1]  TRUE FALSE FALSE