Re: Mathematical models for loop calculations
- From: Richard Heathfield <rjh@xxxxxxxxxxxxxxx>
- Date: Wed, 26 Sep 2007 13:46:20 +0000
Tim Frink said:
Hi,
I'm looking for an approach to represent calculations within
a loop (of a computer program) by mathematical models. To make
things clear, here is a simple example for a loop that iterates
10 times:
i = 0,
b = 2,
c = 2,
d = 2,
e = 2;
while( i < 10 ) {
a = a + 1;
b = b + b;
c = c * c;
d = d + e;
e = e + 1;
i++;
}
Assuming I = number of loop iterations:
a's a tricky one, but broadly speaking a += I will do the trick. The reason
it's tricky is that you didn't spec an initial value.
Overall:
a += I;
b = pow(2, I);
c = pow(2, pow(2, I));
d = I * (I + 1) /2 + 1;
e += I;
And don't forget:
i += I;
--
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:
- Re: Mathematical models for loop calculations
- From: Tim Frink
- Re: Mathematical models for loop calculations
- From: Tim Frink
- Re: Mathematical models for loop calculations
- From: Richard Heathfield
- Re: Mathematical models for loop calculations
- References:
- Mathematical models for loop calculations
- From: Tim Frink
- Mathematical models for loop calculations
- Prev by Date: Mathematical models for loop calculations
- Next by Date: Re: Mathematical models for loop calculations
- Previous by thread: Mathematical models for loop calculations
- Next by thread: Re: Mathematical models for loop calculations
- Index(es):
Relevant Pages
|