Complement[eall,e1,e2,…]
gives the elements in eall that are not in any of the ei.
Complement
Complement[eall,e1,e2,…]
gives the elements in eall that are not in any of the ei.
Details and Options
- The list returned by Complement is sorted into standard order.
- Complement[eall,e1,…,SameTest->test] applies test to each pair of elements in eall and the ei to determine whether they should be considered the same.
Examples
open all close allBasic Examples (1)
Generalizations & Extensions (1)
Complement works with any head, not just List:
Complement[f[a, b, c, d], f[c, a], f[b, b, a]]Options (3)
SameTest (3)
Use equivalence classes based on absolute value:
Complement[{2, -2, 1, 3}, {2, 1, -2, -1}, SameTest -> (Abs[#1] == Abs[#2]&)]Use equivalence classes based on Floor:
Complement[{1.1, 3.4, .5, 7.6, 7.1, 1.9}, {1.2, 3.3, 1.3}, SameTest -> (Floor[#1] == Floor[#2]&)]Use Total of list elements:
Complement[{{1, 2}, {3}, {4, 5, 6}, {9, 5}}, {{2, 1}, {8, 4, 3}}, SameTest -> (Total[#1] == Total[#2]&)]Applications (4)
Find divisors of 20 that are not also divisors of 12:
Complement[Divisors[20], Divisors[12]]Find which triples of digits do not occur in the binary decomposition of 12345:
Complement[Tuples[{0, 1}, 3], Partition[IntegerDigits[12345, 2], 3, 1]]Find which options to Plot are not also options to Graphics:
Complement[First /@ Options[Plot], First /@ Options[Graphics]]Find which length-5 sequences never occur after 2 steps in any elementary cellular automaton:
Complement[Tuples[{0, 1}, 5], Table[Last[CellularAutomaton[i, {{1}, 0}, {2, All}]], {i, 0, 255}]]Properties & Relations (1)
The result of Complement[list1,list2] is sorted and does not contain repeated elements:
Complement[{b, e, d, a, b, c, d}, {b, c}]This returns the same elements, but preserving the original order and multiplicity in list1:
DeleteCases[{b, e, d, a, b, c, d}, Alternatives@@{b, c}]Use DeleteDuplicates to preserve order but remove multiplicity:
DeleteDuplicates[%]See Also
Intersection Union SymmetricDifference UniqueElements Take Select DisjointQ SubsetQ ContainsOnly ContainsAll Diff Diff3
Function Repository: MultisetComplement
Tech Notes
History
Introduced in 1988 (1.0) | Updated in 1996 (3.0)
Text
Wolfram Research (1988), Complement, Wolfram Language function, https://reference.wolfram.com/language/ref/Complement.html (updated 1996).
CMS
Wolfram Language. 1988. "Complement." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 1996. https://reference.wolfram.com/language/ref/Complement.html.
APA
Wolfram Language. (1988). Complement. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/Complement.html
BibTeX
@misc{reference.wolfram_2026_complement, author="Wolfram Research", title="{Complement}", year="1996", howpublished="\url{https://reference.wolfram.com/language/ref/Complement.html}", note=[Accessed: 12-June-2026]}
BibLaTeX
@online{reference.wolfram_2026_complement, organization={Wolfram Research}, title={Complement}, year={1996}, url={https://reference.wolfram.com/language/ref/Complement.html}, note=[Accessed: 12-June-2026]}