Set builder notation, can I switch what's written on the left and right of the vertical bar?

TL;DR: Yes.


Surely for this sweeping answer to make sense we should justify that there are (or could be) universal conventions on mathematical notation (since you don't specify by whom you mean the notation to be acceptable, I interpret your question as something along the lines of:

"Is it acceptable by a sufficiently large group of people sufficiently competent in mathematics to switch what is on the left side of the vertical bar with what is on the right?").

I don't think trying to produce such a justification is fruitful, even if it could be produced; so to bypass it let us suppose we are interested in practicing mathematics that are not that intermingled with foundations (say we only occasionally use the Axiom of Choice etc.). In this case as long as your notation for a specific concept is coherent with the rest of your outlook (or argument, proof etc.) and what you mean by the notation you use makes it communicable (with a sufficiently small error margin, which is quite possibly never zero) any notation you use is very acceptable. Here are a few examples:

  • When I am writing on a board sometimes due to board-scarcity I even write a set with a horizontal separator, LHS (the place for the general form) on the top and RHS (the place for the characterizing property) on the bottom.
  • Sometimes $\in$ and the characterizing property are joined together and the separator is not even used, first instance in the undergraduate curriculum is probably the correspondence of the normal subgroups of a group that contains a given normal subgroup and the normal subgroups of the factor group:

$$\{N\leq K\unlhd G\} \longleftrightarrow \{L\unlhd G/N\},$$

which could also be written as

$$\{K\mid N\leq K\unlhd G\} \longleftrightarrow \{L\mid L\unlhd G/N\},$$

but generally is not ($G$ and $N$ are fixed, $K$ and $L$ are dummy, so the interlocutor expects to be understood contextually).

  • Sometimes it is better not to use the set-builder notation partially, e.g. when defining the topology of a set $X$, writing "let $\mathcal{T}:=\{U\in\mathcal{P}(X)\mid U\mbox{ is open}\}$" is usually not better than writing "let $\mathcal{T}$ be the set (collection) of all open sets of $X$".

The main point of the so-called set builder notation is that the separator separates what form a generic element of the set has and what their characterizing property is.

  • For your first example, observe the following:

\begin{align} A:=\{x\in\Bbb{R}\mid x^2<9\} &=\{x\in\Bbb{R}\mid \vert x\vert<3\}\\ &=\{x\in\Bbb{R}\mid x\in]-3,3[\}\\ &=\{x\mid x\in\Bbb{R}\mbox{ and }x\in]-3,3[\}\\ &=\{x\mid x\in\Bbb{R}\cap]-3,3[\}\\ &=\{x\mid x\in]-3,3[\}\\ &=]-3,3[\\ &=\{x\in]-3,3[\mid x\in\Bbb{R}\}\\ &=\{x\in]-3,3[\mid x\in\Bbb{C}\}\\ &\neq\{x\in\Bbb{C}\mid x^2<9\}, \end{align}

where "observing" stands not for "checking that everything is in compliance with the universal terms and conditions" but for "understanding what I had in mind when I was manipulating the notation" (or "checking that everything is in compliance with the terms and conditions applicable in this instance of mathematical reasoning").

  • If you prefer to be more consistent with the set-builder recipe, $S=\{m\in\Bbb{N}\vert \exists n\in\Bbb{N}: n^2=m\}$.

The examples and the comments above makes way for a somewhat heuristical explanation of the set-builder notation: In general it is preferred to specify the ambient set together with the general form of the elements of the set. This is also in accordance with the ordering of verbal explanations generally used, e.g. "let $A$ be the set of all real numbers whose square is less than $9$" (observe that this is slightly more natural than saying "let $A$ be the set of all numbers whose square is less than $9$, which also happen to be real").


Here is a "soft" exercise for you to thing about:

Not only is the use of the set-builder notation is not set in stone in practice only, this notation may be somewhat vague inherently:

  1. If $S$ is a set, let $P_S(x)$ be the open sentence "$x$ is an element of $S$.", where by an "open sentence" I mean a statement whose truth value $\in\{\mbox{true}, \mbox{false}\}$ is dependent on $x$:

$$P_S(x):="x\in S".$$

  1. If $P(x)$ is an open sentence, let $S_P$ be the set of all $x$'s which render $P(x)$ true:

$$S_P:=\{P\mbox{ is true}\}:=\{x\mid P(x)\mbox{ is true}\}=\{x\mid P(x)\}.$$

Then we have an inherent interchangability associated with LHS and RHS. This inherent interchangability is closely related to "extensionality":

Extensionality: A set is completely determined just by specifying elements.

This is a foundational issue (see Russell's paradox), but in different forms this interchange turns out to be very important, e.g. in measure theory we have the characteristic function of a given (measurable) set $A$:

$$\chi_A(x):=\begin{cases} 1,\mbox{if $x\in A$}\\ 0,\mbox{if $x\not\in A$} \end{cases},$$

which allows us to think of (measurable) sets as (measurable) functions and define a very robust integration.


An excellent book that would supplement your current study would be Mac Lane's Mathematics Form and Function, which contains (in my opinion) just enough information on foundations (and philosophy of mathematics) for doing non-foundational mathematics (and it also gives a very good sense of the "big picture"). The framework of my answer can be thought of this book also: "Form is due to functionality." (if you were to ask for an induced motto).


TL;DR: NO!


The general structure of a set-builder notation is $\{\text{term}(x)\mid\text{condition on }x\}$ or $\{\text{term}(x)\in X\mid\text{condition on }x\}$ when we want to bound the terms we allow.

The left side is some term defined from $x$. This can be $n^2$, or it can be $f(x)$ or whatever. But it is a term. It is a mathematical object in our mathematical universe, which might be bounded by a certain set. On the right side, we look at the condition on $x$. This is a formula which should have one free variable: $x$. And then we know that we take all the terms build from $x$'s satisfying the condition.

What you are allowed to do, however, is retranslate the term and the conditions. You can always arrive at something of the form $\{x\mid\text{condition on }x\}$, because you can always put the bound $x\in X$ in the condition, and you can always say something like "There exist $y$ such that $\text{term}(y)=x$".

So writing $\{n^2\mid n\in\Bbb N\}$ can be written as $\{n\mid\exists k\in\Bbb N:k^2=n\}$.

But translating one thing to the other is not the same as switching sides. The set builder notation $\{n\in\Bbb N\mid n^2\}$ is meaningless, since $n^2$ is a term, not a formula. It does not evaluate to a true/false condition which tells us in which case we put $n$ into our set and in which case we do not.

So really the only thing we can move around is the bounding set. Namely, $\{x^3\in\Bbb N\mid x+1\text{ is even}\}$ and $\{x^3\mid x\in\Bbb N\text{ is odd}\}$ form the same set, although they look differently. Why do we do that?

The answer is readability. You want to write your set in the way that will be the most readable to your audience, and will maximize usability later, when you refer to properties of the elements in the set you defined.

So when you want to take the set of squares in the natural numbers, it is easier to write $n^2$, and not "There is some $k$ such that $k^2=n$". So making the term more complex makes the condition way simpler. But now we are left without any condition, as we want to take all the squares. So we move the bounding set into the condition, then we get that $n\in\Bbb N$ is our condition.

One extremely important caveat here is to note that sometimes the term moves you from one set to another, e.g $f\colon X\to Y$ and $A\subseteq X$, then $\{f(x)\mid x\in A\}$ is in fact a subset of $Y$, so it would be written as $\{y\in Y\mid\exists x\in A: f(x)=y\}$. So when you switch the sides of the bounding conditions, it is important to make sure that the sets you care about are changed if necessary.