18. Setbuilder notation
18.1 Definition: setbuilder notation
A set may be denoted by the expression $\{x\mid P(x)\}$, where $P$ is a predicate. This denotes the set of all elements of the type $x$ for which the predicate $P(x)$ is true. Such notation is called setbuilder notation.
The predicate $P$ is called the defining condition for the set, and the set $\{x\mid P(x)\}$ is called the extension of the predicate $P$.
18.1.1 Usage
a) Sometimes a colon is used instead of ‘$|$’ in the setbuilder notation.
b) The fact that one can define sets using setbuilder notation is called comprehension. See 18.1.11.
18.1.2 Example The set $\{n\mid n\text{ is an integer and }1<n<6\}$ denotes the set $\{2,3,4,5\}$.
18.1.3 Example The set $S=\{n\mid n\text{ is an integer and }n\text{ is prime}\}$ is the set of all primes.
18.1.4 Worked Exercise List the elements of these sets, where $n$ is of type integer.
a) $\{n\mid n^{2}=1\}$.
b) $\{n\mid n\text{ divides }12\}$.
c) $\{n\mid 1<n<3\}$.
Answer a) $\{-1,1\}$. b) $\{1,2,3,4,6,12,-1,-2,-3,-4,-6,-12\}$. c) $\{2\}$.
18.1.5 Exercise How many elements do each of the following sets have? In each case, $x$ is real.
$$\begin{array}{ll} \text{a) } \{2,1,1,1\} & \text{c) } \{x\mid x^{2}-1=0\} \\ \text{b) } \{1,2,-1,\sqrt{4},|-1|\} & \text{d) } \{x\mid x^{2}+1=0\} \end{array}$$
(Answer on page 243.)
18.1.6 Example The extension of the predicate
$$(x\in\mathrm{Z})\wedge(x<5)\wedge(x>2)$$
is the set $\{3,4\}$.
18.1.7 Example The extension of a predicate whose main verb is “equals” is what one would normally call the solution set of the equation. Thus the extension of the predicate $x^{2}=4$ is $\{-2,2\}$.
18.1.8 Exercise Write predicates whose extensions are the sets in exercise 18.1.5 (a) and (b). Use a real variable $x$.
18.1.9 Exercise Give these sets in list notation, where $n$ is of type integer.
a) $\{n\mid n>1\text{ and }n<4\}$.
b) $\{n\mid n\text{ is a factor of }3\}$.
18.1.10 Usage In some texts, a predicate is defined to be what we have called its extension here: in those texts, a predicate $P(x)$ is a subset (see Chapter 31) of the set of elements of type $x$. In such texts, “$(x=2)\vee(x=-2)$” would be regarded as the same predicate as “$x^{2}=4$”.
18.1.11 Method: Comprehension
Let $P(x)$ be a predicate and let $A=\{x\mid P(x)\}$. Then if you know that $a\in A$, it is correct to conclude that $P(a)$. Moreover, if $P(a)$, then you know that $a\in A$.
18.1.12 Remark The Method of Comprehension means that the elements of $\{x\mid P(x)\}$ are exactly all those $x$ that make $P(x)$ true. If $A=\{x\mid P(x)\}$, then every $x$ for which $P(x)$ is an element of $A$, and nothing else is.
This means that in the answer to Worked Exercise 18.1.4, the only correct answer to part (b) is $\{1,2,3,4,6,12,-1,-2,-3,-4,-6,-12\}$. For example, the set $\{1,2,3,4,6,-3,-4,-6,-12\}$ would not be a correct answer because it does not include every integer that makes the statement “$n$ divides $12$” true (it does not contain $-2$, for example).
18.1.13 Rules of inference for sets It follows that we have two rules of inference: If $P(x)$ is a predicate, then for any item $a$ of the same type as $x$,
$$P(a)\vdash a\in\{x\mid P(x)\} \tag{18.1}$$
and
$$a\in\{x\mid P(x)\}\vdash P(a) \tag{18.2}$$
18.1.14 Example The set
$$\mathrm{I}=\{x\mid x\text{ is real and }0\leq x\leq 1\} \tag{18.3}$$
which has among its elements $0$, $1/4$, $\pi/4$, $1$, and an infinite number of other numbers. $\mathrm{I}$ is fairly standard notation for this set — it is called the unit interval.
18.1.15 Usage Notation such as “$a\leq x\leq b$” means $a\leq x$ and $x\leq b$. So the statement “$0\leq x\leq 1$” in the preceding example means “$0\leq x$” and “$x\leq 1$”. Note that it follows from this that $5\leq x\leq 3$ means $(5\leq x)\wedge(x\leq 3)$ — there are no numbers $x$ satisfying that predicate. It does not means “$(5\leq x)\vee(x\leq 3)$”!
18.1.16 Exercise What is required to show that $a\notin\{x\mid P(x)\}$? (Answer on page 243.)
Pages 27–29 of the book (PDF).