Open problems / 137

The rational tree of x + 1 and −1/x

Start at $0$ and repeatedly apply $x \mapsto x+1$ and $x \mapsto -1/x$. Every rational number turns up eventually. Sort them by how many steps they need, and the counts satisfy $a(n) = a(n-1) + a(n-3)$ from $n = 4$ onwards. Kagey asked whether that is true. It is, and $n \ge 4$ cannot be improved.

The setup

Take the two maps $f(x) = x+1$ and $g(x) = -1/x$, start at $0$, and apply them in any order you like. Every rational number is reachable. That is because $f$ and $g$ generate the modular group, and organising the rationals by how many steps they need produces the tree of A226247.

Write $d(x)$ for the least number of steps needed to produce $x$ from $0$, which Kagey calls the rank, and let

$$a(n) = \#\{x \in \mathbb{Q} : d(x) = n\}.$$

The first few values are $1, 1, 2, 2, 3, 5, 7, 10, 15, 22$. Stare at those for a moment and the pattern is hard to miss: each one looks like the sum of the previous and the one three before it.

Does $a(n) = a(n-1) + a(n-3)$ hold for all $n \ge 4$?

It does. Two related questions came with it, and both have clean answers. A vertex is coloured blue when the last map used to reach it is $g$, and it turns out a vertex is blue exactly when its value is negative. And the rank-$n$ rationals can be written down explicitly, not just counted.

Every rational has one parent

The whole solution comes from running the process backwards. Define the parent map on the non-zero rationals by

$$P(x) = \begin{cases} x - 1, & x > 0,\\[2pt] -1/x, & x < 0.\end{cases}$$

This undoes an edge of the tree, and the choice is forced: it undoes $f$ when $x$ is positive and $g$ when $x$ is negative.

Iterating $P$ from any rational reaches $0$ in finitely many steps.

A positive $x$ loses $1$ each step until it lands in $(-1,0)$ or hits $0$. For $z \in (-1,0)$, write $z = -r/q$ in lowest terms with $0 < r < q$. Then $P(z) = q/r > 1$, whose lowest-terms denominator is $r < q$. So each trip through the negatives strictly reduces the denominator, and induction on the denominator finishes it.

So we can define $D(x)$ to be the number of $P$-steps from $x$ to $0$. The point of the argument is that $D$ is not merely an upper bound for the rank, it is the rank.

$d(x) = D(x)$ for every rational $x$.

One direction is easy, since reversing the $P$-orbit exhibits a path of that length. The other needs four increment identities, which follow from unwinding the definition:

  • if $x > 0$, then $D(x) = D(x-1) + 1$,
  • if $x < 0$, then $D(x) = D(-1/x) + 1$,
  • if $x > 0$, then $D(-1/x) = D(x) + 1$,
  • if $x < 0$, then $D(x-1) = D(x) + 3$.

The last one is the interesting one, and it is where the $3$ in the recurrence is born. Following four steps of the orbit of $x - 1$ for negative $x$ gives

$$x - 1 \;\xmapsto{\ P\ }\; \frac{1}{1-x} \;\xmapsto{\ P\ }\; \frac{x}{1-x} \;\xmapsto{\ P\ }\; 1 - \frac1x \;\xmapsto{\ P\ }\; -\frac1x = P(x),$$

so $D(x-1) = D(x) + 3$. Read backwards this says $x - 1 = (g \circ f \circ g \circ f \circ g)(x)$, which is exactly the relation $f^{-1} = gfgfg$ from the problem statement. In group terms it is $(gf)^3 = \mathrm{id}$ in $\mathrm{PSL}_2(\mathbb{Z})$. The cost is the five letters of the relator minus the cancellation $gg = \mathrm{id}$, which leaves $3$.

With the identities in hand, every edge $y \to x$ satisfies $D(x) \le D(y) + 1$, and induction on the shortest path length gives $d \ge D$. Two corollaries drop out immediately.

Each non-zero $x$ has exactly one in-neighbour closer to $0$, namely $P(x)$. So the construction really is a tree, with no ties to break, and a vertex is blue exactly when its value is negative.

0 at rank 001 at rank 11-1 at rank 2-12 at rank 22−1/2 at rank 3−1/23 at rank 331/2 at rank 41/2−1/3 at rank 4−1/34 at rank 44-2 at rank 5-23/2 at rank 53/22/3 at rank 52/3−1/4 at rank 5−1/45 at rank 55−2/3 at rank 6−2/35/2 at rank 65/2−3/2 at rank 6−3/25/3 at rank 65/33/4 at rank 63/4−1/5 at rank 6−1/56 at rank 661/3 at rank 71/3−2/5 at rank 7−2/57/2 at rank 77/2−3/5 at rank 7−3/58/3 at rank 78/3−4/3 at rank 7−4/37/4 at rank 77/44/5 at rank 74/5−1/6 at rank 7−1/67 at rank 7701234567112235710
a(n) = a(n−1) + a(n−3) at n =

The tree through rank 7, one row per rank, with the size of each row in the right margin. Those sizes are the sequence $1, 1, 2, 2, 3, 5, 7, 10$. Pick an $n$ and the two rows being added light up together with the row they add up to, so $a(n) = a(n-1) + a(n-3)$ can be read straight off the drawing. It holds from $n = 4$ on and misses by one at $n = 3$. Marked vertices are the negatives, and the hollow ones, at $x \le -1$, are the leaves whose $f$-image is three ranks old. That three is the same three as in the recurrence.

That settles the first related question. The structure is worth recording too. A vertex $x > 0$ has two children, $x+1$ and $-1/x$. A vertex in $(-1,0)$ has one child. A vertex $x \le -1$ is a leaf, because its $f$-image is not new but three ranks old.

A formula for the rank

Negative continued fractions turn the rank into a digit sum. Write

$$[c_1; c_2, \dots, c_k]^- = c_1 - \cfrac{1}{c_2 - \cfrac{1}{\ddots}}$$

Every positive rational has exactly one such expansion with $c_1 \ge 1$ and $c_i \ge 2$ for $i \ge 2$, and then $c_1 = \lceil x \rceil$.

For $x > 0$ with $x = [c_1; c_2, \dots, c_k]^-$,

$$d(x) = c_1 + c_2 + \cdots + c_k + k - 1,$$

and for $x < 0$, $d(x) = d(-1/x) + 1$.

The proof is a direct reading of the $P$-orbit. It makes $c_1$ subtractions, one flip, and then recurses on $[c_2; \dots, c_k]^-$.

There is an equivalent version in ordinary continued fractions, which is uglier but sometimes more convenient. Normalise $x > 0$ to its odd-length expansion $x = [a_0; a_1, \dots, a_r]$, which is unique, and then

$$d(x) = \sum_{i \text{ even}} a_i + 3\sum_{i \text{ odd}} a_i - 2.$$

For example $\tfrac35 = [0;1,1,2]$ gives $d = (0+1) + 3(1+2) - 2 = 8$. The factor of $3$ on the odd positions is the same $3$ as before, wearing different clothes.

This answers the second related question, because it hands you the rank-$n$ rationals explicitly rather than just their count. The positives of rank $n$ are the digit strings of weight $n+1-k$, and the negatives are $-1/y$ over the positives of rank $n-1$. For $n = 5$ the digit strings are $(5)$, $(1,3)$ and $(2,2)$, giving $5$, $\tfrac23$ and $\tfrac32$, and the negatives come from the rank-$4$ positives $4$ and $\tfrac12$, giving $-\tfrac14$ and $-2$. So rank $5$ is

$$\left\{\,5,\ \tfrac23,\ \tfrac32,\ -\tfrac14,\ -2\,\right\}.$$

Counting each rank

Let $r(n)$ count the positives of rank $n$. Since $x \mapsto -1/x$ matches the negatives of rank $n$ with the positives of rank $n-1$, we get $a(n) = r(n) + r(n-1)$. Counting the digit strings by weight gives a generating function on sight:

$$R(t) = \sum_{k \ge 1}\left(\frac{t}{1-t}\right)\left(\frac{t^3}{1-t}\right)^{k-1} = \frac{t}{1-t-t^3},$$

and therefore

$$A(t) = 1 + (1+t)R(t) = \frac{1 + t^2 - t^3}{1 - t - t^3}.$$

$a(n) = a(n-1) + a(n-3)$ for all $n \ge 4$, and this fails at $n = 3$.

Multiply out to get $(1 - t - t^3)A(t) = 1 + t^2 - t^3$. The numerator has degree $3$, so comparing coefficients of $t^n$ gives $a(n) - a(n-1) - a(n-3) = 0$ for every $n \ge 4$. At $n = 3$ the coefficient is $-1$, which matches $a(3) = 2$ against $a(2) + a(0) = 3$.

So the answer to Kagey's question is yes, and the bound $n \ge 4$ is sharp rather than cautious. The one place it fails is $n = 3$, and it fails by exactly one.

$n$$0$$1$$2$$3$$4$$5$$6$$7$$8$$9$$10$
$a(n)$112235710152232

The counts are not new sequences. $r(n)$ is Narayana's cows, A000930, shifted by one, and $a(n)$ is A097333 shifted by one. From the generating function, $a(n) \sim C\psi^n$ where $\psi = 1.4655712319\ldots$ is the supergolden ratio, the real root of $\psi^3 = \psi^2 + 1$, and $C = 0.7019310679\ldots$

x > 1−1 < x < 00 < x ≤ 1x ≤ −1three steps back to a positive
The four classes and the moves between them. A positive number cannot produce a new positive directly. It has to go out through the negatives and come back, and that round trip takes exactly three steps, which is the $t^3$ in the generating function. The class $x \le -1$ is where the leaves collect.

There is a structural way to see the same thing. Sorting each rank into four classes by where the value sits, $x > 1$, then $0 < x \le 1$, then $-1 < x < 0$, then $x \le -1$, gives exact transition rules between consecutive ranks. The transfer matrix has characteristic polynomial $t(t^3 - t^2 - 1)$. A positive number takes three steps to produce a new positive, going out through the negatives and back, and that three-step detour is the same relation $(gf)^3 = \mathrm{id}$ showing up a third time.

What was checked

Every claim above was verified two ways before it was written down.

  • A breadth-first reconstruction of the tree through rank $41$, about $1.4 \times 10^7$ vertices, confirms the rank formula, the blue-iff-negative characterisation, the child counts, and the recurrence.
  • The rank formula, uniqueness of the parent, the blue-vertex characterisation, the composition characterisation and the recurrence with its failure at $n = 3$ are formalised in Lean 4 with Mathlib, in 96 lemmas with no sorry.

The verification script in the repository reproduces the table in a few seconds, so none of this has to be taken on trust.