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 to compute on a 500 MHz 
Pentium 3 laptop.



----- Original Message ----- 
From: "Skip Cave" <[EMAIL PROTECTED]>
To: "Programming forum" <[email protected]>
Sent: Monday, February 20, 2006 11:06 AM
Subject: Re: [Jprogramming] If Maple can, why can't J?


Roger Hui wrote:

The problem with the phrase that you used,
   _10{. ": >: 28433 * 2^7830457x
is that it computes all the 2.36 million (7830457 * 10^.2) 
digits of the number, and further computes a 2 million digit 
product and a 2 million digit sum, before just taking the 
last 10 digits.

Skip Says:

The amazing thing to me was that that phrase
 
_10{. ": >: 28433 * 2^7830457x   

inefficient as it was, worked! I got the answer I wanted, with minimal 
programming time. Sure, that solution was inefficient computationally, 
and it took awhile to get the answer, but my simple mind would have 
spent hours coming up with an efficient solution anywhere
close to what Roger presented. It took me less than 20 seconds of 
programming time, and less than 15 minutes of processing time 
(which I spent productively in other pursuits) to get the answer
I needed.

It is a testament to the efficiency of J (and Moore's law) 
that even an  inefficient algorithm can often get the right answer.

Skip


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

Reply via email to