Bihomographic functions

Operations such as addition and multiplication on continued fractions can be computed as special cases of bihomographic functions, that is, functions of the form:

$f(x, y) = \frac{a x y + b x + c y + d} {e x y + f x + g y + h }$

The coefficients can be seen as elements of a three-dimensional $$2\times 2\times 2$$ matrix.

To evalute a bihomographic function on two continued fraction inputs, we need a three-dimensional version of the “magic table”. Before, the first row represented the numerator and the second row the denominator. Now we’ll go into the page, instead of down the page, and we’ll use $$p/q$$ to represent this.

Perhaps we should have done this all along. For example, to compute the convergents of $$\pi$$:

 3 7 15 1 292 … 0/1 1/0 3/1 22/7 333/106 355/113 …

When computing homographic functions, we sometimes need the reciprocal. For instance, during the first step of a previous example

 1 2 2 … 3/1 2/5 5/6

we notice the last two convergents have the same integer part, so we subtract and output it (i.e. zero) and invert. To perform the latter, we could erase the last two convergents and write $$5/2, 6/5$$ in their place, but instead, to preserve our intermediate steps and also because it’s more convenient and familiar, we simply append the new denominator:

$[0;1, ...]$
 1 2 2 … 3/1 2/5/2 5/6/5/1 17/12/5

It’s understood that not only do we ignore all but the last two terms, but we also ignore all but the last two numbers in those terms. We have thus freed the vertical dimension.

We may now use the horizontal axis for the input $$x = [a_1;a_2,...]$$, and the vertical axis for $$y = [b_1; b_2,...]$$. We initialize the table with

 $$a_1$$ $$a_2$$ … $$d/h$$ $$b/f$$ $$c/g$$ $$a/e$$ $$b_1$$ $$b_2$$ …

We perform the three-dimensional analogue of computing a homographic function. We focus on 2x2 blocks, applying the recurrence relations along the $$x$$-axis or $$y$$-axis or both until all four floor to the same integer. We subtract and output that integer, then reciprocate and repeat the process.

Let’s take Gosper’s example of computing

$\frac{ x + 2 x y}{y + x y}$

where $$x = \coth 1 = [1;3, 5, 7, 9,...]$$ and $$y = \sqrt{6} = [2;2, 4, 2, 4, ...]$$.

 1 3 5 … 0/0 1/0 0/1 2/1 2 2 4 …

The top two rows are not even well-defined, so we flee along the $$y$$-axis:

 1 3 5 … 0/0 1/0 0/1 2/1 2 0/2 5/2 2 4 …

The right column of the 2x2 focus block, $$2/1$$ and $$5/2$$, have the same integer part, so we move to the right to escape the disagreeable left column:

 1 3 5 … 0/0 1/0 0/1 2/1 2/2 2 0/2 5/2 5/4 2 4 …

The 2x2 block has yet to reach a consensus on the integer part, so we keep moving right.

 1 3 5 … 0/0 1/0 0/1 2/1 2/2 8/7 2 0/2 5/2 5/4 20/14 2 4 …

Now all four terms in question floor to $$1$$, so we output $$1$$, subtract it from each term, and invert:

$[1;...]$
 1 3 5 … 0/0 1/0 0/1 2/1 2/2/0 8/7/1 2 0/2 5/2 5/4/1 20/14/6 2 4 …

Recall the only terms that matter now are $$2/0, 7/1, 4/1, 14/6$$; all other numbers could be erased if desired. These floor to distinct values, so we move on. Either axis will do; we pick the vertical first because the numbers are smaller. Two steps later:

$[1;...]$
 1 3 5 … 0/0 1/0 0/1 2/1 2/2/0 8/7/1 2 0/2 5/2 5/4/1 20/14/6 74/31 2 10/2 35/13 185/67 4 …

Now all four floor to give $$2$$, which we output and subtract before inverting:

$[1;2,...]$
 1 3 5 … 0/0 1/0 0/1 2/1 2/2/0 8/7/1 2 0/2 5/2 5/4/1 20/14/6/2 74/31/12 2 10/2 35/13/9 185/67/51 4 …

The bottom two agree so we move along the $$y$$-axis.

$[1;2,...]$
 1 3 5 … 0/0 1/0 0/1 2/1 2/2/0 8/7/1 2 0/2 5/2 5/4/1 20/14/6/2 74/31/12 2 10/2 35/13/9 185/67/51 4 58/38 299/216 …

This yields $$1$$. And so on:

$[1;2, 1, 2, 1, 1, ...]$
 1 3 5 7 … 0/0 1/0 0/1 2/1 2/2/0 8/7/1 2 0/2 5/2 5/4/1 20/14/6/2 74/31/12 2 10/2 35/13/9/4 185/67/51/16 366/116 4 58/38/20 299/216/83/50/33/17 1550/601/348/253/95 2 483/182/119/63/56 3466/1318/830/488/342 …

We sometimes refer to this procedure as the quadratic algorithm.

Ben Lynn blynn@cs.stanford.edu 💡