https://www.johndcook.com/blog/2025/10/26/987654321/ John D. Cook Skip to content * MATH + PROBABILITY + SIGNAL PROCESSING + NUMERICAL COMPUTING + SEE ALL ... * STATS + EXPERT TESTIMONY + WEB ANALYTICS + FORECASTING + RNG TESTING + SEE ALL ... * PRIVACY + HIPAA + SAFE HARBOR + CRYPTOGRAPHY + DIFFERENTIAL PRIVACY + PRIVACY FAQ * WRITING + BLOG + RSS FEED + TWITTER + SUBSTACK + ARTICLES + TECH NOTES * ABOUT + CLIENTS + ENDORSEMENTS + TEAM + SERVICES (832) 422-8646 Contact 987654321 / 123456789 Posted on 26 October 2025 by John 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 54321[six] and 12345[six] 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/b^b-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. Categories : Math Tags : Number theory Bookmark the permalink Post navigation Previous PostSpacing the circles on the Smith chart Next PostHow blocks are chained in a blockchain 3 thoughts on "987654321 / 123456789" 1. Michael Lugo 26 October 2025 at 15:39 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. siravan 26 October 2025 at 16:37 This reminds me of the old calculator trick of 12345679 * 8 = 98765432 3. Linus Gasser 30 October 2025 at 12:14 The line 14 + 16-14 = 8 + 4 + 2 + 2-56 Can be rewritten using the proposed formula as: 14 + 16^-14 = 16 - 2 + 2^-56 Leave a Reply Your email address will not be published. Required fields are marked * [ ] [ ] [ ] [ ] [ ] [ ] [ ] Comment * [ ] Name * [ ] Email * [ ] Website [ ] [Post Comment] [ ] [ ] [ ] [ ] [ ] [ ] [ ] D[ ] Search for: [ ] [Search] John D. Cook John D. Cook, PhD My colleagues and I have decades of consulting experience helping companies solve complex problems involving data privacy, applied math , and statistics. Let's talk. We look forward to exploring the opportunity to help your company too. John D. Cook (c) All rights reserved. Search for: [ ] [Search] (832) 422-8646 EMAIL