Let $\Gamma=\text{SL}_2(\mathbb Z)$ act on $\mathbb H=\{z \in \mathbb C: Im(z) > 0\}$ by $\gamma z=\frac{az+b}{cz+d}$, where $\gamma$ is the matrix $\left[\begin{matrix} a & b \\ c & d \end{matrix}\right]$.
It is well known that a fundamental domain for this action is $D=\{z \in \mathbb H: |Re(z)|<\frac12, |z|>1\}$.
I want to write a program for which I need to display the unique representative in $D$ of the orbit of various points of $\mathbb H$.
To this end, I think I have write a procedure that finds, given any $z_0$ in $\mathbb H$, the (unique up to sign) element of $\text{SL}_2(\mathbb Z)$ that sends $z_0$ into $D$. How does one do this?
An existing proof of the precise statement contains some constructive ideas.
First we find $c$ and $d$ such that $|cz_0+d|^2$ is minimal. We must have $\gcd(c,d)=1$ automatically, so we pick $a'$ and $b'$ such that $a'd-b'c=1$. It remains to take an integer $n$ closest to the real part of $\frac{a'z_0+b'}{cz_0+d}$ and put $a=a'-nc,b=b'-nd$ to build a final $\gamma$. To ensure it is unique, you have to deal not only with choice of sign, but also with $\gamma z_0$ landing in the boundary of $D$ (and it will still not be unique in some degenerate cases you should be aware of).