Fibonacci sequence: Difference between revisions

Content added Content deleted
m (FutureBasic entry moved out of the Basic group)
Line 10,418: Line 10,418:


===Binary powering===
===Binary powering===
This is an efficient method (similar to the one used internally by <code>fibonacci()</code>), although running it without compilation won't give competitive speed.
<syntaxhighlight lang="parigp">fib(n)={
<syntaxhighlight lang="parigp">fib(n)={
if(n<=0,
if(n<=0,
Line 10,491: Line 10,492:
a
a
};</syntaxhighlight>
};</syntaxhighlight>

===Trigonometric===
This solution uses the complex hyperbolic sine.
<syntaxhighlight lang="parigp">fib(n)=real(2/sqrt(5)/I^n*sinh(n*log(I*(1+sqrt(5))/2)))\/1;</syntaxhighlight>


===Chebyshev===
===Chebyshev===