Function Repository Resource:

AllComplements

Source Notebook

Find elements of lists that are not in other lists

Contributed by: Bob Sandheinrich

ResourceFunction["AllComplements"][{e1,e2,}]

gives the list of elements in each of the ei which are not in any of the other e sets.

Details and Options

ResourceFunction["AllComplements"] also supports a var-args syntax of ResourceFunction["AllComplements"][e1,e2,] when there are at least 2 sets.
The ei can be any expression supported by Complement.
ResourceFunction["AllComplements"] accepts the same options as Complement including SameTest.
ResourceFunction["AllComplements"] reorders subsets in the same order as Complement.

Examples

Basic Examples (2) 

Find unique elements of each sublist:

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

Find key-value pairs that are not included in other associations:

In[2]:=
ResourceFunction[
 "AllComplements"][{<|"a" -> 1, "b" -> 2, "c" -> 3|>, <|"a" -> 100, "b" -> 2|>, <|"a" -> 1, "c" -> 1|>}]
Out[2]=

Scope (3) 

The head can be anything supported by Complement:

In[3]:=
ResourceFunction[
 "AllComplements"][{f[a, b, c, d], f[c, a, e], f[b, b, a]}]
Out[3]=

Do the same without wrapping the sets in a List:

In[4]:=
ResourceFunction["AllComplements"][f[a, b, c, d], f[c, a, e], f[b, b, a]]
Out[4]=

The wrapper of the sets does not need to be a List:

In[5]:=
ResourceFunction["AllComplements"][
 g[f[a, b, c, d], f[c, a, e], f[b, b, a]]]
Out[5]=

Options (1) 

Use SameTest to specify a function for matching elements:

In[6]:=
ResourceFunction["AllComplements"][{{2, -2, 1, 3}, {2, 1, -2, -1, 6}},
  SameTest -> (Abs[#1] == Abs[#2] &)]
Out[6]=

Applications (4) 

Find which options to Plot are not also options to Graphics:

In[7]:=
ResourceFunction["AllComplements"][First /@ Options[Graphics3D], First /@ Options[Graphics]]
Out[7]=

AllComplements can give complimentary complements:

In[8]:=
skills = {"You're so wise", "You write so clearly", "I didn't know you could dunk"};
achievements = {"Nice Tweet!", "I didn't know you could dunk", "Congrats on the Nobel Prize", "I changed my mind based on your dispassionate online post"};
dreams = {"Congrats on the Nobel Prize", "I changed my mind based on your dispassionate online post", "You can fly even better than Superman."};
ResourceFunction["AllComplements"][{skills, achievements, dreams}]
Out[9]=

Find some fun resource functions:

In[10]:=
fun = ResourceSearch[{"Fun", "ResourceType" -> "Function"}, "Name", ResourceSystemPath -> {URL[$ResourceSystemBase]}]
Out[10]=

Find some fun ones:

In[11]:=
games = ResourceSearch[{"Game", "ResourceType" -> "Function"}, "Name",
   ResourceSystemPath -> {URL[$ResourceSystemBase]}]
Out[11]=

Get fun functions that are not games and games that are… not fun:

In[12]:=
ResourceFunction["AllComplements"][fun, games]
Out[12]=

Copy the outputs of BirdSay into AllComplements:

In[13]:=
ResourceFunction["BirdSay"][{"chirp", "chirp", "tweet"}] // CopyToClipboard
In[14]:=
ResourceFunction["BirdSay"][{"tweet", "squak", "caw"}] // CopyToClipboard

BirdSay the complement:

In[15]:=
(* Evaluate this cell to get the example input *) CloudGet["https://www.wolframcloud.com/obj/9dacf484-5306-4c41-99aa-1ad5c356c08d"]
Out[15]=

Possible Issues (1) 

The heads must be the same:

In[16]:=
ResourceFunction[
 "AllComplements"][{f[a, b, c, d], <|"a" -> 1|>, f[b, b, a]}]
Out[16]=

Version History

  • 1.0.0 – 25 March 2020

Related Resources

Author Notes

I'd like to give AllComplements to the Wolfram Function Repository and to its users.

I hope the feedback for this function will be AllComplements.

License Information