Re: Mathematical models for loop calculations



On Wednesday 26 September 2007 09:10, Tim Frink wrote:

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,
...

while( i < 10 ) {
a = a + 1;
b = b + b;
...
i++;
}

So you would want to come up with

a' = a + 10
b' = 2^11

where a' and b' are the values of "a" and "b" after the loop exits,
right?

(If you didn't know the beginning value of i, it is
a' = a + 10-i
b' = 2^(i+1)
instead.)

In the broadest case, the problem is unsolvable: you can't always
prove a loop ends (think Fermat's last theorem or halting problem);
even for the cases you can, you can't easily prove how many times it
will loop (think cascading numbers); even if you can, there may be no
simple way to express the result (think sum of randomoid numbers).

That said, there are lots of ways to get some results.

My first idea was to express the calculations by mathematical series
but I still don't know exactly how to do this.

Yes, solving a mathematical series is probably the best all-around
approach. Some arithmetic and geometric series have nice forms
you can use. There are classes to teach how to solve a series.

Powerful math packages, like Mathematica or Maple, are great at
solving a series.

Sincerely,
-paul-
Paul E. Black (p.black@xxxxxxx)
.



Relevant Pages

  • Re: Mathematica Vs. Matlab
    ... The general DO loop in Macsyma is designed to handle cases where the loop ... Do either Matlab or ... >> number of other software packages. ... >> both Mathematica and MATLAB in the two years since the report was last ...
    (sci.math.symbolic)
  • Re: Mathematica Vs. Matlab
    ... > number of other software packages. ... > both Mathematica and MATLAB in the two years since the report was last ... Looking at the Mathematica code I see the loop implemented is a Do loop ...
    (sci.math.symbolic)
  • Re: Mathematica evaluation
    ... > by Maxim Rytin in the Mathematica newsgroup. ... > Which times a little loop. ... Copyright 1988-97 Wolfram Research, Inc. ...
    (comp.lang.lisp)
  • [Mathematica, Sound, loop] How to PlaySound in a loop?
    ... when inside a Whileor Do loop, ... Mathematica does not wait for sound to be fully played and ... sound file name to be played. ... is there a way to delay the loop untill the sound is played ...
    (sci.math.symbolic)
  • Re: HP35s - solving functions in user programs
    ... user-programmed routines. ... wonder why the HP-35s cannot solve certain user routines just as the 34C ... => SOLVING ... Now try the same function with a loop inside: ...
    (comp.sys.hp48)