# Set-builder notation

(Redirected from Set abstraction)

In set theory and its applications to logic, mathematics, and computer science, set-builder notation is a mathematical notation for describing a set by stating the properties that its members must satisfy. Forming sets in this manner is also known as set comprehension, set abstraction or as defining a set's intension. Although some simply refer to it as set notation, that label may be better reserved for the broader class of means of denoting sets.

## Building sets

Let Φ(x) be a formula in which x appears free. Set builder notation has the form {x : Φ(x)} (or {x | Φ(x)} according to the international standard ISO 31-11 using the vertical bar instead of the colon), denoting the set of all individuals in the universe of discourse satisfying the formula Φ(x), that is, the set whose members are every individual y such that Φ(y) is true: formally, the extension of the predicate. Sometimes the universe of discourse is established within the notation; writing {x ∈ U : Φ(x)} establishes that the universe of discourse is U for purposes of the set being built, though this is done at the expense of making the set membership operator ambiguous in the formal set builder notation. Set builder notation binds the variable x and must be used with the same care applied to variables bound by quantifiers.

Examples:

• $\{ 3, 7, 15, 31\}$ is a set holding the four numbers 3, 7, 15, and 31.
• $\{ 0, 1, 2, \ldots\}$ is the set of natural numbers.
• $\{ 1, 2, 3, \ldots\}$ is the set of counting numbers.
• $\{ 1, 2, 3, \ldots 100 \}$ is the set of integers between 1 and 100 inclusive.
• $\{a, b, c\}$ is the set containing 'a','b', and 'c'.
• $\{ x ~|~ x \in \mathbf R \land x = x^2 \} \,\!$ is the set $\{0, 1\}$,
• $\{ x ~|~ x \in \mathbf R \land x > 0\}$ is the set of all positive real numbers.
• $\{ (x,y) ~|~ 0 < y < f(x) \}$ is the set of (x,y) such that y is greater than 0 and less than f(x).
• $\{k ~|~ (\exists n \in \mathbf{N}) \land (k = 2n)\}$ is the set of all even natural numbers,
• $\{a ~|~ (\exists p, q \in \mathbf{Z}) \land (q \not = 0 \land aq=p) \}$ is the set of rational numbers; that is, numbers that can be written as the ratio of two integers.
• $\mathbf{N}_m = \{ x ~|~ x \in \mathbf{Z} \land x \ge m \} = \{ m, m + 1, m + 2, \ldots\}.$ Thus, e.g., $x_1 = m,\ x_2 = m + 1$, etc. (n.b.: in the case of sets, the order is not important; $x_1 = m + 2$ could be used). As an example, $\mathbf{N}_3 = \{x ~|~ x \in \mathbf{Z} \land x \ge 3 \} = \{ 3, 4, 5, \ldots\}.$

The ellipses means 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.

The $~|~$ is read as "such that", and it separates the variables list on the left from the rule for assigning values to those variables on the right. Often times the rule on the right is a formal logic predicate. However it can be anything that is clear to readers including simple prose. Unless specifically stated the variable is universally quantified over the rule, which means we include in the set all possible values for the variable for which the rule is true. When the meaning is clear the $~|~$ and the rule may be omitted.

When the rule is a predicate then formal logic connectors may be used within the rule. For example, the $\and$ sign stands for and, requiring both clauses to the left of it and to the right of it to be 'true'. As another example, The $\exists$ sign stands for "there exists" and is formally known as existential quantification. Sometimes multiple rules are given separated by a comma (,) or semicolon (;), in this case we take the rules in conjunction, i.e. we interpret the comma or semicolon to mean the same as $\and$.

The $\in$ sign denotes set membership, and can be read as "member of" or informally as "in". In a predicate a clause of the form $x \in \{1, 2, 3\}$ is either true or false, or when used as a constraint means that $x$ can only be one of the values 1, 2, or 3.

When the domain over which the set is defined is already clear it is not necessary to provide it within the rule clause. One could say something such as, "The universe of discourse can be taken to be the set of real numbers, where not specified inside the notation:" and then write:

• $\{ x ~|~ x = x^2 \} \,\!$ is the set $\{0, 1\}$

Rather than the fuller form as shown in the original example given above.

One can also use an expression in the variable list. For example:

• $\{ 2 t + 1 ~|~ t \in \mathbf Z\}$ is the set of odd integers.
• $\{ (t, 2 t + 1) ~|~ t \in \mathbf Z\}$ creates a set of pairs, where each pair puts an integer into correspondence with an odd integer.
• $\{ 2 x + 1 = 5 ~|~ x \in \mathbf N \}$ is the set $\{ true, false \}$ because the expression $2 x + 1 = 5$ evaluates to either true or false given the various natural numbers.

It is known in the literature to just place the domain qualifiers directly in the variable list. For the prior example this would produce:

• $\{ x \in \mathbf R ~|~ x = x^2 \} \,\!$ is the set $\{0, 1\}$,

Technically this would generate the set $\{true, false\}$ as the expression to the left of the 'such that' evaluates to either true or false, but at the expense of introducing ambiguity into our set builder notation we may instead decide to interpret this to mean that x has an additional qualification of being a real number. As another example, consider:

• $\{x \in \mathbf Z ~|~ x \in \mathbf N \land x < 1\}$

If we interpret $x \in \mathbf Z$ to be a domain qualifier, then this is the set $\{0\}$; however, if we interpret $x \in \mathbf Z$ to be an expression then this set is $\{ true \}$. Such ambiguities can be resolved by convention, for example by foregoing the ability to put the set inclusion operator in variable expressions. Another convention for eliminating such ambiguity, one that does not require us to reduce the richness of expressions, is to simply not use domain qualifiers in the variable list, but instead to put them with the rule predicates. For example, the expression

• $\{x ~|~ x \in \mathbf Z \land x \in \mathbf N \land x < 1\},$

denotes the first interpretation of the set given above, and can't be read in the second way.

When we do proofs that reason about the predicate rules, such as shown in the next section, the shortcut of leaving domain qualifiers with the variables is not an option, rather we must rigorously put domain qualifiers into the predicate rules we are operating on. Otherwise we may get fallacious results.

## Equivalent Builder Predicates means Equivalent Sets

Suppose we have two predicates we intend to use as rules for building sets, say these two predicates are $P(x)$ and $Q(x)$. Suppose we have not added additional qualifiers or expressions to the variable list (left of the 'such that'). Now furthermore assume that any value x comes from a domain defined by set $U$, i.e. $x \in U$. Now suppose also that we build two sets from these predicates:

$T=\{t ~|~ t \in U \land P(t)\}$

and,

$S=\{s ~|~ s \in U \land Q(s)\}$

As we already said that the domain is $U$ we could have left out the $t \in U$ and $s \in U$. Indeed, we leave out the understood $x \in U$ qualifier in the next statement. Note also we can give the variable used for building the set any name, as we have overused $x$ here we built the sets against $t$ and $s$. Now we have an interesting result from the field of mathematical logic:

$[T=S] ~\Leftrightarrow~ \forall x : [ P(x) ~\Leftrightarrow~ Q(x)]$

Here we use the square brackets for purposes of grouping. This says that if the two predicates always have the same true or false value given the same argument over the domain $U$, then the two sets T and S will be the same. Also, conversely, if the two sets T and S are identical, i.e. have the same elements,then our two predicates always produce the same logic value for the same argument over the domain U. The use of the colon here after the universal quantifier simply means the quantifier applies to what follows. Note this result is very general as it applies to any such sets and predicates over any given domain U.

The former author of this wiki section chose to state the equivalence between sets with equivalent predicates theorem in the following manner, note he uses the somewhat ambiguous shorthand of putting some simple qualifiers with the variables, and he prefers to use a ':' rather than a vertical bar for 'such that'. This usage of the colon is not to be confused with the use of the colon above after the universal quantifier that means 'apply to'. It is to avoid such confusion that many mathematicians prefer the vertical bar for 'such that':

$\Big[ \{ x \in U : P(x) \} = \{ x \in U : Q(x) \} \Big] \equiv \Big[ ( \forall x \in U ) \big[ P(x) \Leftrightarrow Q(x) \big] \Big]$.

This means that two sets are equal if and only if their "membership requirements" are logically equivalent.

For example, $\{ x \in \mathbf{R} : x^2 = 1 \} = \{ x \in \mathbf{R} : |x| = 1 \}$ because, for any real number x, x2 = 1 if and only if |x| = 1; and, therefore, both constructions produce the same set {-1,1}.

Let $R = \{S ~|~ S \notin S\}$ denote the set R of all sets S that do not belong to themselves. The inconsistency of the existence of this set is known as Russell's paradox.

Solutions to the paradox restrict the notion of set construction in some way. To illustrate this in terms of our notation, let X = {xA | P(x)} denote the set of every element of A satisfying the predicate P(x). The canonical restriction on set builder notation asserts that X is a set only if A is already known to be a set. This restriction is codified in the axiom schema of separation present in standard axiomatic set theory. Note that this axiom schema excludes R from sethood.

## Variations

### Terms more complicated than a single variable

Another variation on set-builder notation replaces the single variable x with a term T which may include one or more variables, combined with functions acting on them. So instead of {x : Φ(x)}, we would have {T : Φ(x1 ... xn)}, where T is a term involving variables x1 through xn. For example:

• {2n : nN}, where N is the set of all natural numbers, is the set of all even natural numbers.
• {p/q : p,qZ, q≠0}, where Z is the set of all integers, is the set of all rational numbers (Q).

### Z notation

In Z notation, the set of all x (in a universe of discourse A) satisfying the condition P(x) would be written $\{x : A \ |\ P(x)\}$. In Z, an element x's set membership is written as $(x : A)$ instead of $(x \in A)$; the vertical bar is used to indicate a predicate. Versions of set builder notation are also available in Z which allow for terms more complicated than a single variable, using a bullet to indicate the form of members of the set. So $\{x : A \ |\ P(x) \bullet F(x)\}$ denotes the set of all values F(x), where x is in A and P(x) holds.

### Parallels 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 set-builder's braces are replaced with square brackets, parentheses, or curly braces, giving list, generator, and set objects, respectively. Python uses an English based syntax. Haskell replaces the set-builder's braces with square brackets and uses symbols, including the standard set-builder vertical bar. Consider these examples given in set-builder notation, Python, and Haskell:

Example 1 Example 2
Set-builder
$\{l\ |\ l \in L\}$
$\{(k, x)\ |\ k \in K \wedge x \in X \wedge P(x) \}$
Python
{l for l in L}

{(k, x) for k in K for x in X if P(x)}

[l | l <- ls]

[(k, x) | k <- ks, x <- xs, p x]