Re: Mathematical models for loop calculations



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
.



Relevant Pages

  • Re: Luban language does threads easy
    ... Marcin 'Qrczak' Kowalczyk wrote: ... >> Thread can be tricky sometimes. ... >> produce output that surprise you. ... > The problem is caused by using a single variable through the whole loop. ...
    (comp.programming.threads)
  • Re: basic to vb6
    ... At the moment I just trying to convert the code to vb6. ... Its a bit tricky the for loops seem to send 153,150,102,105 all at the same time. ... I suspect that may be that the current computer you're running on is so much faster than what the sample code was run on as well as the difference between interpreted BASIC and VB that the delay loop inside the other loop outputting the data is too fast for the device. ...
    (microsoft.public.vb.general.discussion)
  • Re: System.Threading Timer Question
    ... I think you'd have to just have a thread in a loop, I doubt you will see a 1MS precision when using Threading.Timer ... It'll still be tricky to achieve anything exactly every 1MS though I think. ... http://www.capableobjects.com - Think domain, not database ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: for loop in ksh
    ... > Does anyone know how to get a for loop in ksh ... > And I want to feed the whole line into the for loop variable.. ... Since a for loop is tricky, because of the NL->SPC replacement, here is ...
    (comp.unix.shell)
  • Re: Mathematical models for loop calculations
    ... a loop (of a computer program) by mathematical models. ... extracting recursion formulae for _t ...
    (sci.math)