6

I know the sequence called the Fibonacci sequence; it's defined like:

$\begin{align*} F_0&=0\\ F_1&=1\\ F_2&=F_0+F_1\\ &\vdots\\ Fn&=F_{n-1} + F_{n-2}\end{align*}$

And we know that there's Binet formula for computing $n$-th element in the sequence.

However, I'm trying to find something totally different.

We know that $K=2$ for the Fibonacci sequence; let's call $K$ the number of previous elements to get the $n$-th element. For example,

$\begin{align*} K=2&\Rightarrow F_n= F_{n-1} + F_{n-2},\\ K=3&\Rightarrow F_n= F_{n-1} + F_{n-2} + F_{n-3},\\ \end{align*}$

and so on.

How to compute the $n$-th element for given $K$? I couldn't find any formula for $K > 2$.

Thanks for any help.

Luke
  • 2,328

2 Answers2

10

In addition to André's notes, another means of calculating solutions to these recurrence relations is to rephrase them using linear algebra as a single matrix multiply and then apply the standard algorithms for computing large powers of numbers (i.e., via binary representation of the exponent) to computing powers of the matrix; this allows for the $n$th member of the sequence to be computed with $O(\log(n))$ multiplies (of potentially exponentially-large numbers, but the multiplication can also be sped up through more complicated means).

In the Fibonacci case, this comes by forming the vector $\mathfrak{F}_n = {F_n\choose F_{n-1}}$ and recognizing that the recurrence relation can be expressed by multiplying this vector with a suitably-chosen matrix: $$\mathfrak{F}_{n+1} = \begin{pmatrix}F_{n+1} \\\\ F_n \end{pmatrix} = \begin{pmatrix}F_n + F_{n-1} \\\\ F_n \end{pmatrix} = \begin{pmatrix} 1&1 \\\\ 1&0 \end{pmatrix} \begin{pmatrix} F_n \\\\ F_{n-1} \end{pmatrix} = M_F\mathfrak{F}_n $$

where $M_F$ is the $2\times2$ matrix $\begin{pmatrix} 1&1 \\\\ 1&0 \end{pmatrix}$. This lets us find $F_n$ by finding $M_F^n\mathfrak{F}_0$, and as I noted above the matrix power is easily computed by finding $M_F^2, M_F^4=(M_F^2)^2, \ldots$ (note that this also gives an easy way of proving the formulas for $F_{2n}$ in terms of $F_n$ and $F_{n-1}$, which are just the matrix multiplication written out explicitly; similarly, the Binet formula itself can be derived by finding the eigenvalues of the matrix $M_F$ and diagonalizing it).

Similarly, for the Tribonacci numbers the same concept applies, except that the matrix is 3x3: $$\mathfrak{T}_{n+1} = \begin{pmatrix} T_{n+1} \\\\ T_n \\\\ T_{n-1} \end{pmatrix} = \begin{pmatrix} T_n+T_{n-1}+T_{n-2} \\\\ T_n \\\\ T_{n-1} \end{pmatrix} = \begin{pmatrix} 1&1&1 \\\\ 1&0&0 \\\\ 0&1&0 \end{pmatrix} \begin{pmatrix} T_n \\\\ T_{n-1} \\\\ T_{n-2} \end{pmatrix} = M_T\mathfrak{T}_n$$ with $M_T$ the $3\times3$ matrix that appears there; this is (probably) the most efficient all-integer means of finding $T_n$ for large values of $n$, and again it provides a convenient way of proving various properties of these numbers.

  • So having for example K=100 we'll have matrix 100x100 ? – Krzysztof Lewko May 27 '11 at 19:16
  • 1
    That's right - this method becomes a lot more complicated for recurrence sequences with higher values of $K$. In the long run it's still more efficient for calculation than using the defining recurrence relation, even using 'naive' versions of matrix multiplication (that take $O(K^3)$ time to multiply $K\times K$ matrices); ignoring the size of the coefficients, you'll be doing $O(K^3\log n)$ operations to find the $n$th term, rather than $O(Kn)$ operations using the basic recurrence relation, so you need $n$ to be at least on the order of $K^2$ for it to help. – Steven Stadnicki May 27 '11 at 20:32
  • Also, similar to the the way that the values of Fibonacci numbers hew close to powers of the golden ratio, all of these sequences grow as $\alpha_K^n$ for some constant $\alpha_K$, and it's possible to show that $\alpha_K\rightarrow 2$ as $K\rightarrow\infty$. – Steven Stadnicki May 27 '11 at 20:39
  • Note that representing the recursions for $n$-nacci numbers as matrix powers ends up with one taking the powers of an appropriate Frobenius companion matrix, whose characteristic polynomials are (relatively) trivial to derive (and explains why $n$-nacci numbers are expressible as combinations of powers of polynomial roots). – J. M. ain't a mathematician Jun 02 '11 at 04:49
  • @J.M. Any linear recurrence with constant coefficients will give solutions in terms of the roots of the characteristic polinomial. – vonbrand Jan 24 '13 at 00:02
  • @vonbrand Though not all of them will give solutions expressible directly as combinations of powers; consider e.g. the sequence $q_n = 7q_{n-1}-16q_{n-2}+12q_{n-3}$... – Steven Stadnicki Jan 24 '13 at 00:08
  • @StevenStadnicki, that is cheating. No infinite order, please. – vonbrand Jan 24 '13 at 00:20
  • @vonbrand Sorry; the ellipsis there wasn't meant to mean additional terms. It's a third-order recurrence, but since the characteristic polynomial has a double root, there's a linear ($(an+b)\cdot\alpha^n$) term that sneaks in to the pure-powers expansion. – Steven Stadnicki Jan 24 '13 at 00:26
  • 1
    @StevenStadnicki: You are right. Please next time you criticize me, rub it into my face in the comment, so I don't embarass myself multiple times ;-) – vonbrand Jan 24 '13 at 00:29
  • 1
    @user1698948 I'm not sure what you mean; the natural extension of that matrix works for all n-bonacci nbumbers. It corresponds to the system $a_n=a_{n-1}+b_{n-1}+c_{n-1}+d_{n-1}+\ldots$, $b_n=a_{n-1}$, $c_n=b_{n-1}$ (which is equal to $a_{n-2}$, $d_n=c_{n-1} = b_{n-2} = a_{n-3}$, etc. – Steven Stadnicki Jun 21 '22 at 23:06
  • Steven Stadnicki I didn't think my answer through, so I deleted that. I just realized I can change some letters around and be consistent with the 1's you showed. Well, since you know this stuff, have you figured out any interesting algebra in R^3? Like why if you add 1 to a chebyshev polynomial, it's still a root with cos in it. Cool stuff like that. – Thomas Olson Jun 26 '22 at 23:25
7

This is halfway between a comment and an answer. The Binet Formula (misattributed of course, it was known long before Binet) can only in a limited way be thought of as a formula "for computing" the $n$-th term of the Fibonacci sequence. Certainly it works nicely for small $n$. However, for even medium-sized $n$, it demands high-accuracy computation of $\sqrt{5}$. Ironically, such high accuracy computations of $\sqrt{5}$ involve close relatives of the Fibonacci sequence!

You can find a discussion of algorithms for computing the Fibonacci sequence at http://www.ics.uci.edu/~eppstein/161/960109.html.

A Binet-like expression for the "Tribonacci" numbers can be found at http://mathworld.wolfram.com/TribonacciNumber.html

However, the recurrence for the Tribonacci numbers, suitably speeded up, is a better computing method than the formula.

André Nicolas
  • 507,029
  • From your mathworld link you can get to http://mathworld.wolfram.com/Fibonaccin-StepNumber.html where similar formula for n-step Fibonacci sequence is mentioned. – Martin Sleziak May 27 '11 at 16:36
  • The $k$'th "$n$-step Fibonacci" number can be written as $\sum_r \frac{1}{r^k P'(r)}$ where $P(z) = -1 + \sum_{k=1}^n z^n$ and the sum is over the roots of $P(z)$. – Robert Israel May 27 '11 at 18:29
  • As far as your note of necessity of using value $\sqrt{5}$ with high accuracy; I can imagine an algorithm to compute $F_n$ from Binet formula that would work in $\mathbb{Q}[\sqrt{5}]$. (Of course, this algorithm would not have much practical value, just a side-note to the comments on high precision.) – Martin Sleziak May 29 '11 at 09:08