19. Variations on setbuilder notation
Frequently an expression is used left of the vertical line in setbuilder notation, instead of a single variable.
19.1 Typing the variable
One can use an expression on the left side of setbuilder notation to indicate the type of the variable.
19.1.1 Example The unit interval $\mathrm{I}$ could be defined as
$$\mathrm{I}=\{x\in\mathrm{R}\mid 0\leq x\leq 1\}$$
making it clear that it is a set of real numbers rather than, say rational numbers.
19.2 Other expressions on the left side
Other kinds of expressions occur before the vertical line in setbuilder notation as well.
19.2.1 Example The set $\{n^{2}\mid n\in\mathrm{Z}\}$ consists of all the squares of integers; in other words its elements are $0,1,4,9,16,\ldots$.
19.2.2 Example Let $A=\{1,3,6\}$. Then
$$\{n-2\mid n\in A\}=\{-1,1,4\}$$
19.2.3 Remark The notation introduced in the preceding examples is another way of putting an additional condition on elements of the set. Most such definitions can be reworded by introducing an extra variable. For example, the set in Example 19.2.1 could be rewritten as
$$\{n^{2}\mid n\in\mathrm{Z}\}=\{k\mid(k=n^{2})\wedge(n\in\mathrm{Z})\}$$
and the set in Example 19.2.2 as
$$\{n-2\mid n\in A\}=\{m\mid(m=n-2)\wedge(n\in A)\}$$
19.2.4 Warning Care must be taken in reading such expressions: for example, the integer 9 is an element of the set $\{n^{2}\mid n\in\mathrm{Z}\wedge n\neq 3\}$, because although $9=3^{2}$, it is also true that $9=(-3)^{2}$, and $-3$ is an integer not ruled out by the predicate on the right side of the definition.
19.2.5 Exercise Which of these equations are true?
a) $\mathrm{R}^{+}=\{x^{2}\mid x\in\mathrm{R}\}$
b) $\mathrm{N}=\{x^{2}\mid x\in\mathrm{N}\}$
c) $\mathrm{R}=\{x^{3}\mid x\in\mathrm{R}\}$
(Answer on page 243.)
19.2.6 Exercise List the elements of these sets.
a) $\{n-1\in\mathrm{Z}\mid n\text{ divides }12\}$
b) $\{n^{2}\in\mathrm{N}\mid n\text{ divides }12\}$
c) $\{n^{2}\in\mathrm{Z}\mid n\text{ divides }12\}$
(Answer on page 243.)
19.2.7 Exercise List the elements of these sets, where $x$ and $y$ oare of type real:
a) $\{x+y\mid y=1-x\}$.
b) $\{3x\mid x^{2}=1\}$.
19.2.8 Exercise How many elements does the set
$$\left\{\frac{1}{x^{2}}\;\middle|\; x=-\frac{1}{2},\frac{1}{2},-2,2\right\}$$
have?
19.3 More about sets in Mathematica
The Table notation described in 17.2 can use the variations described in 19. For example, Table[kˆ2,{k,1,5}] returns {1,4,9,16,25}.
Defining a set by setbuilder notation in Mathematica is accomplished using the command Select. Select[list,criterion] lists all the elements of the list that meet the criterion. For example, Select[{2,5,6,7,8},PrimeQ] returns {2,5,7}. The criterion must be a Mathematica command that returns True or False for each element of the list. The criterion can be such a command you defined yourself; it does not have to be built in.
19.3.1 Exercise (Mathematica) Explain the result you get when you type
Select[{2,4,Pi,5.0,6.0},IntegerQ]
in Mathematica.
Pages 29–31 of the book (PDF).