Fibonacci( n ) F
returns the nth number of the Fibonacci sequence. The Fibonacci sequence Fn is defined by the initial conditions F1 = F2 = 1 and the recurrence relation Fn+2 = Fn+1 + Fn. For negative n we define Fn = (-1)n+1 F-n, which is consistent with the recurrence relation.
Using generating functions one can prove that Fn = fn - 1/fn, where f is (Ö5 + 1)/2, i.e., one root of x2 - x - 1 = 0. Fibonacci numbers have the property Gcd( Fm, Fn ) = FGcd(m,n). But a pair of Fibonacci numbers requires more division
steps in Euclid's algorithm (see Gcd) than any other pair of
integers of the same size. Fibonnaci(k) is the special case
Lucas(1,-1,k)[1] (see Lucas).
gap> Fibonacci( 10 ); 55 gap> Fibonacci( 35 ); 9227465 gap> Fibonacci( -10 ); -55
Lucas( P, Q, k ) F
returns the k-th values of the Lucas sequence with parameters P and Q, which must be integers, as a list of three integers.
Let a, b be the two roots of x2 - P x + Q then we define Lucas( P, Q, k )[1] = Uk = (ak - bk) / (a- b) and Lucas( P, Q, k )[2] = Vk = (ak + bk) and as a convenience Lucas( P, Q, k )[3] = Qk.
The following recurrence relations are easily derived from the
definition U0 = 0, U1 = 1, Uk = P Uk-1 - Q Uk-2 and V0 = 2, V1 = P, Vk = P Vk-1 - Q Vk-2. Those relations are actually used
to define Lucas if a = b.
Also the more complex relations used in Lucas can be easily derived
U2k = Uk Vk, U2k+1 = (P U2k + V2k) / 2 and V2k = Vk2 - 2 Qk, V2k+1 = ((P2-4Q) U2k + P V2k) / 2.
Fibonacci(k) (see Fibonacci) is simply Lucas(1,-1,k)[1]. In
an abuse of notation, the sequence Lucas(1,-1,k)[2] is sometimes
called the Lucas sequence.
gap> List( [0..10], i->Lucas(1,-2,i)[1] ); [ 0, 1, 1, 3, 5, 11, 21, 43, 85, 171, 341 ] # 2^k - (-1)^k)/3 gap> List( [0..10], i->Lucas(1,-2,i)[2] ); [ 2, 1, 5, 7, 17, 31, 65, 127, 257, 511, 1025 ] # 2^k + (-1)^k gap> List( [0..10], i->Lucas(1,-1,i)[1] ); [ 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55 ] # Fibonacci sequence gap> List( [0..10], i->Lucas(2,1,i)[1] ); [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 ] # the roots are equal
[Top] [Previous] [Up] [Next] [Index]
GAP 4 manual