I was trying different ways to speed up my code and found something strange.
Please, compare these two functions:
function f1(n) s = 0 for i in 2:n s += sum(( ((j^2-1)/(j-1) ) for j in 2:i) end return s end
f1(5) gives 105
function f2(n) s = 0 for i in 2:n s += sum( j+1 ) for j in 2:i) end return s end
f2(5) gives 40.
(j^2-1)/(j-1) should be the same than (j+1)
What am I doing wrong?