It finishes on my system in 46 seconds. It produces a number that is 250785 digits long. That's a humungous, massive, mind-bogglingly large number. A googol (10^100) only has 100 digits. This is 2500x the size of a googol. I would *guess* that although the *algorithm* is linear, you are hitting a non-linearity in the large number representation in Erlang, maybe due to GC or memory growth. I dunno. I mean, you are adding together two massive numbers over and over towards the end. The N > 0 prevents infinite recursion if you call fib(-1). <br>
<br><div class="gmail_quote">2008/7/1 Circular Function <<a href="mailto:circularfunc@yahoo.se">circularfunc@yahoo.se</a>>:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<table border="0" cellpadding="0" cellspacing="0"><tbody><tr><td style="font-family: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; font-size: inherit; line-height: inherit; font-size-adjust: inherit; font-stretch: inherit;" valign="top">
what does when N>0 do here? seems like no difference.<br>
and would you consider this good idiomatic erlang(ofc there is an even faster one that i found, posted at the end)?<br>
<br>
also, this is linear right? so why does fib(1200000) never finsih?
erlang cant handle such big numbers? because 12000 is pretty much
instant and 120000 takes a second or so.<br>
<br>
fib_i(A, _B, 0) -> A;<br>
fib_i(A, B, N) when N > 0 -> fib_i(B, A + B, N - 1).<br>
fib(N) -> fib_i(0, 1, N).<br>
<br>
fib_i(A, _B, 0) -> A;<br>
fib_i(A, B, N)  -> fib_i(B, A + B, N - 1).<br>
fib(N) -> fib_i(0, 1, N).<br>
<br>
<br>
<br>
<br>
<br>
<br>
fibo3(0, _, Pair) -> Pair;<br>
fibo3(N, {Fib1, Fib2}, Pair) when N rem 2 == 0 -><br>
    SquareFib1 = Fib1*Fib1,<br>
    fibo3(N div 2, {2*Fib1*Fib2 - SquareFib1, SquareFib1 + Fib2*Fib2}, Pair);<br>
fibo3(N, {FibA1, FibA2}=Pair, {FibB1, FibB2}) -><br>
    fibo3(N-1, Pair, {FibA1*FibB2 + FibB1*(FibA2 - FibA1), FibA1*FibB1 + FibA2*FibB2}).</td></tr></tbody></table><br>



      <hr size="1"><table><tbody><tr><td>Ta semester! - sök efter resor hos Kelkoo. <br>Jämför pris på flygbiljetter och hotellrum: <a href="http://www.kelkoo.se/c-169901-resor-biljetter.html?partnerId=96914051" target="_blank">http://www.kelkoo.se/c-169901-resor-biljetter.html</a></td>
</tr></tbody></table><br>_______________________________________________<br>
erlang-questions mailing list<br>
<a href="mailto:erlang-questions@erlang.org">erlang-questions@erlang.org</a><br>
<a href="http://www.erlang.org/mailman/listinfo/erlang-questions" target="_blank">http://www.erlang.org/mailman/listinfo/erlang-questions</a><br></blockquote></div><br><br clear="all"><br>-- <br>The great enemy of the truth is very often not the lie -- deliberate, contrived and dishonest, but the myth, persistent, persuasive, and unrealistic. Belief in myths allows the comfort of opinion without the discomfort of thought.<br>
John F. Kennedy 35th president of US 1961-1963 (1917 - 1963)