1
  • I am trying to transform $\mathrm{f}\left(n\right) = \mathrm{f}\left(n - 3\right) + \mathrm{f}\left(n - 1\right)$, where $\mathrm{f}\left(1\right) = \mathrm{f}\left(2\right) = \mathrm{f}\left(3\right) = 1$, $\mathrm{f}\left(4\right) = 2$. This is clearly Fibonacci like sequence.
  • The goal is either: to find a formula like for Fibonacci \begin{align} \mathrm{F}\left(2n - 1\right) & = \mathrm{F}^{\, 2}\left(n - 1\right) + \mathrm{F}^{\, 2}\left(n\right) \\[1mm] \mathrm{F}\left(2n\right) & = \left[2\mathrm{F}\left(n - 1\right) + \mathrm{F}\left(n\right)\right]\mathrm{F}\left(n\right) \end{align} and $\mathrm{F}\left(2n - 2\right)$ in this case so that the $n$-th number can be calculated in $\log (n)$ time.
  • Or to find a direct calculation formula for $n$-th number.

Any help is appreciated.

Felix Marin
  • 94,079
dgrandm
  • 121
  • 2
  • Fix your Latex! –  Aug 11 '20 at 00:26
  • 3
    The closest thing I found in oeis.org/A000930 is matrix power -- you can do quick matrix $n$th power in $O(\log n)$. – Alexey Burdin Aug 11 '20 at 00:33
  • would expect $f(3n)$ instead – Will Jagy Aug 11 '20 at 00:47
  • This is a linear homogenous recurrence relation; finding a closed form for $f(n)$ is very easy. You can see some details here: https://math.berkeley.edu/~arash/55/8_2.pdf – PrincessEev Aug 11 '20 at 00:56
  • Thank you everybody, this is a great collection of answers! Simply Beautiful Art, I was using your approach, and made arithmetic mistake. Then I took approach to solve x^3 - x - 1 = 0 , got that single real root and got stuck then. This entire thread is excellent, thanks everyone! – dgrandm Aug 11 '20 at 21:12

4 Answers4

2

This is so-called Narayana's cows sequence, named after a $14^{th}$ century Indian mathematician and you will find it as A000930 in the OEIS.

If you read the formula section in the linked page, the shortest formula is given by $$a_n=\left\lfloor d\, c^n+\frac{1}{2}\right\rfloor$$ where $c$ is the real root of $x^3-x^2-1=0$ and $d$ is the real root of $31 x^3-31 x^2+9 x-1=0$.

Using the hyperbolic method for solving the cubic equations for one real root $$c=\frac{1}{3} \left(1+2 \cosh \left(\frac{1}{3} \cosh ^{-1}\left(\frac{29}{2}\right)\right)\right)$$ $$d=\frac{1}{3} \left(1+\frac{4}{\sqrt{31}}\cosh \left(\frac{1}{3} \cosh ^{-1}\left(\frac{\sqrt{31}}{2}\right)\right) \right)$$

Asymptotically, $$\frac {a_{2n}}{a_n}\sim c^n$$ which is very good as soon as $n>10$.

1

Write:

$\begin{align*} f(n + 3) &= f(n + 2) + f(n) \qquad f(1) = f(2) = f(3) = 1 \end{align*}$

Define the generating function $F(z) = \sum_{n \ge 0} f(n) z^n$, multiply your recurrence by $z^n$ and sum over $n \ge 0$; recognize the resulting sums:

$\begin{align*} \sum_{n \ge 0} f(n + 3) z^n &= \sum_{n \ge 0} f(n + 2) z^n + \sum_{n \ge 0} f(n) z^n \\ \frac{F(z) - f(0) - f(1) z - f(2) z^2}{z^3} &= \frac{F(z) - f(0) - f(1) z}{z^2} + F(z) \\ \frac{F(z) - 1 - z - z^2}{z^3} &= \frac{F(z) - 1 - z}{z^2} + F(z) \end{align*}$

Solve for $F(z)$:

$\begin{align*} F(z) &= \frac{1}{1 - z - z^3} \end{align*}$

Next step is to write this as partial fractions and expand the terms by using (mostly) the geometric series, and thus read off the coeficients. But the zeros of $r^3 - r - 1$ are very messy expressions, so I'll leave this here.

It turns out that the zeros are a real one ($\rho = 1.465571231876768$) and two complex conjugate ones, of tiny magnitude. Thus the solution is closely approximated by $f(n) = \alpha \cdot \rho^n$. To find $\alpha$, from the expansion:

$\begin{align*} F(z) &= \frac{\alpha}{1 - \rho z} + \frac{\beta}{1 - \rho_2 z} + \frac{\gamma}{1 - \rho_3 z} \\ \lim_{z \to 1 / \rho} F(z) (1 - \rho z) &= \alpha \\ \alpha &= \left. F(z) (1 - \rho z) \right|_{z = 1 / \rho} \end{align*}$

Thus essentially you need to divide $1 - z - z^3$ by $1 - \rho z$ and evaluate the result at $1 / \rho$, take the reciprocal.

Update: You can use l'Hôpital to compute the limit:

$\begin{align*} \alpha &= \lim_{z \to 1 / \rho} \frac{1 - \rho z}{1 - z - z^3} \\ &= \lim_{z \to 1 / \rho} \frac{- \rho}{-1 - 3 z^2} \\ &= \frac{\rho^3}{\rho^2 + 3} \\ &= 0.6114919919508304 \end{align*}$

This gives excellent agreement: from the recurrence, $f(10) = 28$, $\alpha \rho^{10} = 27.955$.

vonbrand
  • 28,394
1

Written in terms of matrices, the recurrence is given by

$$\begin{bmatrix}f(n+1)\\f(n+2)\\f(n+3)\end{bmatrix}=\begin{bmatrix}0&1&0\\0&0&1\\1&0&1\end{bmatrix}\begin{bmatrix}f(n)\\f(n+1)\\f(n+2)\end{bmatrix}$$

and may be solved as

$$\begin{bmatrix}f(n-1)\\f(n)\\f(n+1)\end{bmatrix}=\begin{bmatrix}0&1&0\\0&0&1\\1&0&1\end{bmatrix}^n\begin{bmatrix}f(-1)\\f(0)\\f(1)\end{bmatrix}=\begin{bmatrix}0&1&0\\0&0&1\\1&0&1\end{bmatrix}^n\begin{bmatrix}0\\0\\1\end{bmatrix}$$

$$\begin{bmatrix}f(n-2)\\f(n-1)\\f(n)\end{bmatrix}=\begin{bmatrix}0&1&0\\0&0&1\\1&0&1\end{bmatrix}^n\begin{bmatrix}f(-2)\\f(-1)\\f(0)\end{bmatrix}=\begin{bmatrix}0&1&0\\0&0&1\\1&0&1\end{bmatrix}^n\begin{bmatrix}1\\0\\0\end{bmatrix}$$

$$\begin{bmatrix}f(n-3)\\f(n-2)\\f(n-1)\end{bmatrix}=\begin{bmatrix}0&1&0\\0&0&1\\1&0&1\end{bmatrix}^n\begin{bmatrix}f(-3)\\f(-2)\\f(-1)\end{bmatrix}=\begin{bmatrix}0&1&0\\0&0&1\\1&0&1\end{bmatrix}^n\begin{bmatrix}0\\1\\0\end{bmatrix}$$

Put together, these give us the total result

$$\begin{bmatrix}f(n-2)&f(n-3)&f(n-1)\\f(n-1)&f(n-2)&f(n)\\f(n)&f(n-1)&f(n+1)\end{bmatrix}=\begin{bmatrix}0&1&0\\0&0&1\\1&0&1\end{bmatrix}^n\tag1$$

Note: At this point, any of these formulas may be used to compute $f(n)$ in $\mathcal O(\log(n))$ steps by using exponentiation by squaring to compute the matrix.

Continuing on to derive relations:

By squaring $(1)$, we may see that

\begin{align}&\begin{bmatrix}f(2n-2)&f(2n-3)&f(2n-1)\\f(2n-1)&f(2n-2)&f(2n)\\f(2n)&f(2n-1)&f(2n+1)\end{bmatrix}\\&=\begin{bmatrix}0&1&0\\0&0&1\\1&0&1\end{bmatrix}^{2n}\\&=\begin{bmatrix}f(n-2)&f(n-3)&f(n-1)\\f(n-1)&f(n-2)&f(n)\\ f(n)&f(n-1)&f(n+1)\end{bmatrix}^2\\&=\begin{bmatrix}f_{-2,-2}+f_{-1,-3}+f_{-1,0}&2f_{-2,-3}+f_{-1,-1}&f_{-2,-1}+f_{-3,0}+f_{-1,+1}\\2f_{-2,-1}+f_{0,0}&f_{-3,-1}+f_{-1,-1}+f_{-1,0}&f_{-1,-1}+f_{-2,0}+f_{0,+1}\\f_{-2,0}+f_{-1,-1}+f_{0,+1}&f_{-3,0}+f_{-2,-1}+f_{-1,+1}&2f_{-1,0}+f_{+1,+1}\end{bmatrix}\end{align}

where $f_{a,b}$ is shorthand for $f(n+a)f(n+b)$.

This may be further combined with the original recurrence to rewrite $f(n-2)$ and $f(n-3)$ as

$$f(n-2)=f(n+1)-f(n)$$

$$f(n-3)=f(n)-f(n-1)$$

and likewise for $f(2n-2)$ and $f(n-3)$. This gives identities relating $f(2n)$ and $f(2n\pm1)$ to $f(n)$ and $f(n\pm1)$, which will also allow evaluation in $\mathcal O(\log(n))$ steps.

1

Let $X_n = \pmatrix{f_{n+2}\cr f_{n+1}\cr f_{n}}$. Then $X_{n+1} = M X_n$ where $X_1 = \pmatrix{1\cr 1\cr 1\cr}$ and $M = \pmatrix{1 & 0 & 1\cr 1 & 0 & 0\cr 0 & 1 & 0}$. It can be shown (by induction) that $$ M^k = \pmatrix{f_{k+1} & f_{k-1} & f_k\cr f_k & f_{k-2} & f_{k-1}\cr f_{k-1} & f_{k-3} & f_{k-2}}$$ where we take $f_0 = 0$, $f_{-1} = 0$, $f_{-2} = 1$, $f_{-3} = 0$. Now $M^{j+k} = M^j M^k$ gives us the identity $$ f_{j+k} = (M^{j+k})_{1,3} = f_{j+1} f_k + f_j f_{k-2} + f_{j-1} f_{k-1}$$ In particular, for $k=j$ this says $$ f_{2j} = f_{j+1} f_j + f_{j-1}^2 + f_j f_{j-2}$$ and for $k=j+1$ $$ f_{2j+1} = f_{j+1}^2 + 2 f_{j-1} f_j $$ An efficient way to compute $f_n$ is using repeated squaring to get $M^n$.

Robert Israel
  • 470,583