I noticed the discussion of the time taken to
compute exact large numbers by repeated exponentiation
but I didn't particularly read the later ones.

However they must have lodged in the back of my mind
because a way of computing them efficiently came to
me as I was going to sleep.  It is probably what is
done already, but anyway here goes.

Let E be the running exponent, S be the running square,
and R be the running result.  The loop goes S =. *: S;
if E is odd R =. R * S; E =. <. E % 2.  The execution
time would be of the order of log of the starting exponent.
In other words, use the running squares according to
the bits in the original exponent.

Curiously, this reminds me of a method I discussed in
a paper I once wrote on arithmetic (eprints.utas.edu.au/2003)
that would allow inexact arithmetic to be carried out
on very large and very small numbers with overflow or
underflow a concern.  Any use in J ?

----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to