Mathematica 9 is now available
THIS IS DOCUMENTATION FOR AN OBSOLETE PRODUCT.
SEE THE DOCUMENTATION CENTER FOR THE LATEST INFORMATION.
Mathematica >

Lists as Sets

Mathematica usually keeps the elements of a list in exactly the order you originally entered them. If you want to treat a Mathematica list like a mathematical set, however, you may want to ignore the order of elements in the list.
Union[list1,list2,...]give a list of the distinct elements in the listi
Intersection[list1,list2,...]give a list of the elements that are common to all the listi
Complement[universal,list1,...]give a list of the elements that are in universal, but not in any of the listi
Subsets[list]give a list of all subsets of the elements in list

Set theoretical functions.

Union gives the elements that occur in any of the lists.
In[1]:=
Click for copyable input
Out[1]=
Intersection gives only elements that occur in all the lists.
In[2]:=
Click for copyable input
Out[2]=
Complement gives elements that occur in the first list, but not in any of the others.
In[3]:=
Click for copyable input
Out[3]=
This gives all the subsets of the list.
In[4]:=
Click for copyable input
Out[4]=
Ask a question about this page  |  Suggest an improvement  |  Leave a message for the team