Bill Allombert on Mon, 25 Sep 2023 10:09:04 +0200


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

Re: primorial operator '#' for GP?


On Mon, Sep 25, 2023 at 06:22:02AM +0200, hermann@stamm-wilbrandt.de wrote:
> GP has factorial operator:
> ? 11!
> %6 = 39916800
> ?
> 
> Similarly primorial is product of first n primes.
> 
> prodeuler produces only a floating point approximation:
> ? prodeuler(p=2,11,p)
> %7 = 2310.0000000000000000000000000000000000
> ?

Better do

? vecprod(primes([1,11]))
%1 = 2310

> Something like this is exact:
> ? P(x)={r=1;forprime(p=2,x,r*=p);r}
> %8 = (x)->r=1;forprime(p=2,x,r*=p);r
> ? P(11)
> %9 = 2310
> ?
> 
> Any chance to see "#" as operator in GP like "!"?
> ? 11#
>   ***   syntax error, unexpected '#', expecting end of file: 11#
>   ***                                                          ^-

I suppose we could add a primorial() function but adding a new operator would
be a bit too much.

Cheers,
Bill.