A set is the mathematical model for a collection of different  things;    a set contains elements or members, which can be mathematical objects of any kind: numbers, symbols, points in space, lines, other geometrical shapes, variables, or even other sets.  The set with no element is the empty set; a set with a single element is a singleton. A set may have a finite number of elements or be an infinite set. Two sets are equal if they have precisely the same elements. 

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. 

## 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. Passage with a translation of the original set definition of Georg Cantor. The German word Menge for set is translated with aggregate here.

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 called a set a class: 

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. 

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 xx}, 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.[ citation needed]

## How sets are defined and set notation

Mathematical texts commonly denote sets by capital letters   in italic, such as A, B, C.  A set may also be called a collection or family, especially when its elements are themselves sets.

### Roster notation

Roster or enumeration notation defines a set by listing its elements between curly brackets, separated by commas:    

A = {4, 2, 1, 3}
B = {blue, white, red}.

In a set, all that matters is whether each element is in it or not, so the ordering of the elements in roster notation is irrelevant (in contrast, in a sequence, a tuple, or a permutation of a set, the ordering of the terms matters). For example, {2, 4, 6} and {4, 6, 4, 2} represent the same set.   

For sets with many elements, especially those following an implicit pattern, the list of members can be abbreviated using an ellipsis '...'.   For instance, the set of the first thousand positive integers may be specified in roster notation as

{1, 2, 3, ..., 1000}.

#### Infinite sets in roster notation

An infinite set is a set with an endless list of elements. To describe an infinite set in roster notation, an ellipsis is placed at the end of the list, or at both ends, to indicate that the list continues forever. For example, the set of nonnegative integers is

{0, 1, 2, 3, 4, ...},

and the set of all integers is

{..., −3, −2, −1, 0, 1, 2, 3, ...}.

### Semantic definition

Another way to define a set is to use a rule to determine what the elements are:

Let A be the set whose members are the first four positive integers.
Let B be the set of colors of the French flag.

Such a definition is called a semantic description.  

### Set-builder notation

Set-builder notation specifies a set as a selection from a larger set, determined by a condition on the elements.    For example, a set F can be defined as follows:

$F=\{n\mid n{\text{ is an integer, and }}0\leq n\leq 19\}.$ In this notation, the vertical bar "|" means "such that", and the description can be interpreted as "F is the set of all numbers n such that n is an integer in the range from 0 to 19 inclusive". Some authors use a colon ":" instead of the vertical bar. 

### Classifying methods of definition

Philosophy uses specific terms to classify types of definitions:

• An intensional definition uses a rule to determine membership. Semantic definitions and definitions using set-builder notation are examples.
• An extensional definition describes a set by listing all its elements.  Such definitions are also called enumerative.
• An ostensive definition is one that describes a set by giving examples of elements; a roster involving an ellipsis would be an example.

## Membership

If B is a set and x is an element of B, this is written in shorthand as xB, which can also be read as "x belongs to B", or "x is in B".  The statement "y is not an element of B" is written as yB, which can also be read as "y is not in B".  

For example, with respect to the sets A = {1, 2, 3, 4}, B = {blue, white, red}, and F = {n | n is an integer, and 0 ≤ n ≤ 19},

4 ∈ A and 12 ∈ F; and
20 ∉ F and green ∉ B.

## The empty set

The empty set (or null set) is the unique set that has no members. It is denoted or $\emptyset$ or { }   or ϕ  (or ϕ). 

## Singleton sets

A singleton set is a set with exactly one element; such a set may also be called a unit set.  Any such set can be written as {x}, where x is the element. The set {x} and the element x mean different things; Halmos  draws the analogy that a box containing a hat is not the same as the hat.

## Subsets

If every element of set A is also in B, then A is described as being a subset of B, or contained in B, written AB,  or BA.  The latter notation may be read B contains A, B includes A, or B is a superset of A. The relationship between sets established by ⊆ is called inclusion or containment. Two sets are equal if they contain each other: AB and BA is equivalent to A = B. 

If A is a subset of B, but A is not equal to B, then A is called a proper subset of B. This can be written AB. Likewise, BA means B is a proper superset of A, i.e. B contains A, and is not equal to A.

A third pair of operators ⊂ and ⊃ are used differently by different authors: some authors use AB and BA to mean A is any subset of B (and not necessarily a proper subset),   while others reserve AB and BA for cases where A is a proper subset of B. 

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}.

The empty set is a subset of every set,  and every set is a subset of itself: 

• ∅ ⊆ A.
• AA.

## 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 2n 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).

## Special sets of numbers in mathematics The natural numbers $\mathbb {N}$ are contained in the integers $\mathbb {Z}$ , which are contained in the rational numbers $\mathbb {Q}$ , which are contained in the real numbers $\mathbb {R}$ , which are contained in the complex numbers $\mathbb {C}$ There are sets of such mathematical importance, to which mathematicians refer so frequently, that they have acquired special names and notational conventions to identify them.

Many of these important sets are represented in mathematical texts using bold (e.g. $\mathbf {Z}$ ) or blackboard bold (e.g. $\mathbb {Z}$ ) typeface.  These include

• $\mathbf {N}$ or $\mathbb {N}$ , the set of all natural numbers: $\mathbf {N} =\{0,1,2,3,...\}$ (often, authors exclude 0); 
• $\mathbf {Z}$ or $\mathbb {Z}$ , the set of all integers (whether positive, negative or zero): $\mathbf {Z} =\{...,-2,-1,0,1,2,3,...\}$ ; 
• $\mathbf {Q}$ or $\mathbb {Q}$ , the set of all rational numbers (that is, the set of all proper and improper fractions): $\mathbf {Q} =\left\{{\frac {a}{b}}\mid a,b\in \mathbf {Z} ,b\neq 0\right\}$ . For example, 7/4Q and 5 = 5/1Q; 
• $\mathbf {R}$ or $\mathbb {R}$ , the set of all real numbers, including all rational numbers and all irrational numbers (which include algebraic numbers such as ${\sqrt {2}}$ that cannot be rewritten as fractions, as well as transcendental numbers such as π and e); 
• $\mathbf {C}$ or $\mathbb {C}$ , the set of all complex numbers: C = {a + bi | a, bR}, for example, 1 + 2iC. 

Each of the above sets of numbers has an infinite number of elements. Each is a subset of the sets listed below it.

Sets of positive or negative numbers are sometimes denoted by superscript plus and minus signs, respectively. For example, $\mathbf {Q} ^{+}$ represents the set of positive rational numbers.

## Functions

A function (or mapping) from a set A to a set B is a rule that assigns to each "input" element of A an "output" that is an element of B; more formally, a function is a special kind of relation, one that relates each element of A to exactly one element of B. A function is called

• injective (or one-to-one) if it maps any two different elements of A to different elements of B,
• surjective (or onto) if for every element of B, there is at least one element of A that maps to it, and
• bijective (or a one-to-one correspondence) if the function is both injective and surjective — in this case, each element of A is paired with a unique element of B, and each element of B is paired with a unique element of A, so that there are no unpaired elements.

An injective function is called an injection, a surjective function is called a surjection, and a bijective function is called a bijection or one-to-one correspondence.

## 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 one-to-one correspondence 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. Infinite sets have 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 2S.   

If S has n elements, then P(S) has 2n elements.  For example, {1, 2, 3} has three elements, and its power set has 23 = 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.  

## Basic operations

Suppose that a universal set U (a set containing all elements being discussed) has been fixed, and that A is a subset of U.

• The complement of A is the set of all elements (of U) that do not belong to A. It may be denoted Ac or A. In set-builder notation, $A^{\text{c}}=\{a\in U:a\notin A\}$ . The complement may also be called the absolute complement to distinguish it from the relative complement below. Example: If the universal set is taken to be the set of integers, then the complement of the set of even integers is the set of odd integers.

Given any two sets A and B,

• their union AB is the set of all things that are members of A or B or both.
• their intersection AB is the set of all things that are members of both A and B. If AB = ∅, then A and B are said to be disjoint.
• the set difference A \ B (also written AB) is the set of all things that belong to A but not B. Especially when B is a subset of A, it is also called the relative complement of B in A.
• their symmetric difference A Δ B is the set of all things that belong to A or B but not both. One has $A\,\Delta \,B=(A\setminus B)\cup (B\setminus A)$ .
• their cartesian product A × B is the set of all ordered pairs (a,b) such that a is an element of A and b is an element of B.

Examples:

• {1, 2, 3} ∪ {3, 4, 5} = {1, 2, 3, 4, 5}.
• {1, 2, 3} ∩ {3, 4, 5} = {3}.
• {1, 2, 3} − {3, 4, 5} = {1, 2}.
• {1, 2, 3} Δ {3, 4, 5} = {1, 2, 4, 5}.
• {a, b} × {1, 2, 3} = {(a,1), (a,2), (a,3), (b,1), (b,2), (b,3)}.

The operations above satisfy many identities. For example, one of De Morgan's laws states that (AB)′ = A′ ∩ B (that is, the elements outside the union of A and B are the elements that are outside A and outside B).

The cardinality of A × B is the product of the cardinalities of A and B. (This is an elementary fact when A and B are finite. When one or both are infinite, multiplication of cardinal numbers is defined to make this true.)

The power set of any set becomes a Boolean ring with symmetric difference as the addition of the ring and intersection as the multiplication of the ring.

## 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, x2), 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) = x2.

## Principle of inclusion and exclusion The inclusion-exclusion principle for two finite sets states that the size of their union is the sum of the sizes of the sets minus the size of their intersection.

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}} 