Function Repository Resource:

SymmetricDifference

Source Notebook

The complement of the union and intersection of lists, with duplicates deleted

Contributed by: George Beck

ResourceFunction["SymmetricDifference"][lists]

gives the complement of the Union and Intersection of lists.

Examples

Basic Examples (2) 

The common element 3 is removed from the Union of the sets:

In[1]:=
ResourceFunction["SymmetricDifference"][{1, 2, 3}, {3, 4, 5, 6}]
Out[1]=

Define three lists:

In[2]:=
a = {1, 2, 3, 4};
b = {2, 3, 4, 5};
c = {3, 4, 5, 6};

Here is their Union:

In[3]:=
Union[a, b, c]
Out[3]=

Here is their Intersection:

In[4]:=
Intersection[a, b, c]
Out[4]=

Using those, you can define their symmetric difference:

In[5]:=
Complement[%%, %]
Out[5]=

SymmetricDifference gives the same result:

In[6]:=
ResourceFunction["SymmetricDifference"][a, b, c]
Out[6]=

Possible Issues (3) 

First define four regions:

In[7]:=
{d1, d2, d3, d4} = {
   Disk[{1, 1}, 2],
   Disk[{1, -1}, 2],
   Disk[{-1, -1}, 2],
   Disk[{-1, 1}, 2]
   };

The function RegionSymmetricDifference is like the resource function MultisetSymmetricDifference, not SymmetricDifference:

In[8]:=
Region@RegionSymmetricDifference[d1, d2, d3, d4]
Out[8]=

This construction is like SymmetricDifference:

In[9]:=
Region@RegionDifference[
  RegionUnion[d1, d2, d3, d4],
  RegionIntersection[d1, d2, d3, d4]
  ]
Out[9]=

Publisher

George Beck

Version History

  • 1.0.0 – 22 May 2019

Related Resources

License Information