Re: Mathematical models for loop calculations
- From: Richard Heathfield <rjh@xxxxxxxxxxxxxxx>
- Date: Wed, 26 Sep 2007 15:36:33 +0000
Tim Frink said:
On Wed, 26 Sep 2007 13:46:20 +0000, Richard Heathfield wrote:<snip>
Overall:
a += I;
b = pow(2, I);
c = pow(2, pow(2, I));
d = I * (I + 1) /2 + 1;
e += I;
I just see that these cases work since most of the variables
were assigned the value '2'. If you change them to '3', some
formulas like the one for 'b' will not work any more.
Correct.
Are there also any general formulas that depend on the current
value of the identifiers before entering the loop?
Sometimes, yes. For example, b = b * pow(2, I - 1); (and although I haven't
checked it out, a similar technique probably exists for c). a and e are
the same. d can be done, too, with thought and care. Hint: x + x+1 + x+2 +
x+3 + x+4 + ... + x+n = n * (n + 1) / 2 - x
Other times, no. See my other reply.
--
Richard Heathfield <http://www.cpax.org.uk>
Email: -http://www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999
.
- Follow-Ups:
- References:
- Mathematical models for loop calculations
- From: Tim Frink
- Re: Mathematical models for loop calculations
- From: Richard Heathfield
- Re: Mathematical models for loop calculations
- From: Tim Frink
- Mathematical models for loop calculations
- Prev by Date: Re: Mathematical models for loop calculations
- Next by Date: Re: Mathematical models for loop calculations
- Previous by thread: Re: Mathematical models for loop calculations
- Next by thread: Re: Mathematical models for loop calculations
- Index(es):
Relevant Pages
|