5

Someone on stackoverflow asked a question about tracking score in their game with a Fibonacci like sequence, just starting at different values $(F_1 = 50,~ F_2 = 100)$. I know there's a formula to calculate Fibonacci numbers (based on Wikipedia) but I'm not familiar with most of the math that formula is based on.

Is there a way to adjust the formula to be used with these new initial conditions?

nmasanta
  • 9,640
  • The Sequence look like 25(Fibonacci[n+1] + LucasL[n+1]) as in the SO question 0 => 50; that expend to 25 ((2/(1 + sqrt(5)))^(-n - 1) + (1/2 (1 + sqrt(5)))^(-n - 1) cos(π (n + 1)) + ((2/(1 + sqrt(5)))^(-n - 1) - (1/2 (1 + sqrt(5)))^(-n - 1) cos(π (n + 1)))/sqrt(5)). Then I got lost typing parentese on my phone and quit. – xdtTransform Aug 06 '19 at 10:10

3 Answers3

7

If you have $$G_n=G_{n-1}+G_{n-2} \qquad \text{with} \qquad G_1=a \qquad \text{and} \qquad G_2=b$$ the general formula is given by $$G_n=\frac{1}{2} \left((3 a-b) F_n+(b-a) L_n\right)$$ where appear the usual Fibonacci and Lucas numbers.

For $a=50$ and $b=100$, the sequence would be $$\{50,100,150,250,400,650,1050,1700,2750,4450,7200,11650,18850,30500,49350\}$$

If you divide all numbers by $10$, this becomes sequence $A022088$ in $OEIS$

  • 2
    OP seems to be looking not for the Binet-like formula for $f_n$, but rather for its inverse (getting $n$ from $f_n$). – darij grinberg Aug 06 '19 at 09:00
  • @darijgrinberg I do want the inverse forumula. Is there a way to solve for it from this? – just.another.programmer Aug 06 '19 at 10:59
  • @ClaudeLeibovici Is there a way to write the formula without using $(F_n)$ and $(L_n)$? For $(F_n)$ could I sub in $\lfloor \frac{\phi^n}{\sqrt{5}} + \frac{1}{2} \rfloor$ and for $(L_n)$ sub in $(\frac{(1+\sqrt{5})}{2})^n+(\frac{1-\sqrt{5}}{2})^n$? (I looked those up on Wikipedia). – just.another.programmer Aug 06 '19 at 11:12
  • @just.another.programmer. The formula given by lhf is for sure much simpler. Just use Binet formula – Claude Leibovici Aug 06 '19 at 11:33
6

If a sequence $(G_n)$ is given by $G_1=a$, $G_2=b$, $G_n=G_{n-1}+G_{n-2}$ for $n\ge 3$, then $$G_n=a F_n + (b-a) F_{n-1}$$ where $F_n$ is the $n$-th Fibonacci number, with $F_0=0$, $F_1=1$, $F_2=1$, etc.

Thus, your sequence is $G_n = 50 F_n + 50 F_{n-1} = 50 F_{n+1}$.

To find $n$ given $G_n$, adapt the formula you already know: $$ n = \bigg\lfloor \log_\varphi \left(\frac{G_n}{50}\cdot\sqrt{5} + \frac{1}{2} \right)\bigg\rfloor-1. $$ However, to apply this formula for large numbers, you'll probably need high-precision approximations of $\varphi$ and $\log$ to find $\log_\varphi(x)=\log(x)/\log(\varphi)$.

lhf
  • 221,500
2

The recursion relation $F(n+2) = F(n+1)+F(n)$ suggests the generating function $x^2f(x) = xf(x)+f(x) \rightarrow f(x) = \frac 1 {x^2-x-1} = 1/[(x-\phi)(x+\phi^{-1})]$, where $\phi = \frac {1+\sqrt 5}2$. This fraction can be decomposed by partial fractions into $\frac A {x-\phi}+\frac B {x+\phi^{-1}}$. This is then two geometric sequences $A(\sum (\phi x)^n+B(\sum (-\phi^{_1})^n)$ or $\sum (A\phi^n+B(-\phi^{-1})^n)x^n$.

I've left $A$ and $B$ as variables rather than solving for them, as the above doesn't take into account the initial terms, and the values of $A$ and be $B$ will depend on those terms; when we plug those in, we have two unknowns ($A$ and $B$), and two constraints (the two initial terms). In fact, given any $a_{i},a_{j}$, we can solve for $A$ and $B$ with $A\phi^{i}+B(-\phi^{-1})^{i}=a_{i}$ and $A\phi^{j}+B(-\phi^{-1})^{j}=a_{j}$.

In the particular case you gave, we have that the standard Fibonacci sequence goes $0,1,1,2,3,5,8...$ (although conventions vary whether it starts with $0$ or $1$). Multiply these numbers by $50$ yields $0,50,50,100,150,250,400...$. Your numbers $50,100$ correspond to $a_2,a_3$ of that sequence (with zero indexing), and so if $b_n$ denotes the $n$-th number in your sequence (with $b_1 = 50$, $b_2=100$), and $F_n$ denotes the $n$-th number of the Fibonacci sequence ($F_0=0$, $F_1=1$, $F_2=1$, ...), then $b_n = 50F_{n+1}$.

Acccumulation
  • 12,864