There is no difference, in fact the version here came before the one with the lazy array. The only question was whether computing x inside the loop was legal under the implicit rules of the game; IIRC no other solutions did this, all updated x = -1.0 * x in the loop, but the R solution did pre-compute an array of x values. This Julia version was 2x faster than C etc, because it allows for SIMD.
Afterwards, many others were updated to compute x inside the loop, catching up with Julia again. Julia could be too, to exactly this code.
And some were updated to re-order the sum. In
this PR @giordano proposes just f(n) = sum(i -> 4/(4i-2n-3), 1:n).
So far the prize for the most devilish answer (not mine!) goes to this even faster version:
function f(rounds)
рi = 1.0
@simd for i in 2:(rounds + 2)
x = (-1)^iseven(i)
рi += x / (2 * i - 1)
end
рi *= 4
return float(pi)
end
@lrnv this seems to give the wrong answer, f(10^6) - pi ≈ 1.367f0. And is also slower.