Google query
"base of the natural logarithm e"
reports
e = 2.718281828459
that is, 13 digits.
The calculator with Windows 10 reports
e = 2.7182818284590452353602874713527
that is 32 decimal digits.
Last weekend found
e = 2.71828182845904523536028747135266250
that is, 36 decimal digits.
The math and code are below and could just as easily get e to, say, 500 decimal digits!
How'd that happen?
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!
The code and the core of the Taylor series derivation are below.
In TeX, Taylor series is
f(x) = \sum_{i=0}^n {(x - x_0)^i \over i!} f^{[i]}(x_0) + R_n(x_0)
with R_n(x_0) as the error term.
To derive the Taylor series, really just find the error term
R_n(x_0)
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's all there is to it!
The results are, for some s between x_0 and x:
R_n(x_0) = (x - x_0) {(x-s)^n \over n!} f^{[n+1]}(s)
As above, the final output of the code:
e = 2.71828182845904523536028747135266250
From R_n(x_0) the error is less than
3 x 10^(-40)
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.
A key to why this code is so simple and works so well, Kexx can do arithmetic with 1000 decimal digits of precision!
"Look, Ma, here's the code -- dirt simple":
macro_name = 'NATLOG'
out_file = macro_name || '.out'
'nomsg erase' out_file
Call msgg macro_name': Find natual logarithm base e'
numeric digits 1000
n = 35
sum = 1
factorial = 1
Do i = 1 To n
factorial = i * factorial
sum = sum + 1/factorial
Call msgg Format(i, 5) Format(factorial, 50) Format(sum, 2, 35)
End
error = 3 / factorial
Call msgg macro_name': The error is <='
Call msgg Format( error, 59, 50 )
Call Lineout out_file
Return
msgg:
Procedure expose out_file
Call Lineout out_file, arg(1)
Return