Function Repository Resource:

MultisetSymmetricDifference

Source Notebook

Get the symmetric difference of the given lists

Contributed by: George Beck

ResourceFunction["MultisetSymmetricDifference"][L1,L2,]

gives the list of elements that occur an odd number of times in the lists L1,L2,.

Details and Options

For two lists with no duplicates, ResourceFunction["MultisetSymmetricDifferences"] gives the usual symmetric difference of the lists considered as sets, which is the Complement of the Union and Intersection.
The result is sorted.

Examples

Basic Examples (3) 

Here is the symmetric difference of two sets:

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

Another example:

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

Like Union, Intersection, and Complement, a single list is pruned of duplicates and sorted:

In[3]:=
ResourceFunction[
 "MultisetSymmetricDifference"][{4, 4, 4, 4, 3, 3, 3, 2, 2, 1}]
Out[3]=

Possible Issues (4) 

Define two lists, one with a duplicated element:

In[4]:=
a = {1, 1, 2};
b = {1, 2};

The lists are equal up to duplicates, so the set symmetric difference is empty:

In[5]:=
Complement[Union[a, b], Intersection[a, b]]
Out[5]=

The element 1 occurs an odd number of times in the multiset sum of the lists:

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

Therefore, 1 is in the multiset difference:

In[7]:=
ResourceFunction["MultisetSymmetricDifference"][a, b]
Out[7]=

Publisher

George Beck

Requirements

Wolfram Language 11.3 (March 2018) or above

Version History

  • 1.0.0 – 10 May 2019

Related Resources

License Information