f
(
x
)
=
cos
(
x
)
;
f
(
0
)
=
cos
(
0
)
=
1
{\displaystyle f(x)=\cos(x);\ f(0)=\cos(0)=1}
f
′
(
x
)
=
−
sin
(
x
)
;
f
′
(
0
)
=
−
sin
(
0
)
=
0
{\displaystyle f'(x)=-\sin(x);\ f'(0)=-\sin(0)=0}
f
″
(
x
)
=
−
cos
(
x
)
;
f
″
(
0
)
=
−
cos
(
0
)
=
−
1
{\displaystyle f''(x)=-\cos(x);\ f''(0)=-\cos(0)=-1}
f
‴
(
x
)
=
sin
(
x
)
;
f
‴
(
0
)
=
sin
(
0
)
=
0
{\displaystyle f'''(x)=\sin(x);\ f'''(0)=\sin(0)=0}
f
⁗
(
x
)
=
cos
(
x
)
;
f
⁗
(
0
)
=
cos
(
0
)
=
1
{\displaystyle f''''(x)=\cos(x);\ f''''(0)=\cos(0)=1}
a
0
=
f
(
0
)
=
1
{\displaystyle a_{0}=f(0)=1}
a
1
=
f
′
(
0
)
=
0
{\displaystyle a_{1}=f'(0)=0}
a
2
=
f
″
(
0
)
2
=
−
1
2
!
{\displaystyle a_{2}={\frac {f''(0)}{2}}={\frac {-1}{2!}}}
a
3
=
f
‴
(
0
)
2
∗
3
=
0
3
!
=
0
{\displaystyle a_{3}={\frac {f'''(0)}{2*3}}={\frac {0}{3!}}=0}
a
4
=
f
⁗
(
0
)
2
∗
3
∗
4
=
1
4
!
{\displaystyle a_{4}={\frac {f''''(0)}{2*3*4}}={\frac {1}{4!}}}
cos
(
x
)
=
a
0
+
a
1
x
+
a
2
x
2
+
a
3
x
3
+
a
4
x
4
+
⋯
{\displaystyle \cos(x)=a_{0}+a_{1}x+a_{2}x^{2}+a_{3}x^{3}+a_{4}x^{4}+\cdots }
=
1
+
(
0
)
x
+
−
1
2
x
2
+
0
x
+
1
4
!
x
4
+
⋯
{\displaystyle =1+(0)x+{\frac {-1}{2}}x^{2}+0x+{\frac {1}{4!}}x^{4}+\cdots }
=
1
−
x
2
2
!
+
x
4
4
!
−
x
6
6
!
+
x
8
8
!
−
⋯
{\displaystyle =1-{\frac {x^{2}}{2!}}+{\frac {x^{4}}{4!}}-{\frac {x^{6}}{6!}}+{\frac {x^{8}}{8!}}-\cdots }
y
=
arctan
(
x
)
{\displaystyle y=\arctan(x)}
x
=
tan
(
y
)
{\displaystyle x=\tan(y)}
d
x
d
y
=
sec
2
(
y
)
{\displaystyle {\frac {dx}{dy}}=\sec ^{2}(y)}
y
′
=
d
y
d
x
=
cos
2
(
y
)
=
1
1
+
x
2
{\displaystyle y'={\frac {dy}{dx}}=\cos ^{2}(y)={\frac {1}{1+x^{2}}}}
.
See
cos
(
θ
)
{\displaystyle \cos(\theta )}
.
Second derivative y″
edit
Third derivative y¹¹¹
edit
If you continue to calculate derivatives, you will produce the following sequence:
f
(
0
)
=
0
{\displaystyle f(0)=0}
f
′
(
0
)
=
1
{\displaystyle f'(0)=1}
f
″
(
0
)
=
0
{\displaystyle f''(0)=0}
f
‴
(
0
)
=
−
2
=
−
(
2
!
)
{\displaystyle f'''(0)=-2=-(2!)}
f
⁗
(
0
)
=
0
{\displaystyle f''''(0)=0}
f
v
(
0
)
=
24
=
4
!
{\displaystyle f^{v}(0)=24=4!}
f
v
i
(
0
)
=
0
{\displaystyle f^{vi}(0)=0}
f
v
i
i
(
0
)
=
−
720
=
−
(
6
!
)
{\displaystyle f^{vii}(0)=-720=-(6!)}
f
v
i
i
i
(
0
)
=
0
{\displaystyle f^{viii}(0)=0}
f
v
i
i
i
i
(
0
)
=
40320
=
8
!
{\displaystyle f^{viiii}(0)=40320=8!}
f
x
(
0
)
=
0
{\displaystyle f^{x}(0)=0}
f
x
i
(
0
)
=
−
3628800
=
−
(
10
!
)
{\displaystyle f^{xi}(0)=-3628800=-(10!)}
f
x
i
i
(
0
)
=
0
{\displaystyle f^{xii}(0)=0}
f
x
i
i
i
(
0
)
=
479001600
=
12
!
{\displaystyle f^{xiii}(0)=479001600=12!}
arctan
(
x
)
=
a
0
+
a
1
x
+
a
2
x
2
+
a
3
x
3
+
a
4
x
4
+
⋯
{\displaystyle \arctan(x)=a_{0}+a_{1}x+a_{2}x^{2}+a_{3}x^{3}+a_{4}x^{4}+\cdots }
=
0
+
(
1
)
x
+
(
0
)
x
2
+
−
(
2
!
)
3
!
x
3
+
(
0
)
x
4
+
4
!
5
!
x
5
+
(
0
)
x
6
+
−
(
6
!
)
7
!
x
7
+
(
0
)
x
8
+
8
!
9
!
x
9
+
(
0
)
x
10
+
−
(
10
!
)
11
!
x
11
+
⋯
{\displaystyle =0+(1)x+(0)x^{2}+{\frac {-(2!)}{3!}}x^{3}+(0)x^{4}+{\frac {4!}{5!}}x^{5}+(0)x^{6}+{\frac {-(6!)}{7!}}x^{7}+(0)x^{8}+{\frac {8!}{9!}}x^{9}+(0)x^{10}+{\frac {-(10!)}{11!}}x^{11}+\cdots }
=
x
−
1
3
x
3
+
1
5
x
5
−
1
7
x
7
+
1
9
x
9
−
1
11
x
11
+
⋯
{\displaystyle =x-{\frac {1}{3}}x^{3}+{\frac {1}{5}}x^{5}-{\frac {1}{7}}x^{7}+{\frac {1}{9}}x^{9}-{\frac {1}{11}}x^{11}+\cdots }
Some basic checking:
arctan
(
0
)
=
0
{\displaystyle \arctan(0)=0}
arctan
(
−
x
)
=
−
arctan
(
x
)
.
{\displaystyle \arctan(-x)=-\arctan(x).}
d
(
arctan
(
x
)
)
d
x
{\displaystyle {\frac {d(\arctan(x))}{dx}}}
=
1
−
3
x
2
3
+
5
x
4
5
−
7
x
6
7
+
9
x
8
9
−
11
x
10
11
+
⋯
{\displaystyle =1-{\frac {3x^{2}}{3}}+{\frac {5x^{4}}{5}}-{\frac {7x^{6}}{7}}+{\frac {9x^{8}}{9}}-{\frac {11x^{10}}{11}}+\cdots }
=
1
−
x
2
+
x
4
−
x
6
+
x
8
−
x
10
+
⋯
{\displaystyle =1-x^{2}+x^{4}-x^{6}+x^{8}-x^{10}+\cdots }
Also,
d
(
arctan
(
x
)
)
d
x
=
1
1
+
x
2
{\displaystyle {\frac {d(\arctan(x))}{dx}}={\frac {1}{1+x^{2}}}}
Show that
1
1
+
x
2
{\displaystyle {\frac {1}{1+x^{2}}}}
=
1
−
x
2
+
x
4
−
x
6
+
x
8
−
x
10
+
⋯
{\displaystyle =1-x^{2}+x^{4}-x^{6}+x^{8}-x^{10}+\cdots }
or that
1
=
(
1
+
x
2
)
(
1
−
x
2
+
x
4
−
x
6
+
x
8
−
x
10
+
⋯
)
{\displaystyle 1=(1+x^{2})(1-x^{2}+x^{4}-x^{6}+x^{8}-x^{10}+\cdots )}
(
1
+
x
2
)
(
1
−
x
2
+
x
4
−
x
6
+
x
8
−
x
10
+
⋯
)
{\displaystyle (1+x^{2})(1-x^{2}+x^{4}-x^{6}+x^{8}-x^{10}+\cdots )}
=
1
(
1
−
x
2
+
x
4
−
x
6
+
x
8
−
x
10
+
⋯
)
+
x
2
(
1
−
x
2
+
x
4
−
x
6
+
x
8
−
x
10
+
⋯
)
{\displaystyle =1(1-x^{2}+x^{4}-x^{6}+x^{8}-x^{10}+\cdots )+x^{2}(1-x^{2}+x^{4}-x^{6}+x^{8}-x^{10}+\cdots )}
=
1
−
x
2
+
x
4
−
x
6
+
x
8
−
x
10
+
⋯
+
x
2
−
x
4
+
x
6
−
x
8
+
x
10
−
x
12
+
⋯
{\displaystyle =1-x^{2}+x^{4}-x^{6}+x^{8}-x^{10}+\cdots +x^{2}-x^{4}+x^{6}-x^{8}+x^{10}-x^{12}+\cdots }
=
1
⋯
±
x
2
n
{\displaystyle =1\ \cdots \ \pm \ x^{2n}}
If abs
(
x
)
<
1
,
lim
n
→
∞
x
2
n
=
0.
{\displaystyle (x)<1,\ \lim _{n\rightarrow \infty }x^{2n}=0.}
The expansion of
arctan
(
x
)
{\displaystyle \arctan(x)}
above is theoretically valid for
|
x
|
<
1.
{\displaystyle |x|<1.}
However, if
|
x
|
{\displaystyle |x|}
is close to
1
,
{\displaystyle 1,}
the calculation of
arctan
(
x
)
{\displaystyle \arctan(x)}
will take forever.
This section uses
x
0
{\displaystyle x_{0}}
so that
|
x
−
x
0
|
{\displaystyle |x-x_{0}|}
is small enough to make time of calculation acceptable.
Let
θ
=
36
3
4
∘
.
{\displaystyle \theta =36{\tfrac {3}{4}}^{\circ }.}
To calculate
tan
(
θ
)
:
{\displaystyle \tan(\theta ):}
tan
11
π
60
=
tan
33
∘
=
1
4
[
2
−
(
2
−
3
)
(
3
+
5
)
]
[
2
+
2
(
5
−
5
)
]
{\displaystyle \tan {\frac {11\pi }{60}}=\tan 33^{\circ }={\tfrac {1}{4}}\left[2-\left(2-{\sqrt {3}}\right)\left(3+{\sqrt {5}}\right)\right]\left[2+{\sqrt {2\left(5-{\sqrt {5}}\right)}}\,\right]\,}
tan
(
147
∘
)
=
−
tan
(
33
∘
)
{\displaystyle \tan(147^{\circ })=-\tan(33^{\circ })}
Using the half-angle formula
tan
(
θ
2
)
=
csc
(
θ
)
−
cot
(
θ
)
,
{\displaystyle \tan({\tfrac {\theta }{2}})=\csc(\theta )-\cot(\theta ),}
calculate
tan
(
73
1
2
)
=
tan
(
147
2
)
{\displaystyle \tan(73{\tfrac {1}{2}})=\tan({\tfrac {147}{2}})}
and
tan
(
36
3
4
)
=
tan
(
73
1
2
2
)
{\displaystyle \tan(36{\tfrac {3}{4}})=\tan({\tfrac {73{\tfrac {1}{2}}}{2}})}
θ
=
36
3
4
∘
.
x
0
=
tan
(
θ
)
=
0.7467354177837216717375001402.
{\displaystyle \theta =36{\tfrac {3}{4}}^{\circ }.\ x_{0}=\tan(\theta )=0.7467354177837216717375001402.}
f
(
x
0
)
=
36
3
4
π
180
=
0.6414085001079161195194563572.
{\displaystyle f(x_{0})={\frac {36{\tfrac {3}{4}}\pi }{180}}=0.6414085001079161195194563572.}
This value
(
36
3
4
∘
)
{\displaystyle (36{\tfrac {3}{4}}^{\circ })}
was chosen for
θ
{\displaystyle \theta }
because
x
0
=
tan
(
θ
)
{\displaystyle x_{0}=\tan(\theta )}
is close to
0.75.
{\displaystyle 0.75.}
For
1
≥
x
≥
0.5
,
|
x
−
x
0
|
≤
0.25
{\displaystyle 1\geq x\geq 0.5,\ |x-x_{0}|\leq 0.25}
approx.
0.25
50
=
7.888609052210118
e
−
31.
{\displaystyle 0.25^{50}=7.888609052210118e-31.}
If
|
x
−
x
0
|
==
0.25
,
{\displaystyle |x-x_{0}|==0.25,}
the code below is accurate to
30
{\displaystyle 30}
places of decimals.
This section uses the whole sequence of derivatives:
y
000
=
arctan
(
x
)
{\displaystyle y000=\arctan(x)}
where
y
000
=
y
(
0
)
=
y
{\displaystyle y000=y^{(0)}=y}
y
001
=
1
U
{\displaystyle y001={\frac {1}{U}}}
where
U
=
1
+
x
2
,
y
001
=
y
(
1
)
=
y
′
{\displaystyle U=1+x^{2},\ y001=y^{(1)}=y'}
y
002
=
−
(
2
)
∗
(
x
)
∗
(
y
001
)
U
{\displaystyle y002=-{\frac {(2)*(x)*(y001)}{U}}}
where
y
002
=
y
(
2
)
=
y
″
{\displaystyle y002=y^{(2)}=y''}
y
003
=
−
(
4
)
∗
(
x
)
∗
(
y
002
)
+
(
2
)
∗
(
y
001
)
U
{\displaystyle y003=-{\frac {(4)*(x)*(y002)+(2)*(y001)}{U}}}
where
y
003
=
y
(
3
)
=
y
‴
{\displaystyle y003=y^{(3)}=y'''}
and so on.
y
004
=
−
(
6
)
∗
(
x
)
∗
(
y
003
)
+
(
6
)
∗
(
y
002
)
U
{\displaystyle y004=-{\frac {(6)*(x)*(y003)+(6)*(y002)}{U}}}
y
005
=
−
(
8
)
∗
(
x
)
∗
(
y
004
)
+
(
12
)
∗
(
y
003
)
U
{\displaystyle y005=-{\frac {(8)*(x)*(y004)+(12)*(y003)}{U}}}
y
006
=
−
(
10
)
∗
(
x
)
∗
(
y
005
)
+
(
20
)
∗
(
y
004
)
U
{\displaystyle y006=-{\frac {(10)*(x)*(y005)+(20)*(y004)}{U}}}
y
007
=
−
(
12
)
∗
(
x
)
∗
(
y
006
)
+
(
30
)
∗
(
y
005
)
U
{\displaystyle y007=-{\frac {(12)*(x)*(y006)+(30)*(y005)}{U}}}
y
008
=
−
(
14
)
∗
(
x
)
∗
(
y
007
)
+
(
42
)
∗
(
y
006
)
U
{\displaystyle y008=-{\frac {(14)*(x)*(y007)+(42)*(y006)}{U}}}
y
009
=
−
(
16
)
∗
(
x
)
∗
(
y
008
)
+
(
56
)
∗
(
y
007
)
U
{\displaystyle y009=-{\frac {(16)*(x)*(y008)+(56)*(y007)}{U}}}
y
010
=
−
(
18
)
∗
(
x
)
∗
(
y
009
)
+
(
72
)
∗
(
y
008
)
U
{\displaystyle y010=-{\frac {(18)*(x)*(y009)+(72)*(y008)}{U}}}
⋯
{\displaystyle \cdots }
y
050
=
−
(
98
)
∗
(
x
)
∗
(
y
049
)
+
(
2352
)
∗
(
y
048
)
U
{\displaystyle y050=-{\frac {(98)*(x)*(y049)+(2352)*(y048)}{U}}}
Using
f
(
x
)
=
f
(
x
0
)
(
x
−
x
0
)
0
+
f
′
(
x
0
)
(
x
−
x
0
)
1
+
f
″
(
x
0
)
2
(
x
−
x
0
)
2
+
f
‴
(
x
0
)
2
⋅
3
(
x
−
x
0
)
3
+
⋯
{\displaystyle f(x)=f(x_{0})(x-x_{0})^{0}+f'(x_{0})(x-x_{0})^{1}+{\frac {f''(x_{0})}{2}}(x-x_{0})^{2}+{\frac {f'''(x_{0})}{2\cdot 3}}(x-x_{0})^{3}+\cdots }
then
f
(
x
)
=
y
000
+
y
001
(
x
−
x
0
)
+
y
002
2
(
x
−
x
0
)
2
+
⋯
{\displaystyle f(x)=y000+y001(x-x_{0})+{\frac {y002}{2}}(x-x_{0})^{2}+\cdots }
and:
The calculation of
arctan
(
x
)
{\displaystyle \arctan(x)}
above is suitable as input to application grapher.
The following python code has precision set to
33.
{\displaystyle 33.}
If it is desired to calculate
arctan
(
x
)
{\displaystyle \arctan(x)}
for one value of
x
,
{\displaystyle x,}
the following
python code is much faster than the code supplied to grapher
above.
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 ( ' \n arctan(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 ( ' \n arctan(x): count expired.' , end = '' )
str1 = '''
arctan( {} ) = {} , count = {}
''' . format ( x , y , p )
print ( str1 . rstrip ())
return y
x = Decimal ( '0.75' )
arctan ( x )
arctan(0.75) = 0.643501108793284386802809228717315, count = 12
When
x
{\displaystyle x}
is close to
x
0
,
{\displaystyle x_{0},}
result is achieved with only 12 passes through loop.
Testing with known values
edit
Check results using known combinations of
x
{\displaystyle x}
and
arctan
(
x
)
:
{\displaystyle \arctan(x):}
tan
3
π
20
=
tan
27
∘
=
5
−
1
−
5
−
2
5
.
{\displaystyle \tan {\frac {3\pi }{20}}=\tan 27^{\circ }={\sqrt {5}}-1-{\sqrt {5-2{\sqrt {5}}}}.}
For
tan
27
∘
{\displaystyle \tan 27^{\circ }}
and other exact values of
tan
(
x
)
,
{\displaystyle \tan(x),}
see
Exact Values for Common Angles.
π = "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 )
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
Verifying the recommended limits
edit
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 )
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
For
1.05
≥
x
≥
0.45
{\displaystyle 1.05\geq x\geq 0.45}
the above calculation of
arctan
(
x
)
{\displaystyle \arctan(x)}
is accurate to more than 30 places of decimals.
If input is outside recommended limits, this does not necessarily mean that result is invalid.
If
tan
51
∘
≥
x
≥
tan
9
∘
,
{\displaystyle \tan 51^{\circ }\geq x\geq \tan 9^{\circ },}
result is accurate to precision of python floats, 15 places of decimals.
y
=
arcsin
(
x
)
{\displaystyle y=\arcsin(x)}
x
=
sin
(
y
)
{\displaystyle x=\sin(y)}
d
x
d
y
=
cos
(
y
)
=
1
−
x
2
{\displaystyle {\frac {dx}{dy}}=\cos(y)={\sqrt {1-x^{2}}}}
d
y
d
x
=
1
cos
(
y
)
=
1
1
−
x
2
{\displaystyle {\frac {dy}{dx}}={\frac {1}{\cos(y)}}={\frac {1}{\sqrt {1-x^{2}}}}}
Simple differential equations eliminate the square root and make calculations so much easier.
Let
a
=
d
y
d
x
{\displaystyle a={\frac {dy}{dx}}}
Then
a
2
U
=
1
{\displaystyle a^{2}U=1}
where
U
=
1
−
x
2
{\displaystyle U=1-x^{2}}
and
U
′
=
−
2
x
.
{\displaystyle U^{'}=-2x.}
Differentiating both sides:
a
2
(
−
2
x
)
+
U
2
a
a
′
=
0
{\displaystyle a^{2}(-2x)+U2aa^{'}=0}
U
2
a
a
′
=
2
x
a
2
{\displaystyle U2aa^{'}=2xa^{2}}
a
′
=
2
x
a
a
2
a
U
=
a
x
U
.
{\displaystyle a^{'}={\frac {2xaa}{2aU}}={\frac {ax}{U}}.}
Let
b
=
a
′
{\displaystyle b=a^{'}}
Then
b
U
=
a
x
{\displaystyle bU=ax}
Differentiating both sides:
b
(
−
2
x
)
+
U
b
′
=
a
+
x
a
′
=
a
+
x
b
{\displaystyle b(-2x)+Ub^{'}=a+xa^{'}=a+xb}
Let
c
=
b
′
{\displaystyle c=b^{'}}
Then
c
=
a
+
3
b
x
U
{\displaystyle c={\frac {a+3bx}{U}}}
When
x
=
0
,
U
=
1.
{\displaystyle x=0,\ U=1.}
Calculation of more derivatives yields:
y
=
f
(
x
)
=
arcsin
(
x
)
{\displaystyle y=f(x)=\arcsin(x)}
a
=
f
′
(
x
)
=
1
1
−
x
2
{\displaystyle a=f^{'}(x)={\frac {1}{\sqrt {1-x^{2}}}}}
b
=
f
″
(
x
)
=
a
x
{\displaystyle b=f^{''}(x)=ax}
c
=
f
‴
(
x
)
=
a
+
3
b
x
{\displaystyle c=f^{'''}(x)=a+3bx}
d
=
f
⁗
(
x
)
=
4
b
+
5
c
x
{\displaystyle d=f^{''''}(x)=4b+5cx}
g
=
f
v
(
x
)
=
9
c
+
7
d
x
{\displaystyle g=f^{v}(x)=9c+7dx}
h
=
f
v
i
(
x
)
=
16
d
+
9
g
x
{\displaystyle h=f^{vi}(x)=16d+9gx}
j
=
f
v
i
i
(
x
)
=
25
g
+
11
h
x
{\displaystyle j=f^{vii}(x)=25g+11hx}
k
=
f
v
i
i
i
(
x
)
=
36
h
+
13
j
x
{\displaystyle k=f^{viii}(x)=36h+13jx}
l
=
f
v
i
i
i
i
(
x
)
=
49
j
+
15
k
x
{\displaystyle l=f^{viiii}(x)=49j+15kx}
and so on.
⋯
=
k
=
h
=
d
=
b
=
0
{\displaystyle \cdots =k=h=d=b=0}
a
=
1
;
c
=
1
2
a
;
g
=
3
2
c
;
j
=
5
2
g
;
l
=
7
2
j
;
⋯
.
{\displaystyle a=1;\ c=1^{2}a;\ g=3^{2}c;\ j=5^{2}g;\ l=7^{2}j;\ \cdots .}
arcsin
(
x
)
=
x
+
1
3
!
x
3
+
3
2
5
!
x
5
+
3
2
⋅
5
2
7
!
x
7
+
3
2
⋅
5
2
⋅
7
2
9
!
x
9
+
3
2
⋅
5
2
⋅
7
2
⋅
9
2
11
!
x
11
+
⋯
{\displaystyle \arcsin(x)=x+{\frac {1}{3!}}x^{3}+{\frac {3^{2}}{5!}}x^{5}+{\frac {3^{2}\cdot 5^{2}}{7!}}x^{7}+{\frac {3^{2}\cdot 5^{2}\cdot 7^{2}}{9!}}x^{9}+{\frac {3^{2}\cdot 5^{2}\cdot 7^{2}\cdot 9^{2}}{11!}}x^{11}+\cdots }
arcsin
(
x
)
=
x
+
1
3
!
x
3
+
3
(
2
!
)
(
2
2
)
5
x
5
+
3
⋅
5
(
3
!
)
(
2
3
)
7
x
7
+
3
⋅
5
⋅
7
(
4
!
)
(
2
4
)
9
x
9
+
3
⋅
5
⋅
7
⋅
9
(
5
!
)
(
2
5
)
11
x
11
+
⋯
{\displaystyle \arcsin(x)=x+{\frac {1}{3!}}x^{3}+{\frac {3}{(2!)(2^{2})5}}x^{5}+{\frac {3\cdot 5}{(3!)(2^{3})7}}x^{7}+{\frac {3\cdot 5\cdot 7}{(4!)(2^{4})9}}x^{9}+{\frac {3\cdot 5\cdot 7\cdot 9}{(5!)(2^{5})11}}x^{11}+\cdots }
As programming algorithm:
edit
arcsin
(
x
)
=
x
+
t
o
p
=
1
(
b
o
t
t
o
m
=
2
)
3
(
X
=
x
3
)
{\displaystyle \arcsin(x)=x+{\frac {top=1}{(bottom=2)3}}(X=x^{3})}
+
t
o
p
=
t
o
p
(
5
−
2
)
(
b
o
t
t
o
m
=
b
o
t
t
o
m
(
5
−
1
)
)
5
(
X
=
X
(
x
2
)
)
{\displaystyle +{\frac {top=top(5-2)}{(bottom=bottom(5-1))5}}(X=X(x^{2}))}
+
t
o
p
=
t
o
p
(
7
−
2
)
(
b
o
t
t
o
m
=
b
o
t
t
o
m
(
7
−
1
)
)
7
(
X
=
X
(
x
2
)
)
{\displaystyle +{\frac {top=top(7-2)}{(bottom=bottom(7-1))7}}(X=X(x^{2}))}
+
⋯
{\displaystyle +\cdots }
+
t
o
p
=
t
o
p
(
n
−
2
)
(
b
o
t
t
o
m
=
b
o
t
t
o
m
(
n
−
1
)
)
n
(
X
=
X
(
x
2
)
)
{\displaystyle +{\frac {top=top(n-2)}{(bottom=bottom(n-1))n}}(X=X(x^{2}))}
As implemented in Python:
edit
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
If
|
x
|
{\displaystyle |x|}
is close to
1
,
{\displaystyle 1,}
the calculation of
arcsin
(
x
)
{\displaystyle \arcsin(x)}
will take forever.
If you limit
x
{\displaystyle x}
to
sin
45
∘
>=
x
>=
−
sin
45
∘
,
{\displaystyle \sin 45^{\circ }>=x>=-\sin 45^{\circ },}
then
x
2
<=
0.5
{\displaystyle x^{2}<=0.5}
and each term is guaranteed to be less than half the preceding term.
If
x
>
sin
45
∘
,
{\displaystyle x>\sin 45^{\circ },}
let
t
=
π
2
−
y
.
{\displaystyle t={\frac {\pi }{2}}-y.}
Then
sin
t
=
cos
y
=
1
−
x
2
;
t
=
arcsin
(
cos
y
)
;
y
=
π
2
−
t
.
{\displaystyle \sin t=\cos y={\sqrt {1-x^{2}}};\ t=\arcsin(\cos y);\ y={\frac {\pi }{2}}-t.}
Integral of expression
edit
d
y
d
x
=
a
−
x
2
{\displaystyle {\frac {dy}{dx}}=a^{-x^{2}}}
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
)
=
a
−
x
2
=
1
a
x
2
{\displaystyle y=f(x)=a^{-x^{2}}={\frac {1}{a^{x^{2}}}}}
When
x
=
0
,
y
=
1
{\displaystyle x=0,\ y=1}
and the following sequence can be produced.
y
″
=
−
2
A
y
{\displaystyle y^{''}=-2Ay}
where
A
=
ln
(
a
)
.
{\displaystyle A=\ln(a).}
y
(
4
)
=
−
6
A
y
″
{\displaystyle y^{(4)}=-6Ay^{''}}
y
(
6
)
=
−
10
A
y
(
4
)
{\displaystyle y^{(6)}=-10Ay^{(4)}}
y
(
8
)
=
−
14
A
y
(
6
)
{\displaystyle y^{(8)}=-14Ay^{(6)}}
y
(
10
)
=
−
18
A
y
(
8
)
{\displaystyle y^{(10)}=-18Ay^{(8)}}
y
(
12
)
=
−
22
A
y
(
10
)
{\displaystyle y^{(12)}=-22Ay^{(10)}}
and so on.
Taylor series of
f
(
x
)
{\displaystyle f(x)}
for
x
{\displaystyle x}
close to
0
=
t
(
x
)
=
1
+
c
02
⋅
x
2
+
c
04
⋅
x
4
+
c
06
⋅
x
6
+
⋯
{\displaystyle 0=t(x)=1+c02\cdot x^{2}+c04\cdot x^{4}+c06\cdot x^{6}+\cdots }
where
c
02
=
y
″
2
!
;
c
04
=
y
(
4
)
4
!
;
c
06
=
y
(
6
)
6
!
⋯
{\displaystyle c02={\frac {y^{''}}{2!}};\ c04={\frac {y^{(4)}}{4!}};\ c06={\frac {y^{(6)}}{6!}}\cdots }
For
a
=
2
{\displaystyle 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
{\displaystyle a}
close to
1
{\displaystyle 1}
or
x
{\displaystyle x}
close to
0
,
{\displaystyle 0,}
the Taylor series is a quite accurate
representation of the original expression. When abs
(
x
)
≤
1.6
,
{\displaystyle (x)\leq 1.6,}
the abs(maximum difference) between expression and Taylor series is
<
1
e
−
15.
{\displaystyle <1e-15.}
For greater accuracy, greater precision may be specified in python or more terms after
c
42
{\displaystyle c42}
may be added.
The integral
=
I
(
x
)
=
x
+
C
02
⋅
x
3
+
C
04
⋅
x
5
+
C
06
⋅
x
7
+
⋯
{\displaystyle =I(x)=x+C02\cdot x^{3}+C04\cdot x^{5}+C06\cdot x^{7}+\cdots }
where
C
02
=
c
02
3
;
C
04
=
c
04
5
;
C
06
=
c
06
7
⋯
{\displaystyle C02={\frac {c02}{3}};\ C04={\frac {c04}{5}};\ C06={\frac {c06}{7}}\cdots }
sin(x) using (x - x0)
edit
f
(
x
)
=
sin
(
x
)
{\displaystyle f(x)=\sin(x)}
f
′
(
x
)
=
cos
(
x
)
{\displaystyle f'(x)=\cos(x)}
f
″
(
x
)
=
−
sin
(
x
)
{\displaystyle f''(x)=-\sin(x)}
f
‴
(
x
)
=
−
cos
(
x
)
{\displaystyle f'''(x)=-\cos(x)}
f
(
4
)
=
sin
(
x
)
{\displaystyle f^{(4)}=\sin(x)}
Let
x
0
=
π
4
=
45
∘
{\displaystyle x_{0}={\frac {\pi }{4}}=45^{\circ }}
f
(
x
0
)
=
f
(
π
4
)
=
sin
(
π
4
)
=
2
2
{\displaystyle f(x_{0})=f({\frac {\pi }{4}})=\sin({\frac {\pi }{4}})={\frac {\sqrt {2}}{2}}}
f
′
(
x
0
)
=
f
′
(
π
4
)
=
cos
(
π
4
)
=
2
2
{\displaystyle f'(x_{0})=f'({\frac {\pi }{4}})=\cos({\frac {\pi }{4}})={\frac {\sqrt {2}}{2}}}
f
″
(
x
0
)
=
f
″
(
π
4
)
=
−
sin
(
π
4
)
=
−
2
2
{\displaystyle f''(x_{0})=f''({\frac {\pi }{4}})=-\sin({\frac {\pi }{4}})=-{\frac {\sqrt {2}}{2}}}
f
‴
(
x
0
)
=
f
‴
(
π
4
)
=
−
cos
(
π
4
)
=
−
2
2
{\displaystyle f'''(x_{0})=f'''({\frac {\pi }{4}})=-\cos({\frac {\pi }{4}})=-{\frac {\sqrt {2}}{2}}}
f
(
4
)
(
x
0
)
=
f
(
4
)
(
π
4
)
=
sin
(
π
4
)
=
2
2
{\displaystyle f^{(4)}(x_{0})=f^{(4)}({\frac {\pi }{4}})=\sin({\frac {\pi }{4}})={\frac {\sqrt {2}}{2}}}
t
(
x
)
=
2
2
⋅
(
x
−
x
0
)
0
{\displaystyle t(x)={\frac {\sqrt {2}}{2}}\cdot (x-x_{0})^{0}}
+
2
2
⋅
(
x
−
x
0
)
1
{\displaystyle +{\frac {\sqrt {2}}{2}}\cdot (x-x_{0})^{1}}
−
2
2
⋅
1
2
!
⋅
(
x
−
x
0
)
2
{\displaystyle -{\frac {\sqrt {2}}{2}}\cdot {\frac {1}{2!}}\cdot (x-x_{0})^{2}}
−
2
2
⋅
1
3
!
⋅
(
x
−
x
0
)
3
{\displaystyle -{\frac {\sqrt {2}}{2}}\cdot {\frac {1}{3!}}\cdot (x-x_{0})^{3}}
+
2
2
⋅
1
4
!
⋅
(
x
−
x
0
)
4
+
⋯
{\displaystyle +{\frac {\sqrt {2}}{2}}\cdot {\frac {1}{4!}}\cdot (x-x_{0})^{4}+\cdots }
Let
X
=
(
x
−
x
0
)
=
(
x
−
π
4
)
{\displaystyle X=(x-x_{0})=(x-{\frac {\pi }{4}})}
Then
t
(
x
)
=
2
2
(
{\displaystyle t(x)={\frac {\sqrt {2}}{2}}(}
1
+
X
{\displaystyle 1+X}
−
X
2
2
!
−
X
3
3
!
{\displaystyle -{\frac {X^{2}}{2!}}-{\frac {X^{3}}{3!}}}
+
X
4
4
!
+
X
5
5
!
{\displaystyle +{\frac {X^{4}}{4!}}+{\frac {X^{5}}{5!}}}
−
X
6
6
!
−
X
7
7
!
{\displaystyle -{\frac {X^{6}}{6!}}-{\frac {X^{7}}{7!}}}
⋯
{\displaystyle \ \cdots }
)
{\displaystyle )}
where
t
(
x
)
{\displaystyle t(x)}
is the Taylor series representing
f
(
x
)
=
sin
(
x
)
{\displaystyle f(x)=\sin(x)}
for values of
x
{\displaystyle x}
close to
45
∘
{\displaystyle 45^{\circ }}
or
π
4
.
{\displaystyle {\frac {\pi }{4}}.}
If
π
2
(
90
∘
)
≥
x
≥
0
{\displaystyle {\frac {\pi }{2}}(90^{\circ })\geq x\geq 0}
, then
t
(
x
)
{\displaystyle t(x)}
containing powers of
X
{\displaystyle X}
through
15
{\displaystyle 15}
is sufficient to keep the error to
<
1
e
−
15.
{\displaystyle <1e-15.}
Graph of
t
(
x
)
{\displaystyle t(x)}
representing
sin
(
x
)
{\displaystyle \sin(x)}
with powers of
X
{\displaystyle X}
limited to
5
{\displaystyle 5}
.
Graph of
t
(
x
)
{\displaystyle t(x)}
representing
sin
(
x
)
{\displaystyle \sin(x)}
with powers of
X
{\displaystyle X}
limited to
9
{\displaystyle 9}
.
Graph of
t
(
x
)
{\displaystyle t(x)}
representing
sin
(
x
)
{\displaystyle \sin(x)}
with powers of
X
{\displaystyle X}
limited to
19
{\displaystyle 19}
.
The Taylor series for
f
(
x
)
=
1
x
{\displaystyle f(x)={\frac {1}{x}}}
for
x
{\displaystyle x}
close to
2
{\displaystyle 2}
is:
t
(
x
)
=
1
2
−
1
2
2
⋅
(
x
−
2
)
+
1
2
3
⋅
(
x
−
2
)
2
−
1
2
4
⋅
(
x
−
2
)
3
⋯
{\displaystyle t(x)={\frac {1}{2}}-{\frac {1}{2^{2}}}\cdot (x-2)+{\frac {1}{2^{3}}}\cdot (x-2)^{2}-{\frac {1}{2^{4}}}\cdot (x-2)^{3}\cdots }
The integral of this series is:
I
(
x
)
=
1
2
⋅
(
x
−
2
)
−
(
(
1
2
2
)
/
2
)
⋅
(
x
−
2
)
2
+
(
(
1
2
3
)
/
3
)
⋅
(
x
−
2
)
3
−
(
(
1
2
4
)
/
4
)
⋅
(
x
−
2
)
4
⋯
+
C
{\displaystyle I(x)={\frac {1}{2}}\cdot (x-2)-(({\frac {1}{2^{2}}})/2)\cdot (x-2)^{2}+(({\frac {1}{2^{3}}})/3)\cdot (x-2)^{3}-(({\frac {1}{2^{4}}})/4)\cdot (x-2)^{4}\cdots +C}
The integral of
1
x
=
ln
(
x
)
.
{\displaystyle {\frac {1}{x}}=\ln(x).}
Therefore
ln
(
x
)
=
I
(
x
)
{\displaystyle \ln(x)=I(x)}
but what is the value of
C
?
{\displaystyle C?}
Without
C
,
{\displaystyle C,}
when
x
=
2
,
I
(
x
)
=
0.
I
(
x
)
{\displaystyle x=2,I(x)=0.\ I(x)}
should be
ln
(
2
)
.
{\displaystyle \ln(2).}
Therefore, for
x
{\displaystyle x}
close to
2
:
{\displaystyle 2:}
ln
(
x
)
=
I
(
x
)
{\displaystyle \ln(x)=I(x)}
where
C
=
ln
(
2
)
.
{\displaystyle C=\ln(2).}
But what is the value of
ln
(
2
)
?
{\displaystyle \ln(2)?}
Without
C
,
{\displaystyle C,}
when
x
=
1
,
I
(
x
)
=
−
0.693147180559945.
I
(
x
)
{\displaystyle x=1,\ I(x)=-0.693147180559945.\ I(x)}
should be
0.
{\displaystyle 0.}
Therefore
C
=
0.693147180559945
{\displaystyle C=0.693147180559945}
or
ln
(
2
)
.
{\displaystyle \ln(2).}
For
x
{\displaystyle x}
close to
2
:
{\displaystyle 2:}
ln
(
x
)
=
ln
(
2
)
+
1
2
⋅
(
x
−
2
)
−
(
(
1
2
2
)
/
2
)
⋅
(
x
−
2
)
2
+
(
(
1
2
3
)
/
3
)
⋅
(
x
−
2
)
3
−
(
(
1
2
4
)
/
4
)
⋅
(
x
−
2
)
4
⋯
{\displaystyle \ln(x)=\ln(2)+{\frac {1}{2}}\cdot (x-2)-(({\frac {1}{2^{2}}})/2)\cdot (x-2)^{2}+(({\frac {1}{2^{3}}})/3)\cdot (x-2)^{3}-(({\frac {1}{2^{4}}})/4)\cdot (x-2)^{4}\cdots }
where
ln
(
2
)
=
0.693147180559945
…
{\displaystyle \ln(2)=0.693147180559945\dots }
This section presents a system for calculating
ln
(
x
)
{\displaystyle \ln(x)}
for
10
≥
x
≥
1
,
{\displaystyle 10\geq x\geq 1,}
knowing only that
ln
(
1
)
=
0.
{\displaystyle \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
x
0
{\displaystyle x_{0}}
in which each
value after the first is
≤
10
{\displaystyle \leq 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
{\displaystyle 10}
. This means, for example, if
x
{\displaystyle 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
_
m
i
n
u
s
_
x
0
x
0
{\displaystyle ={\frac {x\_minus\_x_{0}}{x_{0}}}}
is always
≤
1
10
.
{\displaystyle \leq {\frac {1}{10}}.}
When
x
{\displaystyle x}
is very close to
x
0
,
{\displaystyle x_{0},}
time to calculate
ln
(
x
)
{\displaystyle \ln(x)}
is greatly reduced.
The next piece of code progressively calculates
ln
(
1.1
)
,
ln
(
1.2
)
,
ln
(
1.3
)
…
{\displaystyle \ln(1.1),\ \ln(1.2),\ \ln(1.3)\ \dots }
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'),
}
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
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
x
0
:
{\displaystyle x_{0}:}
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
(
x
0
)
:
{\displaystyle \ln(x_{0}):}
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
{\displaystyle x}
is assigned to the next low value or the next high value of
x
0
.
{\displaystyle x_{0}.}
For example, if
x
{\displaystyle x}
is between
1.2
,
1.3
,
{\displaystyle 1.2,\ 1.3,}
the decision point is
1.248.
{\displaystyle 1.248.}
This means that the ratio
1.248
−
1.2
1.2
=
1.3
−
1.248
1.3
=
0.04
{\displaystyle {\frac {1.248-1.2}{1.2}}={\frac {1.3-1.248}{1.3}}=0.04}
and the maximum value of abs
(
x
−
x
0
x
0
)
=
0.04.
{\displaystyle ({\frac {x-x_{0}}{x_{0}}})=0.04.}
During creation of Tln_x0
the maximum value of
x
−
x
0
x
0
=
1
10
.
{\displaystyle {\frac {x-x_{0}}{x_{0}}}={\frac {1}{10}}.}
During normal operations after creation of Tln_x0,
maximum value of
abs
(
x
−
x
0
x
0
)
=
1.047619
⋯
−
1
1
{\displaystyle ({\frac {x-x_{0}}{x_{0}}})={\frac {1.047619\dots -1}{1}}}
between
1.0
,
1.1.
{\displaystyle 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
)
{\displaystyle \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.
Choose random numbers
a
,
b
{\displaystyle a,\ b}
so that
10
≥
a
≥
b
≥
1.
{\displaystyle 10\geq a\geq b\geq 1.}
Produce values
ln
(
a
)
,
ln
(
b
)
.
{\displaystyle \ln(a),\ \ln(b).}
Calculate product
p
=
a
⋅
b
.
{\displaystyle p=a\cdot b.}
Produce value
ln
(
p
)
.
{\displaystyle \ln(p).}
If
p
>
10
,
p
=
(
p
10
)
⋅
10
{\displaystyle p>10,\ p=({\frac {p}{10}})\cdot 10}
and
ln
(
p
)
=
ln
(
p
10
)
+
ln
(
10
)
.
{\displaystyle \ln(p)=\ln({\frac {p}{10}})+\ln(10).}
Verify that
ln
(
p
)
=
ln
(
a
)
+
ln
(
b
)
.
{\displaystyle \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