# Set (mathematics)

In mathematics, a set is a collection of different things; these things are called elements or members of the set and are typically mathematical objects of any kind: numbers, symbols, points in space, lines, other geometrical shapes, variables, or even other sets. A set may be finite or infinite, depending whether the number of its elements is finite or not. There is a unique set with no elements, called the empty set; a set with a single element is a singleton.
Sets are ubiquitous in modern mathematics. Indeed, set theory, more specifically Zermelo–Fraenkel set theory, has been the standard way to provide rigorous foundations for all branches of mathematics since the first half of the 20th century.

## Context

Before the end of the 19th century, sets were not studied specifically, and were not clearly distinguished from sequences. Most mathematicians considered infinity as potential—meaning that it is the result of an endless process—and were reluctant to consider infinite sets, that is sets whose number of members is not a natural number. In particular, a line was not considered as the set of its points, but as a locus where points may be located.
The mathematical study of sets began with Georg Cantor (1845–1918). This provided some counterintuitive facts and paradoxes. For example, the number line has an infinite number of elements that is strictly larger than the infinite number of natural numbers, and any line segment has the same number of elements as the whole space. Also, Russell's paradox implies that the phrase "the set of all sets" is self-contradictory.
Together with other counterintuitive results, this led to the foundational crisis of mathematics, which was eventually resolved with the general adoption of Zermelo–Fraenkel set theory as a robust foundation of set theory and all mathematics.
Meanwhile, sets started to be widely used in all mathematics. In particular, algebraic structures and mathematical spaces are typically defined in terms of sets. Also, many older mathematical results are restated in terms of sets. For example, Euclid's theorem is often stated as "the set of the prime numbers is infinite". This wide use of sets in mathematics was prophesied by David Hilbert when saying: "No one will drive us from the paradise which Cantor created for us."
Generally, the common usage of sets in mathematics does not requires the full power of Zermelo–Fraenkel set theory. In mathematical practice, sets can be manipulated independently of the logical framework of this theory.
The object of this article is to summarize the manipulation rules and properties of sets that are commonly used in mathematics, without reference to any logical framework.

## Definitions

In mathematics, a set is a collection of different things. These things are called elements or members of the set and are typically mathematical objects of any kind such as numbers, symbols, points in space, lines, other geometrical shapes, variables, functions, or even other sets. A set may also be called a collection or family, especially when its elements are themselves sets; this may avoid the confusion between the set and its members, and may make reading easier. A set may be specified either by listing its elements or by a property that characterizes its elements, such as for the set of the prime numbers or the set of all students in a given class.
If ⁠$x$⁠ is an element of a set ⁠$S$⁠, one says that ⁠$x$⁠ belongs to ⁠$S$⁠ or is in ⁠$S$⁠, and this is written as ⁠$x\in S$⁠. The statement "⁠$y$⁠ is not in ⁠$S\,$⁠" is written as ⁠$y\not \in S$⁠, which can also be read as "y is not in B". For example, if ⁠$\mathbb {Z}$⁠ is the set of the integers, one has ⁠$-3\in \mathbb {Z}$⁠ and ⁠$1.5\not \in \mathbb {Z}$⁠. Each set is uniquely characterized by its elements. In particular, two sets that have precisely the same elements are equal (they are the same set). This property, called extensionality, can be written in formula as $A=B\iff \forall x\;(x\in A\iff x\in B).$This implies that there is only one set with no element, the empty set (or null set) that is denoted ⁠$\varnothing ,\emptyset$⁠, or ⁠$\{\,\}.$⁠ A singleton is a set with exactly one element. If ⁠$x$⁠ is this element, the singleton is denoted ⁠$\{x\}.$⁠ If ⁠$x$⁠ is itself a set, it must not be confused with ⁠$\{x\}.$⁠ For example, ⁠$\emptyset$⁠ is a set with no elements, while ⁠$\{\emptyset \}$⁠ is a singleton with ⁠$\emptyset$⁠ as its unique element.
A set is finite if there exists a natural number ⁠$n$⁠ such that the ⁠$n$⁠ first natural numbers can be put in one to one correspondence with the elements of the set. In this case, one says that ⁠$n$⁠ is the number of elements of the set. A set is infinite if such an ⁠$n$⁠ does not exist. The empty set is a finite set with ⁠$0$⁠ elements.
The natural numbers form an infinite set, commonly denoted ⁠$\mathbb {N}$⁠. Other examples of infinite sets include number sets that contain the natural numbers, real vector spaces, curves and most sorts of spaces.

## Specifying a set

Extentionality implies that for specifying a set, one has either to list its elements or to provide a property that uniquely characterizes the set elements.

### Roster notation

Roster or enumeration notation is a notation introduced by Ernst Zermelo in 1908 that specifies a set by listing its elements between braces, separated by commas. For example, one knows that $\{4,2,1,3\}$ and $\{{\text{blue, white, red}}\}$ denote sets and not tuples because of the enclosing braces.
Above notations ⁠$\{\,\}$⁠ and ⁠$\{x\}$⁠ for the empty set and for a singleton are examples of roster notation.
For a set, all that matters is whether each element is in it or not; so, the set is not changed if one changes the order or repeat some elements. So, one has, for example, $\{1,2,3,4\}=\{4,2,1,3\}=\{4,2,4,3,1,3\}.$
When there is a clear pattern for generating all set elements, one can use ellipses for abbreviating the notation, such as in $\{1,2,3,\ldots ,1000\}$ for the positive integers not greater than ⁠$1000$⁠.
Ellipses allow also expanding roster notation to some infinite sets. For example, the set of all integers can be denoted as $\{\ldots ,-3,-2,-1,0,1,2,3,\ldots \}$ or $\{0,1,-1,2,-2,3,-3,\ldots \}.$

### Set-builder notation

Set-builder notation specifies a set as being the set of all elements that satisfy some logical formula. More precisely, if ⁠$P(x)$⁠ is a logical formula depending on a variable ⁠$x$⁠, which evaluates to true or false depending on the value of ⁠$x$⁠, then $\{x\mid P(x)\}$ or $\{x:P(x)\}$ denotes the set of all ⁠$x$⁠ for which ⁠$P(x)$⁠ is true. For example, a set F can be specified as follows: $F=\{n\mid n{\text{ is an integer, and }}0\leq n\leq 19\}.$ In this notation, the vertical bar "|" is read as "such that", and the whole formula can be read as "F is the set of all n such that n is an integer in the range from 0 to 19 inclusive".
Some logical formulas, such as ⁠$\color {red}{S{\text{ is a set}}}$⁠ or ⁠$\color {red}{S{\text{ is a set and }}S\not \in S}$⁠ cannot be used in set-builder notation because there is no set for which the elements are characterized by the formula. There are several ways for avoiding the problem. One may prove that the formula defines a set; this is often almost immediate, but may be very difficult.
One may also introduce a larger set ⁠$U$⁠ that must contain all elements of the specified set, and write the notation as $\{x\mid x\in U{\text{ and ...}}\}$ or $\{x\in U\mid {\text{ ...}}\}.$
One may also define ⁠$U$⁠ once for all and take the convention that every variable that appears on the left of the vertical bat of the notation represents an element of ⁠$U$⁠. This amounts to say that ⁠$x\in U$⁠ is implicit in set-builder notation. In this case, ⁠$U$⁠ is often called the domain of discourse or a universe.
For example, with the convention that a lower case Latin letter may represent a real number and nothing else, the expression $\{x\mid x\not \in \mathbb {Q} \}$ is an abbreviation of $\{x\in \mathbb {R} \mid x\not \in \mathbb {Q} \},$ which defines the irrational numbers.

## Subsets

A subset of a set ⁠$B$⁠ is a set ⁠$A$⁠ such that every element of ⁠$A$⁠ is also an element of ⁠$B$⁠. If ⁠$A$⁠ is a subset of ⁠$B$⁠, one says commonly that ⁠$A$⁠ is contained in ⁠$B$⁠, ⁠$B$⁠ contains ⁠$A$⁠, or ⁠$B$⁠ is a superset of ⁠$A$⁠. This denoted ⁠$A\subseteq B$⁠ and ⁠$B\supseteq A$⁠. However many authors use ⁠$A\subset B$⁠ and ⁠$B\supset A$⁠ instead. The definition of a subset can be expressed in notation as $A\subseteq B\quad {\text{if and only if}}\quad \forall x\;(x\in A\implies x\in B).$
A set ⁠$A$⁠ is a proper subset of a set ⁠$B$⁠ if ⁠$A\subseteq B$⁠ and ⁠$A\neq B$⁠. This is denoted ⁠$A\subset B$⁠ and ⁠$B\supset A$⁠. When ⁠$A\subset B$⁠ is used for the subset relation, or in case of possible ambiguity, one uses commonly ⁠$A\subsetneq B$⁠ and ⁠$B\supsetneq A$⁠.
The relationship between sets established by ⊆ is called inclusion or containment. Equality between sets can be expressed in terms of subsets. Two sets are equal if and only if they contain each other: that is, A ⊆ B and B ⊆ A is equivalent to A = B. The empty set is a subset of every set: ∅ ⊆ A.
Examples:
* The set of all humans is a proper subset of the set of all mammals.
* {1, 3} ⊂ {1, 2, 3, 4}.
* {1, 2, 3, 4} ⊆ {1, 2, 3, 4}

## Basic operations

There are several standard operations that produce new sets from given sets, in the same way as addition and multiplication produce new numbers from given numbers. The operations that are considered in this section are those such that all elements of the produced sets belong to a previously defined set. These operations are commonly illustrated with Venn diagrams.
The main basic operations on sets are the following ones.

### Intersection

The intersection of two sets ⁠$A$⁠ and ⁠$B$⁠ is a set denoted ⁠$A\cap B$⁠ whose elements are those elements that belong to both ⁠$A$⁠ and ⁠$B$⁠. That is, $A\cap B=\{x\mid x\in A\land x\in B\},$ where ⁠$\land$⁠ denotes the logical and.
Intersection is associative and commutative; this means that for proceeding a sequence of intersections, one may proceed in any order, without the need of parentheses for specifying the order of operations. Intersection has no general identity element. However, if one restricts intersection to the subsets of a given set ⁠$U$⁠, intersection has ⁠$U$⁠ as identity element.
If ⁠${\mathcal {S}}$⁠ is a nonempty set of sets, its intersection, denoted ⋂$_{A∈S}$A, {\textstyle \bigcap _{A\in {\mathcal {S}}}A, } is the set whose elements are those elements that belong to all sets in ⁠${\mathcal {S}}$⁠. That is, $\bigcap _{A\in {\mathcal {S}}}A=\{x\mid (\forall A\in {\mathcal {S}})\;x\in A\}.$
These two definitions of the intersection coincide when ⁠${\mathcal {S}}$⁠ has two elements.

### Union

The union of two sets ⁠$A$⁠ and ⁠$B$⁠ is a set denoted ⁠$A\cup B$⁠ whose elements are those elements that belong to ⁠$A$⁠ or ⁠$B$⁠, or both. That is, $A\cup B=\{x\mid x\in A\lor x\in B\},$ where ⁠$\lor$⁠ denotes the logical or.
Union is associative and commutative; this means that for proceeding a sequence of intersections, one may proceed in any order, without the need of parentheses for specifying the order of operations. The empty set is an identity element for the union operation.
If ⁠${\mathcal {S}}$⁠ is a set of sets, its union, denoted ⋃$_{A∈S}$A, {\textstyle \bigcup _{A\in {\mathcal {S}}}A, } is the set whose elements are those elements that belong to at least one set in ⁠${\mathcal {S}}$⁠. That is, $\bigcup _{A\in {\mathcal {S}}}A=\{x\mid (\exists A\in {\mathcal {S}})\;x\in A\}.$
These two definitions of the union coincide when ⁠${\mathcal {S}}$⁠ has two elements.

### Set difference

The set difference of two sets ⁠$A$⁠ and ⁠$B$⁠, is a set, denoted ⁠$A\setminus B$⁠ or ⁠$A-B$⁠, whose elements are those elements that belong to ⁠$A$⁠, but not to ⁠$B$⁠. That is, $A\setminus B=\{x\mid x\in A\land x\not \in B\},$ where ⁠$\land$⁠ denotes the logical and.
When ⁠$B\subseteq A$⁠ the difference ⁠$A\setminus B$⁠ is also called the complement of ⁠$B$⁠ in ⁠$A$⁠. When all sets that are considered are subsets of a fixed universal set ⁠$U$⁠, the complement ⁠$U\setminus A$⁠ is often called the absolute complement of ⁠$A$⁠.
The symmetric difference of two sets ⁠$A$⁠ and ⁠$B$⁠, denoted ⁠$A\,\Delta \,B$⁠, is the set of those elements that belong to A or B but not to both: $A\,\Delta \,B=(A\setminus B)\cup (B\setminus A).$

### Algebra of subsets

The set of all subsets of a set ⁠$U$⁠ is called the powerset of ⁠$U$⁠, often denoted ⁠${\mathcal {P}}(U)$⁠. The powerset is an algebraic structure whose main operations are union, intersection, set difference, symmetric difference and absolute complement (complement in ⁠$U$⁠).
The powerset is a Boolean ring that has the symmetric difference as addition, the intersection as multiplication, the emptyset as additive identity, ⁠$U$⁠ as multiplicative identity, and complement as additive inverse.
The powerset is also a Boolean algebra for which the join ⁠$\lor$⁠ is the union ⁠$\cup$⁠, the meet ⁠$\land$⁠ is the intersection ⁠$\cap$⁠, and the negation is the set complement.
As every Boolean algebra, the power set is also a partially ordered set for set inclusion. It is also a complete lattice.
The axioms of these structures induce many identities relating subsets, which are detailed in the linked articles.

## Functions

A function from a set A—the domain—to a set B—the codomain—is a rule that assigns to each element of A a unique element of B. For example, the square function maps every real number x to x$^2$. Functions can be formally defined in terms of sets by means of their graph, which are subsets of the Cartesian product (see below) of the domain and the codomain.
Functions are fundamental for set theory, and examples are given in following sections.

### Indexed families

Intuitively, an indexed family is a set whose elements are labelled with the elements of another set, the index set. These labels allow the same element to occur several times in the family.
Formally, an indexed family is a function that has the index set as its domain. Generally, the usual functional notation ⁠$f(x)$⁠ is not used for indexed families. Instead, the element of the index set is written as a subscript of the name of the family, such as in ⁠$a_{i}$⁠.
When the index set is ⁠$\{1,2\}$⁠, an indexed family is called an ordered pair. When the index set is the set of the ⁠$n$⁠ first natural numbers, an indexed family is called an ⁠$n$⁠-tuple. When the index set is the set of all natural numbers an indexed family is called a sequence.
In all these cases, the natural order of the natural numbers allows omitting indices for explicit indexed families. For example, ⁠$(b,2,b)$⁠ denotes the 3-tuple ⁠$A$⁠ such that ⁠$A_{1}=b,A_{2}=2,A_{3}=b$⁠.
The above notations ⋃$_{A∈S}$A{\textstyle \bigcup _{A\in {\mathcal {S}}}A} and ⋂$_{A∈S}$A{\textstyle \bigcap _{A\in {\mathcal {S}}}A} are commonly replaced with a notation involving indexed families, namely $\bigcup _{i\in {\mathcal {I}}}A_{i}=\{x\mid (\exists i\in {\mathcal {I}})\;x\in A_{i}\}$ and $\bigcap _{i\in {\mathcal {I}}}A_{i}=\{x\mid (\forall i\in {\mathcal {I}})\;x\in A_{i}\}.$
The formulas of the above sections are special cases of the formulas for indexed families, where ⁠${\mathcal {S}}={\mathcal {I}}$⁠ and ⁠$i=A=A_{i}$⁠. The formulas remain correct, even in the case where ⁠$A_{i}=A_{j}$⁠ for some ⁠$i\neq j$⁠, since ⁠$A=A\cup A=A\cap A.$⁠

## External operations

In § Basic operations, all elements of sets produced by set operations belong to previously defined sets. In this section, other set operations are considered, which produce sets whose elements can be outside all previously considered sets. These operations are Cartesian product, disjoint union, set exponentiation and power set.

### Cartesian product

The Cartesian product of two sets has already be used for defining functions.
Given two sets ⁠$A_{1}$⁠ and ⁠$A_{2}$⁠, their Cartesian product, denoted ⁠$A_{1}\times A_{2}$⁠ is the set formed by all ordered pairs ⁠$(a_{1},a_{2})$⁠ such that ⁠$a_{1}\in A_{1}$⁠ and ⁠$a_{i}\in A_{1}$⁠; that is, $A_{1}\times A_{2}=\{(a_{1},a_{2})\mid a_{1}\in A_{1}\land a_{2}\in A_{2}\}.$
This definition does not supposes that the two sets are different. In particular, $A\times A=\{(a_{1},a_{2})\mid a_{1}\in A\land a_{2}\in A\}.$
Since this definition involves a pair of indices (1,2), it generalizes straightforwardly to the Cartesian product or direct product of any indexed family of sets: $\prod _{i\in {\mathcal {I}}}A_{i}=\{(a_{i})_{i\in {\mathcal {I}}}\mid (\forall i\in {\mathcal {I}})\;a_{i}\in A_{i}\}.$ That is, the elements of the Cartesian product of a family of sets are all families of elements such that each one belongs to the set of the same index. The fact that, for every indexed family of nonempty sets, the Cartesian product is a nonempty set is insured by the axiom of choice.

## Applications

Sets are ubiquitous in modern mathematics. For example, structures in abstract algebra, such as groups, fields and rings, are sets closed under one or more operations.
One of the main applications of naive set theory is in the construction of relations. A relation from a domain A to a codomain B is a subset of the Cartesian product A × B. For example, considering the set S = {rock, paper, scissors} of shapes in the game of the same name, the relation "beats" from S to S is the set B = {(scissors,paper), (paper,rock), (rock,scissors)}; thus x beats y in the game if the pair (x,y) is a member of B. Another example is the set F of all pairs (x, x$^2$), where x is real. This relation is a subset of R × R, because the set of all squares is subset of the set of all real numbers. Since for every x in R, one and only one pair (x,...) is found in F, it is called a function. In functional notation, this relation can be written as F(x) = x$^2$.

## Euler and Venn diagrams

An Euler diagram is a graphical representation of a collection of sets; each set is depicted as a planar region enclosed by a loop, with its elements inside. If A is a subset of B, then the region representing A is completely inside the region representing B. If two sets have no elements in common, the regions do not overlap.
A Venn diagram, in contrast, is a graphical representation of n sets in which the n loops divide the plane into 2$^n$ zones such that for each way of selecting some of the n sets (possibly all or none), there is a zone for the elements that belong to all the selected sets and none of the others. For example, if the sets are A, B, and C, there should be a zone for the elements that are inside A and C and outside B (even if such elements do not exist).

## Cardinality

The cardinality of a set S, denoted |S|, is the number of members of S. For example, if B = {blue, white, red}, then |B| = 3. Repeated members in roster notation are not counted, so |{blue, white, red, blue, white}| = 3, too.
More formally, two sets share the same cardinality if there exists a bijection between them.
The cardinality of the empty set is zero.

### Infinite sets and infinite cardinality

The list of elements of some sets is endless, or infinite. For example, the set $\mathbb {N}$ of natural numbers is infinite. In fact, all the special sets of numbers mentioned in the section above are infinite. An infinite set has an infinite cardinality.
Some infinite cardinalities are greater than others. Arguably one of the most significant results from set theory is that the set of real numbers has greater cardinality than the set of natural numbers. Sets with cardinality less than or equal to that of $\mathbb {N}$ are called countable sets; these are either finite sets or countably infinite sets (sets of the same cardinality as ⁠$\mathbb {N}$⁠); some authors use "countable" to mean "countably infinite". Sets with cardinality strictly greater than that of $\mathbb {N}$ are called uncountable sets.
However, it can be shown that the cardinality of a straight line (i.e., the number of points on a line) is the same as the cardinality of any segment of that line, of the entire plane, and indeed of any finite-dimensional Euclidean space.

### The continuum hypothesis

The continuum hypothesis, formulated by Georg Cantor in 1878, is the statement that there is no set with cardinality strictly between the cardinality of the natural numbers and the cardinality of a straight line. In 1963, Paul Cohen proved that the continuum hypothesis is independent of the axiom system ZFC consisting of Zermelo–Fraenkel set theory with the axiom of choice. (ZFC is the most widely-studied version of axiomatic set theory.)

## Power sets

The power set of a set S is the set of all subsets of S. The empty set and S itself are elements of the power set of S, because these are both subsets of S. For example, the power set of {1, 2, 3} is {∅, {1}, {2}, {3}, {1, 2}, {1, 3}, {2, 3}, {1, 2, 3}}. The power set of a set S is commonly written as P(S) or 2$^S$.
If S has n elements, then P(S) has 2$^n$ elements. For example, {1, 2, 3} has three elements, and its power set has 2$^3$ = 8 elements, as shown above.
If S is infinite (whether countable or uncountable), then P(S) is uncountable. Moreover, the power set is always strictly "bigger" than the original set, in the sense that any attempt to pair up the elements of S with the elements of P(S) will leave some elements of P(S) unpaired. (There is never a bijection from S onto P(S).)

## Partitions

A partition of a set S is a set of nonempty subsets of S, such that every element x in S is in exactly one of these subsets. That is, the subsets are pairwise disjoint (meaning any two sets of the partition contain no element in common), and the union of all the subsets of the partition is S.

## Principle of inclusion and exclusion

The inclusion–exclusion principle is a technique for counting the elements in a union of two finite sets in terms of the sizes of the two sets and their intersection. It can be expressed symbolically as $|A\cup B|=|A|+|B|-|A\cap B|.$
A more general form of the principle gives the cardinality of any finite union of finite sets: ${\begin{aligned}\left|A_{1}\cup A_{2}\cup A_{3}\cup \ldots \cup A_{n}\right|=&\left(\left|A_{1}\right|+\left|A_{2}\right|+\left|A_{3}\right|+\ldots \left|A_{n}\right|\right)\\&-\left(\left|A_{1}\cap A_{2}\right|+\left|A_{1}\cap A_{3}\right|+\ldots \left|A_{n-1}\cap A_{n}\right|\right)\\&+\ldots \\&+\left(-1\right)^{n-1}\left(\left|A_{1}\cap A_{2}\cap A_{3}\cap \ldots \cap A_{n}\right|\right).\end{aligned}}$

## History

The concept of a set emerged in mathematics at the end of the 19th century. The German word for set, Menge, was coined by Bernard Bolzano in his work Paradoxes of the Infinite.
Georg Cantor, one of the founders of set theory, gave the following definition at the beginning of his Beiträge zur Begründung der transfiniten Mengenlehre:
   A set is a gathering together into a whole of definite, distinct objects of our perception or our thought—which are called elements of the set.
Bertrand Russell introduced the distinction between a set and a class (a set is a class, but some classes, such as the class of all sets, are not sets; see Russell's paradox):
   When mathematicians deal with what they call a manifold, aggregate, Menge, ensemble, or some equivalent name, it is common, especially where the number of terms involved is finite, to regard the object in question (which is in fact a class) as defined by the enumeration of its terms, and as consisting possibly of a single term, which in that case is the class.

### Naive set theory

The foremost property of a set is that it can have elements, also called members. Two sets are equal when they have the same elements. More precisely, sets A and B are equal if every element of A is an element of B, and every element of B is an element of A; this property is called the extensionality of sets. As a consequence, e.g. {2, 4, 6} and {4, 6, 4, 2} represent the same set. Unlike sets, multisets can be distinguished by the number of occurrences of an element; e.g. [2, 4, 6] and [4, 6, 4, 2] represent different multisets, while [2, 4, 6] and [6, 4, 2] are equal. Tuples can even be distinguished by element order; e.g. (2, 4, 6) and (6, 4, 2) represent different tuples.
The simple concept of a set has proved enormously useful in mathematics, but paradoxes arise if no restrictions are placed on how sets can be constructed:
* Russell's paradox shows that the "set of all sets that do not contain themselves", i.e., {x | x is a set and x ∉ x}, cannot exist.
* Cantor's paradox shows that "the set of all sets" cannot exist.
Naïve set theory defines a set as any well-defined collection of distinct elements, but problems arise from the vagueness of the term well-defined.

### Axiomatic set theory

In subsequent efforts to resolve these paradoxes since the time of the original formulation of naïve set theory, the properties of sets have been defined by axioms. Axiomatic set theory takes the concept of a set as a primitive notion. The purpose of the axioms is to provide a basic framework from which to deduce the truth or falsity of particular mathematical propositions (statements) about sets, using first-order logic. According to Gödel's incompleteness theorems however, it is not possible to use first-order logic to prove any such particular axiomatic set theory is free from paradox.