Taylor's series

From testwiki
Revision as of 22:22, 29 January 2025 by imported>ThaniosAkro (Integral of 1/x)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

A well-behaved function can be expanded into a power series. This means that for all non-negative integers k there are real numbers ak such that

f(x)=k=0akxk=a0+a1x+a2x2+a3x3+a4x4+

Let us calculate the first four derivatives using (xn)=nxn1:

f(x)=a1+2a2x+3a3x2+4a4x3+5a5x4+
f(x)=2a2+23a3x+34a4x2+45a5x3+
f(x)=23a3+234a4x+345a5x2+
f(x)=234a4+2345a5x+

Setting x equal to zero, we obtain

f(0)=a0,f(0)=a1,f(0)=2a2,f(0)=2×3a3,f(0)=2×3×4a4.

Let us write f(n)(x) for the n-th derivative of f(x). We also write f(0)(x)=f(x) — think of f(x) as the "zeroth derivative" of f(x). We thus arrive at the general result f(k)(0)=k!ak, where the factorial k! is defined as equal to 1 for k=0 and k=1 and as the product of all natural numbers nk for k>1. Expressing the coefficients ak in terms of the derivatives of f(x) at x=0, we obtain

f(x)=k=0f(k)(0)k!xk=f(0)+f(0)x+f(0)x22!+f(0)x33!+

This is the Taylor series for f(x).

A remarkable result: if you know the value of a well-behaved function f(x) and the values of all of its derivatives at the single point x=0 then you know f(x) at all points x. Besides, there is nothing special about x=0, so f(x) is also determined by its value and the values of its derivatives at any other point x0:

f(x)=k=0f(k)(x0)k!(xx0)k.

Examples

cos(x)

f(x)=cos(x); f(0)=cos(0)=1

f(x)=sin(x); f(0)=sin(0)=0

f(x)=cos(x); f(0)=cos(0)=1

f(x)=sin(x); f(0)=sin(0)=0

f(x)=cos(x); f(0)=cos(0)=1


a0=f(0)=1

a1=f(0)=0

a2=f(0)2=12!

a3=f(0)2*3=03!=0

a4=f(0)2*3*4=14!


cos(x)=a0+a1x+a2x2+a3x3+a4x4+ =1+(0)x+12x2+0x+14!x4+ =1x22!+x44!x66!+x88!

Template:RoundBoxTop Some basic checking:

cos(0)=1022!+044!066!+088!=1

cos(x)=1(x)22!+(x)44!(x)66!+(x)88! =1x22!+x44!x66!+x88!=cos(x)

d(cos(x))dx=02x2!+4x34!6x56!+8x78! =x+x33!x55!+x77! =sin(x)

sin(x)=xx33!+x55!x77!+

d(sin(x))dx=13x23!+5x45!7x67!+ =1x22!+x44!x66!+ =cos(x) Template:RoundBoxBottom

arctan(x)

y=arctan(x)

x=tan(y)

dxdy=sec2(y)

y=dydx=cos2(y)=11+x2. See cos(θ).

Second derivative y″

Template:RoundBoxTop (1+x2)y=1

(1+x2)y+y(2x)=0

y=y(2x)1+x2 =2x1+x2.y =2x1+x2.11+x2 =2x(1+x2)2 Template:RoundBoxBottom

Third derivative y¹¹¹

Template:RoundBoxTop (1+2x2+x4)y=2x

(1+2x2+x4)y+y(4x+4x3)=2

y=2y(4x+4x3)1+2x2+x4 =2y4x(1+x2)1+2x2+x4 =22x(1+x2)2.4x(1+x2)1+2x2+x4 =22x1+x2.4x1+2x2+x4 =2+8x21+x21+2x2+x4 =2(1+x2)+8x21+x21+2x2+x4 =22x2+8x21+x21+2x2+x4 =2+6x21+x21+2x2+x4 =2+6x2(1+2x2+x4)(1+x2) =2+6x2(1+x2)3 Template:RoundBoxBottom

(continued)

If you continue to calculate derivatives, you will produce the following sequence:

f(0)=0

f(0)=1

f(0)=0

f(0)=2=(2!)

f(0)=0

fv(0)=24=4!

fvi(0)=0

fvii(0)=720=(6!)

fviii(0)=0

fviiii(0)=40320=8!

fx(0)=0

fxi(0)=3628800=(10!)

fxii(0)=0

fxiii(0)=479001600=12!


arctan(x)=a0+a1x+a2x2+a3x3+a4x4+

=0+(1)x+(0)x2+(2!)3!x3+(0)x4+4!5!x5+(0)x6+(6!)7!x7+(0)x8+8!9!x9+(0)x10+(10!)11!x11+

=x13x3+15x517x7+19x9111x11+ Template:RoundBoxTop Some basic checking:

arctan(0)=0

arctan(x)=arctan(x).

d(arctan(x))dx =13x23+5x457x67+9x8911x1011+ =1x2+x4x6+x8x10+

Also, d(arctan(x))dx=11+x2

Show that 11+x2 =1x2+x4x6+x8x10+

or that 1=(1+x2)(1x2+x4x6+x8x10+)

(1+x2)(1x2+x4x6+x8x10+)

=1(1x2+x4x6+x8x10+)+x2(1x2+x4x6+x8x10+)

=1x2+x4x6+x8x10++x2x4+x6x8+x10x12+

=1  ± x2n

If abs(x)<1, limnx2n=0. Template:RoundBoxBottom

Template:RoundBoxTop

File:0504arctan(x).png
Figure 1: Graph of t(x), Taylor series representing arctan(x) for x close to 0.

In the diagram to the right, t(x) is the Taylor series representing arctan(x) for x close to 0.

In the box above the proof that t(x) is an accurate representation of arctan(x) is valid for abs(x)<1.

When abs(x)>1, the diagram vividly illustrates that the series rapidly diverges.

To be accurate, the line y=π4 should be y=π4 rad or y=π4c meaning y=π4 radians. In theoretical work a value such as π4 is understood to be π4 radians or 45 meaning 45 degrees. Template:RoundBoxBottom

In practice

Template:RoundBoxTop The expansion of arctan(x) above is theoretically valid for |x|<1. However, if |x| is close to 1, the calculation of arctan(x) will take forever.

This section uses x0 so that |xx0| is small enough to make time of calculation acceptable.


Let θ=3634. To calculate tan(θ):

tan11π60=tan33=14[2(23)(3+5)][2+2(55)]

tan(147)=tan(33)

Using the half-angle formula tan(θ2)=csc(θ)cot(θ),

calculate tan(7312)=tan(1472) and tan(3634)=tan(73122)

θ=3634. x0=tan(θ)=0.7467354177837216717375001402.

f(x0)=3634π180=0.6414085001079161195194563572.


This value (3634) was chosen for θ because x0=tan(θ) is close to 0.75. For 1x0.5, |xx0|0.25 approx.

0.2550=7.888609052210118e31. If |xx0|==0.25, the code below is accurate to 30 places of decimals.


This section uses the whole sequence of derivatives:

y000=arctan(x) where y000=y(0)=y

y001=1U where U=1+x2, y001=y(1)=y

y002=(2)*(x)*(y001)U where y002=y(2)=y

y003=(4)*(x)*(y002)+(2)*(y001)U where y003=y(3)=y and so on.

y004=(6)*(x)*(y003)+(6)*(y002)U

y005=(8)*(x)*(y004)+(12)*(y003)U

y006=(10)*(x)*(y005)+(20)*(y004)U

y007=(12)*(x)*(y006)+(30)*(y005)U

y008=(14)*(x)*(y007)+(42)*(y006)U

y009=(16)*(x)*(y008)+(56)*(y007)U

y010=(18)*(x)*(y009)+(72)*(y008)U

y050=(98)*(x)*(y049)+(2352)*(y048)U


Using f(x)=f(x0)(xx0)0+f(x0)(xx0)1+f(x0)2(xx0)2+f(x0)23(xx0)3+

then f(x)=y000+y001(xx0)+y0022(xx0)2+ and: Template:RoundBoxTop

File:0508arctan(x).png
Figure 1: Graph of t(x), Taylor series representing arctan(x) for x close to 0.75.
x0=tan(3634)=0.7467354177837216717375001402, close to 0.75.
f(x0)=arctan(x0)=0.6414085001079161195194563572 rad.
y = 0.6414085001079161195194563572
+(0.6420076723519613087221948458)(x-(0.7467354177837216717375001402))
+(-0.3077848130939266477182675970)(x-0.7467354177837216717375001402)^2
+(0.05934881813852229894809158807)(x-0.7467354177837216717375001402)^3
+(0.05612149216561873709345633871)(x-0.7467354177837216717375001402)^4
+(-0.0659097533448882821311588572)(x-0.7467354177837216717375001402)^5
+(0.02864269115336634046783964776)(x-0.7467354177837216717375001402)^6
+(0.006684824489389227404750195292)(x-0.7467354177837216717375001402)^7
+(-0.01939996954693863883077829889)(x-0.7467354177837216717375001402)^8
+(0.01319629210955273736079467214)(x-0.7467354177837216717375001402)^9
+(-0.001423635337528918097834676738)(x-0.7467354177837216717375001402)^10
+(-0.005690817314508170664127596721)(x-0.7467354177837216717375001402)^11
+(0.005763416294060825609852171147)(x-0.7467354177837216717375001402)^12
+(-0.002009530403041012685757678258)(x-0.7467354177837216717375001402)^13
+(-0.001382413103546475118963526286)(x-0.7467354177837216717375001402)^14
+(0.002355235379425975362106687309)(x-0.7467354177837216717375001402)^15
+(-0.001340525935442931206538139095)(x-0.7467354177837216717375001402)^16
+(-0.0001244720120416846251034920203)(x-0.7467354177837216717375001402)^17
+(0.0008777184853106580549638629701)(x-0.7467354177837216717375001402)^18
+(-0.0007257802485492202930793702930)(x-0.7467354177837216717375001402)^19
+(0.0001539460026510816727324277808)(x-0.7467354177837216717375001402)^20
+(0.0002810020934892180446689969911)(x-0.7467354177837216717375001402)^21
+(-0.0003470330774958963760466009045)(x-0.7467354177837216717375001402)^22
+(0.0001535570475871531716152621841)(x-0.7467354177837216717375001402)^23
+(0.00006313260945054237374661397478)(x-0.7467354177837216717375001402)^24
+(-0.0001488094986598041280906554962)(x-0.7467354177837216717375001402)^25
+(0.00009977993191704606200503722720)(x-0.7467354177837216717375001402)^26
+(-0.000003667561779685224841381874106)(x-0.7467354177837216717375001402)^27
+(-0.00005609286432922550484209657985)(x-0.7467354177837216717375001402)^28
+(0.00005412057738460028511566507574)(x-0.7467354177837216717375001402)^29
+(-0.00001655090242419904039018979491)(x-0.7467354177837216717375001402)^30
+(-0.00001714674178231985986067601799)(x-0.7467354177837216717375001402)^31
+(0.00002588855802866968641107644970)(x-0.7467354177837216717375001402)^32
+(-0.00001372909690493026279553133838)(x-0.7467354177837216717375001402)^33
+(-0.000002866406864208033772447118585)(x-0.7467354177837216717375001402)^34
+(0.00001098036048658105543109288040)(x-0.7467354177837216717375001402)^35
+(-0.000008497717911244361532280438636)(x-0.7467354177837216717375001402)^36
+(0.000001259146436001274560243296183)(x-0.7467354177837216717375001402)^37
+(0.000003992939704019955177003526706)(x-0.7467354177837216717375001402)^38
+(-0.000004497268683100848779169934291)(x-0.7467354177837216717375001402)^39
+(0.000001768945188244137235636524921)(x-0.7467354177837216717375001402)^40
+(0.000001091706749083768850937760502)(x-0.7467354177837216717375001402)^41
+(-0.000002103423912310375893571195410)(x-0.7467354177837216717375001402)^42
+(0.000001301617082996039555612971998)(x-0.7467354177837216717375001402)^43
+(6.937967909808721515382339295E-8)(x-0.7467354177837216717375001402)^44
+(-8.635525611989332402947366709E-7)(x-0.7467354177837216717375001402)^45
+(7.673857631132879175874596987E-7)(x-0.7467354177837216717375001402)^46
+(-1.893140553441536683377149770E-7)(x-0.7467354177837216717375001402)^47
+(-2.944033068289732156296704644E-7)(x-0.7467354177837216717375001402)^48
+(3.930991061512879804635643270E-7)(x-0.7467354177837216717375001402)^49
+(-1.879241426421737899718180888E-7)(x-0.7467354177837216717375001402)^50

Template:RoundBoxBottom

A faster version

Template:RoundBoxTop The calculation of arctan(x) above is suitable as input to application grapher.

The following python code has precision set to 33. If it is desired to calculate arctan(x) for one value of x, the following python code is much faster than the code supplied to grapher above.

python code

Template:RoundBoxTop

data = '''
0.641408500107916119519456357419567
0.642007672351961308722194845349589
-0.307784813093926647718267596858344
0.0593488181385222989480915882567083
0.0561214921656187370934563384765525
-0.0659097533448882821311588570897649
0.0286426911533663404678396477942956
0.00668482448938922740475019519860028
-0.0193999695469386388307782988276083
0.0131962921095527373607946721380589
-0.00142363533752891809783467677853379
-0.00569081731450817066412759667853352
0.00576341629406082560985217113222417
-0.00200953040304101268575767827219472
-0.00138241310354647511896352626325379
0.00235523537942597536210668729668636
-0.00134052593544293120653813909608214
-0.000124472012041684625103492011289663
0.000877718485310658054963862962235904
-0.000725780248549220293079370291315901
0.000153946002651081672732427784261987
0.000281002093489218044668996986822804
-0.000347033077495896376046600902527326
0.000153557047587153171615262184995174
0.0000631326094505423737466139726989411
-0.000148809498659804128090655494778209
0.0000997799319170460620050372271284211
-0.00000366756177968522484138187499300975
-0.0000560928643292255048420965789718678
0.0000541205773846002851156650754617952
-0.0000165509024241990403901897952115479
-0.0000171467417823198598606760175136922
0.0000258885580286696864110764494276036
-0.0000137290969049302627955313384274982
-0.00000286640686420803377244711837064614
0.0000109803604865810554310928802164877
-0.00000849771791124436153228043859514619
0.00000125914643600127456024329626150593
0.00000399293970401995517700352660353714
-0.00000449726868310084877916993424187367
0.00000176894518824413723563652493847337
0.00000109170674908376885093776045369610
-0.00000210342391231037589357119537437086
0.00000130161708299603955561297199526169
6.93796790980872151538233731691180E-8
-8.63552561198933240294736649885292E-7
7.67385763113287917587459691270367E-7
-1.89314055344153668337714983394592E-7
-2.94403306828973215629670453652457E-7
3.93099106151287980463564320621599E-7
-1.87924142642173789971818089630347E-7
'''

from decimal import *
getcontext().prec=33

listOfMultipliers  = [ Decimal(v) for v in data.split() ]

def arctan (x) :
    x = Decimal(str(x))
    if 1.05 >= x >= 0.45 : pass
    else : print ('\narctan(x): input is outside recommended range.',end='')
    y = Decimal(0)
    x0 = Decimal('0.746735417783721671737500140715213') # tan36.75
    x_minus_x0 = x - x0
    X = Decimal(1)
    status = 1
    for p in range(0,51) :
        toBeAdded = listOfMultipliers[p] * X
        if abs(toBeAdded) < Decimal('1e-31') :
            status = 0
            break
        y += toBeAdded
        X *= x_minus_x0
    if status :
        print ('\narctan(x): count expired.', end='')
    str1 = '''
arctan({}) = {}, count = {}
'''.format(x,y,p)
    print (str1.rstrip())
    return y

Template:RoundBoxBottom

x close to x0

Template:RoundBoxTop Template:RoundBoxTop

x = Decimal('0.75')
arctan(x)

Template:RoundBoxBottom Template:RoundBoxTop

arctan(0.75) = 0.643501108793284386802809228717315, count = 12

Template:RoundBoxBottom When x is close to x0, result is achieved with only 12 passes through loop. Template:RoundBoxBottom

Testing with known values

Template:RoundBoxTop Check results using known combinations of x and arctan(x):

tan3π20=tan27=51525.

For tan27 and other exact values of tan(x), see Exact Values for Common Angles. Template:RoundBoxTop

π = "3.14159265358979323846264338327950288419716939937510582097494459230781"
π = Decimal(π)
rt3 = Decimal(3).sqrt()
rt5 = Decimal(5).sqrt()
rt15 = Decimal(15).sqrt()

tan27 = rt5 - 1 - (5 - 2*rt5).sqrt()

tan30 = 1/rt3

v1 = 2 - (2-rt3)*(3+rt5) ; v2 = 2+ (2*(5-rt5)).sqrt()
tan33 = v1*v2/4

tan36 = (5-2*rt5).sqrt()

v1 = (2-rt3)*(3-rt5)-2 ; v2 = 2 - (2*(5+rt5)).sqrt()
tan39 = v1*v2/4

tan42 = ( rt15 + rt3 - (10 + 2*rt5).sqrt() )/2

tan45 = Decimal(1)

values = (
    ( 9*π/60, tan27, 27),
    (10*π/60, tan30, 30),
    (11*π/60, tan33, 33),
    (12*π/60, tan36, 36),
    (13*π/60, tan39, 39),
    (14*π/60, tan42, 42),
    (   π/ 4, tan45, 45),
)

for value in values :
    angleInRadians, tan, angleInDegrees = value
    y = arctan(tan)
    print ('for', angleInDegrees, 'degrees, difference =',  angleInRadians-y)

Template:RoundBoxBottom Template:RoundBoxTop

arctan(0.509525449494428810513706911250666) = 0.471238898038468985769396507491970, count = 41
for 27 degrees, difference = -4.5E-32

arctan(0.577350269189625764509148780501958) = 0.523598775598298873077107230546614, count = 34
for 30 degrees, difference = -3.1E-32

arctan(0.649407593197510576982062911311432) = 0.575958653158128760384817953601229, count = 27
for 33 degrees, difference = 1.3E-32

arctan(0.726542528005360885895466757480614) = 0.628318530717958647692528676655896, count = 17
for 36 degrees, difference = 4E-33

arctan(0.809784033195007148036991374235772) = 0.680678408277788535000239399710521, count = 23
for 39 degrees, difference = 3.7E-32

arctan(0.90040404429783994512047720388537) = 0.733038285837618422307950122765236, count = 33
for 42 degrees, difference = -1.9E-32

arctan(1) = 0.785398163397448309615660845819846, count = 43
for 45 degrees, difference = 3.0E-32

Template:RoundBoxBottom Template:RoundBoxBottom

Template:RoundBoxTop Template:RoundBoxTop

tan24 = ( (50+22*rt5).sqrt() - 3*rt3 - rt15 ) / 2
tan46_5 = Decimal('1.05378012528096218058753672331544') # tan(46.5) 

values = (
    (24*π/180,   tan24,   24),
    (93*π/360, tan46_5, 46.5),
)

for value in values :
    angleInRadians, tan, angleInDegrees = value
    y = arctan(tan)
    print ('for x =', float(tan), 'difference =',  angleInRadians-y)

Template:RoundBoxBottom Template:RoundBoxTop

arctan(x): input is outside recommended range.
arctan(0.44522868530853616392236703064567) = 0.418879020478639098461685784437249, count = 47
for x = 0.44522868530853615 difference = 1.8E-32

arctan(x): input is outside recommended range.
arctan(1.05378012528096218058753672331544) = 0.811578102177363253269516207347250, count = 48
for x = 1.0537801252809622 difference = -4.4E-32

Template:RoundBoxBottom For 1.05x0.45 the above calculation of arctan(x) is accurate to more than 30 places of decimals. Template:RoundBoxBottom

Template:RoundBoxTop If input is outside recommended limits, this does not necessarily mean that result is invalid.

If tan51xtan9, result is accurate to precision of python floats, 15 places of decimals. Template:RoundBoxBottom Template:RoundBoxBottom Template:RoundBoxBottom

arcsin(x)

y=arcsin(x)

x=sin(y)

dxdy=cos(y)=1x2

dydx=1cos(y)=11x2

Simple differential equations eliminate the square root and make calculations so much easier.

Let a=dydx

Then a2U=1 where U=1x2 and U'=2x.


Differentiating both sides:

a2(2x)+U2aa'=0

U2aa'=2xa2

a'=2xaa2aU=axU.

Let b=a'

Then bU=ax


Differentiating both sides:

b(2x)+Ub'=a+xa'=a+xb

Let c=b'

Then c=a+3bxU


When x=0, U=1. Calculation of more derivatives yields:

y=f(x)=arcsin(x)

a=f'(x)=11x2

b=f'(x)=ax

c=f'(x)=a+3bx

d=f'(x)=4b+5cx

g=fv(x)=9c+7dx

h=fvi(x)=16d+9gx

j=fvii(x)=25g+11hx

k=fviii(x)=36h+13jx

l=fviiii(x)=49j+15kx

and so on.


=k=h=d=b=0

a=1; c=12a; g=32c; j=52g; l=72j; .


arcsin(x)=x+13!x3+325!x5+32527!x7+3252729!x9+3252729211!x11+

arcsin(x)=x+13!x3+3(2!)(22)5x5+35(3!)(23)7x7+357(4!)(24)9x9+3579(5!)(25)11x11+


As programming algorithm:

arcsin(x)=x+top=1(bottom=2)3(X=x3) +top=top(52)(bottom=bottom(51))5(X=X(x2)) +top=top(72)(bottom=bottom(71))7(X=X(x2)) + +top=top(n2)(bottom=bottom(n1))n(X=X(x2))


As implemented in Python:

from decimal import * # Default precision is 28.

π = ("3.14159265358979323846264338327950288419716939937510582097494459230781")
π = Decimal(π)

x = Decimal(2).sqrt()/2 # Expecting result of π/4

xSQ = x*x
X = x*xSQ

top = Decimal(1)
bottom = Decimal(2)

bottom1 = bottom*3
sum = x + X*top / bottom1

status = 1
for n in range(5,200,2) :
    X = X*xSQ
    top = top*(n-2)
    bottom = bottom*(n-1)
    bottom1 = bottom*n
    added = X*top/bottom1
    if (added < 1e-29) :
        status = 0
        break
    sum += added

if status :
    print ('error. count expired.')
else :
    print (x, sum==π/4, n)
0.707106781186547524400844362 True 171

In practice

If |x| is close to 1, the calculation of arcsin(x) will take forever.


If you limit x to sin45>=x>=sin45, then x2<=0.5 and each term is guaranteed to be less than half the preceding term.


If x>sin45, let t=π2y.

Then sint=cosy=1x2; t=arcsin(cosy); y=π2t.

Integral of expression

dydx=ax2

According to the reference "this expression cannot be integrated..." However, if we convert the expression to a Taylor series, the integral of the series is quite easily calculated.

Let y=f(x)=ax2=1ax2

When x=0, y=1 and the following sequence can be produced.

y'=2Ay where A=ln(a).

y(4)=6Ay'

y(6)=10Ay(4)

y(8)=14Ay(6)

y(10)=18Ay(8)

y(12)=22Ay(10) and so on.

Taylor series of f(x) for x close to 0=t(x)=1+c02x2+c04x4+c06x6+

where c02=y'2!; c04=y(4)4!; c06=y(6)6!

For a=2 python code produces the following:

c02 = -0.6931471805599453094172321215
c04 = 0.2402265069591007123335512632
c06 = -0.05550410866482157995314226378
c08 = 0.009618129107628477161979071575
c10 = -0.001333355814642844342341222199
c12 = 0.0001540353039338160995443709734
c14 = -0.00001525273380405984028002543902
c16 = 0.000001321548679014430948840375823
c18 = -1.017808600923969972749000760E-7
c20 = 7.054911620801123329875392184E-9
c22 = -4.445538271870811497596408561E-10
c24 = 2.567843599348820514199480240E-11
c26 = -1.369148885390412888089195400E-12
c28 = 6.778726354822545633449104318E-14
c30 = -3.132436707088428621634944443E-15
c32 = 1.357024794875514719311296624E-16
c34 = -5.533046532458242043485546100E-18
c36 = 2.130675335489117996020398479E-19
c38 = -7.773008428857356419088997166E-21
c40 = 2.693919438465583416972861154E-22
c42 = -8.891822206800239171648619811E-24

For a close to 1 or x close to 0, the Taylor series is a quite accurate representation of the original expression. When abs(x)1.6, the abs(maximum difference) between expression and Taylor series is <1e15.

For greater accuracy, greater precision may be specified in python or more terms after c42 may be added.

The integral =I(x)=x+C02x3+C04x5+C06x7+

where C02=c023; C04=c045; C06=c067

Template:RoundBoxTop

File:20200324curve&Taylor.png
Figure 1: Curves of f(x) and t(x) where t(x) is Taylor series representing f(x) for x close to 0.

In figure to right, t(x)=1.5+, separating t(x) from f(x) to illustrate shapes of curves.

The correct value of t(x)=1+.

When x=1, f(x)=0.5 and t(x)=0.4999999999999999999999997281.

To 24 places of decimals t(x)=0.5000_0000_0000_0000_0000_0000. Template:RoundBoxBottom Template:RoundBoxTop

File:20200324curce&Integral.png
Figure 1: Curves of f(x) and I(x) where I(x) is integral of t(x) and represents integral of f(x) for x close to 0.
In this example, constant of integration C=0.

If it were important to calculate the area under f(x) from x=0 to x=1, I(x) returns 0.8100254543909558266292852604, accurate to about 26 places of decimals. Template:RoundBoxBottom

sin(x) using (x - x0)

f(x)=sin(x)

f(x)=cos(x)

f(x)=sin(x)

f(x)=cos(x)

f(4)=sin(x)

Let x0=π4=45

f(x0)=f(π4)=sin(π4)=22

f(x0)=f(π4)=cos(π4)=22

f(x0)=f(π4)=sin(π4)=22

f(x0)=f(π4)=cos(π4)=22

f(4)(x0)=f(4)(π4)=sin(π4)=22

t(x)=22(xx0)0 +22(xx0)1 2212!(xx0)2 2213!(xx0)3 +2214!(xx0)4+

Let X=(xx0)=(xπ4)

Then t(x)=22( 1+X X22!X33! +X44!+X55! X66!X77!   )

where t(x) is the Taylor series representing f(x)=sin(x) for values of x close to 45 or π4.

If π2(90)x0, then t(x) containing powers of X through 15 is sufficient to keep the error to <1e15.

Almost a sine curve

Template:RoundBoxTop

File:0326t(x)29.png
Figure 1: Graph of t(x) representing sin(x) for x close to π4.

Graph to right was produced by Grapher on a Mac.

A python script produced the following data:

( (2^(0.5))/2 )(
 1  +(x-.785398163397448)

 -((x-.785398163397448)^2)/2
 -((x-.785398163397448)^3)/(2(3))

 +((x-.785398163397448)^4)/(24)
 +((x-.785398163397448)^5)/(120)

 -((x-.785398163397448)^6)/(720)
 -((x-.785398163397448)^7)/(5040)

 +((x-.785398163397448)^8)/(40320)
 +((x-.785398163397448)^9)/(362880)

 -((x-.785398163397448)^10)/(3628800)
 -((x-.785398163397448)^11)/(39916800)

 +((x-.785398163397448)^12)/(479001600)
 +((x-.785398163397448)^13)/(6227020800)

 -((x-.785398163397448)^14)/(87178291200)
 -((x-.785398163397448)^15)/(1307674368000)

 +((x-.785398163397448)^16)/(20922789888000)
 +((x-.785398163397448)^17)/(355687428096000)

 -((x-.785398163397448)^18)/(6402373705728000)
 -((x-.785398163397448)^19)/(121645100408832000)

 +((x-.785398163397448)^20)/(2432902008176640000)
 +((x-.785398163397448)^21)/(51090942171709440000)

 -((x-.785398163397448)^22)/(1124000727777607680000)
 -((x-.785398163397448)^23)/(25852016738884976640000)

 +((x-.785398163397448)^24)/(620448401733239439360000)
 +((x-.785398163397448)^25)/(15511210043330985984000000)

 -((x-.785398163397448)^26)/(403291461126605635584000000)
 -((x-.785398163397448)^27)/(10888869450418352160768000000)

 +((x-.785398163397448)^28)/(304888344611713860501504000000)
 +((x-.785398163397448)^29)/(8841761993739701954543616000000)
)

I highlighted the data, copied it with command C and pasted it into the input area of Grapher. Well done! Grapher. Template:RoundBoxBottom

Integral of 1/x

The Taylor series for f(x)=1x for x close to 2 is:

t(x)=12122(x2)+123(x2)2124(x2)3

The integral of this series is:

I(x)=12(x2)((122)/2)(x2)2+((123)/3)(x2)3((124)/4)(x2)4+C

The integral of 1x=ln(x).

Therefore ln(x)=I(x) but what is the value of C?

Without C, when x=2,I(x)=0. I(x) should be ln(2).

Therefore, for x close to 2:

ln(x)=I(x) where C=ln(2).

But what is the value of ln(2)?

Without C, when x=1, I(x)=0.693147180559945. I(x) should be 0.

Therefore C=0.693147180559945 or ln(2).

For x close to 2:

ln(x)=ln(2)+12(x2)((122)/2)(x2)2+((123)/3)(x2)3((124)/4)(x2)4

where ln(2)=0.693147180559945

Template:RoundBoxTop

File:0328ln(x)closeTo2.png
Figure 1: Graph of I(x) representing ln(x) for x close to 2.
y = 0.693147180559945
+ ((1/(2^1))/1)(x - 2)^1
- ((1/(2^2))/2)(x - 2)^2
+ ((1/(2^3))/3)(x - 2)^3
- ((1/(2^4))/4)(x - 2)^4
+ ((1/(2^5))/5)(x - 2)^5
- ((1/(2^6))/6)(x - 2)^6
+ ((1/(2^7))/7)(x - 2)^7
...........................
...........................
- ((1/(2^42))/42)(x - 2)^42
+ ((1/(2^43))/43)(x - 2)^43
- ((1/(2^44))/44)(x - 2)^44
+ ((1/(2^45))/45)(x - 2)^45
- ((1/(2^46))/46)(x - 2)^46
+ ((1/(2^47))/47)(x - 2)^47
- ((1/(2^48))/48)(x - 2)^48
+ ((1/(2^49))/49)(x - 2)^49

Template:RoundBoxBottom Generally, for x close to x0:

ln(x)=ln(x0)+11xx0x0 12(xx0)2x02 +13(xx0)3x03 14(xx0)4x04 +15(xx0)5x05

Calculating ln(x)

This section presents a system for calculating ln(x) for 10x1, knowing only that ln(1)=0.

# python code
L1 = [1, 1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 1.7, 1.8, 1.9, 2.0, 2.2, 2.4, 2.6, 2.8, 
    3.0, 3.3, 3.6, 3.9, 4.2, 4.6, 5.0, 5.5, 6.0, 6.6, 7.2, 7.9, 8.6, 9.3, 10.0]

where L1 is a list containing values of x0 in which each value after the first is 10% more than the preceding value.

# python code
from decimal import *
getcontext().prec=53 # Preparing for values containing 50 places of decimals.
almostZero = Decimal('1e-' + str( getcontext().prec ))

L1 = [ Decimal(str(v)) for v in L1 ]

def ln_x (x, x0, C=0) :
    '''
    return ln(x) for x close to x0.
    ln_x_ = ln_x (x, x0, C) 
    C is the constant of integration. Usually C = ln(x0).
    '''
    x, x0, C = [ Decimal(str(v)) for v in (x,x0,C) ]
    x_minus_x0 = x-x0;
#    print ('x,x0,x_minus_x0 =',x,x0,x_minus_x0)
    sum = 0
    progressiveValue = 1
    status = 1 ; limit = 4*getcontext().prec
    multiplier = x_minus_x0/x0
    for p in range (1, limit, 2) :
        progressiveValue *= multiplier
        added = progressiveValue / p
        sum += added

        progressiveValue *= multiplier
        added = progressiveValue / (p+1)

        if (abs(added) < almostZero) :
            status = 0
            break
        sum -= added
    if (status) :
        print ('ln_x error: count expired, p =',p)
        exit (95)
    return sum+C

The performance of the above code is better than logarithmic to base 10. This means, for example, if x contains 60 significant decimal digits, the above code produces a result with fewer than 30 passes through the loop because each iteration of the lop performs two operations.

L1 is designed so that multiplier =x_minus_x0x0 is always 110. When x is very close to x0, time to calculate ln(x) is greatly reduced.

Template:RoundBoxTop

File:0407ln(x)closeTo(7.9).png
Figure 1: Graph of I(x) representing ln(x) for x close to 7.9.
When value xx0x0>1, the series diverges.
In this case, when x>15.8.
y = ln(7.9)
+ ((1/((7.9)^(1)))/(1))((x - 7.9)^(1))
- ((1/((7.9)^(2)))/(2))((x - 7.9)^(2))
+ ((1/((7.9)^(3)))/(3))((x - 7.9)^(3))
- ((1/((7.9)^(4)))/(4))((x - 7.9)^(4))
+ ((1/((7.9)^(5)))/(5))((x - 7.9)^(5))
- ((1/((7.9)^(6)))/(6))((x - 7.9)^(6))
+ ((1/((7.9)^(7)))/(7))((x - 7.9)^(7))
- ((1/((7.9)^(8)))/(8))((x - 7.9)^(8))
+ ((1/((7.9)^(9)))/(9))((x - 7.9)^(9))
.....................
.....................
- ((1/((7.9)^(22)))/(22))((x - 7.9)^(22))
+ ((1/((7.9)^(23)))/(23))((x - 7.9)^(23))
- ((1/((7.9)^(24)))/(24))((x - 7.9)^(24))
+ ((1/((7.9)^(25)))/(25))((x - 7.9)^(25))
- ((1/((7.9)^(26)))/(26))((x - 7.9)^(26))
+ ((1/((7.9)^(27)))/(27))((x - 7.9)^(27))
- ((1/((7.9)^(28)))/(28))((x - 7.9)^(28))
+ ((1/((7.9)^(29)))/(29))((x - 7.9)^(29))

Template:RoundBoxBottom

The next piece of code progressively calculates ln(1.1), ln(1.2), ln(1.3)  and puts the calculated values in dictionary dict2.

dict2 = dict()
dict2[Decimal('1.0')] = Decimal(0)

for p in range(1, len(L1)) :
    x = L1[p]
    x0 = L1[p-1]
    C = dict2[x0]
#    print ('L1[{}]={}'.format(p,L1[p]))
    ln = ln_x (x, x0, C)
    dict2[x] = ln

print ('dict2 = {')
for x0 in dict2 :
    print ("Decimal('{}'):  +Decimal('{}'),".format( (' '+str(x0))[-4:], dict2[x0]) )
print ('}')
dict2 = {
Decimal(' 1.0'):  +Decimal('0'),
Decimal(' 1.1'):  +Decimal('0.095310179804324860043952123280765092220605365308644199'),
Decimal(' 1.2'):  +Decimal('0.18232155679395462621171802515451463319738933791448698'),
Decimal(' 1.3'):  +Decimal('0.26236426446749105203549598688095439720416645613143414'),
Decimal(' 1.4'):  +Decimal('0.33647223662121293050459341021699209011148337531334347'),
Decimal(' 1.5'):  +Decimal('0.40546510810816438197801311546434913657199042346249420'),
Decimal(' 1.6'):  +Decimal('0.47000362924573555365093703114834206470089904881224805'),
Decimal(' 1.7'):  +Decimal('0.53062825106217039623154316318876232798710152395697182'),
Decimal(' 1.8'):  +Decimal('0.58778666490211900818973114061886376976937976137698120'),
Decimal(' 1.9'):  +Decimal('0.64185388617239477599103597720348932963627777267035586'),
Decimal(' 2.0'):  +Decimal('0.69314718055994530941723212145817656807550013436025527'),
Decimal(' 2.2'):  +Decimal('0.78845736036427016946118424473894166029610549966889947'),
Decimal(' 2.4'):  +Decimal('0.87546873735389993562895014661269120127288947227474225'),
Decimal(' 2.6'):  +Decimal('0.95551144502743636145272810833913096527966659049168941'),
Decimal(' 2.8'):  +Decimal('1.0296194171811582399218255316751686581869835096735987'),
Decimal(' 3.0'):  +Decimal('1.0986122886681096913952452369225257046474905578227494'),
Decimal(' 3.3'):  +Decimal('1.1939224684724345514391973602032907968680959231313936'),
Decimal(' 3.6'):  +Decimal('1.2809338454620643176069632620770403378448798957372364'),
Decimal(' 3.9'):  +Decimal('1.3609765531356007434307412238034801018516570139541836'),
Decimal(' 4.2'):  +Decimal('1.4350845252893226218998386471395177947589739331360929'),
Decimal(' 4.6'):  +Decimal('1.5260563034950493162059934985840084789167789605719180'),
Decimal(' 5.0'):  +Decimal('1.6094379124341003746007593332261876395256013542685177'),
Decimal(' 5.5'):  +Decimal('1.7047480922384252346447114565069527317462067195771619'),
Decimal(' 6.0'):  +Decimal('1.7917594692280550008124773583807022727229906921830047'),
Decimal(' 6.6'):  +Decimal('1.8870696490323798608564294816614673649435960574916489'),
Decimal(' 7.2'):  +Decimal('1.9740810260220096270241953835352169059203800300974917'),
Decimal(' 7.9'):  +Decimal('2.0668627594729758101549540867970467145724397357938367'),
Decimal(' 8.6'):  +Decimal('2.1517622032594620488720831801196593960335348306130377'),
Decimal(' 9.3'):  +Decimal('2.2300144001592102533064181067805187074963279996745685'),
Decimal('10.0'):  +Decimal('2.3025850929940456840179914546843642076011014886287730'),
}

Template:RoundBoxTop A quick check:

ln(2.2) - (ln(1.1) + ln(2.0)) = 0E-50
ln(2.4) - (ln(1.2) + ln(2.0)) = 0E-50
ln(2.6) - (ln(1.3) + ln(2.0)) = 0E-50
ln(2.8) - (ln(1.4) + ln(2.0)) = 0E-50
ln(3.0) - (ln(1.5) + ln(2.0)) = -0E-50
ln(3.3) - (ln(1.1) + ln(3.0)) = 0E-50
ln(3.6) - (ln(1.2) + ln(3.0)) = 0E-50
ln(3.6) - (ln(1.8) + ln(2.0)) = -0E-50
ln(3.9) - (ln(1.3) + ln(3.0)) = 0E-50
ln(4.2) - (ln(1.4) + ln(3.0)) = 0E-50
ln(5.5) - (ln(1.1) + ln(5.0)) = 0E-50
ln(6.0) - (ln(1.2) + ln(5.0)) = 0E-50
ln(6.0) - (ln(2.0) + ln(3.0)) = 0E-50
ln(6.6) - (ln(1.1) + ln(6.0)) = 0E-50
ln(6.6) - (ln(2.2) + ln(3.0)) = 0E-50
ln(6.6) - (ln(3.3) + ln(2.0)) = 0E-50
ln(7.2) - (ln(1.2) + ln(6.0)) = 0E-50
ln(7.2) - (ln(2.4) + ln(3.0)) = 0E-50
ln(10.0) - (ln(5.0) + ln(2.0)) = 0E-50

Template:RoundBoxBottom

Put the data from dict2 into 2 tuples Tx0, Tln_x0

Tx0 = tuple(L1)
Tln_x0 = tuple([ dict2[v] for v in Tx0 ])

Calculate the decision points.

L1 = []
for p in range (0, len(Tx0)-1) :
    a,b = Tx0[p], Tx0[p+1]
    dp = 2*a*b/(a+b)
    L1 += [ dp ]
Tdp = tuple(L1)

Display the three tuples.

for T in ('Tx0', 'Tln_x0', 'Tdp') :
    t = eval(T)
    print (T, '= (')
    for v in t :
        print ("""+Decimal('{}'),""".format(v))
    print (')')
    print ()

Previous code was used to produce three tuples. Operational code follows:


Values of x0:

Tx0 = ( Decimal('1'), Decimal('1.1'), Decimal('1.2'), Decimal('1.3'), Decimal('1.4'), Decimal('1.5'), Decimal('1.6'), Decimal('1.7'), Decimal('1.8'), Decimal('1.9'), Decimal('2.0'), Decimal('2.2'), Decimal('2.4'), Decimal('2.6'), Decimal('2.8'), Decimal('3.0'), Decimal('3.3'), Decimal('3.6'), Decimal('3.9'), Decimal('4.2'), Decimal('4.6'), Decimal('5.0'), Decimal('5.5'), Decimal('6.0'), Decimal('6.6'), Decimal('7.2'), Decimal('7.9'), Decimal('8.6'), Decimal('9.3'), Decimal('10.0'), )


Values of ln(x0):

Tln_x0 = ( +Decimal('0'), +Decimal('0.095310179804324860043952123280765092220605365308644199'), +Decimal('0.18232155679395462621171802515451463319738933791448698'), +Decimal('0.26236426446749105203549598688095439720416645613143414'), +Decimal('0.33647223662121293050459341021699209011148337531334347'), +Decimal('0.40546510810816438197801311546434913657199042346249420'), +Decimal('0.47000362924573555365093703114834206470089904881224805'), +Decimal('0.53062825106217039623154316318876232798710152395697182'), +Decimal('0.58778666490211900818973114061886376976937976137698120'), +Decimal('0.64185388617239477599103597720348932963627777267035586'), +Decimal('0.69314718055994530941723212145817656807550013436025527'), +Decimal('0.78845736036427016946118424473894166029610549966889947'), +Decimal('0.87546873735389993562895014661269120127288947227474225'), +Decimal('0.95551144502743636145272810833913096527966659049168941'), +Decimal('1.0296194171811582399218255316751686581869835096735987'), +Decimal('1.0986122886681096913952452369225257046474905578227494'), +Decimal('1.1939224684724345514391973602032907968680959231313936'), +Decimal('1.2809338454620643176069632620770403378448798957372364'), +Decimal('1.3609765531356007434307412238034801018516570139541836'), +Decimal('1.4350845252893226218998386471395177947589739331360929'), +Decimal('1.5260563034950493162059934985840084789167789605719180'), +Decimal('1.6094379124341003746007593332261876395256013542685177'), +Decimal('1.7047480922384252346447114565069527317462067195771619'), +Decimal('1.7917594692280550008124773583807022727229906921830047'), +Decimal('1.8870696490323798608564294816614673649435960574916489'), +Decimal('1.9740810260220096270241953835352169059203800300974917'), +Decimal('2.0668627594729758101549540867970467145724397357938367'), +Decimal('2.1517622032594620488720831801196593960335348306130377'), +Decimal('2.2300144001592102533064181067805187074963279996745685'), +Decimal('2.3025850929940456840179914546843642076011014886287730'), )


Decision points:

Tdp = ( +Decimal('1.0476190476190476190476190476190476190476190476190476'), +Decimal('1.1478260869565217391304347826086956521739130434782609'), +Decimal('1.248'), +Decimal('1.3481481481481481481481481481481481481481481481481481'), +Decimal('1.4482758620689655172413793103448275862068965517241379'), +Decimal('1.5483870967741935483870967741935483870967741935483871'), +Decimal('1.6484848484848484848484848484848484848484848484848485'), +Decimal('1.7485714285714285714285714285714285714285714285714286'), +Decimal('1.8486486486486486486486486486486486486486486486486486'), +Decimal('1.9487179487179487179487179487179487179487179487179487'), +Decimal('2.0952380952380952380952380952380952380952380952380952'), +Decimal('2.2956521739130434782608695652173913043478260869565217'), +Decimal('2.496'), +Decimal('2.6962962962962962962962962962962962962962962962962963'), +Decimal('2.8965517241379310344827586206896551724137931034482759'), +Decimal('3.1428571428571428571428571428571428571428571428571429'), +Decimal('3.4434782608695652173913043478260869565217391304347826'), +Decimal('3.744'), +Decimal('4.0444444444444444444444444444444444444444444444444444'), +Decimal('4.3909090909090909090909090909090909090909090909090909'), +Decimal('4.7916666666666666666666666666666666666666666666666667'), +Decimal('5.2380952380952380952380952380952380952380952380952381'), +Decimal('5.7391304347826086956521739130434782608695652173913043'), +Decimal('6.2857142857142857142857142857142857142857142857142857'), +Decimal('6.8869565217391304347826086956521739130434782608695652'), +Decimal('7.5337748344370860927152317880794701986754966887417219'), +Decimal('8.2351515151515151515151515151515151515151515151515152'), +Decimal('8.9363128491620111731843575418994413407821229050279330'), +Decimal('9.6373056994818652849740932642487046632124352331606218'), )

At each decision point x is assigned to the next low value or the next high value of x0. For example, if x is between 1.2, 1.3, the decision point is 1.248. This means that the ratio 1.2481.21.2=1.31.2481.3=0.04 and the maximum value of abs(xx0x0)=0.04.

During creation of Tln_x0 the maximum value of xx0x0=110. During normal operations after creation of Tln_x0, maximum value of abs(xx0x0)=1.04761911 between 1.0, 1.1.


Choose a suitable value of x0 with the value of its natural log.

def choose_x0_C (x) :
    '''
    (x0, C) = choose_x0_C (x)
    '''
    if (10 >= x >= 1) : pass
    else: exit (93)

    for p in range (len(Tx0)-2, -1, -1):
        if (x >= Tx0[p]) :
            if (x >= Tdp[p]) : return (Tx0[p+1], Tln_x0[p+1])
            return (Tx0[p], Tln_x0[p])
    exit(92)

Ready to calculate, for example, ln(3.456789)

x = Decimal('3.456789')
(x0, C) = choose_x0_C (x)
ln_x_ = ln_x (x, x0, C)
print ('ln({}) = {}'.format(x, ln_x_.quantize(Decimal('1e-50'))))
ln(3.456789) = 1.24034_01234_96758_02986_53847_82231_30004_00340_53893_89110 # displayed with 50 places of decimals.

Testing ln(x)

Choose random numbers a, b so that 10ab1.

Produce values ln(a), ln(b).

Calculate product p=ab.

Produce value ln(p).

If p>10, p=(p10)10 and ln(p)=ln(p10)+ln(10).

Verify that ln(p)=ln(a)+ln(b).

# python code
import random

ln_10 = Tln_x0[-1]
fiftyPlacesOfDecimals = Decimal('1e-50')

def randomNumber() :
    s1 = str(random.getrandbits(getcontext().prec * 4))
    d1 = Decimal(s1[0] + '.' + s1[1:])
    if (d1 == 0) : d1 = randomNumber()
    while (d1 < 1) : d1 *= 10
    return d1

d1 = randomNumber()
d2 = randomNumber()

(x0, C) = choose_x0_C (d1)
ln_d1_ = ln_x (d1, x0, C)

(x0, C) = choose_x0_C (d2)
ln_d2_ = ln_x (d2, x0, C)

product = d1*d2
add_ln10 = 0
if (product > 10) :
    product /= 10
    add_ln10 += 1

(x0, C) = choose_x0_C (product)
ln_product_ = ln_x (product, x0, C)
if (add_ln10) : ln_product_ += ln_10

difference = (ln_product_ - ( ln_d1_ + ln_d2_ )).quantize(fiftyPlacesOfDecimals)

print ('''
d1          = {}
ln_d1_      = {}
d2          = {}
ln_d2_      = {}
ln_product_ = {}
'''.format(
d1,ln_d1_ ,
d2,ln_d2_ ,
ln_product_ ,
))

if difference :  print ('''
difference  = {} ****
'''.format(
difference,
))

For example: During testing, successive invocations of the above code produced:

d1          = 3.300463847393627263496303126765085976697315885228780009201595937
ln_d1_      = 1.1940630184110798505583266934968432937656468440595029
d2          = 4.727915623201914684885711302927600487326893972103794963997766615
ln_d2_      = 1.5534844337520634527664958773360448454701186698422347
ln_product_ = 2.7475474521631433033248225708328881392357655139017377
d1          = 6.56429212435850275252301147228535243835226966080458915176241218
ln_d1_      = 1.8816446762531860392218213681767770852191644273705970
d2          = 8.15468991518212749204100104755219361919087392341006662123706307
ln_d2_      = 2.0985932114606734087366302984138612677420896519457258
ln_product_ = 3.9802378877138594479584516665906383529612540793163228

Template:Mathematics resourcesTemplate:Sisterlinks