Suppose we have two natural numbers . Define a sequence and . That is, we start with two initial values, and repeatedly subtract the smallest value from the largest value. Since , we know that for all .

Eventually, we will reach the cycle no matter our choice of (to see why, consider the termination function and the invariant that any term must be positive).

Define

We can now make pretty pictures. For each pixel color pixel by which can be calculated using a simple recursive procedure:

int chainLength(int x, int y){ if(x == y || x==0 || y==0) return 0; if(x>y) return 1+chainLength(x-y,y); else return 1+chainLength(x,y-x); }

*Generated using the DELTA library.*

**Connection to Calkin-Wilf trees**

The Calkin-Wilf tree is an infinite binary recursive tree, where the root node is defined as , and every node has a left child and right child .

The Calkin-Wilf tree is useful because it allows us to define a bijection between the natural numbers and the rational numbers, which can be used to show that the rational numbers are a countably infinite set.

Notice that if a node is a left child, then , and if it’s a right child then . This allows us to determine the parent node of a given node.

If for a given node then we know it was the left child of its parent. So we know its parent is . Similarly, if , then its parent is . Notice that at each step, we subtract the smaller number from the larger number, and we terminate the procedure when we reach the fraction .

Going back to , we could interpret a pixel as the rational number . The recursive sequence would then be equivalent to the depth of the node $latex x/y$ in the Calkin-Wilf tree.

Keep in mind that the Calkin-Wilf tree only contains rational numbers in the lowest common term, so the node does not exist in the Calkin-Wilf tree. To circumvent this issue, we convert our input node to the equivalent rational number in lowest common terms.

This image reminds me of the patterns you see when you drive next to a farm field that arranges its crops in rows with stakes. As you drive by, if you look straight down the middle you see a big column where the gap between the rows is, and if you look off to the side a little bit you see fainter column, but still in a straight line formed by the gaps between stakes along various diagonals. Basically, the deeper in the Calkin-Wilf tree the angle of your gaze is, the fainter the column appears. Because only integer values are plotted, and because you’re driving by and it sort of blurs your vision, you see the same picture plotted in your post.

Whenever I drive by such a field, I feel compelled to tell everyone I’m driving with “Look! You can see the rationals! The rationals!” Sadly, I’ve never been able to find a video online that demonstrates this phenomenon, and my phone’s camera has too slow of a frame rate.

Really interesting observation. Thanks for sharing.