Function Repository Resource:

BinetFibonacci

Source Notebook

Generalize the Fibonacci numbers for complex inputs using Binet's Fibonacci formula

Contributed by: Richard Hennigan (Wolfram Research)

ResourceFunction["BinetFibonacci"][n]

gives the Fibonacci number Fn using Binet's Fibonacci formula.

Details and Options

Mathematical function, suitable for both symbolic and numerical manipulation.
For any complex value of n, the Fn are given by the general formula , where ϕ is the golden ratio.
ResourceFunction["BinetFibonacci"] automatically threads over lists.

Examples

Basic Examples (4) 

Compute Fibonacci numbers:

In[1]:=
Table[ResourceFunction["BinetFibonacci"][n], {n, 20}]
Out[1]=

Generalize to real-valued inputs:

In[2]:=
ResourceFunction["BinetFibonacci"][1/2]
Out[2]=
In[3]:=
FullSimplify[%]
Out[3]=

Use symbolic inputs:

In[4]:=
ResourceFunction["BinetFibonacci"][x]
Out[4]=

Compare to the formula used by Fibonacci:

In[5]:=
Fibonacci[x] // FunctionExpand
Out[5]=

Plot the real and imaginary components:

In[6]:=
ParametricPlot[
 ReIm[ResourceFunction["BinetFibonacci"][n]], {n, -4, 5}, Ticks -> {
Fibonacci[
Range[-6, 6]], None}]
Out[6]=

Scope (4) 

Evaluate numerically:

In[7]:=
ResourceFunction["BinetFibonacci"][5.8]
Out[7]=
In[8]:=
ResourceFunction["BinetFibonacci"][8]
Out[8]=

Evaluate to high precision:

In[9]:=
N[ResourceFunction["BinetFibonacci"][15/17], 50]
Out[9]=

Compare the real component to Fibonacci:

In[10]:=
N[Fibonacci[15/17], 50]
Out[10]=

The precision of the output tracks the precision of the input:

In[11]:=
ResourceFunction["BinetFibonacci"][0.2114411444411100011]
Out[11]=

Complex number inputs:

In[12]:=
ResourceFunction["BinetFibonacci"][8 - I]
Out[12]=
In[13]:=
N[%]
Out[13]=

Properties and Relations (5) 

The curve intersects the real axis at the Fibonacci numbers:

In[14]:=
ParametricPlot[
 ReIm[ResourceFunction["BinetFibonacci"][n]], {n, 0, 6}, Sequence[
 AspectRatio -> 1/GoldenRatio, Ticks -> {
Fibonacci[
Range[6]], None}]]
Out[14]=

Negative inputs produce a spiral in order to alternate between positive and negative values:

In[15]:=
ParametricPlot[
 ReIm[ResourceFunction["BinetFibonacci"][n]], {n, 0, -6}, Ticks -> {
Fibonacci[-Range[6]], None}]
Out[15]=

Verify with Fibonacci:

In[16]:=
Fibonacci[-Range[0, 6]]
Out[16]=

For real n, Re[BinetFibonacci[n]] is equivalent to Fibonacci[n]:

In[17]:=
Plot[Re[ResourceFunction["BinetFibonacci"][n]], {n, -5, 5}]
Out[17]=
In[18]:=
Plot[Fibonacci[n], {n, -5, 5}]
Out[18]=

BinetFibonacci automatically threads over lists:

In[19]:=
ResourceFunction["BinetFibonacci"][{1, 2, 3, 4, 5}]
Out[19]=

For large lists, it is more efficient to apply BinetFibonacci directly to the List rather than mapping it:

In[20]:=
r = RandomReal[10, 10000];
In[21]:=
First[RepeatedTiming[ResourceFunction["BinetFibonacci"][r]]]
Out[21]=
In[22]:=
First[RepeatedTiming[ResourceFunction["BinetFibonacci"] /@ r]]
Out[22]=

Possible Issues (2) 

The numerical error can become significant for larger values due to differing formulas:

In[23]:=
LogPlot[Re[ResourceFunction["BinetFibonacci"][n]] - Fibonacci[n], {n, 0, 100}]
Out[23]=

The resource function InverseFibonacci does not accept the complex values produced by BinetFibonacci:

In[24]:=
ResourceFunction["InverseFibonacci"][
 ResourceFunction["BinetFibonacci"][4.2]]
Out[24]=

Extract the real component first using Re:

In[25]:=
ResourceFunction["InverseFibonacci"][
 Re[ResourceFunction["BinetFibonacci"][4.2]]]
Out[25]=

Version History

  • 1.0.0 – 06 July 2020

Related Resources

License Information