Harman Patil (Editor)

Complement (set theory)

Updated on
Edit
Like
Comment
Share on FacebookTweet on TwitterShare on LinkedInShare on Reddit
Complement (set theory)

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 BA, 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 BA according to the ISO 31-11 standard. It is sometimes written BA, but this notation is ambiguous, as in some contexts it can be interpreted as the set of all elements ba, where b is taken from B and a from A.

Formally:

B A = { x B x A } .

Examples

  • { 1 , 2 , 3 } { 2 , 3 , 4 } = { 1 } .
  • { 2 , 3 , 4 } { 1 , 2 , 3 } = { 4 } .
  • If R is the set of real numbers and Q is the set of rational numbers, then R Q is the set of irrational numbers.
  • Properties

    Let A, B, and C be three sets. The following identities capture notable properties of relative complements:

  • C ( A B ) = ( C A ) ( C B ) .
  • C ( A B ) = ( C A ) ( C B ) .
  • C ( B A ) = ( C A ) ( C B ) ,with the important special case C ( C A ) = ( C A ) demonstrating that intersection can be expressed using only the relative complement operation.
  • ( B A ) C = ( B C ) A = B ( C A ) .
  • ( B A ) C = ( B C ) ( A C ) .
  • A A = .
  • A = .
  • A = A .
  • 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:

    A = U A .

    Formally:

    A = { x U x A } .

    The absolute complement of A is usually denoted by A . Other notations include A c , A ¯ , A , U A , and A .

    Examples

  • Assume that the universe is the set of integers. If A is the set of odd numbers, then the complement of A is the set of even numbers. If B is the set of multiples of 3, then the complement of B is the set of numbers congruent to 1 or 2 modulo 3.
  • Assume that the universe is the standard 52-card deck. If the set A is the suit of spades, then the complement of A is the union of the suits of clubs, diamonds, and hearts. If the set B is the union of the suits of clubs and diamonds, then the complement of B is the union of the suits of hearts and spades.
  • 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:

    .NET Framework
    b.Except(a);
    C++
    set_difference(a.begin(), a.end(), b.begin(), b.end(), result.begin());
    Clojure
    (clojure.set/difference a b)
    Common Lisp
    set-difference, nset-difference
    F#
    Set.difference a b

    or

    a - b
    Falcon
    diff = a - b
    Haskell
    difference a ba b
    Java
    diff = a.clone();diff.removeAll(b);
    Julia
    setdiff
    Mathematica
    Complement
    MATLAB
    setdiff
    OCaml
    Set.S.diff
    Octave
    setdiff
    PARI/GP
    setminus
    Pascal
    SetDifference := a - b;
    Perl 5
    Perl 6
    PHP
    array_diff($a, $b);
    Prolog
    a(X),+ b(X).
    Python
    diff = a.difference(b)diff = a - b
    R
    setdiff
    Racket
    (set-subtract a b)
    Ruby
    diff = a - b
    Scala
    a.diff(b)

    or

    a -- b
    Smalltalk (Pharo)
    a difference: b
    SQL
    Unix shell
    comm -23 a bgrep -vf b a # less efficient, but works with small unsorted sets

    References

    Complement (set theory) Wikipedia