1/9998 = 0.0001 0002 0004 0008 0016 0032 0064 0128 0256..
wolframalpha.com
wolframalpha.com
The reason it works is that 9998 = 10^4 - 2. You can expand as
1 / (10^n - 2) = 1/10^n * 1/(1 - 2/10^n)
= 1/10^n * (1 + 2/10^n + 2^2 /10^2n + 2^3 /10^3n + ...)
which gives the observed pattern. It breaks down when 2^k has more than n digits, which happens approximately when 2^k > 10^n => k > n log(10) / log(2)
which comes out to 4 * log(10)/log(2) = 13.28 when n = 4.---
Another pattern can be generated from the power series expansion
x / (1 - x)^2 = x + 2x^2 + 3x^3 + 4x^4 + ...
setting x = 1/10^n gives the infinite series 1/10^n + 2/10^2n + 3/10^3n + ...
which leads to the neat fact that 1 / 998001 = 0.000 001 002 003 004 005 006 007...
---Another example is the fraction
1000 / 997002999 = 0.000 001 003 006 010 015 021 ...
which goes through the triangle numbers[0] in its expansion, or 1 / 998999 = 0.000 001 001 002 003 005 008 013 021 ...
which goes through the Fibonacci numbers[1].---
Getting the squares is harder, but you can do it with
1001000 / 997002999 = 0.001 004 009 016 025 036 049 ...
[0] http://en.wikipedia.org/wiki/Triangle_number1/998999 1/99989999 1/9999899999
To get more 0 spacing and avoid overflow
and even further? 1/8 = 0.125
If I'm not mistaken. We should utilize the self-similarity much more often.
It doesn't actually:
4096 8193 6387
= 4096+8192
+ 1 6384
+ …Deleted comment
1 / (10000 - 2) = 1/10000 * 1/(1 - 2/10000)
Notice that the sum of a geometric series is: 1/(1 - x) = sum_k( x^k )
1/(1 - 2/10000) = sum_k( (2/10000)^k )
So: 1/10000 * 1/(1 - 2/10000) = 1/10000 * (1 + 2/10000 + 2^2/10000^2 + 2^3/10000^3 + ...) 1/9998 is
1/(10000-2) is
(1/10000) / (1 - 2/10000)
which is an infinite sum of geometric progression with an initial value of 1/10000 and ratio of 2/10000. In other words, x1 = 1/10000; // 0.0001
x2 = x1 + x1 * 2/10000; // 0.0001 0002
x3 = x2 + x2 * 2/10000; // 0.0001 0002 0004 0008
...
Magic O_O
[0] http://en.wikipedia.org/wiki/Geometric_progression 11^0 1
11^1 1 1
11^2 1 2 1
11^3 1 3 3 1
11^4 1 4 6 4 1It's also a useful self-test if you think the battery might be going.
I have written an iOS calculator app and had very interesting times trying to find and mimic these shortcuts. I have thought for a long time they had to follow from some simple implementation detail, as all the calculators got them precisely the same, but I never found this one consistent rule, I had to implement the features in a series of hacks.
The old Sinclair pocket calculators had some known arithmetic inaccuracies.
Different operations take noticeably different amounts of time; a "timing attack" like those used for cryptanalysis might yield clues to what's in the black box.
The way new digits appear on the display when typed in suggests it might be implemented as a shift register. It would be interesting to look at high speed video of the display when the answer to a long computation appears; do the answer digits appear (rapidly) one at a time? Do they shift in from the left? Three caveats: (1) I've never noticed it happening; (2) LED displays are almost always multiplexed, but you could probably see through that; and (3) probably wouldn't work on an LCD because too slow. I used to have a vacuum fluorescent display calculator, though; IIRC it was not multiplexed.
There are a few articles on the web about the architecture of calculators, including the Busicom [1] and Sinclair [2]. Personally, I want to hear more about zoul's research---how did you do it?
[2] http://files.righto.com/calculator/sinclair_scientific_simul...
56.96124843225 ^ 56.96124843225
Wolfram confirms that it's pretty close to a full googol. Of course, you can keep adding digits to the end of the number to make it even more precise. Maybe I'll write a script to do that.
5th row: 1 5 10 10 5 1
Writing this a bit backwards, 1 * 1 + 5 * 10 + 10 * 100 + 10 * 1000 + 5 * 10000 + 1 * 100000 = 161051 = 11^5.
def pascal(n):
base = max(2, 2**n)
row = (base+1)**n
return [row/base**i % i for i in range(n+1)]
Nice, but hopelessly inefficient. :) You can also calculate a binomial coefficient the same way without any looping construct (the exponential operator does the looping for you).Needless to say, I didn't get it, but one guy in our class, like an 8th grader, did. He was pretty smart.
http://en.wikipedia.org/wiki/Generating_function
In this case, the sequence 1, 2, 4, ..., 2^n has the generating function,
g(z) = sum[i = 0 to inf] (2^i * z^i)
= 1 + 2z + 4z^2 + ...
= 1 / (1 - 2z)
Substituting a small number 10^-k, such as z = 0.0001 gives 10000/9998, and then right shifting by dividing 10000 leads to 1/9998.What more interesting is that some other useful sequences can often be obtained from the function, by operations like differentiation and integration, or adding / multiplying with other functions.
For example:
2z + (4*2)z^2 + (8*3)z^3 + (16*4)z^4 ...
= d/dz(g(z))
= d/dz(z * 1 / (1 - 2z))
= 2 / (1 - 2z)^2
Put z = 1/10000 = 0.0001, this yields
50000000/24990001 = 2. 0008 0024 0064 0160 0384 ...Wolfram Alpha interprets 1/0x9999998 or 1/0xffffffe correctly as hex input, but still shows the output as decimal approximation, while a hexadecimal approximation would be more useful here. I would be really curious what this thing looks like in other numeric bases.
Unfortunately, the "Other base conversions" section only shows up to 7 or so digits after the point and doesn't allow expanding.
EDIT: found it! I didn't know bc in linux was this awesome! echo "obase=16;ibase=16;scale=1000;1/FFFE" | bc .0001000200040008001000200040008001000200040008001000200040008001000 (....)
1/98 = 0.01 02 04 08 16 32 ...
1/998 = 0.001 002 004 008 016 032 064 128 256 ...
but there's also a degenerate case, where you have no 9s at all:
1/8 = 0.1 + 0.02 + 0.004 + 0.0008 + ...
and what's surprising here is that everything adds up and gives you the terminating decimal 0.125 that you were expecting.
The sum of a convergent series is a / (1 - r) where a is the first value, and r is the ratio between the n+1th and nth term.
a = 1/10, r = 1/5
n = (1 / 10) / (1 - (1 / 5))
n = (1 / 10) / (4 / 5)
n = 5 / 40
n = 1 / 8(a0 + (d - a0)(1/10^n)) / (1 - 1/10^n)^2
For instance the sequence 1, 4, 7, 10, 13...
(1 + (3 - 1)(1/10^2)) / (1 - 1/10^2) = 1.02 / 0.9801 = 3400/3267 = 1.004 007 010 013 016...
For any kind of recursive sequence, you can find its generating function G(x) and then substitute some integer power of 0.1 for x to generate cool decimal expansions like this.
The generating function for the Fibonacci sequence is:
G(x) = x / (1 - x - x^2)
Substituting in 0.001 gives 0.001 / 0.998999 = 0.001 001 002 003 005 008...
x = 1x^1
x * g(x) = 1x^2 + 1x^3 + 2x^4 + 3x^5 + 5x^6 + ...
+ x^2 * g(x) = 1x^3 + 1x^4 + 2x^5 + 3x^6 + ...
------------------------------------------------------------
= g(x) = 1x^1 + 1x^2 + 2x^3 + 3x^4 + 5x^5 + 8x^6 + ...
Hence, x = (1 - x - x^2) * g(x)
g(x) = x / (1 - x - x^2)1 / 99998 will return:
0.00001 00002 00004 00008 00016 ....
[0]http://www.wolframalpha.com/input/?i=1%2F99998&dataset=&equa...
which is a geometric sequence with common ratio 2/10000 and first term 1/10000
So it has an infinite sum of (1/10000)/(9998/10000) = 1/9998
Same for powers of 3: 1/9997
Actually 1/8 = 0.125 is an example of this; it just breaks down very early because 4+0.8+0.16+0.032+0.0064+... = 5
1/9998 = 1/(10000-2) = 1/(10000)*1/(1-2/(10000)
Since 2/10000 is very small, it is well approximated by the taylor expansion for 1/(1-x), which is simply
Sum(x^n)
Since x is 2/10000, we get powers of two, which keep getting shifted to the right. Like a bit pattern, they don't overlap when added, so we get the sequence above.
S = 0.00010002000400080016...
S = 0.0001 + 0.0000 0002 + 0.0000 0000 0004 + 0.0000 0000 0000 0008 + ...
S = 2^0 / 10000^0 + 2^1 / 10000^1 + 2^2 / 10000^2 + 2^3 / 10000^3 + ...
S = sum to infinity of (2/10000)^i
You might have noticed this is a geometric series with ratio 2/10000 = 0.0002. S = 0.0001 / (1 - 0.0002) = 0.0001 / 0.9998 = 1/9998so,
1/(1 - .0002) = 1 + .0002 + .0002^2 + ...
and
1/9998 = .0001/(1 - .0002).
Powers of 3:
1/9997 = 0.0001 0003 0009 0027 0081 ...
Powers of 4:
1/9996 = 0.0001 0004 0016 0064 0256 ...
Powers of 5:
1/9995 = 0.0001 0005 0025 0125 0625 ...
And so on...echo "scale=10000;1/999999999999999999999999998" | bc
http://blog.zyrthofar.com/2012/07/multiplying-recurring-deci...
<http://texify.com/?$\frac{1}{10^n-m} = \sum_{i=0}^\infty \frac{m^i}{(10^n)^{i+1}}$>
And here's OP's result where n=4 and m=2:
http://www.wolframalpha.com/input/?i=%5Csum_%7Bi%3D0%7D%5E%5...
See also the Interesting number paradox[1].
It never hurts to be reminded how cool it is to learn.
fibonacci: 100000000/99989999=1.000100020003000500080013002100340055...
integers: 1000000/998001=1.002003004005006...
square numbers: 1001000000/997002999=1.004009016025036...
explanations and proofs at: http://www.joefkelley.com/?p=635
sum k^3*1000^(-k) for k=1 to infinity ( = 334667000/332001998667 = 0.001 008 027 064 125 216 343 512 730 ...)
Also see if you can guess which one this is: 40920041/997002999 = 0.041 043 047 053 061 071 083 097 113 131 151 173 197 223 251 281 313 347 383 421...
Mmmh. Primes.
Look at the equation and then plug in (-2) for x
Feynman, R. P. 'Surely You're Joking, Mr. Feynman!': Adventures of a Curious Character. New York: W. W. Norton, 1997.
http://www.youtube.com/watch?v=daro6K6mym8
If you wanted to extend this, make it something like 1/999999998 instead.
Can we use WolframAlpha to show why 0.1 cannot be represented as a floating binary?
And why floating numbers shouldn't be used for currency operations.
http://www.wolframalpha.com/input/?i=1%2F10+in+base+2
TL;DR: 1/10 has an infinite repeating binary expansion. (think 1/3 in decimal - 0.3333333) The part that really gets you into trouble is that the repeating pattern is 0011, which means it rounds differently depending on how many digits of precision you give it.
Source: Richard Feynman, "Surely you're joking, Mr. Feynman!"
fpprintprec:100; fpprec:100; s : string(bfloat(1)/bfloat(9998)); makelist(substring(s,3+4i,7+4i),i,0,15); [0002, 0004, 0008, 0016, 0032, 0064, 0128, 0256, 0512, 1024, 2048,4096, 8193,broken pattern,6387, 2774, 5549]
(you get the idea)