Ramanujan's constant: Difference between revisions

m (→‎{{header|REXX}}: added a hyphen to a word.)
Line 84:
NB. approximation as a rational number
 
]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
 
Line 105:
)
 
 
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
NB. returns u to at least y significant digits
format=. ' _.' -.~ ((j.~ 50&+) y)&":
i =. 5
Line 119 ⟶ 118:
)
 
cf=: 0.1&$: :(4 :0) NB. tolerance cf value -> continued fraction approximation of value to tolerance
rationalize_decimal=: 3 :0 NB. rationalize_decimal LITERAL
yY =. y -. ' '
iX =. y0 (, i>. ]) '.'x
Iterms =. 'x'0 ,~ i {.$ y0x
whilst. X < | approximation - y do.
F=. 'x' ,~ y }.~ >: i
'term Y' =. <.`([:%1&|)`:0 Y
I +&". (, ' % ' , 'x' ,~ '1' #!.'0'~ 1 j. <:@:#) F
terms =. terms , term
approximation =. +`%/ }: 1j1 #!.1 terms
end.
)
 
assert (-: 0&cf) 649r200
assert 13r4 (-: cf) 649r200
 
 
NB. pi is sufficiently fast for partial series recomputation.
Line 139 ⟶ 145:
 
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_decimal1e_36 cf 37j34":1r8*P*S
f=: exp&Y M. NB. memoize
59j40 ": 8 ^~ f Digits 34
262537412640768743.99999999999925005844602752370749735164389999999999992500711164316586918409066184
NB. ^
</lang>
 
Anonymous user