Live data from Hacker News

Tail Recursion Tactics: Fibonacci

blog.des.io

1–10 of 38 posts

Re: Tail Recursion Tactics: Fibonacci

#2
Silly question: Both this post and the earlier one linked from it show that a manually written loop easily beats the tail-recursive version. That is, Go doesn't seem to do tail recursion optimization. In which case, why bother with all of this?

Re: Tail Recursion Tactics: Fibonacci

#3

Silly question: Both this post and the earlier one linked from it show that a manually written loop easily beats the tail-recursive version. That is, Go doesn't seem to do tail recursion optimization. In which case, why bother with all of this?

All of these versions are correct in theory, and the Go example in here is because Go is easily readable as a lingua franca. This whole post can be easily translated to other languages, including ones that do tail call optimization.

Also note that, despite Go having no TCO, the author has nonetheless managed to get a huge improvement over the naïve case by using proper tail recursion.

Re: Tail Recursion Tactics: Fibonacci

#5

Silly question: Both this post and the earlier one linked from it show that a manually written loop easily beats the tail-recursive version. That is, Go doesn't seem to do tail recursion optimization. In which case, why bother with all of this?

The tail-recursive version is a good intermediate step towards the loop version - especially if you have more complex algorithms. It would however be great, if Go would do tail call optimization, making the tail-recursive version as efficient as the explicit loop.

Re: Tail Recursion Tactics: Fibonacci

#9
post #7
post #6

Great post, please add RSS for at least one subscriber!

I'm flattered! I added an rss feed for you: https://blog.des.io/rss.xml

Many thanks, and very very nice article. I used to spend time reading about linear recurrences and all things fibonacci. I stopped but this reminds me I should go back into it.

Re: Tail Recursion Tactics: Fibonacci

#10
I love your explanation of how to arrive at the vector transformation function. You might enjoy reading an article I wrote a few years ago that touches on maxtrix/vector computation of linear recurrences: http://aperiodical.com/2014/06/discovering-integer-sequences...

Not as detailed as your post though. Thanks for a great write up!

Post reply on HN