Denis Simon on Mon, 11 Sep 2023 13:10:21 +0200 |
[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]
Re: Power (^) function speed depending on argument types |
Hi, what we learn with this example, is that the function (x) -> x^(1/5) can increase the precision of x when x is a t_REAL. Is it true for all x t_REAL ? For which values is this still true, instead of 1/5 ? Denis SIMON. ----- Mail original ----- > De: "Bill Allombert" <Bill.Allombert@math.u-bordeaux.fr> > À: "pari-users" <pari-users@pari.math.u-bordeaux.fr> > Envoyé: Dimanche 10 Septembre 2023 23:02:15 > Objet: Re: Power (^) function speed depending on argument types > On Sun, Sep 10, 2023 at 11:40:22PM +0300, Дмитрий Рыбас wrote: >> Hi All, >> >> I observe the following >> >> ? s=0.0;n=2000;for(i=1,n,s=(s+i)^(1/5)); >> *cpu time = 4,148 ms,* real time = 4,148 ms. >> ? s=0.0;n=2000;for(i=1,n,s=(s+i+0.0)^(1/5)); >> *cpu time = 51 ms,* real time = 51 ms. >> ? s=0.0;n=2000;for(i=1,n,s=(s+i)^(0.2)); >> *cpu time = 70 ms,* real time = 73 ms. >> ? s=0.0;n=2000;for(i=1.0,n,s=(s+i)^(1/5)); >> *cpu time = 50 ms,* real time = 49 ms. >> ? >> >> Please advise why the difference in computation time is so drastic? > > You are not computing s with the same accuracy! > > ? s=0.0;n=2000;for(i=1,n,s=(s+i)^(1/5));precision(s) > %10 = 38281 > ? s=0.0;n=2000;for(i=1,n,s=(s+i+0.0)^(1/5));precision(s) > %11 = 57 > > Cheers, > Bill.