[Math] How to evalulate a fraction (example 1/998001) accurately to 100 decimal places and then display it in maxima/wxmaxima?

decimal-expansion

I am trying to evaluate a decimal expansion of a fractional value to a large number of digits of precision (in this example 100):

    block([FPPREC:100],y=bfloat(1)/bfloat(998001));

I am trying to do this in wxMaxima, that's what the expression above works in. It's trying to take a high precision floating point value numerator and denominator, and evaluate them to a particular precision (100 digits).

My trouble is perhaps just a display issue in Maxima:

    1.0020030040050060070080090100[44 digits]920930940950960970980991001b-6

I am not sure what the above means, but I think it means that the middle 44 digits are not being shown on the screen even though they are available internally. What I was hoping for would be:

  1. A way to get the period of the repeating decimal, if there is one,

  2. The full precision (100 digits as requested above) shown on the screen as the result.

Perhaps I'm just doing it wrong. So my question is really (a) how can I determine a precise value for the above, and (b) do something similar to what wolfram alpha does with respect to showing me the period of a repeating decimal if the expansion is periodic. It is very interesting that Wolfram Alpha automatically reports the period of the decimal expansion, if it repeats.

Best Answer

$$ \frac{1}{(1000-1)^2} =\frac{10^{-6}}{(1-\frac{1}{1000})^2} =\frac{10^{-6}}{(1-x)^2} =10^{-6}\left(\sum_{n=0}^{\infty}x^n\right)^2 =10^{-6}\sum_{n=1}^{\infty}nx^{n-1} $$ for $x=.001$, which has no carries in its decimal expansion for $n<1000$. Thus the first $1000$ triplets ($3000$ digits after the decimal place) will be $0.000\;001\;002\;003\;\dots\;996\;997\;999\;000$, which brings us up to the first digit which receives a carry. If you want to see it without the scientific notation, add one before formatting. In sage:

(1+(10^3-1)^(-2)).n(digits=3001) # ignore the leading one in the output!

or in scientific notation:

((10^3-1)^(-2)).n(digits=3001) # note the e-6 at the end, meaning times 10^{-6}

As to the formula above, it can be derived by differentiation: $$ \left(\sum_{n=0}^{\infty}x^n\right)^2 =(1-x)^{-2} =\frac{d}{dx}(1-x)^{-1} =\frac{d}{dx}\left(\sum_{n=0}^{\infty}x^n\right) =\sum_{n=1}^{\infty}nx^{n-1} \qquad\text{for} \qquad|x|<1 $$

Related Question