Solution (source code)

= Solution

Choose a coprime presentation
$$
f(X,Y)=\frac{p(X,Y)}{q(X,Y)},
\qquad p,q\in\mathbb C[X,Y].
$$
For a <polynomial> $r$, write $r^*(X,Y)=r(Y,X)$. Symmetry of $f$ gives
$$
p q^*=p^*q.
$$
Since $\mathbb C[X,Y]$ is a <unique factorization domain> and $\gcd(p,q)=1$, one has $p\mid p^*$ and $q\mid q^*$. Exchanging the variables preserves total degree, so
$$
p^*=\lambda p,\qquad q^*=\mu q
$$
for nonzero constants $\lambda,\mu$. The displayed identity gives $\lambda=\mu$, and applying the exchange twice gives $\lambda^2=1$.

If $\lambda=-1$, then $p(X,X)=q(X,X)=0$, so $X-Y$ divides both <polynomials>, contradicting coprimality. Therefore $\lambda=1$, and both $p$ and $q$ are symmetric. Taking $g=p$ and $h=q$ proves the claim, which is the <symmetric rational function in two variables> result.