Unexpected appearance of Pythagorean triples in a homeomorphism between the 1-sphere and the extended real line

pythagorean triples I was thinking about various kinds of mappings of prime numbers and wondered in particular what prime numbers would look like when projected from the (extended) real line to the 1-sphere by a homeomorphism linking these two spaces. When I did the calculations I was amazed to find that prime numbers are mapped to a family of Pythagorean triples on the 1-sphere! This came as a complete surprise to me but I later learned that the link between stereographic projection and Pythagorean triples is already well known. Nevertheless, in this note I want to quickly record how I stumbled on this result.

onesphere Consider the three points N, Q and P in the diagram. Since they are collinear there must be a scalar t such that

P = N + t(Q - N)

Writing this equation in vector form we get

(x, 0) = (0, 1) + t\big((x_1, x_2) - (0, 1) \big)

= (x_1 t, t(x_2 - 1) + 1)

from which we deduce

x = x_1 t

\implies t = \frac{x}{x_1}

and

t(x_2 - 1) + 1 = 0

\implies t = \frac{1}{1 - x_2}

Equating these two expressions for t we get

\frac{x}{x_1} = \frac{1}{1 - x_2}

\implies x = \frac{x_1}{1 - x_2}

The function \pi(x_1, x_2) = \frac{x_1}{1 - x_2} is the homeomorphism which maps points on the 1-sphere to points on the extended real line.

I was more interested in the inverse function \pi^{-1}(x) which maps points on the extended real line to the 1-sphere. To find this, observe that

x^2 + 1 = \frac{x_1^2}{(1 - x_2)^2} + \frac{(1 - x_2)^2}{(1 - x_2)^2}

Using x_1^2 + x_2^2 = 1 we have x_1^2 = 1 - x_2^2 so the above equation can be written as

x^2 + 1 = \frac{1 - x_2^2}{(1 - x_2)^2} + \frac{(1 - 2x_2 + x_2^2)}{(1 - x_2)^2}

= \frac{2 - 2x_2}{(1 - x_2)^2} = \frac{2}{1 - x_2}

Therefore

x^2 + 1 = \frac{2}{1 - x_2}

\implies x_2 = \frac{x^2 - 1}{x^2 + 1}

and then

x = \frac{x_1}{1 - x_2}

\implies x_1 = \frac{2x}{x^2 + 1}

Therefore if x is a prime, the corresponding point on the 1-sphere is

\bigg( \frac{2x}{x^2 + 1}, \frac{x^2 - 1}{x^2 + 1} \bigg)

However, the numbers 2x, x^2 - 1 and x^2 + 1 are then Pythagorean triples, as can easily be demonstrated by showing that these terms satisfy the identity

(2x)^2 + (x^2 - 1)^2 \equiv (x^2 + 1)^2