So if I take a number, $n=10$, $$f(n)=6$$ Because there are only 6 Fibonacci terms below it ($1,1,2,3,5,8$). So is there any formula for this?
-
1This sequence appears to be A130233 in the OEIS. – Semiclassical Sep 17 '19 at 13:40
-
Also related: https://math.stackexchange.com/q/536810/42969. – Martin R Sep 17 '19 at 13:44
2 Answers
Well, the $k$th fibonacci number is $$ a_k = \frac{ \left(\frac{1+\sqrt{5}}{2}\right)^k - \left(\frac{1-\sqrt{5}}{2}\right)^k }{\sqrt{5}}. $$ which is very nearly equal to $$ b_k = \frac{ \left(\frac{1+\sqrt{5}}{2}\right)^k }{\sqrt{5}}. $$ If $n = b_k$, then $$ \ln(n) = k \ln \left(\frac{1+\sqrt{5}}{2}\right) - \ln(\sqrt{5}) $$ so $$ \ln(\sqrt{5}n) = k \ln \left(\frac{1+\sqrt{5}}{2}\right) $$ so $$ k = \frac{\ln(\sqrt{5}n)}{\ln \left(\frac{1+\sqrt{5}}{2}\right) } $$ So your answer is that for large $n$ (perhaps $20$ or so?) the number of fibonacci numbers less than or equal to $n$ is (very nearly) $$ k = \left\lfloor \frac{\ln(\sqrt{5}n)}{\ln \left(\frac{1+\sqrt{5}}{2}\right) } \right\rfloor $$
If you want the exact value, you can use this estimate of $k$, and then compute the $k-1$st, $k$th, and $k+1$st Fibonacci numbers (using the first formula) and then see which ones are less than $n$, and you'll have your answer.
A reasonably practical alternative is to start with twice the estimated value I've given for $k$, and then perform a binary search to find the largest $i$ for which $a_i < n$. Since you'll be computing powers of $\phi$ and $1/\phi$, you can probably cache the computed values and do this really quickly.

- 93,729
If you want to find $n$ such that $$F_n=k$$ you could use Binet formula $$F_n = \frac{\varphi^n-\psi^n}{\varphi-\psi} = \frac{\varphi^n-\psi^n}{\sqrt 5} $$ $$\varphi = \frac{1 + \sqrt{5}}{2}\qquad \text{and} \qquad \psi=\frac 1 \varphi$$ As soon as $n$ becomes large, $\psi^n$ become negligible making $$F_n \sim \frac{\varphi^n}{\sqrt 5} $$ Now, take logarithms to get $n$.

- 260,315
-
-
@JohnHughes: Your were both beaten by some years by the answers in https://math.stackexchange.com/q/67707/42969 :) – But who cares to search for duplicates :( – Martin R Sep 17 '19 at 13:46
-
@JohnHughes. Beating the ooold man ... ! You have a nice answer $\to +1$. – Claude Leibovici Sep 17 '19 at 13:46
-
1You, too. (And I too am an old man...) But as Martin R points out, we're both faster at answering than at searching for duplicates. :( – John Hughes Sep 17 '19 at 14:06