Given $p/q, r/s \in \mathbb{Q}$, where $\gcd(p,q)=\gcd(r,s)=1$, choose the triangles in the Farey tessellation whose interior intersects the geodesic connecting $p/q$ and $r/s$ in $\mathbb{H}^2$. ![alt text][1] If $ps-qr=1$, then $d(p/q,r/s)=1$ and there is a geodesic of the Farey tessellation connecting the two points. Otherwise, there will be a non-trivial triangle intersecting the geodesic. Associated to this sequence of triangles is a canonical sequence $[p_1,p_2, \ldots, p_k]$, where $p_1>1, p_k>1$. Define $l([p_1,p_2,\ldots,p_k])=d(p/q,r/s)$. ![alt text][2] Note that the sequence of triangles $[1,p_2, \ldots, p_k]$ is the same as the sequence $[1+p_2, \ldots, p_k]$, since the lone triangle may be absorbed into the next sequence, which is why we may assume that $p_1>1$, and similarly $p_k>1$. The formula for the the Farey distance is computed inductively by $l([p_1,p_2,\ldots,p_k]) = 1+ l([p_2,\ldots,p_k])$, and for $k=1$, $l(p_1)= 2$ (we are assuming that $p_1>1$, since otherwise $d(p/q,r/s)=1$). Here, if $p_2=1$, then $l([p_2,\ldots,p_k])=l([1+p_3,\ldots,p_k])$. To prove this formula, notice that in the diagram there is a sequence of $k+1$ "pivots", starting with $p/q$ and ending with $r/s$. One can see that a shortest path from $p/q$ to $r/s$ must go through the adjacent pivot. If not, a case-by-case analysis shows that one can find a shorter path, unless $p_1=2$ and the path goes through the lower two edges. But then one can take an equal length path going through the pivot. To relate this to the continued fraction expansion, use an element of $A\in PGL_2(\mathbb{Z})$ such that $A(p/q)=\infty$, and $0\leq A(r/s) \leq 1/2$. Then $d(p/q,r/s)=d(A(p/q),A(r/s))=d(\infty,A(r/s))$. To compute the triangle sequence in this case, we may use the continued fraction expansion for $A(r/s)$ to get $[p_1,\ldots,p_k]$ via $A(r/s)=1/(p_1+1/(p_2+\cdots +1/p_k)\cdots )$: ![convex][3] In this example, $p/q=\infty=1/0$, $r/s=2/5$, and the continued fraction is $[2,2]$, since $2/5=1/(2+1/2)$. [1]: http://math.berkeley.edu/~ianagol/tree2.pdf [2]: http://dl.dropbox.com/u/8592391/pivotseq2.pdf [3]: http://math.berkeley.edu/~ianagol/convex.pdf