Wolfram Research

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

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 are their Union and Intersection:

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

Here is their symmetric difference:

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

Possible Issues

First define four regions:

In[6]:=
{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 MultisetSymmetricDifference, not SymmetricDifference:

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

This construction is like SymmetricDifference:

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

Resource History

See Also

License Information