Bill Allombert on Sun, 24 Mar 2024 22:07:43 +0100


[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]

Re: Question on PARI/GP realprecision


On Sun, Mar 24, 2024 at 08:59:37PM +0100, hermann@stamm-wilbrandt.de wrote:
> 
> hermann@7950x:~$ gp -q
> ? #
>    timer = 1 (on)
> ? P=extern("curl -s https://oeis.org/A080076/a080076.json.txt";);
> cpu time = 118 ms, real time = 1,417 ms.
> ? s=0;foreach(P,p,s+=1/p);
> cpu time = 18,464 ms, real time = 18,469 ms.

You can do this much faster by summing pair-wise recursively.
Also you can avoid all the gcd by using the addition formula
for fractions without reduction.

\\if wget is installed but not curl :)
P=extern("wget --quiet -O- https://oeis.org/A080076/a080076.json.txt";);
{
  Q=apply(x->[1,x],P);
  while(#Q>1,
    Q=vector((#Q+1)\2,i,
     if(2*i<=#Q, my(a=Q[2*i-1],b=Q[2*i]);
       [a[1]*b[2]+b[1]*a[2],a[2]*b[2]],
       Q[2*i-1])));
}
##
  ***   last result computed in 249 ms.
\\ It is easy to prove that Q[1][1]/Q[1][2] is irreducible,
\\ but pari needs half a second to check it:
t=Q[1][1]/Q[1][2];
##
  ***   last result computed in 542 ms.
s==t
%5 = 1

Cheers,
Bill.