Wolfram Function Repository
Instant-use add-on functions for the Wolfram Language
Function Repository Resource:
Perform the intersection operation on multisets
ResourceFunction["MultisetIntersection"][list1,list2,…] gives a sorted list of the elements common to all the listi. The number of occurrences of each distinct element is the minimum of the counts in each of the listi. | |
ResourceFunction["MultisetIntersection"][assoc1,assoc2,…] gives an Association where the keys are the union of the keys in the associations associ and the values are the minimum of the merged values. |
Find largest subsets of elements common to all the lists given:
In[1]:= | ![]() |
Out[1]= | ![]() |
Multisets as an Association of counts:
In[2]:= | ![]() |
Out[2]= | ![]() |
If there is no intersection, the result is {}:
In[4]:= | ![]() |
Out[4]= | ![]() |
If there is no intersection of the Association multisets, the result is <||>:
In[5]:= | ![]() |
Out[5]= | ![]() |
Compare to Intersection:
In[6]:= | ![]() |
Out[6]= | ![]() |
In[7]:= | ![]() |
Out[7]= | ![]() |
Wolfram Language 11.3 (March 2018) or above
This work is licensed under a Creative Commons Attribution 4.0 International License