Difference between revisions of "Complement (set theory)"

From formulasearchengine
Jump to navigation Jump to search
en>Philmac
m (Copyedit (minor))
en>FrescoBot
m (Bot: link syntax and minor changes)
 
(One intermediate revision by one other user not shown)
Line 1: Line 1:
In [[set theory]], a '''complement''' of a set ''A'' refers to things not in (that is, things outside of) ''A''. The '''relative complement''' of ''A'' with respect to a set ''B'', 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 all elements in ''U'' but not in ''A''.
In [[set theory]], a '''complement''' of a set ''A'' refers to things not in (that is, things outside of) ''A''. The '''relative complement''' of ''A'' with respect to a set ''B'' 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 all elements in ''U'' but not in ''A''.


== Relative complement ==
== Relative complement ==
Line 9: Line 9:


[[File:Venn0010.svg|250px|thumb|The '''relative complement''' of ''A'' (left circle) in ''B'' (right circle):
[[File:Venn0010.svg|250px|thumb|The '''relative complement''' of ''A'' (left circle) in ''B'' (right circle):
<math>A^c \cap B~~~~=~~~~B \smallsetminus A</math>]]
<math>B \cap A^c~~~~=~~~~B \setminus A</math>]]


The relative complement of ''A'' in ''B'' is denoted {{nowrap|''B'' ∖ ''A''}} according to the [[ISO 31-11#Sets|ISO 31-11 standard]] (sometimes written {{nowrap|''B'' – ''A''}}, but this notation is ambiguous, as in some contexts it can be interpreted as the set of all {{nowrap|''b'' – ''a''}}, where ''b'' is taken from ''B'' and ''a'' from ''A'').
The relative complement of ''A'' in ''B'' is denoted {{nowrap|''B'' ∖ ''A''}} according to the [[ISO 31-11#Sets|ISO 31-11 standard]] (sometimes written {{nowrap|''B'' – ''A''}}, but this notation is ambiguous, as in some contexts it can be interpreted as the set of all {{nowrap|''b'' – ''a''}}, where ''b'' is taken from ''B'' and ''a'' from ''A'').
Line 15: Line 15:
Formally
Formally


: <math>B \smallsetminus A = \{ x\in B \, | \, x \notin A \}. </math>
: <math>B \setminus A = \{ x\in B \, | \, x \notin A \}. </math>


Examples:
Examples:
Line 21: Line 21:
:* {1,2,3}&nbsp;∖&nbsp;{2,3,4}&nbsp;&nbsp;&nbsp;=&nbsp;&nbsp;&nbsp;{1}
:* {1,2,3}&nbsp;∖&nbsp;{2,3,4}&nbsp;&nbsp;&nbsp;=&nbsp;&nbsp;&nbsp;{1}
:* {2,3,4}&nbsp;∖&nbsp;{1,2,3}&nbsp;&nbsp;&nbsp;=&nbsp;&nbsp;&nbsp;{4}
:* {2,3,4}&nbsp;∖&nbsp;{1,2,3}&nbsp;&nbsp;&nbsp;=&nbsp;&nbsp;&nbsp;{4}
:* If <math>\mathbb{R}</math> is the set of [[real number]]s and <math>\mathbb{Q}</math> is the set of [[rational number]]s, then <math> \mathbb{R}\smallsetminus\mathbb{Q} = \mathbb{J} </math> is the set of [[irrational number]]s.
:* If <math>\mathbb{R}</math> is the set of [[real number]]s and <math>\mathbb{Q}</math> is the set of [[rational number]]s, then <math> \mathbb{R}\setminus\mathbb{Q} = \mathbb{I} </math> is the set of [[irrational number]]s.


The following lists some notable properties of relative complements in relation to the set-theoretic [[operation (mathematics)|operations]] of [[union (set theory)|union]] and [[intersection (set theory)|intersection]].
The following lists some notable properties of relative complements in relation to the set-theoretic [[operation (mathematics)|operations]] of [[union (set theory)|union]] and [[intersection (set theory)|intersection]].
Line 41: Line 41:
==Absolute complement==<!-- This section is linked from [[Bayes' theorem]] and [[absolute set complement]] -->
==Absolute complement==<!-- This section is linked from [[Bayes' theorem]] and [[absolute set complement]] -->


[[File:Venn1010.svg|250px|thumb|The '''absolute complement''' of A in U:
[[File:Venn1010.svg|250px|thumb|The '''absolute complement''' of <math>A</math> in <math>U</math>:
<math>A^c=U \smallsetminus A</math>]]
<math>A^c=U \setminus A</math>]]


If a [[universe (mathematics)|universe]] '''U''' is defined, then the relative complement of ''A'' in '''U''' is called the '''absolute complement''' (or simply '''complement''') of ''A'', and is denoted by ''A''<sup>c</sup> or sometimes ''A''′, also the same set often{{citation needed|date=August 2012}} is denoted by <MATH>\complement_U A</MATH> or <MATH>\complement A</MATH> if '''U''' is fixed, that is:
If a [[universe (mathematics)|universe]] '''U''' is defined, then the relative complement of ''A'' in '''U''' is called the '''absolute complement''' (or simply '''complement''') of ''A'', and is denoted by ''A''<sup>c</sup> or sometimes ''A''′. The same set often<ref name="Bou">Bourbaki p. E II.6</ref> is denoted by <math>\complement_U A</math> or <math>\complement A</math> if '''U''' is fixed, that is:


: ''A''<sup>c</sup>&nbsp;&nbsp;=&nbsp;'''U'''&nbsp;∖&nbsp;''A''.
: ''A''<sup>c</sup>&nbsp;&nbsp;=&nbsp;'''U'''&nbsp;∖&nbsp;''A''.
Line 74: Line 74:
== Notation ==
== Notation ==


In the [[LaTeX]] typesetting language, the command <code>\setminus</code> is usually used for rendering a set difference symbol, which is similar to a [[backslash]] symbol. When rendered the <code>\setminus</code> command looks identical to <code>\backslash</code> except that it has a little more space in front and behind the slash, akin to the LaTeX sequence <code>\mathbin{\backslash}</code>. A variant <code>\smallsetminus</code> is available in the amssymb package.
In the [[LaTeX]] typesetting language, the command <code>\setminus</code><ref name="The Comprehensive LaTeX Symbol List">[http://ctan.unsw.edu.au/info/symbols/comprehensive/symbols-a4.pdf] The Comprehensive LaTeX Symbol List</ref> is usually used for rendering a set difference symbol, which is similar to a [[backslash]] symbol. When rendered the <code>\setminus</code> command looks identical to <code>\backslash</code> except that it has a little more space in front and behind the slash, akin to the LaTeX sequence <code>\mathbin{\backslash}</code>. A variant <code>\smallsetminus</code> is available in the amssymb package.


== Complements in various programming languages ==
== Complements in various programming languages ==
Line 92: Line 92:
; [[Common Lisp]]
; [[Common Lisp]]
: <code>set-difference, nset-difference</code><ref name="CLHS_set-difference">[http://www.lispworks.com/documentation/HyperSpec/Body/f_set_di.htm Common Lisp HyperSpec, Function set-difference, nset-difference].  Accessed on September 8, 2009.</ref>
: <code>set-difference, nset-difference</code><ref name="CLHS_set-difference">[http://www.lispworks.com/documentation/HyperSpec/Body/f_set_di.htm Common Lisp HyperSpec, Function set-difference, nset-difference].  Accessed on September 8, 2009.</ref>
; [[Falcon (programming language)| Falcon]]
: <code>diff = a - b</code><ref name="Falcon Array Subtraction">[http://falconpl.org/index.ftd?page_id=sitewiki&prj_id=_falcon_site&sid=wiki&pwid=Survival%20Guide&wid=Survival%3ABasic+Structures#Arrays, Array subtraction, data structures]. Accessed on July 28, 2014.</ref>


; [[Haskell (programming language)|Haskell]]
; [[Haskell (programming language)|Haskell]]
: <code>a \\ b</code> <ref name="Data.Set">[http://haskell.org/ghc/docs/latest/html/libraries/containers/Data-Set.html Data.Set (Haskell)]</ref>
: <code>difference a b</code>
: <code>a \\ b</code><ref name="Data.Set">[http://haskell.org/ghc/docs/latest/html/libraries/containers/Data-Set.html Data.Set (Haskell)]</ref>


; [[Java (programming language)|Java]]
; [[Java (programming language)|Java]]
: <code>diff = a.clone();
: <code>diff = a.clone();
: diff.removeAll(b);</code><ref name="J2SE_Set">[http://java.sun.com/j2se/1.5.0/docs/api/java/util/Set.html Set (Java 2 Platform SE 5.0)]. ''JavaTM 2 Platform Standard Edition 5.0 API Specification'', updated in 2004. Accessed on February 13, 2008.</ref>
: diff.removeAll(b);</code><ref name="J2SE_Set">[http://java.sun.com/j2se/1.5.0/docs/api/java/util/Set.html Set (Java 2 Platform SE 5.0)]. ''JavaTM 2 Platform Standard Edition 5.0 API Specification'', updated in 2004. Accessed on February 13, 2008.</ref>
; [[Julia_(programming_language)|Julia]]
: <code>setdiff</code><ref name="Julia_set">[http://julia.readthedocs.org/en/latest/stdlib/base/#set-like-collections]. The Standard Library--Julia Language documentation. Accessed on September 24, 2014</ref>


; [[Mathematica]]
; [[Mathematica]]
Line 130: Line 137:


; [[Python (programming language)|Python]]
; [[Python (programming language)|Python]]
: <code>diff = a.difference(b)</code><ref name="Python_set">[http://docs.python.org/2/library/stdtypes.html?highlight=difference#set.difference]. ''Python v2.7.3 documentation''. Accessed on January 17, 2013.</ref>
: <code>diff = a.difference(b)</code><ref name="Python_set">[https://docs.python.org/2/library/stdtypes.html?highlight=difference#set.difference]. ''Python v2.7.3 documentation''. Accessed on January 17, 2013.</ref>
: <code>diff = a - b</code><ref name="Python_set" />
: <code>diff = a - b</code><ref name="Python_set" />


Line 148: Line 155:
: <code> SELECT * FROM A
: <code> SELECT * FROM A


MINUS
EXCEPT
SELECT * FROM B
SELECT * FROM B


Line 169: Line 176:
* {{cite book | last=Halmos | first=Paul R. | authorlink=Paul Halmos | title=Naive set theory | series=The University Series in Undergraduate Mathematics | publisher=van Nostrand Company | year=1960 | zbl=0087.04403 }}
* {{cite book | last=Halmos | first=Paul R. | authorlink=Paul Halmos | title=Naive set theory | series=The University Series in Undergraduate Mathematics | publisher=van Nostrand Company | year=1960 | zbl=0087.04403 }}
* {{cite book | last=Devlin | first=Keith J. | authorlink=Keith Devlin | title=Fundamentals of contemporary set theory | series=Universitext | publisher=[[Springer-Verlag]] | year=1979 | isbn=0-387-90441-7 | zbl=0407.04003 }}
* {{cite book | last=Devlin | first=Keith J. | authorlink=Keith Devlin | title=Fundamentals of contemporary set theory | series=Universitext | publisher=[[Springer-Verlag]] | year=1979 | isbn=0-387-90441-7 | zbl=0407.04003 }}
*{{cite book
| last=Bourbaki
| first=N.
| authorlink=Nicolas Bourbaki
| title=Théorie des ensembles
| publisher=Hermann
| place=Paris
| year=1970
| isbn=978-3-540-34034-8
| language=french}}


== External links ==
== External links ==

Latest revision as of 16:47, 23 December 2014

In set theory, a complement of a set A refers to things not in (that is, things outside of) A. The relative complement of A with respect to a set B 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 all elements in U but not in A.

Relative complement

If A and B are sets, then the relative complement of A in B,[1] also termed the set-theoretic difference of B and A,[2] is the set of elements in B, but not in A.

File:Venn0010.svg
The relative complement of A (left circle) in B (right circle):

The relative complement of A in B is denoted BA according to the ISO 31-11 standard (sometimes written BA, but this notation is ambiguous, as in some contexts it can be interpreted as the set of all ba, where b is taken from B and a from A).

Formally

Examples:

The following lists some notable properties of relative complements in relation to the set-theoretic operations of union and intersection.

If A, B, and C are sets, then the following identities hold:

  • C ∖ (A ∩ B)  =  (C ∖ A)∪(C ∖ B)
  • C ∖ (A ∪ B)  =  (C ∖ A)∩(C ∖ B)
  • C ∖ (B ∖ A)  =  (C ∩ A)∪(C ∖ B)

[ Alternately written: A ∖ (B ∖ C)  =  (A ∖ B)∪(A ∩ C) ]

  • (B ∖ A) ∩ C  =  (B ∩ C) ∖ A  =  B∩(C ∖ A)
  • (B ∖ A) ∪ C  =  (B ∪ C) ∖ (A ∖ C)
  • A ∖ A  =  Ø
  • Ø ∖ A  =  Ø
  • A ∖ Ø  =  A

Absolute complement

If a universe U is defined, then the relative complement of A in U is called the absolute complement (or simply complement) of A, and is denoted by Ac or sometimes A′. The same set often[3] is denoted by or if U is fixed, that is:

Ac  = U ∖ A.

For example, if the universe is the set of integers, then the complement of the set of odd numbers is the set of even numbers.

The following lists some important properties of absolute complements in relation to the set-theoretic operations of union and intersection.

If A and B are subsets of a universe U, then the following identities hold:

De Morgan's laws:[1]
Complement laws:[1]
Involution or double complement law:
Relationships between relative and absolute complements:
  • A ∖ B = A ∩ Bc
  • (A ∖ B)c = Ac ∪ B

The first two complement laws above shows that if A is a non-empty, proper subset of U, then {A, Ac} is a partition of U.

Notation

In the LaTeX typesetting language, the command \setminus[4] is usually used for rendering a set difference symbol, which is similar to a backslash symbol. When rendered the \setminus command looks identical to \backslash except that it has a little more space in front and behind the slash, akin to the LaTeX sequence \mathbin{\backslash}. 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
a.Except(b);
C++
set_difference(a.begin(), a.end(), b.begin(), b.end(), result.begin());
Clojure
(clojure.set/difference a b)[5]
Common Lisp
set-difference, nset-difference[6]
Falcon
diff = a - b[7]
Haskell
difference a b
a \\ b[8]
Java
diff = a.clone();
diff.removeAll(b);[9]
Julia
setdiff[10]
Mathematica
Complement[11]
MATLAB
setdiff[12]
OCaml
Set.S.diff[13]
Octave
setdiff[14]
Pascal
SetDifference := a - b;
Perl 5
#for perl version >= 5.10
@a = grep {not $_ ~~ @b} @a;
Perl 6
$A ∖ $B
$A (-) $B # texas version
PHP
array_diff($a, $b);[15]
Prolog
a(X),\+ b(X).
Python
diff = a.difference(b)[16]
diff = a - b[16]
R
setdiff[17]
Ruby
diff = a - b[18]
Scala
diff = a—b[19]
Smalltalk (Pharo)
a difference: b
SQL
SELECT * FROM A

EXCEPT SELECT * FROM B

Unix shell
comm -23 a b[20]
grep -vf b a # less efficient, but works with small unsorted sets

See also

References

  1. 1.0 1.1 1.2 Halmos (1960) p.17
  2. Devlin (1979) p.6
  3. Bourbaki p. E II.6
  4. [1] The Comprehensive LaTeX Symbol List
  5. [2] clojure.set API reference
  6. Common Lisp HyperSpec, Function set-difference, nset-difference. Accessed on September 8, 2009.
  7. Array subtraction, data structures. Accessed on July 28, 2014.
  8. Data.Set (Haskell)
  9. Set (Java 2 Platform SE 5.0). JavaTM 2 Platform Standard Edition 5.0 API Specification, updated in 2004. Accessed on February 13, 2008.
  10. [3]. The Standard Library--Julia Language documentation. Accessed on September 24, 2014
  11. Complement. Mathematica Documentation Center for version 6.0, updated in 2008. Accessed on March 7, 2008.
  12. Setdiff. MATLAB Function Reference for version 7.6, updated in 2008. Accessed on May 19, 2008.
  13. Set.S (OCaml).
  14. [4]. GNU Octave Reference Manual
  15. PHP: array_diff, PHP Manual
  16. 16.0 16.1 [5]. Python v2.7.3 documentation. Accessed on January 17, 2013.
  17. R Reference manual p. 410.
  18. Class: Array Ruby Documentation
  19. scala.collection.Set. Scala Standard Library release 2.8.1, Accessed on December 09, 2010.
  20. comm(1), Unix Seventh Edition Manual, 1979.
  • {{#invoke:citation/CS1|citation

|CitationClass=book }}

  • {{#invoke:citation/CS1|citation

|CitationClass=book }}

  • {{#invoke:citation/CS1|citation

|CitationClass=book }}

External links

Template:Set theory