The obstacle is not implementational but definitional. The assumed requirement was that x m&|@^ y should be equivalent to m|x^y , and therefore can not be used to compute inverses in the group of integers mod m without redefining the meaning of x^y for negative powers. This assumption should perhaps be reexamined because it seems much more useful for x m&|@^ y to compute powers mod m rather than m|x^y .
Note that if you use instead the phrase x m&|@^ (y mo m)|y where mo is the multiplicative order function posted a few days ago, then you can compute powers mod m for all integer y (and obtain tremendous efficiency gains for large magnitude y). ----- Original Message ----- From: "Mike Day" <[EMAIL PROTECTED]> To: "Programming forum" <[email protected]> Sent: Monday, February 27, 2006 2:18 AM Subject: Re: [Jprogramming] If Maple can, why can't J? ... 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
