Difference between revisions of "Complement (set theory)"

From formulasearchengine
Jump to navigation Jump to search
en>Deon Steyn
(→‎Complements in various programming languages: Correct total and utter misunderstand of SQL set theory)
 
en>Philmac
m (Copyedit (minor))
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==
<!-- Many links redirect to this section:
<!-- Many links redirect to this section:
[[difference (set theory)]], [[difference of two sets]], [[relative complement]], [[set-theoretic difference]], [[set difference]], [[set minus]], [[set subtraction]], [[set theoretic difference]], [[setminus]] -->
[[difference (set theory)]], [[difference of two sets]], [[relative complement]], [[set-theoretic difference]], [[set difference]], [[set minus]], [[set subtraction]], [[set theoretic difference]], [[setminus]] -->


If ''A'' and ''B'' are [[set (mathematics)|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''.
If ''A'' and ''B'' are [[set (mathematics)|sets]], then the '''relative complement''' of ''A'' in ''B'',<ref name="H17">Halmos (1960) p.17</ref> also termed the '''set-theoretic difference''' of ''B'' and ''A'',<ref>Devlin (1979) p.6</ref> is the set of elements in ''B'', but not in ''A''.


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


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'').


Formally
Formally


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


Examples:
Examples:


:*{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}\smallsetminus\mathbb{Q} = \mathbb{J} </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 25: Line 27:
If ''A'', ''B'', and ''C'' are sets, then the following [[identity (mathematics)|identities]] hold:
If ''A'', ''B'', and ''C'' are sets, then the following [[identity (mathematics)|identities]] hold:


:*''C''&nbsp;∖&nbsp;(''A''&nbsp;∩&nbsp;''B'')&nbsp;&nbsp;=&nbsp;&nbsp;(''C''&nbsp;∖&nbsp;''A'')∪(''C''&nbsp;∖&nbsp;''B'')
:* ''C''&nbsp;∖&nbsp;(''A''&nbsp;∩&nbsp;''B'')&nbsp;&nbsp;=&nbsp;&nbsp;(''C''&nbsp;∖&nbsp;''A'')∪(''C''&nbsp;∖&nbsp;''B'')
:*''C''&nbsp;∖&nbsp;(''A''&nbsp;∪&nbsp;''B'')&nbsp;&nbsp;=&nbsp;&nbsp;(''C''&nbsp;∖&nbsp;''A'')∩(''C''&nbsp;∖&nbsp;''B'')
:* ''C''&nbsp;∖&nbsp;(''A''&nbsp;∪&nbsp;''B'')&nbsp;&nbsp;=&nbsp;&nbsp;(''C''&nbsp;∖&nbsp;''A'')∩(''C''&nbsp;∖&nbsp;''B'')
:*''C''&nbsp;∖&nbsp;(''B''&nbsp;∖&nbsp;''A'')&nbsp;&nbsp;=&nbsp;&nbsp;(''A''&nbsp;∩&nbsp;''C'')(''C''&nbsp;∖&nbsp;''B'')
:* ''C''&nbsp;∖&nbsp;(''B''&nbsp;∖&nbsp;''A'')&nbsp;&nbsp;=&nbsp;&nbsp;(''C''&nbsp;∩&nbsp;''A'')∪(''C''&nbsp;∖&nbsp;''B'')
:*(''B''&nbsp;∖&nbsp;''A'')&nbsp;∩&nbsp;''C''&nbsp;&nbsp;=&nbsp;&nbsp;(''B''&nbsp;∩&nbsp;''C'')&nbsp;∖&nbsp;''A''&nbsp;&nbsp;=&nbsp;&nbsp;''B''∩(''C''&nbsp;∖&nbsp;''A'')
 
:*(''B''&nbsp;∖&nbsp;''A'')&nbsp;∪&nbsp;''C''&nbsp;&nbsp;=&nbsp;&nbsp;(''B''&nbsp;∪&nbsp;''C'')&nbsp;∖&nbsp;(''A''&nbsp;∖&nbsp;''C'')
[&nbsp;Alternately written: ''A''&nbsp;∖&nbsp;(''B''&nbsp;∖&nbsp;''C'')&nbsp;&nbsp;=&nbsp;&nbsp;(''A''&nbsp;∖&nbsp;''B'')∪(''A''&nbsp;∩&nbsp;''C'')&nbsp;]
:*''A''&nbsp;∖&nbsp;''A''&nbsp;&nbsp;=&nbsp;&nbsp;Ø
 
:*Ø&nbsp;∖&nbsp;''A''&nbsp;&nbsp;=&nbsp;&nbsp;Ø
:* (''B''&nbsp;∖&nbsp;''A'')&nbsp;∩&nbsp;''C''&nbsp;&nbsp;=&nbsp;&nbsp;(''B''&nbsp;∩&nbsp;''C'')&nbsp;∖&nbsp;''A''&nbsp;&nbsp;=&nbsp;&nbsp;''B''∩(''C''&nbsp;∖&nbsp;''A'')
:*''A''&nbsp;∖&nbsp;Ø&nbsp;&nbsp;=&nbsp;&nbsp;''A''
:* (''B''&nbsp;∖&nbsp;''A'')&nbsp;∪&nbsp;''C''&nbsp;&nbsp;=&nbsp;&nbsp;(''B''&nbsp;∪&nbsp;''C'')&nbsp;∖&nbsp;(''A''&nbsp;∖&nbsp;''C'')
:* ''A''&nbsp;∖&nbsp;''A''&nbsp;&nbsp;=&nbsp;&nbsp;Ø
:* Ø&nbsp;∖&nbsp;''A''&nbsp;&nbsp;=&nbsp;&nbsp;Ø
:* ''A''&nbsp;∖&nbsp;Ø&nbsp;&nbsp;=&nbsp;&nbsp;''A''


==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 '''complement''' of A in U:<br><math>A^c=U \smallsetminus A</math>]]
[[File:Venn1010.svg|250px|thumb|The '''absolute complement''' of A in U:
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''&prime;, 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:
<math>A^c=U \smallsetminus 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:


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


For example, if the universe is the set of [[integer]]s, then the complement of the set of odd numbers is the set of even numbers.
For example, if the universe is the set of [[integer]]s, then the complement of the set of odd numbers is the set of even numbers.
Line 46: Line 53:


If ''A'' and ''B'' are subsets of a [[universe (mathematics)|universe]] '''U''', then the following identities hold:
If ''A'' and ''B'' are subsets of a [[universe (mathematics)|universe]] '''U''', then the following identities hold:
:[[De Morgan's laws]]:
 
::*<math>\left(A \cup B \right)^{c}=A^{c} \cap B^{c} .</math>
: [[De Morgan's laws]]:<ref name="H17" />
::*<math>\left(A \cap B \right)^{c}=A^{c} \cup B^{c} .</math>
::* <math>\left(A \cup B \right)^{c}=A^{c} \cap B^{c} .</math>
:Complement laws:
::* <math>\left(A \cap B \right)^{c}=A^{c} \cup B^{c} .</math>
::*<math>A \cup A^{c} =U .</math>
: Complement laws:<ref name="H17" />
::*<math>A \cap A^{c} =\empty .</math>
::* <math>A \cup A^{c} =U .</math>
::*<math>\empty ^{c} =U.</math>
::* <math>A \cap A^{c} =\empty .</math>
::*<math> U^{c} =\empty.</math>
::* <math>\empty ^{c} =U.</math>
::*<math>\text{If }A\subset B\text{, then }B^{c}\subset A^{c}.</math>
::* <math> U^{c} =\empty.</math>
::* <math>\text{If }A\subset B\text{, then }B^{c}\subset A^{c}.</math>
::*: (this follows from the equivalence of a conditional with its [[contrapositive]])
::*: (this follows from the equivalence of a conditional with its [[contrapositive]])
:[[involution (mathematics)|Involution]] or double complement law:
: [[involution (mathematics)|Involution]] or double complement law:
::*<math>\left(A^{c}\right)^{c}=A.</math>
::* <math>\left(A^{c}\right)^{c}=A.</math>
:Relationships between relative and absolute complements:
: Relationships between relative and absolute complements:
::*''A''&nbsp;∖&nbsp;''B'' = ''A''&nbsp;∩&nbsp;''B''<sup>c</sup>
::* ''A''&nbsp;∖&nbsp;''B'' = ''A''&nbsp;∩&nbsp;''B''<sup>c</sup>
::*(''A''&nbsp;∖&nbsp;''B'')<sup>c</sup> = ''A''<sup>c</sup>&nbsp;∪&nbsp;''B''
::* (''A''&nbsp;∖&nbsp;''B'')<sup>c</sup> = ''A''<sup>c</sup>&nbsp;∪&nbsp;''B''


The first two complement laws above shows that if ''A'' is a non-empty, [[proper subset]] of '''U''', then {''A'', ''A''<sup>c</sup>} is a [[partition of a set|partition]] of '''U'''.
The first two complement laws above shows that if ''A'' is a non-empty, [[proper subset]] of '''U''', then {''A'', ''A''<sup>c</sup>} is a [[partition of a set|partition]] of '''U'''.
Line 68: Line 76:
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> 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 ==
 
Some programming languages allow for manipulation of [[set (computer science)|sets as data structures]], using these operators or functions to construct the difference of sets <code>a</code> and <code>b</code>:
Some programming languages allow for manipulation of [[set (computer science)|sets as data structures]], using these operators or functions to construct the difference of sets <code>a</code> and <code>b</code>:
<!-- please keep in alphabetical order of programming language name -->


;[[SQL]]
; [[.NET Framework]]
:<code> SELECT * FROM A <br /> MINUS <br /> SELECT * FROM B
: <code>a.Except(b);</code>
</code>
 
; [[C++]]
: <code>set_difference(a.begin(), a.end(), b.begin(), b.end(), result.begin());</code>
 
; [[Clojure]]
: <code>(clojure.set/difference a b)</code><ref>[http://richhickey.github.com/clojure/clojure.set-api.html#clojure.set/difference] clojure.set API reference</ref>
 
; [[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>
 
; [[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>
 
; [[Java (programming language)|Java]]
: <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>


;[[Mathematica]]
; [[Mathematica]]
:<code>Complement</code><ref name="Mathematica_set">[http://reference.wolfram.com/mathematica/ref/Complement.html Complement]. ''Mathematica Documentation Center'' for version 6.0, updated in 2008. Accessed on March 7, 2008.</ref>
: <code>Complement</code><ref name="Mathematica_set">[http://reference.wolfram.com/mathematica/ref/Complement.html Complement]. ''Mathematica Documentation Center'' for version 6.0, updated in 2008. Accessed on March 7, 2008.</ref>


;[[MATLAB]]
; [[MATLAB]]
:<code>setdiff</code><ref name="MATLAB_set">[http://www.mathworks.com/access/helpdesk/help/techdoc/ref/setdiff.html Setdiff]. ''MATLAB Function Reference'' for version 7.6, updated in 2008. Accessed on May 19, 2008.</ref>
: <code>setdiff</code><ref name="MATLAB_set">[http://www.mathworks.com/access/helpdesk/help/techdoc/ref/setdiff.html Setdiff]. ''MATLAB Function Reference'' for version 7.6, updated in 2008. Accessed on May 19, 2008.</ref>


;[[MathML]]
; [[OCaml]]
:<code>&lt;apply xmlns="http://www.w3.org/1998/Math/MathML"&gt; &lt;setdiff/&gt; &lt;ci type="set"&gt;A&lt;/ci&gt; &lt;ci type="set"&gt;B&lt;/ci&gt;&lt;/apply&gt;</code>
: <code>Set.S.diff</code><ref name="OCaml_Set_S_diff">[http://caml.inria.fr/pub/docs/manual-ocaml/libref/Set.S.html Set.S (OCaml)].</ref>


;[[Pascal (programming language)|Pascal]]
; [[GNU Octave|Octave]]
:<code>SetDifference := a - b;</code>
: <code>setdiff</code><ref>[http://www.gnu.org/software/octave/doc/interpreter/index.html]. ''GNU Octave Reference Manual''</ref>


;[[Python (programming language)|Python]]
; [[Pascal (programming language)|Pascal]]
:<code>diff = a.difference(b)</code><ref name="Python_set">[http://docs.python.org/lib/types-set.html Set Types -- set, frozenset]. ''Python Library Reference'' release 2.5, updated on September 19, 2006. Accessed on February 13, 2008.</ref>
: <code>SetDifference := a - b;</code>
:<code>diff = a - b</code><ref name="Python_set" />


;[[Java (programming language)|Java]]
; [[Perl 5]]
:<code>diff = a.clone();
: <code>#for perl version >= 5.10</code>
: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>
: <code>@a = grep {not $_ ~~ @b} @a;</code>


;[[Scala (programming language)|Scala]]
; [[Perl 6]]
:<code>diff = a -- b</code><ref name="Scala_set">[http://www.scala-lang.org/api/current scala.collection.Set]. ''Scala Standard Library'' release 2.8.1, Accessed on December 09, 2010.</ref>
: <code>$A ∖ $B</code>
: <code>$A (-) $B # texas version</code>


;[[C++]]
; [[PHP]]
:<code>set_difference(a.begin(), a.end(), b.begin(), b.end(), result.begin());</code>
: <code>array_diff($a, $b);</code><ref>[http://php.net/manual/en/function.array-diff.php PHP: array_diff], PHP Manual</ref>


;[[.NET Framework]]
; [[Prolog]]
:<code>a.Except(b);</code>
: <code>a(X),\+ b(X).</code>


;[[Haskell (programming language)|Haskell]]
; [[Python (programming language)|Python]]
:<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>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 - b</code><ref name="Python_set" />


;[[Common Lisp]]
; [[R (programming language)|R]]
:<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>setdiff</code><ref>[http://cran.r-project.org/doc/manuals/fullrefman.pdf R Reference manual p. 410].</ref>


;[[OCaml]]
; [[Ruby (programming language)|Ruby]]
:<code>Set.S.diff</code><ref name="OCaml_Set_S_diff">[http://caml.inria.fr/pub/docs/manual-ocaml/libref/Set.S.html Set.S (OCaml)].</ref>
: <code>diff = a - b</code><ref>[http://www.ruby-doc.org/core/classes/Array.html Class: Array] Ruby Documentation</ref>


;[[Unix shell]]
; [[Scala (programming language)|Scala]]
:<code>comm -23 a b</code><ref name="Unix_comm">[http://plan9.bell-labs.com/7thEdMan/ comm(1)], Unix Seventh Edition Manual, 1979.</ref>
: <code>diff = a—b</code><ref name="Scala_set">[http://www.scala-lang.org/api/current scala.collection.Set]. ''Scala Standard Library'' release 2.8.1, Accessed on December 09, 2010.</ref>
:<code>grep -vf b a</code> # less efficient, but works with small unsorted sets


;[[PHP]]
; [[Smalltalk (Pharo)]]
:<code>array_diff($a, $b);</code><ref>[http://php.net/manual/en/function.array-diff.php PHP: array_diff], PHP Manual</ref>
: <code>a difference: b</code>


;[[R (programming language)|R]]
; [[SQL]]
:<code>setdiff</code><ref>[http://cran.r-project.org/doc/manuals/fullrefman.pdf R Reference manual p. 410].</ref>
: <code> SELECT * FROM A


;[[Ruby (programming language)|Ruby]]
MINUS
:<code>diff = a - b</code><ref>[http://www.ruby-doc.org/core/classes/Array.html Class: Array] Ruby Documentation</ref>
SELECT * FROM B


;[[Perl]]
</code>
:<code>#for perl version >= 5.10</code>
:<code>@a = grep {not $_ ~~ @b} @a;</code>


;[[Prolog]]
; [[Unix shell]]
:<code>a(X),\+ b(X).</code>
: <code>comm -23 a b</code><ref name="Unix_comm">[http://plan9.bell-labs.com/7thEdMan/ comm(1)], Unix Seventh Edition Manual, 1979.</ref>
: <code>grep -vf b a</code> # less efficient, but works with small unsorted sets


== See also ==
== See also ==
* [[Algebra of sets]]
* [[Algebra of sets]]
* [[Naive set theory]]
* [[Naive set theory]]
Line 139: Line 164:


== References ==
== References ==
<references/>
<references/>
* {{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 }}
== External links ==
* {{MathWorld |title=Complement |id=Complement }}
* {{MathWorld |title=Complement Set |id=ComplementSet }}
{{Set theory}}


{{DEFAULTSORT:Complement (set theory)}}
{{DEFAULTSORT:Complement (set theory)}}
[[Category:Basic concepts in set theory]]
[[Category:Basic concepts in set theory]]
[[Category:Binary operations]]
[[Category:Binary operations]]
[[am:የውጭ ስብስብ]]
[[ar:مجموعة مكملة]]
[[be:Дапаўненне мностваў]]
[[bg:Разлика (теория на множествата)]]
[[ca:Complementari]]
[[cs:Doplněk množiny]]
[[de:Komplement (Mengenlehre)]]
[[es:Complemento de un conjunto]]
[[eo:Komplemento (aroteorio)]]
[[eu:Osagarri (multzo-teoria)]]
[[fr:Complémentaire (théorie des ensembles)]]
[[xal:Немгн]]
[[ko:여집합]]
[[is:Fyllimengi]]
[[it:Insieme complemento]]
[[he:משלים (מתמטיקה)]]
[[nl:Complement (verzamelingenleer)]]
[[ja:差集合]]
[[oc:Ensemble complementari]]
[[pl:Dopełnienie zbioru]]
[[pt:Complementar]]
[[ru:Разность множеств]]
[[sk:Rozdiel množín]]
[[fi:Joukkoerotus]]
[[sv:Komplement]]
[[th:ส่วนเติมเต็ม]]
[[uk:Доповнення множин]]
[[vi:Phần bù]]
[[zh-classical:補集]]
[[zh:补集]]

Revision as of 21:26, 15 January 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.

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′, also the same set often{{ safesubst:#invoke:Unsubst||date=__DATE__ |$B= {{#invoke:Category handler|main}}{{#invoke:Category handler|main}}[citation needed] }} 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 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)[3]
Common Lisp
set-difference, nset-difference[4]
Haskell
a \\ b [5]
Java
diff = a.clone();
diff.removeAll(b);[6]
Mathematica
Complement[7]
MATLAB
setdiff[8]
OCaml
Set.S.diff[9]
Octave
setdiff[10]
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);[11]
Prolog
a(X),\+ b(X).
Python
diff = a.difference(b)[12]
diff = a - b[12]
R
setdiff[13]
Ruby
diff = a - b[14]
Scala
diff = a—b[15]
Smalltalk (Pharo)
a difference: b
SQL
SELECT * FROM A

MINUS SELECT * FROM B

Unix shell
comm -23 a b[16]
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. [1] clojure.set API reference
  4. Common Lisp HyperSpec, Function set-difference, nset-difference. Accessed on September 8, 2009.
  5. Data.Set (Haskell)
  6. Set (Java 2 Platform SE 5.0). JavaTM 2 Platform Standard Edition 5.0 API Specification, updated in 2004. Accessed on February 13, 2008.
  7. Complement. Mathematica Documentation Center for version 6.0, updated in 2008. Accessed on March 7, 2008.
  8. Setdiff. MATLAB Function Reference for version 7.6, updated in 2008. Accessed on May 19, 2008.
  9. Set.S (OCaml).
  10. [2]. GNU Octave Reference Manual
  11. PHP: array_diff, PHP Manual
  12. 12.0 12.1 [3]. Python v2.7.3 documentation. Accessed on January 17, 2013.
  13. R Reference manual p. 410.
  14. Class: Array Ruby Documentation
  15. scala.collection.Set. Scala Standard Library release 2.8.1, Accessed on December 09, 2010.
  16. comm(1), Unix Seventh Edition Manual, 1979.
  • {{#invoke:citation/CS1|citation

|CitationClass=book }}

  • {{#invoke:citation/CS1|citation

|CitationClass=book }}

External links

Template:Set theory