Live data from Hacker News

987654321 / 123456789

johndcook.com

21–30 of 120 posts

Re: 987654321 / 123456789

#21
post #6

Earlier quoted context omitted.

Care to elaborate? Why does 0.987654 simplify to 80/81 and 0.123456 to 10/81?

.123456... = x + 2 x^2 + 3 x^3 + ... with x = 1/10. Then you have (x + 2 x^2 + 3 x^3 + ...) = (x + x^2 + x^3 + x^4 + ...) + (x^2 + x^3 + x^4 + x^5 + ...) + (x^3 + x^4 + x^5 + x^6 + ...) (count the number of occurrences of each power of x^n on the right-hand side) and from the sum of a geometric series the RHS is x/(1-x) + x^2/(1-x) + x^3/(1-x) + ..., which itself is a geometric series and works out to x/(1-x)^2. Then…

I don't know who downvoted this, but it's correct.

The use of series is a little "sloppy", but x + 2 x^2 + 3 x^3 + ... has absolute uniform convergence when |x|The super nice property of complex analysis is that you can be almost ridiculously "sloppy" inside that open circle and the Conway book will tell you everything is ok.

[I'll post a similar proof, but mine use -1/10 and rounding, so mine is probably worse.]

Re: 987654321 / 123456789

#24
post #19

Earlier quoted context omitted.

The 8 is there but then it's followed by a 9 and a 10, and the carry from the 10 ends up bumping it up.

Shouldn't wee see two zeros then?

The reason you don't see two zeroes is as follows: you have

  .123456789
then add 10 on the end, as the tenth digit after the decimal point, to get

  .123456789(10)
where the parentheses denote a "digit" that's 10 or larger, which we'll have to deal with by carrying to get a well-formed decimal. Then carry twice to get

  .12345678(10)0

  .1234567900
So for a moment we have two zeroes, but now we need to add 11 to the 11th digit after the decimal point to get

  .1234567900(11)
or after carrying

  .12345679011
and now there is only one zero.

Re: 987654321 / 123456789

#26
See perhaps various "What every programmer / CSist should know about floating-point arithmetic" papers and articles:

* David Goldberg, 1991: https://dl.acm.org/doi/10.1145/103162.103163

* 2014, "Floating Point Demystified, Part 1": https://blog.reverberate.org/2014/09/what-every-computer-pro... ; https://news.ycombinator.com/item?id=8321940

* 2015: https://www.phys.uconn.edu/~rozman/Courses/P2200_15F/downloa...

Re: 987654321 / 123456789

#28
post #19

Earlier quoted context omitted.

Shouldn't wee see two zeros then?

The reason you don't see two zeroes is as follows: you have .123456789 then add 10 on the end, as the tenth digit after the decimal point, to get .123456789(10) where the parentheses denote a "digit" that's 10 or larger, which we'll have to deal with by carrying to get a well-formed decimal. Then carry twice to get .12345678(10)0 .1234567900 So for a moment we have two zeroes, but now we need to add 11 to the 11th di…

Ah, that's cool. Thanks!

Re: 987654321 / 123456789

#29
Why the b > 2 condition? In the b=2 case, all three formulas also work perfectly, providing a ratio of 1. And this is interesting case where the error term is integer and the only case where that error term (1) is dominant (b-2=0), while the b-2 part dominates for larger bases.

Re: 987654321 / 123456789

#30

Somewhat interesting, 123456789 * 8 is 987654312 (the last two digits are swapped). This holds for other bases as well: 0x123456789ABCDEF * 14 is 0xFEDCBA987654312. Also, adding 123456789 to itself eight times on an abacus is a nice exercise, and it's easy to visually control the end result.

Another interesting thing is that these seem to work:

base 16: 123456789ABCDEF~16 * (16-2) + 16 - 1 = FEDCBA987654321~16

base 10: 123456789~10 * (10-2) + 10 - 1 = 987654321~10

base 9: 12345678~9 * (9-2) + 9 - 1 = 87654321~9

base 8: 1234567~8 * (8-2) + 8 - 1 = 7654321~8

base 7: 123456~7 * (7-2) + 7 - 1 = 654321~7

base 6: 12345~6 * (6-2) + 6 - 1 = 54321~6

and so on..

or more generally:

base n: sequence * (n - 2) + n - 1

Post reply on HN