Denis Simon on Mon, 11 Sep 2023 15:59:32 +0200


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

Re: Power (^) function speed depending on argument types



----- Mail transféré -----
De: "Denis Simon" <denis.simon@unicaen.fr>
À: "Markus Grassl" <markus.grassl@ug.edu.pl>
Envoyé: Lundi 11 Septembre 2023 15:53:27
Objet: Re: Power (^) function speed depending on argument types

Thank you Markus for your answer.

Here is what I now understand:
coming back to the initial example of Dmitry,
the true precision increases by 1 or 2 digits at each step, hence should be of the size of 1000 at the end.
But the gp precision, equal to the size needed to store the t_REAL increases by 64 bits = 19 digits at each step.
Whence the final precision of 19*2000 = 38281.

Denis SIMON.

----- Mail original -----
> De: "Markus Grassl" <markus.grassl@ug.edu.pl>
> À: "Denis Simon" <denis.simon@unicaen.fr>
> Envoyé: Lundi 11 Septembre 2023 15:37:55
> Objet: Re: Power (^) function speed depending on argument types

> Salut Denis,
> 
> I am not a developer, but partially following this thread my
> interpretation is that the floating point objects are converted to
> floating point objects with a larger number of bits to represent them.
> This is what "precision" tells you. But that does not mean that the
> value is necessarily accurate to that precision.
> So  when you start with the value 3.141 for Pi, and stored that in data
> type with 1000 digit precision, Pari would not add the missing digits of
> Pi, but just add trailing zeros.
> 
> 
> Markus
> 
> Am 11/09/2023 um 15:33 schrieb Denis Simon:
>> Centrum Informatyczne UG: Ta wiadomość e-mail pochodzi spoza Uczelni
>> Fahrenheita. Zachowaj ostrożność. Nie klikaj linków ani nie otwieraj
>> załączników, chyba że rozpoznajesz nadawcę i wiesz, że zawartość jest
>> bezpieczna.
>> ________________________________
>> UG IT Center: This email comes from outside the Fahrenheit Universities. Use
>> caution. Do not click links or open attachments unless you recognize the sender
>> and know that the content is safe.
>>
>> Hi Karim and Bill,
>>
>> An increase of 64 bits ???
>> I find it a little optimistic.
>> I would understand 1 or 2, or up to 14 when I compute 20000 + s
>> (because log_2(i) ~= 14 and log_2(s) ~= 0), but not 64.
>>
>> In the example of Bill
>> precision(Pi)
>> precision(100+Pi)
>> I suspect that the huge increase of precision comes from the hidden digits of Pi
>> ?
>> Otherwise, where would the last digits of 100+Pi come from ?
>>
>> Denis SIMON.
>>
>>
>>
>> ----- Mail original -----
>>> De: "Karim Belabas" <Karim.Belabas@u-bordeaux.fr>
>>> À: "Denis Simon" <denis.simon@unicaen.fr>
>>> Cc: "pari-users" <pari-users@pari.math.u-bordeaux.fr>
>>> Envoyé: Lundi 11 Septembre 2023 13:56:10
>>> Objet: Re: Power (^) function speed depending on argument types
>>> 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/
>>