One sparkling gem at the intersection of number theory and geometry is Aubry's *reflective* generation of primitive Pythagorean triples, i.e. coprime naturals $\,(x,y,z)\,$with $\,x^2 + y^2 = z^2.\,$ Dividing by $z^2$ yields $\,(x/z)^2\!+(y/z)^2 = 1,\,$ so each triple corresponds to a rational point $(x/z,\,y/z)$ on the unit circle. Aubry showed that we can generate all such triples by a very simple geometrical process. Start with the trivial point $(0,-1)$. Draw a line to the point $\,P = (1,1).\,$ It intersects the circle in the *rational* point $\,A = (4/5,3/5)\,$ yielding the triple $\,(3,4,5).\,$ Next reflect the point $\,A\,$ into the other quadrants by taking all possible signs of each component, i.e. $\,(\pm4/5,\pm3/5),\,$ yielding the inscribed rectangle below. As before, the line through $\,A_B = (-4/5,-3/5)\,$ and $P$ intersects the circle in $\,B = (12/13, 5/13),\,$ yielding the triple $\,(12,5,13).\,$ Similarly the points $\,A_C,\, A_D\,$ yield the triples $\,(20,21,29)\,$ and $\,(8,15,17),\,$

We can iterate this process with the new points $\,B,C,D\,$ doing the same we did for $\,A,\,$ obtaining further triples. By induction this process generates the primitive triples as a ternary tree

$\qquad\qquad$

Descent in the tree is given by the formula (whose *reflective* geometric genesis is given below)

$$\begin{eqnarray} (x,y,z)\,\mapsto &&(x,y,z)-2(x\!+\!y\!-\!z)\,(1,1,1)\\ = &&(-x-2y+2z,\,-2x-y+2z,\,-2x-2y+3z)\end{eqnarray}$$

e.g. $\ (12,5,13)\mapsto (12,5,13)-8(1,1,1) = (-3,4,5),\ $ yielding $\,(4/5,3/5)\,$ when reflected into the first quadrant.

Ascent in the tree is by inverting this map, combined with trivial sign-changing reflections:

$\quad\quad (-3,+4,5) \,\mapsto\, (-3,+4,5) - 2 \; (-3+4-5) \; (1,1,1) = ( 5,12,13)$

$\quad\quad (-3,-4,5) \,\mapsto\, (-3,-4,5) - 2 \; (-3-4-5) \; (1,1,1) = (21,20,29)$

$\quad\quad (+3,-4,5) \,\mapsto\, (+3,-4,5) - 2 \; (+3-4-5) \; (1,1,1) = (15,8,17)$

Continuing in this manner we can reflectively generate the entire tree of primitive Pythagorean triples, e.g. the topmost edge of the triples tree corresponds to the ascending $C$-inscribed zigzag line
$(-1,0), (3/5,4/5), (-3/5,4/5), (5/12,12/13), (-5/12,12/13), (7/25,24/25), (-7/25,24/25) \ldots$

Let's look a bit closer at the underlying geometry. Consider the quadratic space $Z$ of the form $Q(x,y,z) = x^2 + y^2 - z^2\,$
with Lorentzian inner product $(Q(x\!+\!y)-Q(x)-Q(y))/2\,$ given by

$\qquad v \cdot u\, =\, v_1 u_1 + v_2 u_2 - v_3 u_3.\ \ $
Recall that the *reflection* of $v$ in $u$ is given by

$\quad\quad v\, \mapsto\, v - 2 \dfrac{v \cdot u}{u \cdot u} u \quad$ Reflectivity is clear: $\; u \mapsto -u$, and $\; v \mapsto v$ if $\; v\perp u, \;$ i.e. $v\cdot u = 0$.

With $\; v = (x,y,z)$ and $\; u = (1,1,1)$ of norm $1$ we have

$\quad\quad (x,y,z)\; \mapsto (x,y,z) - 2 \dfrac{(x,y,z)\cdot(1,1,1)}{(1,1,1)\cdot(1,1,1)} (1,1,1)$

$\qquad\qquad\qquad =\, (x,y,z) - 2 \; (x\!+\!y\!-\!z) \; (1,1,1)$

$\qquad\qquad\qquad =\, (-x\!-\!2y\!+\!2z, \; -2x\!-\!y\!+\!2z, \; -2x\!-\!2y\!+\!3z)$

This is the nontrivial reflection that effects the descent in the triples tree. Said more simply: $ $ if $\,x^2 + y^2 = z^2\,$ then $\,(x/z, y/z)\,$ is a rational point $P$ on the unit circle $C$ then a simple calculation shows that the line through $P$ and $(1,1)$ intersects $C$ in a *smaller* rational point, given projectively via the above reflection.

This technique easily generalizes to the form $ x_1^2 + x_2^2 + \cdots + x_{n-1}^2 = x_n^2$
for $4 \le n \le 9$, but for
$n \ge 10 $ the Pythagorean n-tuples fall into at least $[(n+6)/8]$
distinct orbits under the automorphism group of the form - see Cass & Arpaia (1990) [1]

There are also generalizations to different shape forms that were first used by L. Aubry (Sphinx-Oedipe 7 (1912), 81-84) to give elementary proofs of the $3$ & $4$ square theorem (see
Appendix 3.2 p. 292 of Weil's: *Number Theory an Approach Through History*). These results show that if an
integer is represented by a form rationally, then it must also be so integrally. The method also applies to the following forms $x^2+y^2, x^2 \pm 2y^2, x^2 \pm 3y^2,
x^2+y^2+2z^2, x^2+y^2+z^2+t^2,\ldots$ More precisely, essentially the same proof as for
Pythagorean triples shows

**Theorem** $ $ Suppose that the $n$-ary quadratic form $F(x)$ has integral
coefficients and has no nontrivial zero in ${\mathbb Z}^n$, and suppose
that for any $x \in {\mathbb Q}^n$ there is $\,y \in {\mathbb Z}^n$ such that
$\; |F(x\!-\!y)| < 1$. Then $F$ represents $m$ over $\mathbb Q$ $\iff$ $F$ represents
$m$ over $\mathbb Z$, for all nonzero integers $m$.

The condition $|F(x\!-\!y)| < 1$ is closely connected to the Euclidean algorithm.
In fact there is a function-field analog that employs the Euclidean algorithm which was independently rediscovered by Cassels in 1963: $ $ a polynomial is a sum of $n$ squares in $k(x)$ iff the same holds true in $k[x]$.
Pfister immediately applied this to obtain a complete solution of the level problem
for fields. Shortly thereafter he generalized Cassels result to arbitrary quadratic forms, founding the modern algebraic theory of quadratic forms ("Pfister forms").

Aubry's results are, in fact, very special cases of general results of Wall, Vinberg, Scharlau et al. on **reflective lattices**, i.e. arithmetic groups of isometries generated by reflections in hyperplanes. Generally reflections generate the orthogonal group of Lorentzian quadratic forms in dim $< 10$.

[1] Daniel Cass; Pasquale J. Arpaia

Matrix Generation of Pythagorean n-Tuples.

Proc. Amer. Math. Soc. 109, 1, 1990, 1-7.