Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

setsymdiff

Symmetric Difference of Two Sets


Description

Returns the symmetric difference of two objects inheriting from class Set.

Usage

setsymdiff(x, y, simplify = TRUE)

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.

Details

The symmetric difference, aka disjunctive union, of two sets, X, Y, is defined as the set of elements that exist in set X or in Y but not both,

{z : (z ε X or z ε Y) and !(z ε X and z ε Y)}

The symmetric difference can also be expressed as the union of two sets minus the intersection. Therefore setsymdiff is written as a thin wrapper over these operations, so for two sets, A,B:
A %-% B = (A | B) - (A & B).

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

Value

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

See Also

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

Examples

# symmetrical difference compared to union and intersection
Set$new(1, 2, 3) %-% Set$new(3, 4)
(Set$new(1, 2, 3) | Set$new(3, 4)) - (Set$new(1, 2, 3) & Set$new(3, 4))

# ConditionalSets demonstrate the internal logic
ConditionalSet$new(function(x) x > 0) %-%
  ConditionalSet$new(function(y) y == 0)

set6

R6 Mathematical Sets Interface

v0.2.1
MIT + file LICENSE
Authors
Raphael Sonabend [aut, cre] (<https://orcid.org/0000-0001-9225-4654>), Franz Kiraly [aut]
Initial release

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.