Returns the set difference of two objects inheriting from class Set. If y is missing then the complement of x from its universe is returned.

setcomplement(x, y, simplify = TRUE)

# S3 method for Set
setcomplement(x, y, simplify = TRUE)

# S3 method for Interval
setcomplement(x, y, simplify = TRUE)

# S3 method for FuzzySet
setcomplement(x, y, simplify = TRUE)

# S3 method for ConditionalSet
setcomplement(x, y, simplify = TRUE)

# S3 method for Reals
setcomplement(x, y, simplify = TRUE)

# S3 method for Rationals
setcomplement(x, y, simplify = TRUE)

# S3 method for Integers
setcomplement(x, y, simplify = TRUE)

# S3 method for ComplementSet
setcomplement(x, y, simplify = TRUE)

# S3 method for Set
-(x, y)

Arguments

x, y

Set

simplify

logical, if TRUE (default) returns the result in its simplest form, usually a Set or UnionSet, otherwise a ComplementSet.

Value

An object inheriting from Set containing the set difference of elements in x and y.

Details

The difference of two sets, \(X, Y\), is defined as the set of elements that exist in set \(X\) and not \(Y\), $$X-Y = \{z : z \epsilon X \quad and \quad \neg(z \epsilon Y)\}$$

The set difference of two ConditionalSets is defined by combining their defining functions by a negated 'and', !&, operator. See examples.

The complement of fuzzy and crisp sets first coerces fuzzy sets to crisp sets by finding their support.

See also

Other operators: powerset(), setintersect(), setpower(), setproduct(), setsymdiff(), setunion()

Examples

# absolute complement
setcomplement(Set$new(1, 2, 3, universe = Reals$new()))
#> (-∞,1) ∪ (1,2) ∪ (2,3) ∪ (3,+∞) 
setcomplement(Set$new(1, 2, universe = Set$new(1, 2, 3, 4, 5)))
#> {3, 4, 5} 

# complement of two sets

Set$new(-2:4) - Set$new(2:5)
#> {-1, -2, 0, 1} 
setcomplement(Set$new(1, 4, "a"), Set$new("a", 6))
#> {1, 4} 

# complement of two intervals

Interval$new(1, 10) - Interval$new(5, 15)
#> [1,5) 
Interval$new(1, 10) - Interval$new(-15, 15)
#>
Interval$new(1, 10) - Interval$new(-1, 2)
#> (2,10] 

# complement of mixed set types

Set$new(1:10) - Interval$new(5, 15)
#> 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, 2, 3, 4} 
Set$new(5, 7) - Tuple$new(6, 8, 7)
#> {5} 

# FuzzySet-Set returns a FuzzySet
FuzzySet$new(1, 0.1, 2, 0.5) - Set$new(2:5)
#> {1(0.1)} 
# Set-FuzzySet returns a Set
Set$new(2:5) - FuzzySet$new(1, 0.1, 2, 0.5)
#> {3, 4, 5} 

# complement of conditional sets

ConditionalSet$new(function(x, y, simplify = TRUE) x >= y) -
  ConditionalSet$new(function(x, y, simplify = TRUE) x == y)
#> {x ∈ 𝕍, y ∈ 𝕍, simplify ∈ 𝕍 : x >= y & !(x == y)} 

# complement of special sets
Reals$new() - NegReals$new()
#> ℝ+ 
Rationals$new() - PosRationals$new()
#> ℚ- 
Integers$new() - PosIntegers$new()
#> ℤ-