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 allclose all

Basic 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)

SameTest  (3)

Use equivalence classes based on absolute value:

Use equivalence classes based on Floor:

Use Total of list elements:

Applications  (4)

Find divisors of 20 that are not also divisors of 12:

Find which triples of digits do not occur in the binary decomposition of 12345:

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

Find which length-5 sequences never occur after 2 steps in any elementary cellular automaton:

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:

Wolfram Research (1988), Complement, Wolfram Language function, https://reference.wolfram.com/language/ref/Complement.html (updated 1996).

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_2024_complement, author="Wolfram Research", title="{Complement}", year="1996", howpublished="\url{https://reference.wolfram.com/language/ref/Complement.html}", note=[Accessed: 06-December-2024 ]}

BibLaTeX

@online{reference.wolfram_2024_complement, organization={Wolfram Research}, title={Complement}, year={1996}, url={https://reference.wolfram.com/language/ref/Complement.html}, note=[Accessed: 06-December-2024 ]}