Math Is Fun Forum
  Discussion about math, puzzles, games and fun.   Useful symbols: √ ∞ ≠ ≤ ≥ ≈ ⇒ ∈ Δ θ ∴ ∑ ∫ π -

Login

Username

Password

Not registered yet?

#1 2006-10-30 00:13:34

All_Is_Number
Power Member

Offline

Finite Series and For Next Loops

I realized recently that the mathematical equivalent of a For Next loop in programming is the finite series. I'm sure many on this forum already knew that, but I had never made the connection.

A simple example:



is the same as

10 y = 0
20 for x = 1 to 10
30 y = y + 1
40 next x
50 print y
60 end

(I've used BASIC as the program language, but many programming languages have For Next loops.)

Nested loops can also be represented by "nested" finite series. Each loop has its own sigma representation.

This is nothing groundbreaking, to be sure, but it is handy to know because sometimes one method is more convenient to use than the other.


You can shear a sheep many times but skin him only once.
 

#2 2006-10-30 03:27:49

luca-deltodesco
Super Member
Award: Wink Alive

Offline

Re: Finite Series and For Next Loops

yes. although you can have far more complicated strucrures in a program that would look rather silly in maths.


The Beginning Of All Things To End.
The End Of All Things To Come.
 

#3 2006-10-30 03:46:25

luca-deltodesco
Super Member
Award: Wink Alive

Offline

Re: Finite Series and For Next Loops

theres one thing that always bugged me, how can you use a sigma notation, when you dont want to go up in integer steps?

what if you wanted a summation from -2 to -4.89 in 0.01 intervals for e^x? would you just have to do something like



and carrying on from what you said.

you could think of a (dont know its name)



as being either a for loop in the format

float csum = 1;
for(int i = 0; i<=10; i++) csum *= exp(i);

or maybe as a recursive function

function prodex(float n = 1, int i = 0)
{
    if(i<=10)
       return prodex(n*exp(n),i+1);
    else
       return n;
}


The Beginning Of All Things To End.
The End Of All Things To Come.
 

#4 2006-10-30 03:54:31

All_Is_Number
Power Member

Offline

Re: Finite Series and For Next Loops

luca-deltodesco wrote:

theres one thing that always bugged me, how can you use a sigma notation, when you dont want to go up in integer steps?

what if you wanted a summation from -2 to -4.89 in 0.01 intervals for e^x? would you just have to do something like

perhaps:


You can shear a sheep many times but skin him only once.
 

#5 2006-10-30 04:50:23

Dross
Power Member

Offline

Re: Finite Series and For Next Loops

You don't have to have a sumation in that format, you could use a capital sigma over a set, like:


Bad speling makes me [sic]
 

#6 2006-10-30 12:31:48

krassi_holmz
Real Member

Offline

Re: Finite Series and For Next Loops

Or you can define abstract operators, which act as programs:


Or you can use them as "constructors" for more complex objects:

Last edited by krassi_holmz (2006-10-30 12:36:28)


IPBLE:  Increasing Performance By Lowering Expectations.
 

Board footer

Powered by FluxBB