Incidentally (or is it?) I've just noticed that not only,
as Roger said:

  2 (10^10x)&|@^ 10^100x
1787109376

,but also (discovered while wondering about factoring powers):

  2 (10^10x)&|@^ 10^10x
1787109376

which led me to observe this! :
  1787109376 (10^10x)&|@^ 1 2x
1787109376 1787109376
and so :
  1787109376 (10^10x)&|@^ i.10x
1 1787109376 1787109376 1787109376 1787109376 1787109376 1787109376 1787109376 1787109376 1787109376

I suppose there are many such numbers but it's a bit surprising
that this arises for a power of two - or is it?
All truncated versions of this number have similar properties, eg 376,
and I've found one single digit LH extension,
  81787109376x(10^11x)&|@^1 2x
81787109376 81787109376

Roger mentioned that Mathematica's PowerMod function also offers a
fast solution.  I looked at its online description at
  http://documents.wolfram.com/mathematica/book/section-3.2.5
which shows that it's also implemented for negative powers:

   This gives the modular inverse of 3 modulo 7
   In[19]:=  PowerMod[3, -1, 7]
   Out[19]= 5

whereas in J:
  3(7&|@^)0 6 - 1 NB. could J have integer solutions for neg powers?
0.333333 5
Mike

Roger Hui wrote:

Unfortunately (or fortunately), it is still often a case of
"think more, compute less". For example, if what's required is the last 10 digits of 2^10^100, you won't be able to get away with the "brute force" solution

  _10 {. ": 2^10^100x

2^10^100x has 3e99 decimal digits, which is far larger than
what any conceivable computer can store. (I believe 3e99 is larger than the number of elementary particles in the universe.)

On the other hand,

  2 (10^10x)&|@^ 10^100x
1787109376

just took less than 1 millisecond [later corrected to 10ms] to compute on a 500 MHz Pentium 3 laptop.

... [ snipped Skip's spoiler etc]
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm


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

Reply via email to