Elementary set theory and the reuse of previously defined notation In a text with deals with a type of objects $x$, I define a set like 
$\mathcal{S}=\{x\in\mathcal{K}\mid p(x)\}$. Someone I know claims this is wrong because $\mathcal{S}$ will 'inherit' properties that are defined for $x$ elsewhere in my text. In particular, it may very well be the case that $x\notin\mathcal{K}$. The right way, they argue, is to write $\mathcal{S}=\{y\in\mathcal{K}\mid p(y)\}$ instead. But I believe that, by definition, the $\{\cdot|$ part of a set $\{\cdot \mid \cdot\}$ cannot depend on anything aside from $\mathcal{K}$ and the ${}\mid\cdot\}$ part. The ${}\mid\cdot\}$ part may however depend on objects defined elsewhere. Am I wrong? Can you provide me with a textbook for reference?
 A: Consider the following example:

Be $x=3$. Be $M=\{x\in\mathbb N|x=5\}$.

Does $M$ contain any elements? Is it empty because $3\ne 5$, or does it contain the single element $5$? That depends on  whether the $x$ on the right hand side of the set builder notation refers to the $x$ defined on the left hand side, or to the $x$ defined before. In short, inside the definition of $M$,  you've got two conflicting definition of $x$: One that says that $x=3$, and one that says that $x$ is an arbitrary element of $\mathbb N$.
Therefore the simple rule is: Don't do it. If you have different entities, give them different names.
Note however, that the name inside the set builder notation is only defined inside that notation, so there's nothing wrong with reusing that in another set building, as for example:

Be $A = \{x\in\mathbb N|x > 0\}$ and $B = \{x\in\mathbb N|x < 10\}$.

Also note that if the names are not already in use, it indeed does not matter which name you use, so $\{x\in X|P(x)\}$ and $\{y\in X|P(y)\}$ are indeed the same set.
A: If you've used $x$ before in a specific way, then using it again like this will confuse your reader, though it is not technically incorrect - the format $\{x \in K \mid p(x)\}$ carries the implication that $x$ is being treated as a new variable. But if you say, for example, "$x = 4; \{x \in K \mid p(x)\}$", it'll be all kinds of confusing - by $p(x)$, do you mean to say that $p$ holds of the variable $x \in K$, or the $x$ which is $4$?
Unless it's this specific, I wouldn't worry about it - for example,"$\{x \in K \mid p(x)\}, \{x \in K \mid q(x)\}$" is fine. Likewise, if you defined $x$ to be $4$, but it was two pages earlier and you aren't going to use it again, no problem.
A: This question is very similar to asking what is the difference between:
$$x^2+3x+2=0$$
$$y^2+3y+2=0$$
And the answer is, absolutely nothing!.
A: Formally, the $x$ in $\{x\in K\mid p(x)\}$ is bound by the set builder notation, so it is "not visible" from outside the set builder and is completely distinct from any uses the letter $x$ may have outside it.
So for example,
$$ \bigl\{x\in\mathbb R \bigm| x-1 \in \{ x\in \mathbb R \mid x+x=x \} \bigr\} $$
is exactly the same as
$$ \bigl\{x\in\mathbb R \bigm| x-1 \in \{ y\in \mathbb R \mid y+y=y \} \bigr\} = \{ x\in\mathbb R \mid x-1 \in \{0\} \} = \{1\} $$
and cannot have any other meaning than this.

However in practice using a dummy variable to "shadow" another use of the same variable letter can be confusing for a human reader and invites mistakes when he tries to disentagle what you have written. Since the purpose of mathematical writing is to communicate ideas to other humans, rather than instructing a machine, you should not do this without having a good reason to. And even if you have a good reason, you should probably also call out the potential for confusion explicitly in the surrounding text.
