I have the book saying that
and says that this is equivalent to saying
I created this while loop illustrating sigma notation elements in detail.
//Illustrates how loops are similar to Sigmas in Math
//This is equal to:
//100
//Sigma x+5
//x=1
package justscratch;
public class SigmaCalculatorWhileLoop {
private static int initial = 0; //Initial. Will increment by one until it reaches limit.
private static final int limit = 100; //Limit
private static final int incr = 5; //Number Incremental
private static int pass = 0; //Will illustrate the current pass
private static int tempAnswer = 0; //The previous sum
private static int finalAnswer = 0; //The current sum
public static void main(String[] args) {
while(pass<=limit) {
System.out.println("Pass: " + pass); //Prints out current Loop Pass
System.out.println(tempAnswer); //Prints out the sequences generated by each iteration from the "sigma"
tempAnswer = initial + incr; //Creates a new increased sequence until the limit is reached
finalAnswer = tempAnswer + finalAnswer; //Adds the previous sequence with the current sequence
pass++; //Increases the current pass
initial++; //The initial value will increase by 1 until it reaches it's limit
}
System.out.println("Sigma Answer: " + finalAnswer); //Prints the final sum of the "Sigma"
}
}
In summary, this app will simulate the sigma 100 Σ n+5 n=0. The app works by generating a previous and current sequence based on the sigma, and adding these both the current & previous sequence together until the sigma limit is reached to calculate the total returned by the sigma. So the sequences {5+6+7+8+9+10,11+. . . . 105} will be added altogether.
Surely it is saying the sum is equivalent to
for (i = 1; i <= N; i++)
Sum += 1;
?
I think that we have limitations for calculating For loops through Sigma notation
for example
x=0
For i=2 to n-1 do
For j=i+1 To n-2 do
x=x+1
for n=5 we have x=1
but when I calculate it by Sigma
Sigma i=2 to n-1 (Sigma j=i+1 to n-2)= (n^2 -7*n+10 )/2
if we substitute n=5 then answer is zero, Why?
If you don't understand C code, it is because of mistakes in it.
It must be 1 instead of i in first case:
for(i = 1; i <= N; i++)
Sum += 1;
It must be i instead of 1 and 1 instead of k there in the second case:
for(k = j; k <= i; k++)
Sum += 1;
P.S. Also you have mistypo in the formula itself. 1 is skipped after Sigma by some reason. and j and i are swaped...
What is this book you are talking about?
I'm by no means a calculus guru, just a layman, but perhaps the layman's terms will be useful for somebody. Again I'm no guru, so holler if you spot mistakes. Anyway, lets just plug and chug through the "loop"...
Given the number on the right hand side of Sigma we are told this sum starts at 1, so
First iteration,
Sum = 1+1
Second iteration,
2 + 2
Third iteration
4 + 3
Fourth iteration
7 + 4
all the way up until the LIMIT where you will have
SumBeforeLast + N
What is the "Limit?" Well in C you would define it as (i=1; i<=N;). In English, if N is 100 then the Limit would be "where i=100." If N=5 then the "Limit" is "where i=5" and so on.
If you want to be pedantic (and you should) you might also say that the Limit has two parts, i's original value at the "start" of "execution" (Lambda Calculus does not relate computation to neither time nor a machine, but you can always strip that model away once you get the concept) is the "lower limit" and i's "final value" is the "upper limit."
You want to know the "magic" of Derivatives? It's hard to explain, but basically, sometimes, just sometimes when N = Infinity or some other value, and again just SOMETIMES, if the algebra lines up in such a way so that the algebra produced cancels itself out, we are left with a new simplified algebra which no longer takes "infinite" or "N iterations" to reach some wanted result. Finding these "derivatives" is a huge part of both mathematics and algorithm development.
To put it another way, the "magic" of Calculus is nothing but the Sigma operation producing a pattern like (x/x)*someEquation combined with the fact that something (such as (x/x)) divided by itself equals 1, and the fact that 1 multiplied by "someEquation" causes "someEquation" no change, which means large parts of the equation are not needed to compute the Sigma operation at some iteration.
Keep in mind if we discard x/x or rather just x, then all the complexity is discarded with it be discrete or even infinite in which case entirely new computations can not only be optimized but simply made possible to achieve with our limited hardware.
I have little experience in this, but as I understand it, in algorithm design derivatives are used to make optimizations to algorithms as they extract complexity from a recursive series. Sometimes these optimizations bring problems of infinite complexity into the realm of the finite, which makes them solvable by computers which after all have finite lifespans and resources and are thus limited to finite or discrete mathematics.
An integral on the other hand while it increases the complexity of the integral function has been fundamental in discovering many new algorithms especially those with complexity extending above and beyond our ability to discover using our intuition and raw mathematical reasoning alone.
Looks like the book just says that for given x
and y
for (int i = x; i <= y; ++i) Sum += 1;
is similar to
and thus, replacing x = 1
and y = N
,
for (int i = 1; i <= N; ++i) Sum += 1;
is similar to
This is of course what you expect: when counting from 1
to N
, you count a total of N
items. More generally, when counting from x
to y
, you count y - x + 1
items (+ 1
since you include both boundaries).