Karim Belabas on Sat, 30 Dec 2017 00:52:33 +0100


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

Re: iteration and stack overfloow


* Elim Qiu [2017-12-30 00:32]:
> I think this was posted a while before, but I don't really have a workable
> solution yet:
> 
> an(n) =
> { my(v = 0.5);
>   for(k=1,n,v=log(1+v));
>   return(n*v)
> }
> 
> call an(10000) will cause stack overfloow, but I'd like to computer
> an(700000).
> 
> What should I do? Thanks

What's wrong with the solution I proposed in

  https://pari.math.u-bordeaux.fr/archives/pari-users-1710/msg00003.html

i.e. replace log(1+v) by log(1.0 + v)  ?

an(n) =
{ my(v = 0.5);
  for(k=1,n,v=log(1.0+v));
  return(n*v)
}

(00:50) gp > \p100
   realprecision = 115 significant digits (100 digits displayed)
(00:50) gp > an(700000)
time = 3,484 ms.
%2 = 2.000000030748801227547974016573628694175648260690729744041327635338895366437421419555015684249138657

Cheers,

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