I don’t know why I’m so fascinated that the **rational numbers** are countable even though they’re a dense subset of the *uncountable* real numbers. A rational number can be arbitrarily close to any real number, making you *think* they’d be infinite like the reals, but in fact, nearly all numbers are * irrational* (and an uncountable subset of the reals).

So, the rational numbers — good old ** p/q** fractions — though still infinite are

*countably*infinite (see this post for details).

More to the point here, a common way of enumerating the rational numbers, when graphed results in some pretty curves and illustrates some fun facts about the rational numbers.

This started because I was sitting listening to music and was doodling and free associating. I got to thinking about how the common way to enumerate the set of rational numbers outputs a list of chains of fractions. Each chain has one more fraction than the previous, so their lengths grow towards infinity.

Crucially, each fraction in a given chain has the same numerator-denominator sum. Further, that sum identifies (or indexes) the chain. For example, the #4 chain is:

Note how the numerator (*p*) and denominator (*q*) of each fraction sum to **4**. Note also that the chain has four members. Lastly, note that there is no **4/0** fraction because division by zero is undefined. Therefore, the last member of the chain has the value *one-minus-the-sum*. Of course, the first member always has the value zero.

As another example, here’s the #9 chain:

Note that it has nine members. The last one has the value eight (*one-minus-the-sum*), and the first has the value zero. Note also that, because it’s an odd-numbered chain, its fractions straddle the value of one. The #4 chain above, because it’s even-numbered, has a fraction in the middle with the value of one.

The shortest possible chain, the #1 chain, is just [**0/1**], which evaluates to [**0**], so it doesn’t have much graphic potential (but might be useful if we turn this into a group and need an additive identity element). The shortest chain with length, the #2 chain is:

And, as mentioned, there’s no ceiling on chain length. It’s whatever the chain’s number is.

**§**

Crucial for the graphs, the fractions in a chain can be evaluated as decimal numbers. They all have numeric values, and those values are interesting to us. Or to me, anyway. Those values are what I noticed while doodling.

For instance, the #4 chain listed above has the values:

The #9 chain listed above has the values:

The #2 chain obviously evaluates to [**0**, **1**]. (Remember that all chains start with zero and end with the sum minus one.)

I began to wonder what a graph of those chains would look like. The code seemed dead easy to write, and it was:

002|

003| def fraction_list (n):

004| “””Fraction chain generator.”””

005| p = 0

006| q = n

007| while 0 < q:

008| yield (p,q)

009| p += 1

010| q -= 1

011|

012| for n in range(number_of_chains+1):

013| for p,q in fraction_list(n):

014| print(‘%2d: %d/%d; %.6f’ % (n,p,q,p/q))

015| print()

016| print()

017|

018|

Hand that off to some boilerplate matplotlib code, and voilà:

Kind of pretty! Each line traces one fraction chain. Each dot represents one fraction.

Remember, all chains start at zero (in the lower-left corner). Each chain ends at their sum-1 max value — that top-most angled row of dots. For example, the orange dot at coordinates (**20**,**20**), just above the center of the graph, is the end of the #21 chain. That dot is the fraction **20/1**, hence the y-value of **20**.

The x-axis is the fraction’s numerator. The orange dot just mentioned has a numerator of **20**, hence the x-value of **20**.

It’s not obvious in *Chart 1*, but each chain has half its length above **1.0** and half its length below. As mentioned above, the even-numbered chains all have a fraction that evaluates to exactly **1.0**, but the rest are split half above **1.0** and half below. The odd-numbered chains, which lack a center member with the value **1.0**, have exactly half their members above and half below.

[The sole exception is the #2 chain, which has members only at zero and one. It has a member with the value one, but that member isn’t in the center.]

These chains feature a large jump in value between the penultimate fraction and the ultimate one. That last fraction always has the value of some ** m/1** (or just

**, and note that**

*m***, where**

*m*=*n*-1**is the chain number.).**

*n*But the second-to-last fraction always has the value:

Which is slightly less than half, so that last step is a doozy and keeps getting bigger! The larger ** m** gets, the larger the last step is (always roughly

**). As Chart 1 shows, the steps become smaller going down the chain (towards zero). For example, the third-to-last fraction has the value:**

*m*/2So less than one-third of whatever ** m** was.

The end result is that fractions in the “upper” half of the chain are as spread out as the “lower” half is compressed between zero and one.

This next chart zooms in on lower region of y-values:

Note that the y-axis only goes up to **3.0** now and the x-axis to **25.0**. Importantly, note all the fractions (dots) below the horizontal **1.0** y-value. Also note how only every other chain (the even-numbered ones) has a fraction that evaluates to **1.0** (has a dot directly on the **1.0** y-value).

For bonus credit, note that on the **2.0** y-value, it’s every *third* chain with a fraction that has a value of exactly **2.0** (for instance **2/1**, **4/2**, **10/5**, **26/13**, and so on). For the **3.0** y-value, it’s every fourth chain. (Can you see why that pattern exists?)

Just for fun and because it’s free, here’s a slightly closer zoom:

If you look closely, you might see how the dots from different chains also make patterns. A very noticeable one starts in the lower-left corner, rises quickly (red dot) and then forms a curve that approaches but never meets the **1.0** y-value line.

That curve is mirrored by one that starts in the upper left and sweeps down towards, but never meeting, the **1.0** y-value line from above. There is a whole series of such curves approaching that line.

Similar curves can be found approaching other horizontal value lines but increasing sparsity of dots above **1.0** makes them hard to spot.

Here’s a final zoom to really show off the population of fractions with values below **1.0**:

For any given numerator, the fractions become closer and closer together as chains pile on. For instance, the blue dot on the top edge at center, on the vertical x-value line **5**, is a fraction from the #10 chain. It has the value **1.0** and the sum **10**, so the fraction is **5/5**. Going down the vertical line, the values are:

The values get smaller and smaller. The values start at **1.0** with **5/5**, but five chains later it’s down to **5/10** — **0/5**. The lowest dot on the line (the orange one at the bottom) is **5/36** (**0.1388**).

**§ §**

I wondered what the graph of the chains would look like, and now I know. They’re kind of cool. It almost looks like the growth rate isn’t exponential but something similar. The curve seems to have a different shape than an exponential one.

I’m probably wrong about that. It’s probably exponential and the exponent is a function rather than a constant. Something to think about when I’m listening to music.

Stay fractional, my friends! Go forth and spread beauty and light.

∇

April 22nd, 2023 at 10:13 am

“And now for something completely different!”😎April 22nd, 2023 at 5:22 pm

BTW: You can click on the charts for a larger version.

April 22nd, 2023 at 10:31 am

On any given vertical line (given numerator), the top-most fraction is always

, wherex/1is the numerator. Going down from the top-most, the sequence is simply:xWhere

is the number of chains. The length of these sequences is obviously constrained by bothNandx(the longest sequence for a givenNoccurring whenN).x=1