Ramanujan's constant: Difference between revisions

Line 81:
*Taking a rational power of an extended integer produces a floating-point result whenever the denominator of the power is not 1.
 
==continued fraction==
<pre>
NB. approximation as a rational number
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}
}
)
 
]RC=: +`%/ 1j1 (#!.1) 262537412640768743 1 1333462407511 1 8 1 1 5 1 4 1 7 1 1 1 9 1 1 2 12 4 1 15 4 299 3 5 1 4 5 5 1 28 3 1 9 4 1 6 1 1 1 1 1 1 51 11 5 3 2 1 1 1 1 2 1 5 1 9 1x
45120712325606158012363304056579024470785114628332049030433r171863933112440071790625667019825998411698
 
NB. expressed in decimal
NB. returns u to about y significant digits
59j40 ":8^~0{::32 exp XRC
Digits=: adverb define NB. u Digits y u y is less accurate than u y+1
262537412640768743.9999999999992500725971981856888793538563
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
)
 
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
)
 
Note 'exp'
exp=:10&$: :(([: +/ ((^ % !@:]) i.@:x:))~)
 
x exp y sums x terms of Taylor series for Exp[y]
)
 
NB. combines digits with exp terms.
exp=: 1&$: :(4 : 0)
format=. ((j.~ 50&+) x)&":
ex =. term=. 0x
current=. ''
whilst. last -.@-: current do.
last =. current
ex =. ex + y (^ % !@:]) term
current=. format ex
term =. >: term
end.
ex
)
 
decimal_fraction=: 3 :0 NB. decimal_fraction literal
y=. y -. ' '
i=. y (, i. ]) '.'
I=. 'x' ,~ i {. y
F=. 'x' ,~ y }.~ >: i
I +&". (, ' % ' , 'x' ,~ '1' #!.'0'~ 1 j. <:@:#) F
)
</pre>
 
<lang>
NB. takes the constant beyond the repeat 9s.
S=: cf_sqrt&163 Digits 34
P=: pi Digits 34
X=: decimal_fraction 37j34":1r8*P*S
59j40":8^~0{::32 exp X
262537412640768743.9999999999992500541677354265492332557331
NB. ^xxxxxxxxxxxxxxxxxxxxxxx
</lang>
 
=={{header|Java}}==
Anonymous user