Defining ordered pairs and Cartesian products. I was working through an analysis textbook (I am very inexperienced) and am confused.
The first exercise was to prove that an ordered pair $(x,y)$ can be represented as the set$\{\{x\},\{x,y\}\}$, which I think I successfully proved. However, the next question was to prove that $(x,y):=\{x,\{x,y\}\}$ is also a valid definition of an ordered pair.
The question states that to do so, you need to use the axiom of regularity.
However, I don't understand where this is needed.
Where am I wrong in this:
If $(x,y):=\{x,\{x,y\}\}$ is a valid definition, then $\{x,\{x,y\}\}$ uniquely specifies $x$ and $y$.
In other words, if this definition satisfies $(x,y) = (x',y')$ if and only if $x=x'$ and $y=y'$, then it is a successful definition. Now, consider if $\{x,\{x,y\}\} = \{x',\{x',y'\}\}$. Considering the elements of the two sets, one is a set and one is not a set. Hence, if all elements are equal, as per the definition of set equality, $x=x'$ and $\{x,y\} = \{x',y'\}$. Now, as $x=x'$, $\{x,y\} = \{x',y'\}$ if and only if $y=y'$. Hence, $(x,y):=\{x,\{x,y\}\}$  satisfies $(x,y) = (x',y')$ if and only if $x=x'$ and $y=y'$ and is thus a successful definition.
Where is the flaw in this reasoning?
 A: "Considering the elements of the two sets, one is a set and one is not a set." - No. It may well be that $x$ and $y$ themselves are sets (and in set theory they almost always will be sets as "everything" is a set there)
From $\{x,\{x,y\}\}=\{x',\{x',y'\}\}$ you can conclude (among others)  that $x=x'\lor x=\{x',y'\}$, but you cannot simply eliminate the second option because you claim that $x$ is not a set.
So what if $x\ne x'$? Then, as mentioned, $x=\{x',y'\}$ and by the same argument $x'=\{x,y\}$. Hence $x=\{\{x,y\},y'\}$, an this kind of nesting is what the Axiom of Regularity (or Foundation) tells us is impossible.
A: 
Considering the elements of the two sets, one is a set and one is not a set.

This is incorrect. Remember that in set theory, everything is a set. E.g. $x$ could be $\{\{\}, \{\{\}\},\{\{\{\{\},\{\{\}\}\}\}\}\}$ (have fun parsing that!). More importantly, we could have $x$ be a set with two elements - then both $x$ and $\{x, y\}$ look the same at first glance (they're both sets with two elements).
Now in some sense, we should still be able to distinguish them: since $\{x, y\}$ contains $x$ as an element, it's reasonable to guess that $\{x, y\}$ is somehow "more complicated" than $x$, in a way that (if we're lucky) will let us distinguish them in $\{x, \{x, y\}\}$. This is where Regularity comes in. Namely, we obviously have $x\in\{x, y\}$ - if we can just rule out $\{x, y\}\in x$, then we can tell which part of the ordered pair is which. But ruling out $\{x, y\}\in x$ can't be done without Regularity - indeed, it's consistent with ZFC - Regularity that there are sets satisfying $a=\{a\}$!
A: In set theory, all objects are considered sets, so you can't use the argument "one element is a set, the other isn't". Instead, suppose $x=\{x',y'\}$ and derive a contradiction to the axiom of regularity.
