Karim Belabas on Mon, 11 Sep 2023 14:01:20 +0200
|
[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]
Re: Power (^) function speed depending on argument types
|
- To: Denis Simon <denis.simon@unicaen.fr>
- Subject: Re: Power (^) function speed depending on argument types
- From: Karim Belabas <Karim.Belabas@u-bordeaux.fr>
- Date: Mon, 11 Sep 2023 13:56:10 +0200
- Arc-authentication-results: i=1; smail; arc=none
- Arc-message-signature: i=1; a=rsa-sha256; d=math.u-bordeaux.fr; s=openarc; t=1694433362; c=relaxed/relaxed; bh=JnDmsEFfaFFAN/+Ie+zN0TOlg9uHYR4lvUmU9jCaWO4=; h=Date:From:To:Cc:Subject:Message-ID:Mail-Followup-To:References: MIME-Version:Content-Type:Content-Disposition: Content-Transfer-Encoding:In-Reply-To; b=jz/kzdjfImrLkxHXChLCuGN9I+9houalzRlESj1preMcNi5rK2eImUWZE+WEZ3tQ1HlQP46w5qKzZwLkFPzO4JQ7L9u3ddMAxEARVvXkiJj9FnzqxZuI2pJSpA/MaU1zTVO+EIbhgcR/pA6+IWrINO+4SCaezZPi1HQZdglcsWpDz/hF7a855HxgqNpI5wlo3xDpN44c+oBoTpbGabYdGBHdfexWJgR4U0xAVImVt8GY/DNvZUzQUGoZpUHsT+3waAMwy3ENdGdzwftvyFI1lD/EbAmrNtg3Kcwhu7pr52vgOrKuwyHJzwM4d78aGvTFvtkpPxjQrckLc2q0tboFFwjWKbuDgEQiKAyzBerQllCHIbQDVgZuwGgPSM0mMpj6L3D4u+5MppxyoLfEeHHBTcnu6WcB/Gj30YfS+aYOYyK11LBMy2V4ccTRlIqywhRjufRG0MUY1VxST1F1+fSphxZkiKCYOxGuoZa8vPsCqdxZkwC+ZhOBFk7odXqIYyJ59X+DEEw0MNupJ3sJRzBKW6DVqFW06Z0D0/pc+hWm0KQF6I3UcLOksBBIbDOwSos8LDyQs/HbpMz0vQES+8YamV7HjxZ67A1sMLL+J+3/rzesqplcfOaMZiESg9YntEigjo621Ur29LQU9xOy8aHmJ3T1hI41k9wbalcc/UyN5bI=
- Arc-seal: i=1; a=rsa-sha256; d=math.u-bordeaux.fr; s=openarc; t=1694433362; cv=none; b=B0ATOUSZEDw9xnn9tt0x4qMWzvVN2Zt0Cs7SM7Pq17JiSh3L5fMRilK/QCLpYJaQG7Oh4+4GgcySix8F/2+tO85MCStQki64w0J4T3S5CEOM+mb/UXukbidU80sJmXrItU4/rEN3+tQbQoiAHYA6lZcKN9XFU0bWppeJcMjT96oLD1m2wJgr1YDqdpFrMTQpVWNLJVb/8v1Y/NcnsrxZHQa1T7rkhqcQxIMNEj7fcCMk6E8JrVSPWN/JSzl9Iqbt3PMluOb+d5P+4Iqw1wzVYTfydFVX3xLUhVqEk9/mXVmNE6HL2IYcc61ntqwP3TcPUsha8GvBGhsn0B2fwR8jgiwoSKcP0Vv7XtpgF8BUtI/bde1FRQEPMhlKGwazOEDKkur1+TtTZ6t6GamnWp/UOQfw8Cdh3g1G6bcKxfHa4aHuU+xhJA61/MCoISFFhvwrkffn123LhbpIMaFQSpUaJjY81G8aHt36Wwruh3oikrpQex+z59bxyDh2orSjsrNotl7sXxTlx40LnwFesIXQWa0MPgVHiAkU5dIYHi4/s2aiLJjvUHLKPtu7iaHRRVbTRguQ7Abz53AOkUE6XeAvXm/L+7HRi/pHcIocxtjpyDY6PgHfWPCpA0Od+6+WflurPlgwmS4Tw98DUT0YD7dxF4Fnq2V8e40Ho1ojmJKvLpM=
- Authentication-results: smail; dmarc=none header.from=u-bordeaux.fr
- Authentication-results: smail; arc=none
- Cc: pari-users <pari-users@pari.math.u-bordeaux.fr>
- Delivery-date: Mon, 11 Sep 2023 14:01:20 +0200
- In-reply-to: <2093030652.9384973.1694430327575.JavaMail.zimbra@unicaen.fr>
- Mail-followup-to: Denis Simon <denis.simon@unicaen.fr>, pari-users <pari-users@pari.math.u-bordeaux.fr>
- References: <CAEn4z=7cVuuh-mxX9juiexKpty=9_-prUnF9-q2NYO5yxdbY7A@mail.gmail.com> <ZP4u14Spwnw6uhu0@seventeen> <2093030652.9384973.1694430327575.JavaMail.zimbra@unicaen.fr>
Hi Denis,
actually, the only command that increases the precision there is
the addition s + i; we add to the t_REAL s the t_INT i which has
- infinite accuracy (obviously)
- larger exponent than s after the first few loops
So the result s + i has a larger precision than s (in fact, the
bitprecision increases by 64 which is the minimal amount), raising that
to the power 1/5 keeps that precision. But the next loop with the new s
increases it again.
In practice, the precision increases by 64 bits every loop.
Cheers,
K.B.
* Denis Simon [2023-09-11 13:05]:
> 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.
--
Pr. Karim Belabas, U. Bordeaux, Vice-président en charge du Numérique
Institut de Mathématiques de Bordeaux UMR 5251 - (+33) 05 40 00 29 77
http://www.math.u-bordeaux.fr/~kbelabas/