There are 2 tree roots (so technically it's a "forest") and each node has 3 children. The points are numbered by rows starting from N=0. This numbering corresponds to powers in a polynomial product generating function.

Which as X,Y coordinates means vertical, 45-degree diagonal, and horizontal.

X,Y+2X X+(X+Y),Y+(X+Y)
| /
| /
| /
| /
X,Y------- X+2Y,Y

The slowest growth is on the far left of the tree 1/2, 1/4, 1/6, 1/8, etc advancing by just 2 at each level. Similarly on the far right 2/1, 4/1, 6/1, etc. This means that to cover such an X or Y requires a power-of-3, N=3^(max(X,Y)/2).

Chan shows that these top nodes and children visit all rationals X/Y with X,Y one odd, one even. But the X,Y are not in least terms, they may have a power-of-3 common factor GCD(X,Y)=3^m for some m.

The GCD is unchanged in the first and third children. The middle child GCD might gain an extra factor 3. This means the power is at most the number of middle legs taken, which is the count of ternary 1-digits of its position across the row.

As per "N Start" below, N+1 in ternary has high digit 1 or 2 which indicates the tree root. Ignoring that high digit gives an offset into the row of that tree and the digits are 0,1,2 for left,middle,right.

For example the first GCD is at N=9 with X=6,Y=9 common factor GCD=3. N+1=10="101" ternary, which without the high digit is "01" which has a single "1" so GCD <= 3^1. The mirror image of this point is X=9,Y=6 at N=24 and there N+1=24+1=25="221" ternary which without the high digit is "21" with a single 1-digit likewise.

Notice the list for k odd or k even is the same except that for k even there's an extra middle term h/h. The first few tops are as follows. The list in each row is spread to show how successive bigger h adds terms in the middle.

The coefficients of X and Y run up to h=ceil(k/2) starting from either 0, 1 or 2 and ending 2, 1 or 0. When k is even there's two h coeffs in the middle. When k is odd there's just one. The resulting tree for example with k=4 is

if k odd: rationals X/Y with X,Y one odd, one even
possible GCD(X,Y)=k^m for some integer m
if k even: all rationals X/Y
possible GCD(X,Y) a divisor of (k/2)^m

When k odd GCD(X,Y) is a power of k, so for example as described above k=3 gives GCD=3^m. When k even GCD(X,Y) is a divisor of (k/2)^m but not necessarily a full such power. For example with k=12 the first such non-power GCD is at N=17 where X=16,Y=18 has GCD(16,18)=2 which is only a divisor of k/2=6, not a power of 6.

The n_start => $n option can select a different initial N. The tree structure is unchanged, just the numbering shifted. As noted above the default Nstart=0 corresponds to powers in a generating function.

n_start=>1 makes the numbering correspond to digits of N written in base-k. For example k=10 corresponds to N written in decimal,

N written in base-k digits
depth = numdigits(N)-1
NdepthStart = k^depth
= 100..000 base-k, high 1 in high digit position of N
N-NdepthStart = position across whole row of all top trees

And the high digit of N selects which top-level tree the given N is under, so

N written in base-k digits
top tree = high digit of N
(1 to k, selecting the k-1 many top nodes)
Nrem = digits of N after the highest
= position across row within the high-digit tree
depth = numdigits(Nrem) # top node depth=0
= numdigits(N)-1

The case k=2 is precisely the Calkin-Wilf tree. There's just one top node 1/1, being the even k "middle" form h/h with h=k/2=1 as described above. Then there's two children of each node (the "middle" pair of the even k case),

Return a list of the N values which are the root nodes of $path. This is n_start() through n_start()+k-2 inclusive, being the first k-1 many points. For example in the default k=2 and Nstart=0 the return is two values (0,1).

Math-PlanePath is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3, or (at your option) any later version.

Math-PlanePath is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.