Ramanujan's constant: Difference between revisions
Content deleted Content added
Line 91: | Line 91: | ||
262537412640768743.9999999999992500725971981856888793538563 |
262537412640768743.9999999999992500725971981856888793538563 |
||
</pre> |
</pre> |
||
=== 𝑒**(π*√x) === |
|||
<pre> |
|||
Note 'citation for pi computation' |
|||
@MISC {3129700, |
|||
TITLE = {Series that converge to $\pi$ quickly}, |
|||
AUTHOR = {El Ectric (https://math.stackexchange.com/users/301661/el-ectric)}, |
|||
HOWPUBLISHED = {Mathematics Stack Exchange}, |
|||
NOTE = {URL:https://math.stackexchange.com/q/3129700 (version: 2019-02-28)}, |
|||
EPRINT = {https://math.stackexchange.com/q/3129700}, |
|||
URL = {https://math.stackexchange.com/q/3129700} |
|||
} |
|||
) |
|||
NB. returns u to at least y significant digits |
|||
Digits=: adverb define NB. u Digits y u y is less accurate than u y+1 |
|||
format=. ' _.' -.~ ((j.~ 50&+) y)&": |
|||
i =. 5 |
|||
current=. format u i |
|||
whilst. last -.@-: current do. |
|||
last =. current |
|||
i =. i + 2 |
|||
current=. format result =. u i |
|||
end. |
|||
result |
|||
) |
|||
rationalize_decimal=: 3 :0 NB. rationalize_decimal LITERAL |
|||
y=. y -. ' ' |
|||
i=. y (, i. ]) '.' |
|||
I=. 'x' ,~ i {. y |
|||
F=. 'x' ,~ y }.~ >: i |
|||
I +&". (, ' % ' , 'x' ,~ '1' #!.'0'~ 1 j. <:@:#) F |
|||
) |
|||
NB. pi is sufficiently fast for partial series recomputation. |
|||
numerator=: (*&! +:) * _3 25&p. |
|||
denominator=: 2&^ * !@:(3&*) |
|||
pi=: (2 * [: +/ numerator % denominator)@:i.@:x: NB. use: pi TERMS |
|||
cf_sqrt=: 10&$: :(4 :0) NB. continued fraction approximation to square root. x sqrt y then x is the depth, y the square |
|||
a =. x: <. %: y NB. estimate |
|||
r =. y - *: a NB. remainder |
|||
a + %`+/ (+: x) $ r , +: a |
|||
) |
|||
exp=: (1x"_)`((($:~<:)+^%!@x:@])~)@.(0<[) NB. recursive Taylor series x exp y recursively sums x terms of Taylor series for Exp[y], memoization candidate. |
|||
</pre> |
|||
<lang> |
|||
NB. takes the constant beyond the repeat 9s. |
|||
S=: cf_sqrt&163 Digits 34 |
|||
P=: pi Digits 34 |
|||
Y=: rationalize_decimal 37j34":1r8*P*S |
|||
f=: exp&Y M. NB. memoize |
|||
59j40 ": 8 ^~ f Digits 34 |
|||
262537412640768743.9999999999992500584460275237074973516438 |
|||
NB. ^ |
|||
</lang> |
|||
=={{header|Java}}== |
=={{header|Java}}== |