Solution (source code)

= Solution

Let $\zeta=e^{2\pi i/n}$ and define Möbius transformations
$$
r(z)=\zeta z,
\qquad
s(z)=\frac1z.
$$
They satisfy
$$
r^n=s^2=1,
\qquad srs=r^{-1},
$$
and the $2n$ maps $r^k$ and $sr^k$ are distinct. They therefore give a faithful action of the <dihedral group> $D_{2n}$ on the <Riemann sphere>.

The <rational function>
$$
\boxed{
f(z)=z^n+z^{-n}=\frac{z^{2n}+1}{z^n}
}
$$
is invariant under both $r$ and $s$, so it is constant on every orbit. Conversely, for nonzero finite $z_1,z_2$, put $u=z_1^n$ and $v=z_2^n$. Equality of the function values gives
$$
u+u^{-1}=v+v^{-1}
\quad\Longleftrightarrow\quad
(u-v)(uv-1)=0.
$$
If $u=v$, then $z_2=\zeta^kz_1=r^kz_1$ for some $k$. If $uv=1$, then $z_2=\zeta^k/z_1=r^ksz_1$ for some $k$. Finally, zero and infinity both map to infinity and are interchanged by $s$. Hence
$$
\boxed{f(z_1)=f(z_2)\quad\Longleftrightarrow\quad z_1,z_2\text{ lie in the same }D_{2n}\text{-orbit}}.
$$
This is the <orbit-separating invariant for the standard dihedral action on the Riemann sphere>.