| Karim Belabas on Sun, 30 May 2004 12:36:53 +0200 |
[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]
| Re: sigma |
* Jon Perry [2004-03-22 17:10]:
> ? sigma(4,1.5)
> *** this should be an integer: sigma(4,1.5)
> ^----
>
> ? ?sigma
> sigma(x,{k=1}): sum of the k-th powers of the divisors of x. k is optional
> and
> if omitted is assumed to be equal to 1.
>
> Is there a technical reason for k being an integer?
Speed and backward compatibility mostly [ k is a C-long integer in library
code ]. Allowing general exponents would require duplicating a significant
amount of source code, and I see no real application for it.
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.
Hope this helps,
Karim.
P.S: I have fixed the documentation in CVS
--
Karim Belabas Tel: (+33) (0)1 69 15 57 48
Dep. de Mathematiques, Bat. 425 Fax: (+33) (0)1 69 15 60 19
Universite Paris-Sud http://www.math.u-psud.fr/~belabas/
F-91405 Orsay (France) http://pari.math.u-bordeaux.fr/ [PARI/GP]