TITLE: Definability of Gödel's pairing function on ordinals
QUESTION [14 upvotes]: Given an infinite cardinal $\kappa$, Gödel's function is a well-known bijection $p:\kappa^2\to\kappa$.
Is $p$ definable in the structure $\langle\kappa;\in\rangle$?
Is $p$ definable in a bigger 2nd order structure $\langle\kappa;\mathcal P(\kappa);\in\rangle$?
It looks like any typical attempt to code something like this (even + on ordinals) somehow refers to a pairing function.

REPLY [11 votes]: For $\langle\kappa,{\in}\rangle$, James Hanson has already answered the question as stated. However, let me mention a generalization: it’s not just Gödel’s pairing function that’s not definable in $\langle\kappa,{\in}\rangle$—in fact, there is no injective pairing function definable in these structures.
The reason for this is the computational complexity (or rather, easiness) of $\mathrm{Th}(\kappa,{\in})$. The results on quantifier elimination in [1] easily imply that if $\phi$ is an $\exists_n$ sentence, then
$$\langle\kappa,{\in}\rangle\models\phi\iff\langle\omega^n,{\in}\rangle\models\phi.$$
Moreover, $\langle\omega^n,{\in}\rangle$ has an obvious $n$-dimensional interpretation in $\langle\omega,{\in}\rangle$. This provides a polynomial-time reduction of the theory of $\langle\kappa,{\in}\rangle$ to the theory of $\langle\omega,{\in}\rangle$, which is known to be decidable in PSPACE; therefore,

Proposition: $\mathrm{Th}(\kappa,{\in})$ is decidable in PSPACE.

On the other hand, [2] proved that no consistent theory with a definable pairing function is in ELEMENTARY (which includes PSPACE, and much, much more).

Corollary: No pairing function is definable in $\langle\kappa,{\in}\rangle$.

References:
[1] John E. Doner, Andrzej Mostowski, Alfred Tarski: The elementary theory of well-ordering—a metamathematical study—, in: Logic Colloquium ’77 (A. Macintyre, L. Pacholski, J. Paris, eds.), Studies in Logic and the Foundations of Mathematics vol. 96, Elsevier, 1978, pp. 1–54, doi 10.1016/S0049-237X(08)71988-8.
[2] Jeanne Ferrante, Charles W. Rackoff: The computational complexity of logical theories, Lecture Notes in Mathematics vol. 718, Springer-Verlag, 1979, Chapter 8, doi 10.1007/BFb0062837.