Defining ordered pairs using only first-order logic

$p= \langle x, y \rangle \iff \forall z (z \in p \iff \exists w_1 \exists w_2 ((z=w_1 \lor z=w_2) \land ((\forall t_1(t_1 \in w_1 \iff t_1=x)) \land \forall t_2(t_2 \in w_2 \iff (t_2 = x \lor t_2 = y)))).$

Translating this to English, $w_1$ and $w_2$ are the two elements of the set comprising our ordered pair, with $t_1$ as the element of $w_1$ (which we're forcing to be $x$) and $t_2$ as the elements of $w_2$ (which we're forcing to be $x$ or $y$).


Here is a more or less mechanical way to do the expansion. First, $p = \langle x, y \rangle = \{ \{ x \}, \{ x, y \} \}$ is equivalent to: $$\forall a, a \in p \leftrightarrow (a = \{ x \} \vee a = \{ x, y \}).$$ Now, we can (by manual recursion) replace $a = \{ x \}$ with: $$\forall b, b \in a \leftrightarrow b = x.$$ Similarly, replace $a = \{ x, y \}$ with: $$\forall b, b \in a \leftrightarrow (b = x \vee b = y).$$ Therefore, substituting in, we get that $p = \langle x, y \rangle$ is equivalent to: $$\forall a, a \in p \leftrightarrow [(\forall b, b \in a \leftrightarrow b = x) \vee (\forall b, b \in a \leftrightarrow (b = x \vee b = y))].$$


Note that a generalization of this procedure (formalized) comes up in model theory, under the name of "conversative extension by definition". (However, in general, in expanding a formula not of the form variable = definition, we might need to introduce some more variables. For example, if you wanted to expand $\langle x, y \rangle \in z$ instead, then you would first need to expand this to $\exists p, p = \langle x, y \rangle \wedge p \in z$, and then proceed to expand $p = \langle x, y \rangle$ as above.)