Finding representatives of PSL_2(Z) orbits Given $\tau$ in the upper half plane, what is a good, systematic way to find a representative in the usual fundamental domain for the $PSL_2(Z)$-orbit of $\tau$? For example, let $\tau=\frac{2}{3} + \frac{1}{2}i$. Similarly, given $\tau$ and $\tau'$ in the upper half-plane, is there a practical way to check if they lie in the same orbit? 
 A: The algorithm mentioned by Qiaochu and Franz is the following.


*

*Let $z\in\mathbb{C}$ be arbitrary with $\Im z>0$.

*Replace $z$ by $z+n$, where $n\in\mathbb{Z}$ is uniquely determined by $-1/2<\Re (z+n)\leq 1/2$.

*If $|z|<1$, then replace $z$ by $-1/z$ and go back to step 2.

*$z$ is in the standard fundamental domain, so stop.
To prove that the algorithm stops in a finite number of steps it suffices to show that it arrives at step 3 only finitely many times. Note that whenever the algorithm arrives at step 3, it increases the imaginary part of $z$, then in step 2 it produces another $z$ with the same imaginary part, but in the strip $-1/2<\Re z\leq 1/2$. Hence it suffices to show the following.
Proposition. Let $z\in\mathbb{C}$ be arbitrary with $\Im z>0$. Then there are only finitely many $\gamma\in\mathrm{SL}_2(\mathbb{Z})$ such that $-1/2<\Re(\gamma z)\leq 1/2$
and $\Im(\gamma z)>\Im z$.
Proof. Let $\gamma=\left(\begin{matrix}a b \\\ c d\end{matrix}\right)\in\mathrm{SL}_2(\mathbb{Z})$ be such that $-1/2<\Re(\gamma z)\leq 1/2$
and $\Im(\gamma z)>\Im z$. Then
$\Im(\gamma z)=|cz+d|^{-2}\Im z$, hence $|cz+d|^2<1$. In other words, denoting $z=x+iy$, we have $(cx+d)^2+(cy)^2<1$. This shows that there are finitely many choices for $c$, and for each $c$ there are finitely many choices for $d$. On the other hand, for fixed coprime $c$ and $d$, it is straightforward to see that the matrices $\gamma=\left(\begin{matrix}a b \\\ c d\end{matrix}\right)\in\mathrm{SL}_2(\mathbb{Z})$ form a right coset of the subgroup $\left(\begin{matrix}1 \mathbb{Z} \\\ 0 1\end{matrix}\right)$, hence there is precisely one such $\gamma$ with
$-1/2<\Re(\gamma z)\leq 1/2$. Done.
A: Use the  continued fraction algorithm: repeatedly add an integer to make the real part at most 1/2, then invert if this increases the absolute value. For real numbers this usually continues indefinitely and produces a continued fraction expansion, while for non-real numbers it terminates after a finite number of steps, producing an element in a fundamental domain. 
