987654321 / 123456789

I recently saw someone post [1] that 987654321/123456789 is very nearly 8, specifically 8.0000000729.

I wondered whether there’s anything distinct about base 10 in this. For example, would the ratio of 54321six and 12345six be close to an integer? The ratio is 4.00268, which is pretty close to 4.

What about a larger base? Let’s try base 16. The expression

0xFEDCBA987654321 / 0x123456789ABCDEF

in Python returns 14. The exact ratio is not 14, but it’s as close to 14 as a standard floating point number can be.

For a base b, let denom(b) to be the number formed by concatenating all the digits in ascending order and let num(b) be the number formed by concatenating all the digits in descending order.

\begin{align*} \text{num}(b) &= \sum_{k=1}^{b-1} kb^{k-1} \\ \text{denom}(b) &= \sum_{k=1}^{b-1} (b-k)b^{k-1} \end{align*}

Then for b > 2 we have

\frac{\text{num}(b)}{\text{denom}(b)} = b - 2 + \frac{b-1}{\text{denom}(b)}

The following Python code demonstrates [2] that this is true for b up to 1000.

num = lambda b: sum([k*b**(k-1) for k in range(1, b)])
denom = lambda b: sum([(b-k)*b**(k-1) for k in range(1, b)])

for b in range(3, 1001):
    n, d = num(b), denom(b)
    assert(n // d == b-2)
    assert(n % d == b-1)

So for any base the ratio is nearly an integer, namely b − 2, and the fractional part is roughly 1/bb−2.

When b = 16, as in the example above, the result is approximately

14 + 16−14 = 8 + 4 + 2 + 2−56

which would take 60 bits to represent exactly, but a floating point fraction only has 53 bits. That’s why our calculation returned exactly 14 with no fractional part.

 

[1] I saw @ColinTheMathmo post it on Mastodon. He said he saw it on Fermat’s Library somewhere. I assume it’s a very old observation and that the analysis I did above has been done many times before.

[2] Why include a script rather than a proof? One reason is that the proof is straight-forward but tedious and the script is compact.

A more general reason that I give computational demonstrations of theorems is that programs are complementary to proofs. Programs and proofs are both subject to bugs, but they’re not likely to have the same bugs. And because programs made details explicit by necessity, a program might fill in gaps that aren’t sufficiently spelled out in a proof.

4 thoughts on “987654321 / 123456789

  1. 8.0000000729 looks an awful lot like it’s 8 + 9^3/10^10, which suggests a conjecture that

    num(b) / denom(b) ~ (b-2) + (b-1)^3 / b^b.

    and similarly, for example in base 9 we have num(9) / denom(9) = 7.000000628, in base 8 we have num(8) / denom(8) = 6.00000527, etc. (In base b, (b-1)^3 has the digits (b-3), 2, (b-1).)

    In fact num(b) = ((b^b*(b-2) + 1)/(b-1)^2 and denom(b) = (b^b – b^2 + b – 1)/(b-1)^2. These are A051846 and A023811 in the OEIS, respectively; I would have done the algebra but I looked them up there.

    Straightforward algebra shows that num(b) – (b-2) denom(b) = b-1, from which

    num(b) / denom(b) = (b-2) + (b-1)^3 / (b^b – b^2 + b – 1)

    which is our conjecture with some low-order terms in the denominator.

  2. Since, 987,654,321 equals 1,000,000,000 – 123,456,789, we can also conclude that:
    1,000,000,000 / 123,456,789 in base 10 equals ~8.1
    10,000,000 / 1,234,567 in base 8 equals ~6.1
    … and so forth.

    Alternatively,
    10 / 81 in base 10 returns value 0.123,456,790,123,…
    10 / 61 in base 8 returns 0.123,457,012,3…
    10 / E1 in base 16 returns 0.123,456,789,abc,df0,123,…

    By the way, 81 is 9^2, 61 (or 49 in base 10) is 7^2, and E1 (225 in base 10) is 15^2.

Comments are closed.