Math Is Fun Forum

  Discussion about math, puzzles, games and fun.   Useful symbols: ÷ × ½ √ ∞ ≠ ≤ ≥ ≈ ⇒ ± ∈ Δ θ ∴ ∑ ∫ • π ƒ -¹ ² ³ °

You are not logged in.

#1 2006-10-29 01:13:34

All_Is_Number
Member
Registered: 2006-07-10
Posts: 258

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.

Offline

#2 2006-10-29 04:27:49

luca-deltodesco
Member
Registered: 2006-05-05
Posts: 1,470

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.

Offline

#3 2006-10-29 04:46:25

luca-deltodesco
Member
Registered: 2006-05-05
Posts: 1,470

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.

Offline

#4 2006-10-29 04:54:31

All_Is_Number
Member
Registered: 2006-07-10
Posts: 258

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.

Offline

#5 2006-10-29 05:50:23

Dross
Member
Registered: 2006-08-24
Posts: 325

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]

Offline

#6 2006-10-29 13:31:48

krassi_holmz
Real Member
Registered: 2005-12-02
Posts: 1,905

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-29 13:36:28)


IPBLE:  Increasing Performance By Lowering Expectations.

Offline

Board footer

Powered by FluxBB