Hacker News new | past | comments | ask | show | jobs | submit login

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.)



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.


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.


Last time I checked, numerical analysis was still considered a field of mathematics. It's all about the approximations.


Pssh, it's not abstract enough, it can't be real mathematics. ;P

(But seriously: yes, agreed.)


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.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: