Bill Allombert on Sun, 30 May 2004 12:58:23 +0200


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

Re: sigma


On Sun, May 30, 2004 at 12:18:57PM +0200, Karim Belabas wrote:
> * Jon Perry [2004-03-22 17:10]:
> > ? sigma(4,1.5)
> >   ***   this should be an integer: sigma(4,1.5)
> >                                            ^----
> You may use something like
> 
> SIGMA(n, k) = 
> { local(R, S, f, pk); 
>   R = 1; f = factor(n);
>   for (i = 1, matsize(f)[1],
>     pk = f[i, 1]^k; S = 1 + pk; 
>     for (j = 2, f[i, 2], S = 1 + pk*S);
>     R *= S
>   ); R 
> }
> 
> it's about 2 to 10 times slower than the built-in sigma [ for smooth n ! ].
> The latter makes heavy use of immediate small integers which is tough to
> emulate in GP.

Much simpler, just use sumdiv
SIGMA(n, k)=sumdiv(n,d,d^k)

Cheers,
Bill