Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Java (http://www.velocityreviews.com/forums/f30-java.html)
-   -   An efficient computation idea. Please comment (http://www.velocityreviews.com/forums/t139374-an-efficient-computation-idea-please-comment.html)

Aaron Fude 12-17-2004 09:16 PM

An efficient computation idea. Please comment
 
Hi,

In my program I evaluate long trigonometric polynomials a lot! For example,

final int N = 1000;
double[] c = new double[N];
// Populate c
double x = .5, sum = 0.0;

for (int i = 0; i < N; i++)
sum += c[i]*cos(i*x);

And this function is evaluated very many times (about 100,000). So why not
create a java snippet, compile it, load it as a class and use the compiled
version. So I would have something like;

String sum = "0"; // A String buffer, of course...
for (int i = 0; i < N; i++)
sum += "+" + c[i] + "*cos(" + i + "*x)";
sum += ";";


I think it's a pretty cool idea. But before I implement it, I would like to
know what you think about it!

Thank you in advance!

Aaron Fude



Patrick May 12-17-2004 09:24 PM

Re: An efficient computation idea. Please comment
 
"Aaron Fude" <aaronfude@yahoo.com> writes:
> In my program I evaluate long trigonometric polynomials a lot! For example,
>
> final int N = 1000;
> double[] c = new double[N];
> // Populate c
> double x = .5, sum = 0.0;
>
> for (int i = 0; i < N; i++)
> sum += c[i]*cos(i*x);
>
> And this function is evaluated very many times (about 100,000). So
> why not create a java snippet, compile it, load it as a class and
> use the compiled version. So I would have something like;
>
> String sum = "0"; // A String buffer, of course...
> for (int i = 0; i < N; i++)
> sum += "+" + c[i] + "*cos(" + i + "*x)";
> sum += ";";
>
> I think it's a pretty cool idea. But before I implement it, I would
> like to know what you think about it!


Greenspun's Tenth Rule of Programming:
"Any sufficiently complicated C or Fortran program contains an
ad-hoc, informally-specified, bug-ridden, slow implementation of
half of Common Lisp."

You have added Fude's Lemma: "Java programs, too."

Look up defmacro in the Common Lisp Hyperspec
(http://www.lispworks.com/reference/HyperSpec, among others). Java
doesn't allow you to do this particularly well. Lisp does.

Regards,

Patrick

------------------------------------------------------------------------
S P Engineering, Inc. | The experts in large scale distributed OO
| systems design and implementation.
pjm@spe.com | (C++, Java, ObjectStore, Oracle, CORBA, UML)

Aaron Fude 12-17-2004 09:46 PM

Re: An efficient computation idea. Please comment
 

"Patrick May" <pjm@spe.com> wrote in message
news:m21xdor52s.fsf@gulch.intamission.com...
> "Aaron Fude" <aaronfude@yahoo.com> writes:
>> In my program I evaluate long trigonometric polynomials a lot! For
>> example,
>>
>> final int N = 1000;
>> double[] c = new double[N];
>> // Populate c
>> double x = .5, sum = 0.0;
>>
>> for (int i = 0; i < N; i++)
>> sum += c[i]*cos(i*x);
>>
>> And this function is evaluated very many times (about 100,000). So
>> why not create a java snippet, compile it, load it as a class and
>> use the compiled version. So I would have something like;
>>
>> String sum = "0"; // A String buffer, of course...
>> for (int i = 0; i < N; i++)
>> sum += "+" + c[i] + "*cos(" + i + "*x)";
>> sum += ";";
>>
>> I think it's a pretty cool idea. But before I implement it, I would
>> like to know what you think about it!

>
> Greenspun's Tenth Rule of Programming:
> "Any sufficiently complicated C or Fortran program contains an
> ad-hoc, informally-specified, bug-ridden, slow implementation of
> half of Common Lisp."
>
> You have added Fude's Lemma: "Java programs, too."
>
> Look up defmacro in the Common Lisp Hyperspec
> (http://www.lispworks.com/reference/HyperSpec, among others). Java
> doesn't allow you to do this particularly well. Lisp does.
>
> Regards,
>
> Patrick



Hi Patrck,

I myself love Scheme and agree with that quote which I heard as "Inside
every C program there's a Lisp yearning to get out."

I expect that Java won't do this well. Nevertheless, will this be worth my
effort?

Thanks.

Aaron



Mark Thornton 12-17-2004 10:02 PM

Re: An efficient computation idea. Please comment
 
Aaron Fude wrote:
> Hi,
>
> In my program I evaluate long trigonometric polynomials a lot! For example,
>
> final int N = 1000;
> double[] c = new double[N];
> // Populate c
> double x = .5, sum = 0.0;
>
> for (int i = 0; i < N; i++)
> sum += c[i]*cos(i*x);
>
> And this function is evaluated very many times (about 100,000). So why not
> create a java snippet, compile it, load it as a class and use the compiled
> version. So I would have something like;


A far better scheme would be to mathematically transform the calculation
to something which can be evaluated more cheaply. For example suppose we
calculate t = cos(x)

cos(0*x) = 1
cos(2*x) = 2*t*t-1
cos(3*x) = -3*t+4*t*t*t

etc

So we need only compute cos(x) (and perhaps sin(x)) and then find the
result with a series of much simpler operations (multiplication and
addition).

There are a number of different transformations which might be employed,
depending on the range of values expected for x and other
considerations. This approach can yield much more efficient evaluation
than the technique you suggest.

You might also want to review the literature on Fourier series.

Mark Thornton

Mark Thornton 12-17-2004 10:06 PM

Re: An efficient computation idea. Please comment
 
Patrick May wrote:
> "Aaron Fude" <aaronfude@yahoo.com> writes:
>
>>In my program I evaluate long trigonometric polynomials a lot! For example,
>>
>>final int N = 1000;
>>double[] c = new double[N];
>>// Populate c
>>double x = .5, sum = 0.0;
>>
>>for (int i = 0; i < N; i++)
>> sum += c[i]*cos(i*x);
>>
>>And this function is evaluated very many times (about 100,000). So
>>why not create a java snippet, compile it, load it as a class and
>>use the compiled version. So I would have something like;
>>
>>String sum = "0"; // A String buffer, of course...
>>for (int i = 0; i < N; i++)
>> sum += "+" + c[i] + "*cos(" + i + "*x)";
>>sum += ";";
>>
>>I think it's a pretty cool idea. But before I implement it, I would
>>like to know what you think about it!

>
>
> Greenspun's Tenth Rule of Programming:
> "Any sufficiently complicated C or Fortran program contains an
> ad-hoc, informally-specified, bug-ridden, slow implementation of
> half of Common Lisp."
>
> You have added Fude's Lemma: "Java programs, too."
>
> Look up defmacro in the Common Lisp Hyperspec
> (http://www.lispworks.com/reference/HyperSpec, among others). Java
> doesn't allow you to do this particularly well. Lisp does.
>


However in this particular case there is a much better way of evaluating
the required function. A good understanding of mathematics is what is
required.

Mark Thornton

Aaron Fude 12-17-2004 10:33 PM

Re: An efficient computation idea. Please comment
 

"Mark Thornton" <mark-p-thornton@ntlworld.com> wrote in message
news:32h3iiF3mgv5gU1@individual.net...
> Patrick May wrote:
>> "Aaron Fude" <aaronfude@yahoo.com> writes:
>>
>>>In my program I evaluate long trigonometric polynomials a lot! For
>>>example,
>>>
>>>final int N = 1000;
>>>double[] c = new double[N];
>>>// Populate c
>>>double x = .5, sum = 0.0;
>>>
>>>for (int i = 0; i < N; i++)
>>> sum += c[i]*cos(i*x);
>>>
>>>And this function is evaluated very many times (about 100,000). So
>>>why not create a java snippet, compile it, load it as a class and
>>>use the compiled version. So I would have something like;
>>>
>>>String sum = "0"; // A String buffer, of course...
>>>for (int i = 0; i < N; i++)
>>> sum += "+" + c[i] + "*cos(" + i + "*x)";
>>>sum += ";";
>>>
>>>I think it's a pretty cool idea. But before I implement it, I would
>>>like to know what you think about it!

>>
>>
>> Greenspun's Tenth Rule of Programming:
>> "Any sufficiently complicated C or Fortran program contains an
>> ad-hoc, informally-specified, bug-ridden, slow implementation of
>> half of Common Lisp."
>>
>> You have added Fude's Lemma: "Java programs, too."
>>
>> Look up defmacro in the Common Lisp Hyperspec
>> (http://www.lispworks.com/reference/HyperSpec, among others). Java
>> doesn't allow you to do this particularly well. Lisp does.
>>

>
> However in this particular case there is a much better way of evaluating
> the required function. A good understanding of mathematics is what is
> required.
>
> Mark Thornton


Your comment about unwrapping cosines is undoubtedly correct. To tell you
the truth, I don't even have cosines, I have elementary polynomials. I have
contrived the cosine example so I wouldn't get responses about summing the
series in inverse order - and it backfired. (BTW, how many flops does a
cosine take? I have no idea, but I would guess about 50. Wouldn't that mean
that by the time you get to cos(50*x) it's cheaper to evaluate the cosine?)

In any case, now that we know that I have polynomial, perhaps you could
answer the posed question in the context of polynomials. Is there added
value to the compilation trick if my series has about 1000 terms and needs
to be evaluated 100k times?

Aaron Fude



Mark Thornton 12-17-2004 11:01 PM

Re: An efficient computation idea. Please comment
 
Aaron Fude wrote:
> "Mark Thornton" <mark-p-thornton@ntlworld.com> wrote in message
> news:32h3iiF3mgv5gU1@individual.net...
>
>>Patrick May wrote:
>>
>>>"Aaron Fude" <aaronfude@yahoo.com> writes:
>>>
>>>
>>>>In my program I evaluate long trigonometric polynomials a lot! For
>>>>example,
>>>>
>>>>final int N = 1000;
>>>>double[] c = new double[N];
>>>>// Populate c
>>>>double x = .5, sum = 0.0;
>>>>
>>>>for (int i = 0; i < N; i++)
>>>> sum += c[i]*cos(i*x);
>>>>
>>>>And this function is evaluated very many times (about 100,000). So
>>>>why not create a java snippet, compile it, load it as a class and
>>>>use the compiled version. So I would have something like;
>>>>
>>>>String sum = "0"; // A String buffer, of course...
>>>>for (int i = 0; i < N; i++)
>>>> sum += "+" + c[i] + "*cos(" + i + "*x)";
>>>>sum += ";";
>>>>
>>>>I think it's a pretty cool idea. But before I implement it, I would
>>>>like to know what you think about it!
>>>
>>>
>>>Greenspun's Tenth Rule of Programming:
>>> "Any sufficiently complicated C or Fortran program contains an
>>> ad-hoc, informally-specified, bug-ridden, slow implementation of
>>> half of Common Lisp."
>>>
>>>You have added Fude's Lemma: "Java programs, too."
>>>
>>>Look up defmacro in the Common Lisp Hyperspec
>>>(http://www.lispworks.com/reference/HyperSpec, among others). Java
>>>doesn't allow you to do this particularly well. Lisp does.
>>>

>>
>>However in this particular case there is a much better way of evaluating
>>the required function. A good understanding of mathematics is what is
>>required.
>>
>>Mark Thornton

>
>
> Your comment about unwrapping cosines is undoubtedly correct. To tell you
> the truth, I don't even have cosines, I have elementary polynomials. I have
> contrived the cosine example so I wouldn't get responses about summing the
> series in inverse order - and it backfired. (BTW, how many flops does a
> cosine take? I have no idea, but I would guess about 50. Wouldn't that mean
> that by the time you get to cos(50*x) it's cheaper to evaluate the cosine?)


No, because in practice a recurrence relation is used to compute each
successive term from previous values. Just as with evaluating
polynomials you don't compute x^n from scratch at each term. It is in
fact very similar as exp(iz) = cos(z) + i.sin(z) (where 'i' here is the
sqrt of -1). Now note that exp(i.n.z) = exp(iz)^n

> In any case, now that we know that I have polynomial, perhaps you could
> answer the posed question in the context of polynomials. Is there added
> value to the compilation trick if my series has about 1000 terms and needs
> to be evaluated 100k times?


It still isn't worth generating byte code. Many JIT compilers will have
been tuned to recognise this type of loop and may do some unrolling
themselves.

More seriously you need to consider the numerical stability of a power
series with 1000 terms. There are a number of methods to 'improve' such
series, which would then usually leave you with a much smaller
polynomial to evaluate. However this a complex subject which filled many
lectures during my maths degree (25 years ago).

I suggest you find a mathematician to help economise the series, and
evaluate it in the straight forward manner.

Mark Thornton

Aaron Fude 12-18-2004 03:29 AM

Re: An efficient computation idea. Please comment
 
Mark,

Here's some funny code for you which shows that compiled code may run faster
(typically by a factor of 3 on my machine).
In really, the effect will be even greater for me since the series would
have coefficients that come from some kind of a list with potentially
significant access time. Now, as you wisely noted, .999^555 is quickly
computed as .999^554*.999. That's very true, but perhaps it won't change the
fact that the compilation trick on top of your keen observation is a good
idea.

Aaron

public static void main(String[] inStr) {
int N = 0;
int M = 0;
try {
N = Math.max(1000, System.in.read()); // To prevent simple
unwrapping...
M = Math.max(100, System.in.read());
}
catch (Exception inE) { }

{
long start = System.currentTimeMillis();
double sum = 0;
for (int m = 0; m < M; m++)
for (int n = 0; n < N; n++)
sum += Math.pow(.999, n);
System.out.println(System.currentTimeMillis() - start);
}

{
long start = System.currentTimeMillis();
double sum = 0;
for (int m = 0; m < M; m++)
sum = 0 + Math.pow(.999, 0) + Math.pow(.999, 1) + Math.pow(.999,
2) + Math.pow(.999, 3) + Math.pow(.999, 4) + Math.pow(.999, 5) +
Math.pow(.999, 6) + Math.pow(.999, 7) + Math.pow(.999, 8) +
Math.pow(.999, 9) + Math.pow(.999, 10) + Math.pow(.999, 11) +
Math.pow(.999, 12) + Math.pow(.999, 13) + Math.pow(.999, 14) +
Math.pow(.999, 15) + Math.pow(.999, 16) + Math.pow(.999, 17) +
Math.pow(.999, 18) + Math.pow(.999, 19) + Math.pow(.999, 20) +
Math.pow(.999, 21) + Math.pow(.999, 22) + Math.pow(.999, 23) +
Math.pow(.999, 24) + Math.pow(.999, 25) + Math.pow(.999, 26) +
Math.pow(.999, 27) + Math.pow(.999, 28) + Math.pow(.999, 29) +
Math.pow(.999, 30) + Math.pow(.999, 31) + Math.pow(.999, 32) +
Math.pow(.999, 33) + Math.pow(.999, 34) + Math.pow(.999, 35) +
Math.pow(.999, 36) + Math.pow(.999, 37) + Math.pow(.999, 38) +
Math.pow(.999, 39) + Math.pow(.999, 40) + Math.pow(.999, 41) +
Math.pow(.999, 42) + Math.pow(.999, 43) + Math.pow(.999, 44) +
Math.pow(.999, 45) + Math.pow(.999, 46) + Math.pow(.999, 47) +
Math.pow(.999, 48) + Math.pow(.999, 49) + Math.pow(.999, 50) +
Math.pow(.999, 51) + Math.pow(.999, 52) + Math.pow(.999, 53) +
Math.pow(.999, 54) + Math.pow(.999, 55) + Math.pow(.999, 56) +
Math.pow(.999, 57) + Math.pow(.999, 58) + Math.pow(.999, 59) +
Math.pow(.999, 60) + Math.pow(.999, 61) + Math.pow(.999, 62) +
Math.pow(.999, 63) + Math.pow(.999, 64) + Math.pow(.999, 65) +
Math.pow(.999, 66) + Math.pow(.999, 67) + Math.pow(.999, 68) +
Math.pow(.999, 69) + Math.pow(.999, 70) + Math.pow(.999, 71) +
Math.pow(.999, 72) + Math.pow(.999, 73) + Math.pow(.999, 74) +
Math.pow(.999, 75) + Math.pow(.999, 76) + Math.pow(.999, 77) +
Math.pow(.999, 78) + Math.pow(.999, 79) + Math.pow(.999, 80) +
Math.pow(.999, 81) + Math.pow(.999, 82) + Math.pow(.999, 83) +
Math.pow(.999, 84) + Math.pow(.999, 85) + Math.pow(.999, 86) +
Math.pow(.999, 87) + Math.pow(.999, 88) + Math.pow(.999, 89) +
Math.pow(.999, 90) + Math.pow(.999, 91) + Math.pow(.999, 92) +
Math.pow(.999, 93) + Math.pow(.999, 94) + Math.pow(.999, 95) +
Math.pow(.999, 96) + Math.pow(.999, 97) + Math.pow(.999, 98) +
Math.pow(.999, 99) + Math.pow(.999, 100) + Math.pow(.999, 101) +
Math.pow(.999, 102) + Math.pow(.999, 103) + Math.pow(.999, 104) +
Math.pow(.999, 105) + Math.pow(.999, 106) + Math.pow(.999, 107) +
Math.pow(.999, 108) + Math.pow(.999, 109) + Math.pow(.999, 110) +
Math.pow(.999, 111) + Math.pow(.999, 112) + Math.pow(.999, 113) +
Math.pow(.999, 114) + Math.pow(.999, 115) + Math.pow(.999, 116) +
Math.pow(.999, 117) + Math.pow(.999, 118) + Math.pow(.999, 119) +
Math.pow(.999, 120) + Math.pow(.999, 121) + Math.pow(.999, 122) +
Math.pow(.999, 123) + Math.pow(.999, 124) + Math.pow(.999, 125) +
Math.pow(.999, 126) + Math.pow(.999, 127) + Math.pow(.999, 128) +
Math.pow(.999, 129) + Math.pow(.999, 130) + Math.pow(.999, 131) +
Math.pow(.999, 132) + Math.pow(.999, 133) + Math.pow(.999, 134) +
Math.pow(.999, 135) + Math.pow(.999, 136) + Math.pow(.999, 137) +
Math.pow(.999, 138) + Math.pow(.999, 139) + Math.pow(.999, 140) +
Math.pow(.999, 141) + Math.pow(.999, 142) + Math.pow(.999, 143) +
Math.pow(.999, 144) + Math.pow(.999, 145) + Math.pow(.999, 146) +
Math.pow(.999, 147) + Math.pow(.999, 148) + Math.pow(.999, 149) +
Math.pow(.999, 150) + Math.pow(.999, 151) + Math.pow(.999, 152) +
Math.pow(.999, 153) + Math.pow(.999, 154) + Math.pow(.999, 155) +
Math.pow(.999, 156) + Math.pow(.999, 157) + Math.pow(.999, 158) +
Math.pow(.999, 159) + Math.pow(.999, 160) + Math.pow(.999, 161) +
Math.pow(.999, 162) + Math.pow(.999, 163) + Math.pow(.999, 164) +
Math.pow(.999, 165) + Math.pow(.999, 166) + Math.pow(.999, 167) +
Math.pow(.999, 168) + Math.pow(.999, 169) + Math.pow(.999, 170) +
Math.pow(.999, 171) + Math.pow(.999, 172) + Math.pow(.999, 173) +
Math.pow(.999, 174) + Math.pow(.999, 175) + Math.pow(.999, 176) +
Math.pow(.999, 177) + Math.pow(.999, 178) + Math.pow(.999, 179) +
Math.pow(.999, 180) + Math.pow(.999, 181) + Math.pow(.999, 182) +
Math.pow(.999, 183) + Math.pow(.999, 184) + Math.pow(.999, 185) +
Math.pow(.999, 186) + Math.pow(.999, 187) + Math.pow(.999, 188) +
Math.pow(.999, 189) + Math.pow(.999, 190) + Math.pow(.999, 191) +
Math.pow(.999, 192) + Math.pow(.999, 193) + Math.pow(.999, 194) +
Math.pow(.999, 195) + Math.pow(.999, 196) + Math.pow(.999, 197) +
Math.pow(.999, 198) + Math.pow(.999, 199) + Math.pow(.999, 200) +
Math.pow(.999, 201) + Math.pow(.999, 202) + Math.pow(.999, 203) +
Math.pow(.999, 204) + Math.pow(.999, 205) + Math.pow(.999, 206) +
Math.pow(.999, 207) + Math.pow(.999, 208) + Math.pow(.999, 209) +
Math.pow(.999, 210) + Math.pow(.999, 211) + Math.pow(.999, 212) +
Math.pow(.999, 213) + Math.pow(.999, 214) + Math.pow(.999, 215) +
Math.pow(.999, 216) + Math.pow(.999, 217) + Math.pow(.999, 218) +
Math.pow(.999, 219) + Math.pow(.999, 220) + Math.pow(.999, 221) +
Math.pow(.999, 222) + Math.pow(.999, 223) + Math.pow(.999, 224) +
Math.pow(.999, 225) + Math.pow(.999, 226) + Math.pow(.999, 227) +
Math.pow(.999, 228) + Math.pow(.999, 229) + Math.pow(.999, 230) +
Math.pow(.999, 231) + Math.pow(.999, 232) + Math.pow(.999, 233) +
Math.pow(.999, 234) + Math.pow(.999, 235) + Math.pow(.999, 236) +
Math.pow(.999, 237) + Math.pow(.999, 238) + Math.pow(.999, 239) +
Math.pow(.999, 240) + Math.pow(.999, 241) + Math.pow(.999, 242) +
Math.pow(.999, 243) + Math.pow(.999, 244) + Math.pow(.999, 245) +
Math.pow(.999, 246) + Math.pow(.999, 247) + Math.pow(.999, 248) +
Math.pow(.999, 249) + Math.pow(.999, 250) + Math.pow(.999, 251) +
Math.pow(.999, 252) + Math.pow(.999, 253) + Math.pow(.999, 254) +
Math.pow(.999, 255) + Math.pow(.999, 256) + Math.pow(.999, 257) +
Math.pow(.999, 258) + Math.pow(.999, 259) + Math.pow(.999, 260) +
Math.pow(.999, 261) + Math.pow(.999, 262) + Math.pow(.999, 263) +
Math.pow(.999, 264) + Math.pow(.999, 265) + Math.pow(.999, 266) +
Math.pow(.999, 267) + Math.pow(.999, 268) + Math.pow(.999, 269) +
Math.pow(.999, 270) + Math.pow(.999, 271) + Math.pow(.999, 272) +
Math.pow(.999, 273) + Math.pow(.999, 274) + Math.pow(.999, 275) +
Math.pow(.999, 276) + Math.pow(.999, 277) + Math.pow(.999, 278) +
Math.pow(.999, 279) + Math.pow(.999, 280) + Math.pow(.999, 281) +
Math.pow(.999, 282) + Math.pow(.999, 283) + Math.pow(.999, 284) +
Math.pow(.999, 285) + Math.pow(.999, 286) + Math.pow(.999, 287) +
Math.pow(.999, 288) + Math.pow(.999, 289) + Math.pow(.999, 290) +
Math.pow(.999, 291) + Math.pow(.999, 292) + Math.pow(.999, 293) +
Math.pow(.999, 294) + Math.pow(.999, 295) + Math.pow(.999, 296) +
Math.pow(.999, 297) + Math.pow(.999, 298) + Math.pow(.999, 299) +
Math.pow(.999, 300) + Math.pow(.999, 301) + Math.pow(.999, 302) +
Math.pow(.999, 303) + Math.pow(.999, 304) + Math.pow(.999, 305) +
Math.pow(.999, 306) + Math.pow(.999, 307) + Math.pow(.999, 308) +
Math.pow(.999, 309) + Math.pow(.999, 310) + Math.pow(.999, 311) +
Math.pow(.999, 312) + Math.pow(.999, 313) + Math.pow(.999, 314) +
Math.pow(.999, 315) + Math.pow(.999, 316) + Math.pow(.999, 317) +
Math.pow(.999, 318) + Math.pow(.999, 319) + Math.pow(.999, 320) +
Math.pow(.999, 321) + Math.pow(.999, 322) + Math.pow(.999, 323) +
Math.pow(.999, 324) + Math.pow(.999, 325) + Math.pow(.999, 326) +
Math.pow(.999, 327) + Math.pow(.999, 328) + Math.pow(.999, 329) +
Math.pow(.999, 330) + Math.pow(.999, 331) + Math.pow(.999, 332) +
Math.pow(.999, 333) + Math.pow(.999, 334) + Math.pow(.999, 335) +
Math.pow(.999, 336) + Math.pow(.999, 337) + Math.pow(.999, 338) +
Math.pow(.999, 339) + Math.pow(.999, 340) + Math.pow(.999, 341) +
Math.pow(.999, 342) + Math.pow(.999, 343) + Math.pow(.999, 344) +
Math.pow(.999, 345) + Math.pow(.999, 346) + Math.pow(.999, 347) +
Math.pow(.999, 348) + Math.pow(.999, 349) + Math.pow(.999, 350) +
Math.pow(.999, 351) + Math.pow(.999, 352) + Math.pow(.999, 353) +
Math.pow(.999, 354) + Math.pow(.999, 355) + Math.pow(.999, 356) +
Math.pow(.999, 357) + Math.pow(.999, 358) + Math.pow(.999, 359) +
Math.pow(.999, 360) + Math.pow(.999, 361) + Math.pow(.999, 362) +
Math.pow(.999, 363) + Math.pow(.999, 364) + Math.pow(.999, 365) +
Math.pow(.999, 366) + Math.pow(.999, 367) + Math.pow(.999, 368) +
Math.pow(.999, 369) + Math.pow(.999, 370) + Math.pow(.999, 371) +
Math.pow(.999, 372) + Math.pow(.999, 373) + Math.pow(.999, 374) +
Math.pow(.999, 375) + Math.pow(.999, 376) + Math.pow(.999, 377) +
Math.pow(.999, 378) + Math.pow(.999, 379) + Math.pow(.999, 380) +
Math.pow(.999, 381) + Math.pow(.999, 382) + Math.pow(.999, 383) +
Math.pow(.999, 384) + Math.pow(.999, 385) + Math.pow(.999, 386) +
Math.pow(.999, 387) + Math.pow(.999, 388) + Math.pow(.999, 389) +
Math.pow(.999, 390) + Math.pow(.999, 391) + Math.pow(.999, 392) +
Math.pow(.999, 393) + Math.pow(.999, 394) + Math.pow(.999, 395) +
Math.pow(.999, 396) + Math.pow(.999, 397) + Math.pow(.999, 398) +
Math.pow(.999, 399) + Math.pow(.999, 400) + Math.pow(.999, 401) +
Math.pow(.999, 402) + Math.pow(.999, 403) + Math.pow(.999, 404) +
Math.pow(.999, 405) + Math.pow(.999, 406) + Math.pow(.999, 407) +
Math.pow(.999, 408) + Math.pow(.999, 409) + Math.pow(.999, 410) +
Math.pow(.999, 411) + Math.pow(.999, 412) + Math.pow(.999, 413) +
Math.pow(.999, 414) + Math.pow(.999, 415) + Math.pow(.999, 416) +
Math.pow(.999, 417) + Math.pow(.999, 418) + Math.pow(.999, 419) +
Math.pow(.999, 420) + Math.pow(.999, 421) + Math.pow(.999, 422) +
Math.pow(.999, 423) + Math.pow(.999, 424) + Math.pow(.999, 425) +
Math.pow(.999, 426) + Math.pow(.999, 427) + Math.pow(.999, 428) +
Math.pow(.999, 429) + Math.pow(.999, 430) + Math.pow(.999, 431) +
Math.pow(.999, 432) + Math.pow(.999, 433) + Math.pow(.999, 434) +
Math.pow(.999, 435) + Math.pow(.999, 436) + Math.pow(.999, 437) +
Math.pow(.999, 438) + Math.pow(.999, 439) + Math.pow(.999, 440) +
Math.pow(.999, 441) + Math.pow(.999, 442) + Math.pow(.999, 443) +
Math.pow(.999, 444) + Math.pow(.999, 445) + Math.pow(.999, 446) +
Math.pow(.999, 447) + Math.pow(.999, 448) + Math.pow(.999, 449) +
Math.pow(.999, 450) + Math.pow(.999, 451) + Math.pow(.999, 452) +
Math.pow(.999, 453) + Math.pow(.999, 454) + Math.pow(.999, 455) +
Math.pow(.999, 456) + Math.pow(.999, 457) + Math.pow(.999, 458) +
Math.pow(.999, 459) + Math.pow(.999, 460) + Math.pow(.999, 461) +
Math.pow(.999, 462) + Math.pow(.999, 463) + Math.pow(.999, 464) +
Math.pow(.999, 465) + Math.pow(.999, 466) + Math.pow(.999, 467) +
Math.pow(.999, 468) + Math.pow(.999, 469) + Math.pow(.999, 470) +
Math.pow(.999, 471) + Math.pow(.999, 472) + Math.pow(.999, 473) +
Math.pow(.999, 474) + Math.pow(.999, 475) + Math.pow(.999, 476) +
Math.pow(.999, 477) + Math.pow(.999, 478) + Math.pow(.999, 479) +
Math.pow(.999, 480) + Math.pow(.999, 481) + Math.pow(.999, 482) +
Math.pow(.999, 483) + Math.pow(.999, 484) + Math.pow(.999, 485) +
Math.pow(.999, 486) + Math.pow(.999, 487) + Math.pow(.999, 488) +
Math.pow(.999, 489) + Math.pow(.999, 490) + Math.pow(.999, 491) +
Math.pow(.999, 492) + Math.pow(.999, 493) + Math.pow(.999, 494) +
Math.pow(.999, 495) + Math.pow(.999, 496) + Math.pow(.999, 497) +
Math.pow(.999, 498) + Math.pow(.999, 499) + Math.pow(.999, 500) +
Math.pow(.999, 501) + Math.pow(.999, 502) + Math.pow(.999, 503) +
Math.pow(.999, 504) + Math.pow(.999, 505) + Math.pow(.999, 506) +
Math.pow(.999, 507) + Math.pow(.999, 508) + Math.pow(.999, 509) +
Math.pow(.999, 510) + Math.pow(.999, 511) + Math.pow(.999, 512) +
Math.pow(.999, 513) + Math.pow(.999, 514) + Math.pow(.999, 515) +
Math.pow(.999, 516) + Math.pow(.999, 517) + Math.pow(.999, 518) +
Math.pow(.999, 519) + Math.pow(.999, 520) + Math.pow(.999, 521) +
Math.pow(.999, 522) + Math.pow(.999, 523) + Math.pow(.999, 524) +
Math.pow(.999, 525) + Math.pow(.999, 526) + Math.pow(.999, 527) +
Math.pow(.999, 528) + Math.pow(.999, 529) + Math.pow(.999, 530) +
Math.pow(.999, 531) + Math.pow(.999, 532) + Math.pow(.999, 533) +
Math.pow(.999, 534) + Math.pow(.999, 535) + Math.pow(.999, 536) +
Math.pow(.999, 537) + Math.pow(.999, 538) + Math.pow(.999, 539) +
Math.pow(.999, 540) + Math.pow(.999, 541) + Math.pow(.999, 542) +
Math.pow(.999, 543) + Math.pow(.999, 544) + Math.pow(.999, 545) +
Math.pow(.999, 546) + Math.pow(.999, 547) + Math.pow(.999, 548) +
Math.pow(.999, 549) + Math.pow(.999, 550) + Math.pow(.999, 551) +
Math.pow(.999, 552) + Math.pow(.999, 553) + Math.pow(.999, 554) +
Math.pow(.999, 555) + Math.pow(.999, 556) + Math.pow(.999, 557) +
Math.pow(.999, 558) + Math.pow(.999, 559) + Math.pow(.999, 560) +
Math.pow(.999, 561) + Math.pow(.999, 562) + Math.pow(.999, 563) +
Math.pow(.999, 564) + Math.pow(.999, 565) + Math.pow(.999, 566) +
Math.pow(.999, 567) + Math.pow(.999, 568) + Math.pow(.999, 569) +
Math.pow(.999, 570) + Math.pow(.999, 571) + Math.pow(.999, 572) +
Math.pow(.999, 573) + Math.pow(.999, 574) + Math.pow(.999, 575) +
Math.pow(.999, 576) + Math.pow(.999, 577) + Math.pow(.999, 578) +
Math.pow(.999, 579) + Math.pow(.999, 580) + Math.pow(.999, 581) +
Math.pow(.999, 582) + Math.pow(.999, 583) + Math.pow(.999, 584) +
Math.pow(.999, 585) + Math.pow(.999, 586) + Math.pow(.999, 587) +
Math.pow(.999, 588) + Math.pow(.999, 589) + Math.pow(.999, 590) +
Math.pow(.999, 591) + Math.pow(.999, 592) + Math.pow(.999, 593) +
Math.pow(.999, 594) + Math.pow(.999, 595) + Math.pow(.999, 596) +
Math.pow(.999, 597) + Math.pow(.999, 598) + Math.pow(.999, 599) +
Math.pow(.999, 600) + Math.pow(.999, 601) + Math.pow(.999, 602) +
Math.pow(.999, 603) + Math.pow(.999, 604) + Math.pow(.999, 605) +
Math.pow(.999, 606) + Math.pow(.999, 607) + Math.pow(.999, 608) +
Math.pow(.999, 609) + Math.pow(.999, 610) + Math.pow(.999, 611) +
Math.pow(.999, 612) + Math.pow(.999, 613) + Math.pow(.999, 614) +
Math.pow(.999, 615) + Math.pow(.999, 616) + Math.pow(.999, 617) +
Math.pow(.999, 618) + Math.pow(.999, 619) + Math.pow(.999, 620) +
Math.pow(.999, 621) + Math.pow(.999, 622) + Math.pow(.999, 623) +
Math.pow(.999, 624) + Math.pow(.999, 625) + Math.pow(.999, 626) +
Math.pow(.999, 627) + Math.pow(.999, 628) + Math.pow(.999, 629) +
Math.pow(.999, 630) + Math.pow(.999, 631) + Math.pow(.999, 632) +
Math.pow(.999, 633) + Math.pow(.999, 634) + Math.pow(.999, 635) +
Math.pow(.999, 636) + Math.pow(.999, 637) + Math.pow(.999, 638) +
Math.pow(.999, 639) + Math.pow(.999, 640) + Math.pow(.999, 641) +
Math.pow(.999, 642) + Math.pow(.999, 643) + Math.pow(.999, 644) +
Math.pow(.999, 645) + Math.pow(.999, 646) + Math.pow(.999, 647) +
Math.pow(.999, 648) + Math.pow(.999, 649) + Math.pow(.999, 650) +
Math.pow(.999, 651) + Math.pow(.999, 652) + Math.pow(.999, 653) +
Math.pow(.999, 654) + Math.pow(.999, 655) + Math.pow(.999, 656) +
Math.pow(.999, 657) + Math.pow(.999, 658) + Math.pow(.999, 659) +
Math.pow(.999, 660) + Math.pow(.999, 661) + Math.pow(.999, 662) +
Math.pow(.999, 663) + Math.pow(.999, 664) + Math.pow(.999, 665) +
Math.pow(.999, 666) + Math.pow(.999, 667) + Math.pow(.999, 668) +
Math.pow(.999, 669) + Math.pow(.999, 670) + Math.pow(.999, 671) +
Math.pow(.999, 672) + Math.pow(.999, 673) + Math.pow(.999, 674) +
Math.pow(.999, 675) + Math.pow(.999, 676) + Math.pow(.999, 677) +
Math.pow(.999, 678) + Math.pow(.999, 679) + Math.pow(.999, 680) +
Math.pow(.999, 681) + Math.pow(.999, 682) + Math.pow(.999, 683) +
Math.pow(.999, 684) + Math.pow(.999, 685) + Math.pow(.999, 686) +
Math.pow(.999, 687) + Math.pow(.999, 688) + Math.pow(.999, 689) +
Math.pow(.999, 690) + Math.pow(.999, 691) + Math.pow(.999, 692) +
Math.pow(.999, 693) + Math.pow(.999, 694) + Math.pow(.999, 695) +
Math.pow(.999, 696) + Math.pow(.999, 697) + Math.pow(.999, 698) +
Math.pow(.999, 699) + Math.pow(.999, 700) + Math.pow(.999, 701) +
Math.pow(.999, 702) + Math.pow(.999, 703) + Math.pow(.999, 704) +
Math.pow(.999, 705) + Math.pow(.999, 706) + Math.pow(.999, 707) +
Math.pow(.999, 708) + Math.pow(.999, 709) + Math.pow(.999, 710) +
Math.pow(.999, 711) + Math.pow(.999, 712) + Math.pow(.999, 713) +
Math.pow(.999, 714) + Math.pow(.999, 715) + Math.pow(.999, 716) +
Math.pow(.999, 717) + Math.pow(.999, 718) + Math.pow(.999, 719) +
Math.pow(.999, 720) + Math.pow(.999, 721) + Math.pow(.999, 722) +
Math.pow(.999, 723) + Math.pow(.999, 724) + Math.pow(.999, 725) +
Math.pow(.999, 726) + Math.pow(.999, 727) + Math.pow(.999, 728) +
Math.pow(.999, 729) + Math.pow(.999, 730) + Math.pow(.999, 731) +
Math.pow(.999, 732) + Math.pow(.999, 733) + Math.pow(.999, 734) +
Math.pow(.999, 735) + Math.pow(.999, 736) + Math.pow(.999, 737) +
Math.pow(.999, 738) + Math.pow(.999, 739) + Math.pow(.999, 740) +
Math.pow(.999, 741) + Math.pow(.999, 742) + Math.pow(.999, 743) +
Math.pow(.999, 744) + Math.pow(.999, 745) + Math.pow(.999, 746) +
Math.pow(.999, 747) + Math.pow(.999, 748) + Math.pow(.999, 749) +
Math.pow(.999, 750) + Math.pow(.999, 751) + Math.pow(.999, 752) +
Math.pow(.999, 753) + Math.pow(.999, 754) + Math.pow(.999, 755) +
Math.pow(.999, 756) + Math.pow(.999, 757) + Math.pow(.999, 758) +
Math.pow(.999, 759) + Math.pow(.999, 760) + Math.pow(.999, 761) +
Math.pow(.999, 762) + Math.pow(.999, 763) + Math.pow(.999, 764) +
Math.pow(.999, 765) + Math.pow(.999, 766) + Math.pow(.999, 767) +
Math.pow(.999, 768) + Math.pow(.999, 769) + Math.pow(.999, 770) +
Math.pow(.999, 771) + Math.pow(.999, 772) + Math.pow(.999, 773) +
Math.pow(.999, 774) + Math.pow(.999, 775) + Math.pow(.999, 776) +
Math.pow(.999, 777) + Math.pow(.999, 778) + Math.pow(.999, 779) +
Math.pow(.999, 780) + Math.pow(.999, 781) + Math.pow(.999, 782) +
Math.pow(.999, 783) + Math.pow(.999, 784) + Math.pow(.999, 785) +
Math.pow(.999, 786) + Math.pow(.999, 787) + Math.pow(.999, 788) +
Math.pow(.999, 789) + Math.pow(.999, 790) + Math.pow(.999, 791) +
Math.pow(.999, 792) + Math.pow(.999, 793) + Math.pow(.999, 794) +
Math.pow(.999, 795) + Math.pow(.999, 796) + Math.pow(.999, 797) +
Math.pow(.999, 798) + Math.pow(.999, 799) + Math.pow(.999, 800) +
Math.pow(.999, 801) + Math.pow(.999, 802) + Math.pow(.999, 803) +
Math.pow(.999, 804) + Math.pow(.999, 805) + Math.pow(.999, 806) +
Math.pow(.999, 807) + Math.pow(.999, 808) + Math.pow(.999, 809) +
Math.pow(.999, 810) + Math.pow(.999, 811) + Math.pow(.999, 812) +
Math.pow(.999, 813) + Math.pow(.999, 814) + Math.pow(.999, 815) +
Math.pow(.999, 816) + Math.pow(.999, 817) + Math.pow(.999, 818) +
Math.pow(.999, 819) + Math.pow(.999, 820) + Math.pow(.999, 821) +
Math.pow(.999, 822) + Math.pow(.999, 823) + Math.pow(.999, 824) +
Math.pow(.999, 825) + Math.pow(.999, 826) + Math.pow(.999, 827) +
Math.pow(.999, 828) + Math.pow(.999, 829) + Math.pow(.999, 830) +
Math.pow(.999, 831) + Math.pow(.999, 832) + Math.pow(.999, 833) +
Math.pow(.999, 834) + Math.pow(.999, 835) + Math.pow(.999, 836) +
Math.pow(.999, 837) + Math.pow(.999, 838) + Math.pow(.999, 839) +
Math.pow(.999, 840) + Math.pow(.999, 841) + Math.pow(.999, 842) +
Math.pow(.999, 843) + Math.pow(.999, 844) + Math.pow(.999, 845) +
Math.pow(.999, 846) + Math.pow(.999, 847) + Math.pow(.999, 848) +
Math.pow(.999, 849) + Math.pow(.999, 850) + Math.pow(.999, 851) +
Math.pow(.999, 852) + Math.pow(.999, 853) + Math.pow(.999, 854) +
Math.pow(.999, 855) + Math.pow(.999, 856) + Math.pow(.999, 857) +
Math.pow(.999, 858) + Math.pow(.999, 859) + Math.pow(.999, 860) +
Math.pow(.999, 861) + Math.pow(.999, 862) + Math.pow(.999, 863) +
Math.pow(.999, 864) + Math.pow(.999, 865) + Math.pow(.999, 866) +
Math.pow(.999, 867) + Math.pow(.999, 868) + Math.pow(.999, 869) +
Math.pow(.999, 870) + Math.pow(.999, 871) + Math.pow(.999, 872) +
Math.pow(.999, 873) + Math.pow(.999, 874) + Math.pow(.999, 875) +
Math.pow(.999, 876) + Math.pow(.999, 877) + Math.pow(.999, 878) +
Math.pow(.999, 879) + Math.pow(.999, 880) + Math.pow(.999, 881) +
Math.pow(.999, 882) + Math.pow(.999, 883) + Math.pow(.999, 884) +
Math.pow(.999, 885) + Math.pow(.999, 886) + Math.pow(.999, 887) +
Math.pow(.999, 888) + Math.pow(.999, 889) + Math.pow(.999, 890) +
Math.pow(.999, 891) + Math.pow(.999, 892) + Math.pow(.999, 893) +
Math.pow(.999, 894) + Math.pow(.999, 895) + Math.pow(.999, 896) +
Math.pow(.999, 897) + Math.pow(.999, 898) + Math.pow(.999, 899) +
Math.pow(.999, 900) + Math.pow(.999, 901) + Math.pow(.999, 902) +
Math.pow(.999, 903) + Math.pow(.999, 904) + Math.pow(.999, 905) +
Math.pow(.999, 906) + Math.pow(.999, 907) + Math.pow(.999, 908) +
Math.pow(.999, 909) + Math.pow(.999, 910) + Math.pow(.999, 911) +
Math.pow(.999, 912) + Math.pow(.999, 913) + Math.pow(.999, 914) +
Math.pow(.999, 915) + Math.pow(.999, 916) + Math.pow(.999, 917) +
Math.pow(.999, 918) + Math.pow(.999, 919) + Math.pow(.999, 920) +
Math.pow(.999, 921) + Math.pow(.999, 922) + Math.pow(.999, 923) +
Math.pow(.999, 924) + Math.pow(.999, 925) + Math.pow(.999, 926) +
Math.pow(.999, 927) + Math.pow(.999, 928) + Math.pow(.999, 929) +
Math.pow(.999, 930) + Math.pow(.999, 931) + Math.pow(.999, 932) +
Math.pow(.999, 933) + Math.pow(.999, 934) + Math.pow(.999, 935) +
Math.pow(.999, 936) + Math.pow(.999, 937) + Math.pow(.999, 938) +
Math.pow(.999, 939) + Math.pow(.999, 940) + Math.pow(.999, 941) +
Math.pow(.999, 942) + Math.pow(.999, 943) + Math.pow(.999, 944) +
Math.pow(.999, 945) + Math.pow(.999, 946) + Math.pow(.999, 947) +
Math.pow(.999, 948) + Math.pow(.999, 949) + Math.pow(.999, 950) +
Math.pow(.999, 951) + Math.pow(.999, 952) + Math.pow(.999, 953) +
Math.pow(.999, 954) + Math.pow(.999, 955) + Math.pow(.999, 956) +
Math.pow(.999, 957) + Math.pow(.999, 958) + Math.pow(.999, 959) +
Math.pow(.999, 960) + Math.pow(.999, 961) + Math.pow(.999, 962) +
Math.pow(.999, 963) + Math.pow(.999, 964) + Math.pow(.999, 965) +
Math.pow(.999, 966) + Math.pow(.999, 967) + Math.pow(.999, 968) +
Math.pow(.999, 969) + Math.pow(.999, 970) + Math.pow(.999, 971) +
Math.pow(.999, 972) + Math.pow(.999, 973) + Math.pow(.999, 974) +
Math.pow(.999, 975) + Math.pow(.999, 976) + Math.pow(.999, 977) +
Math.pow(.999, 978) + Math.pow(.999, 979) + Math.pow(.999, 980) +
Math.pow(.999, 981) + Math.pow(.999, 982) + Math.pow(.999, 983) +
Math.pow(.999, 984) + Math.pow(.999, 985) + Math.pow(.999, 986) +
Math.pow(.999, 987) + Math.pow(.999, 988) + Math.pow(.999, 989) +
Math.pow(.999, 990) + Math.pow(.999, 991) + Math.pow(.999, 992) +
Math.pow(.999, 993) + Math.pow(.999, 994) + Math.pow(.999, 995) +
Math.pow(.999, 996) + Math.pow(.999, 997) + Math.pow(.999, 998) +
Math.pow(.999, 999);
System.out.println(System.currentTimeMillis() - start);
}

// StringBuffer s = new StringBuffer(" sum = 0");
// for (int n = 0; n < N; n++)
// s.append(" + Math.pow(.999, " + n + ")");
// s.append(";");
// System.out.println(s);
}




Aaron Fude 12-18-2004 03:39 AM

Re: An efficient computation idea. Please comment
 
For the record, the computational efficiency you are suggesting speeds up
the code by a factor of 100. All I'm saying, why not speed it up by a factor
of 2 or 3 on top of that. (I think it would be even better than a factor of
2 or 3 on top of that since it's obvious that most of the time is spent
computing powers and not performing the loop. Once computing the powers is
removed and only looping remains, unwinding and compiling should make a big
difference.)



bugbear 12-20-2004 10:43 AM

Re: An efficient computation idea. Please comment
 
Aaron Fude wrote:

I think a book on numerical analysis would serve
you better than one on compiler design.

BugBear


All times are GMT. The time now is 08:09 AM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.