# Function that maps the “pureness” of a rational number?

By pureness I mean a number that shows how much the numerator and denominator are small.

E.g. $\frac{1}{1}$ is purest, $\frac{1}{2}$ is less pure (but the same as $\frac{2}{1}$), $\frac{2}{3}$ is less pure than the previous examples, $\frac{53}{41}$ is worse, .... $\pi$ isn't pure at all (as well as e...).

• Nice question! $\;$ – goblin Apr 10 '16 at 2:48

You can take, $$\frac{a}{b}\mapsto \frac{a+b}{\gcd(a,b)},$$ Note that this is independent of the choice of representative since $\gcd(na,nb)=n\gcd(a,b)$ for non-negative integers $n$.

For your examples, $$\frac{1}{1}\mapsto 2,\quad \frac{1}{2}\mapsto 3,\quad\frac{2}{3}\mapsto 5,\quad\frac{53}{41}\mapsto 94.$$

Another possibility is $$\frac{a}{b}\mapsto \frac{ab}{(\gcd(a,b))^2},$$ which yields $$\frac{1}{1}\mapsto 1,\quad\frac{1}{2}\mapsto 2,\quad\frac{2}{3}\mapsto 6,\quad\frac{53}{41}\mapsto 2173.$$

Both these "pureness" functions have the property that $a/b$ is as pure as $b/a$, as we would expect.

The following table shows how the first choice partitions the positive rationals into "pureness classes". Each row corresponds to rationals of the same pureness.

\begin{align} & \frac{1}{1} \\ & \frac{1}{2}\quad\frac{2}{1} \\ & \frac{1}{3}\quad\frac{3}{1} \\ & \frac{1}{4}\quad\frac{2}{3}\quad\frac{3}{2}\quad\frac{4}{1} \\ & \frac{1}{5}\quad\frac{5}{1} \\ & \frac{1}{6}\quad\frac{2}{5}\quad\frac{3}{4}\quad\frac{4}{3}\quad\frac{2}{5}\quad\frac{6}{1} \\ & \frac{1}{7}\quad\frac{3}{5}\quad\frac{5}{3}\quad\frac{7}{1} \\ & \frac{1}{8}\quad\frac{2}{7}\quad\frac{4}{5}\quad\frac{5}{4}\quad\frac{7}{2}\quad\frac{8}{1} \\ & \frac{1}{9}\quad\frac{3}{7}\quad\frac{7}{3}\quad\frac{9}{1} \\ & \frac{1}{10}\quad\frac{2}{9}\quad\frac{3}{8}\quad\frac{4}{7}\quad\frac{5}{6}\quad\frac{6}{5}\quad\frac{7}{4}\quad\frac{8}{3}\quad\frac{9}{2}\quad\frac{10}{1} \end{align}

• You'd map the irrationals to $\infty$, right? – YoTengoUnLCD Apr 9 '16 at 15:13
• Put another way, your "another possibility" is just the ratio of the LCM to the GCD. – J. M. is a poor mathematician Apr 10 '16 at 5:53
• Why would you expect $2/1$ to be "as pure" as $1/2$? Shouldn't integers be purer? – Benjamin Lindqvist Apr 12 '16 at 14:04

I have often used the sum of the terms in the Continued Fraction. This is

1. finite for rational numbers
2. the same for $x$ and $\frac1x$
3. for $0\lt x\lt 1$, the same for $x$ and $1-x$

$$1=(1)\to1$$ $$\frac12=(0,2)\to2\quad\text{and}\quad2=(2)\to2$$ $$\frac23=(0,1,2)\to3$$ $$\frac{53}{41}=(1,3,2,2,2)\to10$$ etc.

• curious, used when/how? – djechlin Apr 11 '16 at 3:49
• @djechlin: Comparing simplicity of rational expressions. If there were a quantitative use for this, there would probably be a numerical way to judge which function was better. So far this seems to be purely recreational. The simpler a rational number is, the nicer a ratio of frequencies seems to sound together. – robjohn Apr 11 '16 at 4:26

The order of the Farey sequence where the (fractional part) of the rational number first occurs is a measure that should be of interest to you. As you will see from the link, the Farey sequences have many fascinating properties.

• I disagree. The wikipedia link in question will be a very stable one. If you are looking for this kind of thing with a bot, then there's a bug in your bot (see abcdef's answer). – Rob Arthan Apr 10 '16 at 17:31
• thanks, I've downvotwd that as well. And it's not just about link stability. Sending users on a tab chase is an annoying chore. How hard is it to add a sentence or two summarizing what will be found? – MichaelChirico Apr 10 '16 at 17:34
• Keep at it! You haven't finished yet. – Rob Arthan Apr 10 '16 at 17:37
• As is mentioned in How do I write a good answer?: Provide context for links Links to external resources are encouraged, but please add context around the link so your fellow users will have some idea what it is and why it’s there. Always quote the most relevant part of an important link, in case the target site is unreachable or goes permanently offline. – robjohn Apr 11 '16 at 4:33

A natural pureness measure is the level of the Stern-Brocot tree at which the fraction occurs. Since each run of consecutive left or right steps in the tree corresponds to a continued fraction term equal to the length of the run, the pureness may be defined as the sum of the continued fraction terms.

• Which is the same as @robjohn's answer, by the way. – Anton Sherwood Apr 10 '16 at 0:29
• @Anton True, but I wanted to explicitly mention the connection to the S-B tree – inversed Apr 10 '16 at 12:16
• (+1) Nice reference to the Stern-Brocot tree. I often forget to mention that when talking about the relation to Continued Fractions. – robjohn Apr 10 '16 at 17:57

In the same spirit as Rob Arthan's answer, you could use the first time a rational number appears in the Calfin-Wilf sequence.

Define a sequence $a_n$ with $a_0 = 0$, $a_1 = 1$ obeying the recurrences $a_{2n} = a_n$ and $a_{2n + 1} = a_n + a_{n+1}$. We get

$$0, 1, 1, 2, 1, 3, 2, 3, 1, 4, 3, 5, \ldots$$

The Calfin-Wilf sequence is $c_n = a_n / a_{n+1}$:

$$\frac{0}{1},\frac{1}{1}, \frac{1}{2}, \frac{2}{1}, \frac{1}{3}, \frac{3}{2}, \ldots$$

Every positive rational number appears exactly once in this sequence. Thus with this measure of "purity", you can always tell which of two rational numbers is "purer".

How about $f(\frac{p}{q})=pq$ for rational numbers and $f(x)=0$ when it's irrational?

• Something well-defined on different representatives of the rational number would be preferable. – Patrick Stevens Apr 9 '16 at 14:52
• @PatrickStevens: That would be good to mention explicitly, but they can't really be faulted here given that for lots of people it goes without saying that $(p, q) = 1$. – Vandermonde Apr 11 '16 at 5:01
• Intuitively, wouldn't you want $f(\pi)$ to be closer to $f(99999/76543)$ than to $f(1)$? – Anton Sherwood Apr 12 '16 at 18:21
• Yeah, it's intuitive to regard irrationals as having infinite denominator (since the divisions have to be so fine), and I think Euler or someone called them such; maybe that's a case for taking $f( \pi ) := \infty$ – Vandermonde Apr 21 '16 at 5:09

I've read that Euler ranked the harmoniousness of musical intervals, and thus the simplicity of rational numbers, in a way consistent with this function:

• $$f(p) = p-1$$, if $$p$$ is prime
• $$f(ab) = f(a)+f(b)$$
• $$f(a:b:c:\dots) = f(\mathrm{lcm}(a,b,c,\dots))$$

assuming, of course, that the argument is expressed in lowest terms.

Much later: I should mention that I read this in On the Sensations of Tone by Hermann Helmholtz; in Alexander Ellis's translation (1885), it's the last paragraph on page 230.

• Very interesting, because my mental trip started from musical harmony... thank you! – simpego81 Apr 10 '16 at 11:08

Maybe you can get inspiration from the Thomae's function.

$f(\frac{a}{b})=\frac{1}{|a|+|b|}$

For the following conditions on $x$, $f(x)$ is either zero or not defined:

• $x$ irrational
• $x=0$

Higher output values implies high purity.