Re: constant expressions

Bill Allombert <[email protected]>
Newsgroups gmane.comp.mathematics.pari.devel
Message-ID <ZRwpkzI6eSdLu5iB@seventeen>
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.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.