News for hackers. Stuff that matters.
Re:Pushing Nginx to its limit with Lua by smegel on Saturday December 08, 2012 @04:49PM (#4892806)
But what happens when people put big numbers in my Fibonacci calculator?
Re:Pushing Nginx to its limit with Lua by cheald on Saturday December 08, 2012 @06:39PM (#4893132)
Lua implements TCO, so it'll do just fine. :P
Re:Pushing Nginx to its limit with Lua by dbaupp on Saturday December 08, 2012 @07:34PM (#4893281)
If we are being pedantic, the naive Fibonacci implementation isn't tail recursive. (And any tail recursive implementation is unlikely to need TCO before the numbers get too large.)
Re:Pushing Nginx to its limit with Lua by InclinedPlane on Sunday December 09, 2012 @07:58AM (#4894624)
Sorry friend, it's time to be SUPER pedantic.

Silly Computer Science nerds spend a lot of time trying to figure out the most efficient implementation of a recursive Fibonacci number function. "Ooo, let's make sure to take advantage of tail-call optimization, oh, and memoization, aren't we fancy?"

Meanwhile, mathematicians look at the problem and then cock their heads to the side and say "uh, guys, that's way too much trouble, just use the closed form solution and calculate any value in constant time using a tiny number of floating point operations". Because Fib(n) = (phi^n - (1-phi)^n)/sqrt(5), where phi is the golden ratio.

Re:Pushing Nginx to its limit with Lua by dbaupp on Sunday December 09, 2012 @12:09PM (#4895139)
No, if there's any computations happening, that's engineers and physicists, especially if there are approximations happening.

A mathematician looks at the recurrence formula and generalises it (e.g. f(n) = a f(n-1) + b f(n-2) or f(n) = f(n-1)*f(n-2) (solve this one, hint: xkcd) or ...) and investigates its properties. The actual values of the numbers are not of much interest.

And a^n can only be computed in constant time if one uses exp(n log(a)), and (I think) that the scale of the numbers can have a large impact on the accuracy of the result, and so for large n, one needs more operations within both exp and log to give the same (relative) accuracy.

Re:Pushing Nginx to its limit with Lua by pjscott on Sunday December 09, 2012 @03:53PM (#4896099)
Last time I checked, numerical analysis was still considered a field of mathematics. It's all about the approximations.
Re:Pushing Nginx to its limit with Lua by dbaupp on Sunday December 09, 2012 @05:26PM (#4896431)
Pssh, it's not abstract enough, it can't be real mathematics. ;P

(But seriously: yes, agreed.)

Re:Pushing Nginx to its limit with Lua by ufo on Sunday December 09, 2012 @08:40AM (#4894708)
And then the paranoid Computer Science nerd gets freaks out because of is immortal fear of floating point errors and uses the alternate fast matrix exponentiation implementation that takes just in log(n) time.