Solution (source code)

= Solution

Under the <axiom of choice>, identify every infinite cardinal $\kappa$ with its <initial ordinal>. We prove $\kappa^2=\kappa$ by <transfinite induction> on infinite cardinals. The countable case follows from the usual diagonal enumeration of $\mathbb N\times\mathbb N$.

For the induction step, well-order the <Cartesian product> $\kappa\times\kappa$ by first comparing
$$
\max\{\alpha,\beta\}
$$
and then using lexicographic order among pairs with the same maximum. The predecessors of $(\alpha,\beta)$ lie in $(\eta+1)\times(\eta+1)$, where $\eta=\max\{\alpha,\beta\}<\kappa$. Put $\mu=|\eta+1|<\kappa$. If $\mu$ is infinite, the induction hypothesis makes this predecessor set have cardinal at most $\mu^2=\mu<\kappa$; if $\mu$ is finite, the same conclusion is immediate.

Let $\theta$ be the order type of this well-order. Every proper initial segment of $\theta$ therefore has cardinal less than $\kappa$. Hence $\theta<\kappa^+$, since otherwise its initial segment of order type $\kappa$ would have cardinal $\kappa$. Thus $|\kappa\times\kappa|=|\theta|\leq\kappa$. The map $\alpha\mapsto(\alpha,0)$ gives the reverse injection, and the <Cantor-Schröder-Bernstein theorem> yields
$$
\boxed{\kappa^2=\kappa.}
$$