Was developing some notes on calculus for
a nephew, derived Taylor series, and just
as an example wrote some code for editor
KEdit, with 1000 decimal digit precision,
to calculate natural log base e to 36
decimal digits. Amazing how well the code
worked. Including the code here.
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 expression for R_n(x_0),
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.
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)
Final results of the code:
e = 2.71828182845904523536028747135266250
The error is less than
2.90 x 10^(-40)
The code is in the language KEdit macro
language Kexx, a version of Rexx:
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