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)
Find which elements in the first list are not in any of the subsequent lists:
Generalizations & Extensions (1)
Complement works with any head, not just List :
Options (3)
Applications (4)
Properties & Relations (1)
The result of Complement [list1,list2] is sorted and does not contain repeated elements:
This returns the same elements, but preserving the original order and multiplicity in list1:
Use DeleteDuplicates to preserve order but remove multiplicity:
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_2025_complement, author="Wolfram Research", title="{Complement}", year="1996", howpublished="\url{https://reference.wolfram.com/language/ref/Complement.html}", note=[Accessed: 17-November-2025]}
BibLaTeX
@online{reference.wolfram_2025_complement, organization={Wolfram Research}, title={Complement}, year={1996}, url={https://reference.wolfram.com/language/ref/Complement.html}, note=[Accessed: 17-November-2025]}