Hey Devon,

Try replacing the ^ with (x:@^)

 chudSeries=: 13 : '((!6x*x: y)*13591409x+545140134x*x: y)%(!3x*x:y)*(3x^~!x: 
y)*640320x^3r2+3x*x: y'

  chudSeries 2
2.59929e_30

     chudSeriesa=: 13 : '((!6x*x: y)*13591409x+545140134x*x: 
y)%(!3x*x:y)*(3x^~!x: y)*640320x(x:@^)3r2+3x*x: y'
    chudSeriesa 2
109283296023r42043485816167757079388237309725665918976

I see Henry has spotted it as well. I got there by thinking about the well 
conditioned matrices talk at the last NYCJUG and the answer I was given about 
transcendental functions returning floats. That got me to thinking about 
forcing rational with x:@^, since ^ returns a float as well. I am not sure that 
it solves the problem as there may be a gap in accuracy in the transfer between 
float and rational in that translation.

Cheers, bob

> On Dec 22, 2020, at 09:29, Devon McCormick <[email protected]> wrote:
> 
> The Chudnovsky algorithm -
> https://en.wikipedia.org/wiki/Chudnovsky_algorithm - is supposed to have
> the fastest convergence for pi (or 1/pi, to be exact).  I had tried this
> one which is OK but only seems to add one digit for each power of 10:
>   6!:2 'pi=. 4*-/%>:+:i. 1e6'
> 0.0145579
>   20j18":pi
> 3.141591653589793420
>   6!:2 'pi=. 4*-/%>:+:i. 1e7'
> 0.140673
>   20j18":pi
> 3.141592553589793280
>   6!:2 'pi=. 4*-/%>:+:i. 1e8'
> 1.44487
>   20j18":pi
> 3.141592643589793177
>   6!:2 'pi=. 4*-/%>:+:i. 1e9'
> 16.7988
>   20j18":pi
> 3.141592652589793477
> 
> The Chudnovsky series is fast and gives me 15 correct decimal digits for
> only 2 iterations but fails to improve after that presumably because of
> floating point limitations:
>   20j18":%12*-/chudSeries i.2
> 3.141592653589795336
>   20j18":%12*-/chudSeries i.3
> 3.141592653589795336
>   20j18":%12*-/chudSeries i.4
> 3.141592653589795336
>   chudSeries i.4
> 0.0265258 4.98422e_16 2.59929e_30 1.45271e_44
> 
> However, when I try to use extended precision, it does not seem to give me
> extended precision results:
>   chudSeries=: 13 : '((!6x*x: y)*13591409x+545140134x*x: y)%(!3x*x:
> y)*(3x^~!x: y)*640320x^3r2+3x*x: y'
> 
> I get the same fp values for the "i.4" argument as shown above.  Am I doing
> something wrong or overlooking something?
> 
> Thanks,
> 
> Devon
> 
> -- 
> 
> Devon McCormick, CFA
> 
> Quantitative Consultant
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm

----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to