![]() | ||
In set theory, the complement of a set A refers to elements not in A. The relative complement of A with respect to a set B, also termed the difference of sets A and B, written B ∖ A, is the set of elements in B but not in A. When all sets under consideration are considered to be subsets of a given set U, the absolute complement of A is the set of elements in U but not in A.
Contents
Definition
If A and B are sets, then the relative complement of A in B, also termed the set-theoretic difference of B and A, is the set of elements in B but not in A.
The relative complement of A in B is denoted B ∖ A according to the ISO 31-11 standard. It is sometimes written B − A, but this notation is ambiguous, as in some contexts it can be interpreted as the set of all elements b − a, where b is taken from B and a from A.
Formally:
Examples
Properties
Let A, B, and C be three sets. The following identities capture notable properties of relative complements:
Definition
If A is a set, then the absolute complement of A (or simply the complement of A) is the set of elements not in A. In other words, if U is the universe that contains all the elements under study, and there is no need to mention it because it is obvious and unique, then the absolute complement of A is the relative complement of A in U:
Formally:
The absolute complement of A is usually denoted by
Examples
Properties
Let A and B be two sets in a universe U. The following identities capture important properties of absolute complements:
De Morgan's laws:Complement laws:Involution or double complement law:Relationships between relative and absolute complements:Relationship with set difference:The first two complement laws above show that if A is a non-empty, proper subset of U, then {A, A∁} is a partition of U.
LaTeX notation
In the LaTeX typesetting language, the command setminus
is usually used for rendering a set difference symbol, which is similar to a backslash symbol. When rendered, the setminus
command looks identical to ackslash
except that it has a little more space in front and behind the slash, akin to the LaTeX sequence mathbin{ackslash}
. A variant smallsetminus
is available in the amssymb package.
Complements in various programming languages
Some programming languages allow for manipulation of sets as data structures, using these operators or functions to construct the difference of sets a
and b
:
b.Except(a);
set_difference(a.begin(), a.end(), b.begin(), b.end(), result.begin());
(clojure.set/difference a b)
set-difference, nset-difference
Set.difference a b
or
a - b
diff = a - b
difference a b
a b
diff = a.clone();
diff.removeAll(b);
setdiff
Complement
setdiff
Set.S.diff
setdiff
setminus
SetDifference := a - b;
array_diff($a, $b);
a(X),+ b(X).
diff = a.difference(b)
diff = a - b
setdiff
(set-subtract a b)
diff = a - b
a.diff(b)
or
a -- b
a difference: b
comm -23 a b
grep -vf b a # less efficient, but works with small unsorted sets