Ask HN: What interesting problems are you working on?
How to find an accurate numerical
approximation to e, the base of the
natural logarithm?  Last weekend stumbled
onto a shockingly easy and effective
way!<p>Google query<p>&quot;base of the natural logarithm e&quot;<p>reports<p>e = 2.718281828459<p>that is, 13 digits.<p>The calculator with Windows 10 reports<p>e = 2.7182818284590452353602874713527<p>that is 32 decimal digits.<p>Last weekend found<p>e = 2.71828182845904523536028747135266250<p>that is, 36 decimal digits.<p>The math and code are below and could just
as easily get e to, say, 500 decimal
digits!<p>How&#x27;d that happen?<p>Last weekend worked on some short but
relatively careful notes to get a nephew
of 9 started on calculus, and part of that
was Taylor series in just two pages with
large fonts!<p>The code and the core of the Taylor series
derivation are below.<p>In TeX, Taylor series is<p>f(x) = \sum_{i=0}^n {(x - x_0)^i \over i!}
f^{[i]}(x_0) + R_n(x_0)<p>with R_n(x_0) as the error term.<p>To <i>derive</i> the Taylor series, really just
find the error term<p>R_n(x_0)<p>and for that just differentiate f(x) with
respect to x_0 where then nearly all the
terms cancel, simplify, integrate from x_0
to x, and apply the mean value theorem.
That&#x27;s all there is to it!<p>The results are, for some s between x_0
and x:<p>R_n(x_0) = (x - x_0)
{(x-s)^n \over n!} f^{[n+1]}(s)<p>As above, the final output of the code:<p>e = 2.71828182845904523536028747135266250<p>From R_n(x_0) the error is less than<p>3 x 10^(-40)<p>The numerical output of the code is
curious:  Get a little over 1 decimal
digit of accuracy for each term of the
series!  So the output shows two big
triangles, one for the values of n! and
one for the number of correct digits in
the estimate of e.<p>A key to why this code is so simple and
works so well, Kexx can do arithmetic with
1000 decimal digits of precision!<p>&quot;Look, Ma, here&#x27;s the code -- dirt
simple&quot;:<p><pre><code>          macro_name = &#x27;NATLOG&#x27;

          out_file = macro_name || &#x27;.out&#x27;

          &#x27;nomsg erase&#x27; out_file

          Call msgg macro_name&#x27;:  Find natual logarithm base e&#x27;

          numeric digits 1000

          n = 35

          sum = 1

          factorial = 1

          Do i = 1 To n
            factorial = i * factorial
            sum = sum + 1&#x2F;factorial
            Call msgg Format(i, 5) Format(factorial, 50) Format(sum, 2, 35)
          End

          error = 3 &#x2F; factorial

          Call msgg macro_name&#x27;:  The error is &lt;=&#x27;

          Call msgg Format( error, 59, 50 )

          Call Lineout out_file

          Return
     msgg:
          Procedure expose out_file

          Call Lineout out_file, arg(1)

          Return</code></pre>