  It has long been known that the set of primitive pythagorean triples can be
enumerated by descending certain ternary trees. We unify these treatments by
considering hyperbolic billiard tables in the Poincare disk model. Our tables
have m>=3 ideal vertices, and are subject to the restriction that reflections
in the table walls are induced by matrices in the triangle group
PSU^\pm_{1,1}\Zbb[i]. The resulting billiard map \tilde B acts on the de Sitter
space x_1^2+x_2^2-x_3^2=1, and has a natural factor B on the unit circle, the
pythagorean triples appearing as the B-preimages of fixed points. We compute
the invariant densities of these maps, and prove the Lagrange and Galois
theorems: A complex number of unit modulus has a preperiodic (purely periodic)
B-orbit precisely when it is quadratic (and isolated from its conjugate by a
billiard wall) over Q(i).
  Each B as above is a (m-1)-to-1 orientation-reversing covering map of the
circle, a property shared by the group character T(z)=z^{-(m-1)}. We prove that
there exists a homeomorphism Phi, unique up to postcomposition with elements in
a dihedral group, that conjugates B with T; in particular Phi -- whose
prototype is the classical Minkowski question mark function -- establishes a
bijection between the set of points of degree <=2 over Q(i) and the torsion
subgroup of the circle. We provide an explicit formula for Phi, and prove that
Phi is singular and Holder continuous with exponent log(m-1) divided by the
maximal periodic mean free path in the associated billiard table.
