Excellent, thank you both for the detective work, It's a pity gp can't compute this innocent-looking function, but then again I see that Mathematica miscomputes it so we're still a step ahead by failing to claim precision.

Charles Greathouse
Analyst/Programmer
Case Western Reserve University


On Mon, Nov 4, 2013 at 5:53 PM, Karim Belabas <Karim.Belabas@math.u-bordeaux1.fr> wrote:
* Charles Greathouse [2013-11-04 07:33]:
> Package: pari
> Version: 2.6.2 (development 15281-15d6bae)
>
> I noticed that when I run sumnum I don't get more precise output after 38
> digits. The calculations take longer, but no more digits are returned. I
> expected to see output precision increase (even if not as high as input
> precision due to cancellation) but I don't see any increase at all.
>
> > f()=sumnum(n=1,1,-log(cos(1/n)));
> > #
> > \p 38
> > f()
> time = 113 ms.
> %2 = 0.94536905472633293526609521540827019799 + 0.E-33*I
> > \p 308
>    realprecision = 308 significant digits
> > f()
> time = 3,417 ms.
> %3 = 0.94536905472633293526609521540827019712 + 0.E-32*I
> > \p1001
>    realprecision = 1001 significant digits
> > f()
> time = 29,858 ms.
> %4 = 0.94536905472633293526609521540827019613 + 0.E-31*I

I understand now. Try rather

f()=
{
  my (N = 10^(precision(1.)/4));
  sumnum(n=1,1,if (abs(n) > N, 1/(2*n^2), -log(cos(1/n))));
}

(23:28) gp > f()
%1 = 0.94536905472633293526609521540827019811699609206609798837271471777594170631719038689429214813862409338201926396154189364853510050296254552637808044433374474487557341460689150208807639480591067818894413559266753217660760759452909980129660883512317807699746458373223879753855765773611167420618821122695271229088195730876892414285152969481105230570126672059134497223435514666198018226620042448379828704457223938205960500232052423753085818957243248654564489082380169394801970216219169374504075436949412140140240010488611791905761154387054002957049075467762860810603766857623654705923741502943184619633567280721100446778726347228969588855124785572263891249809516102217629240268530374331304632985539343232748496415439280648813597168566506223192721129326808551599507926373040062012544640083041450017118468289860465927 + 0.E-808*I

log(cos(1/n)) involves catastrophic cancellation for large n, and almost no
accuracy is left: the (double-exponential) method involves evaluating the
function at huge arguments and multiplying by huge weights. Catastrophic
cancellation in log(cos(1/n)) (yielding 0. + 0.*I to the current accuracy) is
thus reinforced in a catastrophic way...

This kind of examples is discussed in ??intnum, see f & F.

I'd say it's not a bug.

Cheers,

    K.B.
--
Karim Belabas, IMB (UMR 5251)  Tel: (+33) (0)5 40 00 26 17
Universite Bordeaux 1          Fax: (+33) (0)5 40 00 69 50
351, cours de la Liberation    http://www.math.u-bordeaux1.fr/~kbelabas/
F-33405
Talence (France)       http://pari.math.u-bordeaux1.fr/  [PARI/GP]
`