Setbuilder notation
The set of all even integers,
expressed in setbuilder notation.
In set theory and its applications to logic, mathematics, and computer science, setbuilder notation is a mathematical notation for describing a set by enumerating its elements, or stating the properties that its members must satisfy.^{[1]}
Defining sets by properties is also known as set comprehension, set abstraction or as defining a set's intension.
Sets defined by enumeration
A set can be described directly by enumerating all of its elements between curly brackets, as in the following two examples:
 [math]\displaystyle{ \{ 7, 3, 15, 31\} }[/math] is the set containing the four numbers 3, 7, 15, and 31, and nothing else.
 [math]\displaystyle{ \{a, c, b\}=\{a, b, c\} }[/math] is the set containing a, b, and c, and nothing else (there is no order among the elements of a set).
This is sometimes called the "roster method" for specifying a set.^{[2]}
When it is desired to denote a set that contains elements from a regular sequence, an ellipses notation may be employed, as shown in the next examples:
 [math]\displaystyle{ \{ 1, 2, 3, \ldots, 100 \} }[/math] is the set of integers between 1 and 100 inclusive.
 [math]\displaystyle{ \{1, 2, 3, \ldots\} }[/math] is the set of natural numbers.
 [math]\displaystyle{ \{\ldots,2, 1, 0, 1, 2, \ldots\}= \{0, 1, 1, 2, 2, \ldots\} }[/math] is the set of all integers.
There is no order among the elements of a set (this explains and validates the equality of the last example), but with the ellipses notation, we use an ordered sequence before (or after) the ellipsis as a convenient notational vehicle for explaining which elements are in a set. The first few elements of the sequence are shown, then the ellipses indicate that the simplest interpretation should be applied for continuing the sequence. Should no terminating value appear to the right of the ellipses, then the sequence is considered to be unbounded.
In general, [math]\displaystyle{ \{1, \dots, n\} }[/math] denotes the set of all natural numbers [math]\displaystyle{ i }[/math] such that [math]\displaystyle{ 1\leq i\leq n }[/math]. Another notation for [math]\displaystyle{ \{1, \dots, n\} }[/math] is the bracket notation [math]\displaystyle{ [n] }[/math]. A subtle special case is [math]\displaystyle{ n=0 }[/math], in which [math]\displaystyle{ [0] = \{1, \dots, 0\} }[/math] is equal to the empty set [math]\displaystyle{ \emptyset }[/math]. Similarly, [math]\displaystyle{ \{a_1, \dots, a_n\} }[/math] denotes the set of all [math]\displaystyle{ a_i }[/math] for [math]\displaystyle{ 1\leq i\leq n }[/math].
In each preceding example, each set is described by enumerating its elements. Not all sets can be described in this way, or if they can, their enumeration may be too long or too complicated to be useful. Therefore, many sets are defined by a property that characterizes their elements. This characterization may be done informally using general prose, as in the following example.
 [math]\displaystyle{ \{ }[/math] addresses on Pine Street [math]\displaystyle{ \} }[/math] is the set of all addresses on Pine Street.
However, the prose approach may lack accuracy or be ambiguous. Thus, setbuilder notation is often used with a predicate characterizing the elements of the set being defined, as described in the following section.
Sets defined by a predicate
Setbuilder notation can be used to describe a set that is defined by a predicate, that is, a logical formula that evaluates to true for an element of the set, and false otherwise.^{[3]} In this form, setbuilder notation has three parts: a variable, a colon or vertical bar separator, and a predicate. Thus there is a variable on the left of the separator, and a rule on the right of it. These three parts are contained in curly brackets:
 [math]\displaystyle{ \{x \mid \Phi(x)\} }[/math]
or
 [math]\displaystyle{ \{x : \Phi(x)\}. }[/math]
The vertical bar (or colon) is a separator that can be read as "such that", "for which", or "with the property that". The formula Φ(x) is said to be the rule or the predicate. All values of x for which the predicate holds (is true) belong to the set being defined. All values of x for which the predicate does not hold do not belong to the set. Thus [math]\displaystyle{ \{x \mid \Phi(x)\} }[/math] is the set of all values of x that satisfy the formula Φ.^{[4]} It may be the empty set, if no value of x satisfies the formula.
Specifying the domain
A domain E can appear on the left of the vertical bar:^{[5]}
 [math]\displaystyle{ \{x \in E \mid \Phi(x)\}, }[/math]
or by adjoining it to the predicate:
 [math]\displaystyle{ \{ x \mid x \in E \text{ and } \Phi(x)\}\quad\text{or}\quad\{ x \mid x \in E \land \Phi(x)\}. }[/math]
The ∈ symbol here denotes set membership, while the [math]\displaystyle{ \land }[/math] symbol denotes the logical "and" operator, known as logical conjunction. This notation represents the set of all values of x that belong to some given set E for which the predicate is true (see "Set existence axiom" below). If [math]\displaystyle{ \Phi(x) }[/math] is a conjunction [math]\displaystyle{ \Phi_1(x)\land\Phi_2(x) }[/math], then [math]\displaystyle{ \{x \in E \mid \Phi(x)\} }[/math] is sometimes written [math]\displaystyle{ \{x \in E \mid \Phi_1(x), \Phi_2(x)\} }[/math], using a comma instead of the symbol [math]\displaystyle{ \land }[/math].
In general, it is not a good idea to consider sets without defining a domain of discourse, as this would represent the subset of all possible things that may exist for which the predicate is true. This can easily lead to contradictions and paradoxes. For example, Russell's paradox shows that the expression [math]\displaystyle{ \{x ~~ x\not\in x\}, }[/math] although seemingly well formed as a set builder expression, cannot define a set without producing a contradiction.^{[6]}
In cases where the set E is clear from context, it may be not explicitly specified. It is common in the literature for an author to state the domain ahead of time, and then not specify it in the setbuilder notation. For example, an author may say something such as, "Unless otherwise stated, variables are to be taken to be natural numbers," though in less formal contexts where the domain can be assumed, a written mention is often unnecessary.
Examples
The following examples illustrate particular sets defined by setbuilder notation via predicates. In each case, the domain is specified on the left side of the vertical bar, while the rule is specified on the right side.
 [math]\displaystyle{ \{ x \in \mathbb{R} \mid x \gt 0\} }[/math] is the set of all strictly positive real numbers, which can be written in interval notation as [math]\displaystyle{ (0, \infty) }[/math].
 [math]\displaystyle{ \{ x \in \mathbb{R} \mid x = 1 \} }[/math] is the set [math]\displaystyle{ \{1, 1\} }[/math]. This set can also be defined as [math]\displaystyle{ \{x \in \mathbb{R} \mid x^2 = 1\} }[/math]; see equivalent predicates yield equal sets below.
 For each integer m, we can define [math]\displaystyle{ G_m = \{x \in \mathbb{Z} \mid x \ge m \} = \{ m, m + 1, m + 2, \ldots\} }[/math]. As an example, [math]\displaystyle{ G_3 = \{x \in \mathbb{Z} \mid x \ge 3 \} = \{ 3, 4, 5, \ldots\} }[/math] and [math]\displaystyle{ G_{2} = \{ 2, 1, 0, \ldots\} }[/math].
 [math]\displaystyle{ \{ (x,y) \in \mathbb{R} \times \mathbb{R} \mid 0 \lt y \lt f(x) \} }[/math] is the set of pairs of real numbers such that y is greater than 0 and less than f(x), for a given function f. Here the cartesian product [math]\displaystyle{ \mathbb{R}\times\mathbb{R} }[/math] denotes the set of ordered pairs of real numbers.
 [math]\displaystyle{ \{n \in \mathbb{N} \mid (\exists k) [k\in \mathbb{N}\land n = 2k] \} }[/math] is the set of all even natural numbers. The [math]\displaystyle{ \land }[/math] sign stands for "and", which is known as logical conjunction. The ∃ sign stands for "there exists", which is known as existential quantification. So for example, [math]\displaystyle{ (\exists x) P(x) }[/math] is read as "there exists an x such that P(x)".
 [math]\displaystyle{ \{n \mid (\exists k \in \mathbb{N} ) [n = 2k] \} }[/math] is a notational variant for the same set of even natural numbers. It is not necessary to specify that n is a natural number, as this is implied by the formula on the right.
 [math]\displaystyle{ \{a \in \mathbb{R} \mid (\exists p\in \mathbb{Z} )(\exists q\in \mathbb{Z} )[ q \not = 0 \land aq=p] \} }[/math] is the set of rational numbers; that is, real numbers that can be written as the ratio of two integers.
More complex expressions on the left side of the notation
An extension of setbuilder notation replaces the single variable x with an expression. So instead of [math]\displaystyle{ \{ x \mid \Phi(x)\} }[/math], we may have [math]\displaystyle{ \{ f(x) \mid \Phi(x)\}, }[/math] which should be read
 [math]\displaystyle{ \{ f(x) \mid \Phi(x)\}=\{y\mid\exists x (y=f(x)\wedge\Phi(x))\} }[/math].
For example:
 [math]\displaystyle{ \{2 n \mid n \in \mathbb N\} }[/math], where [math]\displaystyle{ \mathbb N }[/math] is the set of all natural numbers, is the set of all even natural numbers.
 [math]\displaystyle{ \{p/q \mid p,q \in \mathbb Z, q \not = 0 \} }[/math], where [math]\displaystyle{ \mathbb Z }[/math] is the set of all integers, is [math]\displaystyle{ \mathbb{Q}, }[/math] the set of all rational numbers.
 [math]\displaystyle{ \{ 2 t + 1 \mid t \in \mathbb Z\} }[/math] is the set of odd integers.
 [math]\displaystyle{ \{ (t, 2 t + 1) \mid t \in \mathbb Z\} }[/math] creates a set of pairs, where each pair puts an integer into correspondence with an odd integer.
When inverse functions can be explicitly stated, the expression on the left can be eliminated through simple substitution. Consider the example set [math]\displaystyle{ \{ 2 t + 1 \mid t \in \mathbb Z\} }[/math]. Make the substitution [math]\displaystyle{ u = 2t + 1 }[/math], which is to say [math]\displaystyle{ t = (u1)/2 }[/math], then replace t in the set builder notation to find
 [math]\displaystyle{ \{ 2 t + 1 \mid t \in \mathbb Z\} = \{ u \mid (u 1)/2 \in \mathbb Z\}. }[/math]
Equivalent predicates yield equal sets
Two sets are equal if and only if they have the same elements. Sets defined by set builder notation are equal if and only if their set builder rules, including the domain specifiers, are equivalent. That is
 [math]\displaystyle{ \{ x \in A \mid P(x) \}=\{ x \in B \mid Q(x) \} }[/math]
if and only if
 [math]\displaystyle{ (\forall t)[ (t \in A \land P(t)) \Leftrightarrow (t \in B \land Q(t))] }[/math].
Therefore, in order to prove the equality of two sets defined by set builder notation, it suffices to prove the equivalence of their predicates, including the domain qualifiers.
For example,
 [math]\displaystyle{ \{ x \in \mathbb{R}\mid x^2 = 1 \} = \{ x \in \mathbb{Q} \mid x = 1 \} }[/math]
because the two rule predicates are logically equivalent:
 [math]\displaystyle{ (x \in \mathbb{R} \land x^2 = 1) \Leftrightarrow (x \in \mathbb{Q} \land x = 1). }[/math]
This equivalence holds because, for any real number x, we have [math]\displaystyle{ x^2 = 1 }[/math] if and only if x is a rational number with [math]\displaystyle{ x=1 }[/math]. In particular, both sets are equal to the set [math]\displaystyle{ \{1,1\} }[/math].
Set existence axiom
In many formal set theories, such as Zermelo–Fraenkel set theory, set builder notation is not part of the formal syntax of the theory. Instead, there is a set existence axiom scheme, which states that if E is a set and Φ(x) is a formula in the language of set theory, then there is a set Y whose members are exactly the elements of E that satisfy Φ:
 [math]\displaystyle{ (\forall E)(\exists Y)(\forall x)[x \in Y \Leftrightarrow x \in E \land \Phi(x)]. }[/math]
The set Y obtained from this axiom is exactly the set described in set builder notation as [math]\displaystyle{ \{ x \in E \mid \Phi(x)\} }[/math].
In programming languages
A similar notation available in a number of programming languages (notably Python and Haskell) is the list comprehension, which combines map and filter operations over one or more lists.
In Python, the setbuilder's braces are replaced with square brackets, parentheses, or curly braces, giving list, generator, and set objects, respectively. Python uses an Englishbased syntax. Haskell replaces the setbuilder's braces with square brackets and uses symbols, including the standard setbuilder vertical bar.
The same can be achieved in Scala using Sequence Comprehensions, where the "for" keyword returns a list of the yielded variables using the "yield" keyword.^{[7]}
Consider these setbuilder notation examples in some programming languages:
Example 1  Example 2  

Setbuilder  [math]\displaystyle{ \{l\ \ l \in L\} }[/math]  [math]\displaystyle{ \{(k, x)\ \ k \in K \wedge x \in X \wedge P(x) \} }[/math] 
Python  {l for l in L} 
{(k, x) for k in K for x in X if P(x)} 
Haskell  [l  l < ls] 
[(k, x)  k < ks, x < xs, p x] 
Scala  for (l < L) yield l 
for (k < K; x < X if P(x)) yield (k,x) 
C#  from l in L select l 
from k in K from x in X where P(x) select (k,x) 
SQL  SELECT l FROM L_set 
SELECT k, x FROM K_set, X_set WHERE P(x) 
Prolog  setof(L,member(L,Ls),Result) 
setof((K,X),(member(K,Ks),member(X,Xs),call(P,X)),Result) 
Ruby  L.map{l l} 
K.product(X).select{k,x P(x) } 
Erlang  [l  l < ls] 

Julia  [l for l ∈ L] 
[(k, x) for k ∈ K for x ∈ X if P(x)] 
The set builder notation and list comprehension notation are both instances of a more general notation known as monad comprehensions, which permits map/filterlike operations over any monad with a zero element.
See also
Notes
 ↑ Rosen, Kenneth (2007). Discrete Mathematics and its Applications (6th ed.). New York, NY: McGrawHill. pp. 111–112. ISBN 9780072880083. https://books.google.com/books?id=ZYZfQgAACAAJ&pg=PA111.
 ↑ Richard Aufmann, Vernon C. Barker, and Joanne Lockwood, 2007, Intermediate Algebra with Applications, Brooks Cole, p. 6.
 ↑ Michael J Cullinan, 2012, A Transition to Mathematics with Proofs, Jones & Bartlett, pp. 44ff.
 ↑ Weisstein, Eric W.. "Set" (in en). https://mathworld.wolfram.com/Set.html.
 ↑ "SetBuilder Notation". https://www.mathsisfun.com/sets/setbuildernotation.html.
 ↑ Irvine, Andrew David; Deutsch, Harry (9 October 2016). "Russell's Paradox". Stanford Encyclopedia of Philosophy. http://plato.stanford.edu/entries/russellparadox/. Retrieved 6 August 2017.
 ↑ "Sequence Comprehensions". Scala. http://docs.scalalang.org/tutorials/tour/sequencecomprehensions.html.
is:Mengjaskilgreiningarritháttur
Original source: https://en.wikipedia.org/wiki/Setbuilder notation.
Read more 