| Home | Forums | Reviews | Guides | Newsgroups | Register | Search |
![]() |
| Thread Tools |
| Aaron Fude |
|
|
|
| |
|
Patrick May
Guest
Posts: n/a
|
"Aaron Fude" <> 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. | (C++, Java, ObjectStore, Oracle, CORBA, UML) |
|
|
|
|
|||
|
|||
| Patrick May |
|
|
|
| |
|
Aaron Fude
Guest
Posts: n/a
|
"Patrick May" <> wrote in message news:... > "Aaron Fude" <> 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 |
|
|
|
|
|||
|
|||
| Aaron Fude |
|
Mark Thornton
Guest
Posts: n/a
|
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 |
|
Mark Thornton
Guest
Posts: n/a
|
Patrick May wrote:
> "Aaron Fude" <> 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 |
|
|
|
|
|||
|
|||
| Mark Thornton |
|
Aaron Fude
Guest
Posts: n/a
|
"Mark Thornton" <mark-p-> wrote in message news:... > Patrick May wrote: >> "Aaron Fude" <> 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 |
|
|
|
|
|||
|
|||
| Aaron Fude |
|
Mark Thornton
Guest
Posts: n/a
|
Aaron Fude wrote:
> "Mark Thornton" <mark-p-> wrote in message > news:... > >>Patrick May wrote: >> >>>"Aaron Fude" <> 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 |
|
|
|
|
|||
|
|||
| Mark Thornton |
|
Aaron Fude
Guest
Posts: n/a
|
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, 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, 1 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, 2 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, 3 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, 4 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, 5 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, 6 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, 7 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, 8 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, 9 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, 10 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, 11 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, 12 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, 13 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, 14 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, 15 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, 16 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, 17 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, 18 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, 19 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, 20 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, 21 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, 22 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, 23 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, 24 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, 25 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, 26 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, 27 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, 28 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, 29 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, 30 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, 31 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, 32 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, 33 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, 34 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, 35 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, 36 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, 37 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, 38 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, 39 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, 40 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, 41 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, 42 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, 43 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, 44 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, 45 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, 46 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, 47 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, 48 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, 49 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, 50 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, 51 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, 52 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, 53 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, 54 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, 55 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, 56 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, 57 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, 58 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, 59 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, 60 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, 61 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, 62 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, 63 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, 64 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, 65 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, 66 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, 67 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, 68 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, 69 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, 70 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, 71 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, 72 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, 73 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, 74 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, 75 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, 76 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, 77 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, 78 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, 79 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, 80 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, 81 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, 82 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, 83 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, 84 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, 85 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, 86 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, 87 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, 88 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, 89 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, 90 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, 91 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, 92 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, 93 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, 94 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, 95 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, 96 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, 97 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, 98 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, 99 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 |
|
Aaron Fude
Guest
Posts: n/a
|
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.) |
|
|
|
|
|||
|
|||
| Aaron Fude |
![]() |
| Thread Tools | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| where can I find good samples for efficient computation of matrix multiplication? | walala | VHDL | 2 | 03-24-2010 10:06 AM |
| GPS : Basic pseudo-distance computation | le Cl? | VHDL | 15 | 04-11-2009 09:22 AM |
| "please wait..." in content frame during computation | tanager | Javascript | 4 | 11-08-2007 07:14 PM |
| "please wait..." in content frame during computation | carson.clan.nc@gmail.com | Javascript | 0 | 11-06-2007 08:29 PM |
| ? ELSE Conditional Comment / Using Conditional Comments Inside Other Tags To Comment Out Attributes | Alec S. | HTML | 10 | 04-16-2005 02:21 AM |
Powered by vBulletin®. Copyright ©2000 - 2013, vBulletin Solutions, Inc..
SEO by vBSEO ©2010, Crawlability, Inc. |




