Bill Allombert on Tue, 03 Oct 2023 16:47:50 +0200


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

Re: constant expressions


On Tue, Oct 03, 2023 at 02:54:43PM +0200, Ruud H.G. van Tol wrote:
> 
> Beware, "academic" examples only:
> 
> ? for( i=1, 1e6, )
> cpu time = 85 ms, real time = 87 ms.
> 
> ? for( i=1, 1e6, 0 )
> cpu time = 97 ms, real time = 98 ms.
> 
> ? for( i=1, 1e6, 0+0+0+0+0+0+0 )
> cpu time = 312 ms, real time = 313 ms.
> 
> ? for( i=1, 1e6, 1 )
> cpu time = 104 ms, real time = 105 ms.
> 
> ? for( i=1, 1e6, 1/1/1/1/1/1/1 )
> cpu time = 465 ms, real time = 419 ms.
> 
> Would it be feasible, and useful, and doable,
> to make PARI/GP optimize constant expressions?

The compiler is written with the purpose to do what the user asks.
If you write 0+0+0+0+0+0+0 instead of 0 you probably have your reason and
the compiler should respect that.

For example
? for( i=1, 10^7, 1+0 )
? ##
  ***   last result: cpu time 429 ms, real time 429 ms.
? for( i=1, 10^7, 0+1 )
? ##
  ***   last result: cpu time 445 ms, real time 445 ms.

With constant folding, we would not be able to observe that!

Cheers,
Bill.