Decomposition of modular group elements The modular group $PSL_2(\mathbb{Z})$ acts on the hyperbolic half-space $H$ by
$$h\cdot z=\frac{az+b}{cz+d},\;z\in H,\;h=\begin{pmatrix}a&b\\c&d\end{pmatrix}\in PSL_2(\mathbb{Z})$$
with $ad-bc=1$. The modular group is generated by two elements $S$ and $T$ such that
$$S^2=(ST)^3=1,$$
where we can represent them (remembering this is a projective group, so overall sign doesn't matter) as
$$S=\begin{pmatrix}0&-1\\1&0\end{pmatrix},\quad T=\begin{pmatrix}1&1\\0&1\end{pmatrix}.$$
I know that there is a simple rationalizing procedure for going from
$$T^{a_1}ST^{a_2}S\cdots ST^{a_k}\to\begin{pmatrix}a&b\\c&d\end{pmatrix}$$
(or simple matrix multiplication), but is there a way to generate a sequence of $a_i$ from known $a,b,c,d$? I know that the sequence is not unique; perhaps conditions on what values of $a_i$ can be or how large/small $k$ can be can make this unique?
 A: Corrected posting: ${\rm PSL}(2,\mathbb{Z})$ is the free product of $\langle S \rangle$ and $\langle ST \rangle,$ so, setting $U = ST$,  for a given matrix $M$ (mod scalars), the  expression for $M$ is unique if we write it in the form $S^{\alpha} U^{b_{1}}SU^{b_{2}}SU^{b_{3}}\ldots SU^{b_{n}}S^{\beta}$, where each $b_{i} \in \{1,-1\}$ (or $\{1,2 \}$ if you prefer), and $\alpha, \beta \in \{0, 1\}$ with $\alpha \beta = 0$ if $n=0.$ (The possibility than $n=0$ is allowed yielding $S$ if $n=0$ and $\alpha \beta = 0 \neq \alpha + \beta$, and $I$ if $\alpha  = \beta =0$. Note that when $ n= 0$, there is no distinction between $\alpha = 0, \beta =1$ and $\alpha = 1, \beta = 0).$
Actually, given a word in $S$ and $T$, we can write it as a word in $S$ and $SU$, and apart from obvious cancellations in the resulting word, no further simplification is possible.
so, for example, $T^{m} = (SU)^{m}$ can't be shortened in any way as a word in $S$ and $U.$
Also, $ST^{m} = (US)^{m-1}U,$ can't be shortened.  So when we write the word in terms of $S$ and $T,$ there will generally be no upper bound on the powers of $T$ that might appear.
There is a standard algorithm for expressing the matrix you gave as a word in $S$ and $T$. The idea is to keep reducing $|c|$ whenever $c \neq 0$- when we get to $c =0,$which we do,  we are left with (up to a factor of $\pm 1$ ) with a power of $T.$ We can assume $|c| \leq |a|$, otherwise we could multiply by $S$ to make it so. Now we write $a = qc+ r$ where $0 \leq |r| < |c|$. Multiplying our matrix by $T^{-q}$ gives us a matrix with $r$ in the $(1,1)$-position. Now we can multiply by $S$ to obtain a matrix with $(2,1)$ entry of absolute value less than than $|c|.$
