--- In

primenumbers@yahoogroups.com, "maximilian_hasler" >

> It took me some time to understand the motivation for this,

> but actually it is not needed (I think) --- even worse:

> because of the above "shortcut", your script gives a

> wrong result not only for 0^0 but also for (km)^0 with any k,

> so you should rather consider the case n=0 (prior to x %= m).

>

Hi Maximilian,

You're right, this script does not handle the special case where exponent is 0. However, M61 is a litle bit different from 0. ;-)

I also agree that for exponent n >= 1 the test "if (x == 0) { return 0 }" is not strictly required but it's a shortcut to avoid doing the general loop in this case... After all, I don't see any reason to do many computations when we already know the result is 0.

So, finally, the correct test is :

if (n == 0) {

return 1

}

x = x%m

if (x == 0) {

return 0

}

...

>

> (and, it's nice to recall that even bc can do that -

>

Of course, bc is not GP/PARI but one can however develop a lot of number theory functions with bc scripting. What I especially like with bc is the fact that its scripting language is very close to C language.

About 5 or 6 years ago, I built (for the fun) a special version of gnu bc that was doing all computations thanks to libgmp. It was much faster than the native internal bc implementation. I also added more predefined functions like gcd(), lcm(), issprp(), expm(), fibon(), lucas(), nextprime(), factorize(), ...

Unfortunately, I lost this work after a stupid disk crash; and of course, I had no backup of my work!

jl