Excuse my incorrect use of terminology, I hope my question is clear:
I am coding a Python module which tests whether a given number is a member of the Fibonacci series. No problem with that. Additionally, should a number not be a member of the series, I would like to test whether it is significantly close to its nearest Fibonacci neighbor. Here an increasing deviation margin of what is considered "close" is needed, along the lines of:
deviation margin (x) increases as given number (n) increases
For my purposes 9 is significantly close to Fibonacci number 8 but 10 is not. 1600 is significantly close to Fibonacci number 1597 but 1610 is not, etc. So, the test for "significant closeness" is applying a deviation margin of 1 at lower numbers and an increasing deviation margin as the series increments up to infinity.
I figured a logical candidate for inclusion in the test would be Standard Deviation. So I have calculated a coarse margin as follows:
margin = (StdDev / ( n + closestfibneighbor)) * StdDev
This does not give me good control over the margin rate of increase and I am sure there is a more appropriate function to express the growth in margin caused by increments in x. Please feel free to elaborate on the mathematics of this - I am seeking a general solution and not a Python-specific function.
The Fibonacci numbers, the larger ones in particular, are very close to being given by the formula $$ F_n\approx\frac1{\sqrt5} \left(\frac{1+\sqrt5}2\right)^n $$ ($F_n$ is always the closest integer to the r.h.s.). In light of this I would also consider calculating, given input $x$, how far the ratio $$ r(x):=\frac{\log(x\cdot\sqrt5)}{\log\big((1+\sqrt5)/2\big)} $$ is from being an integer. In other words, I might use the number $$ s(x)=\left|r(x)-round(r(x))\right| $$ for measuring how far $x$ is from being a Fibonacci number.
The point is that a test based on Binet's formula should be faster than anything recursive. Of course, you need very precise floating point operations to be able to use that as a test, whether an integer $x$ actually is a Fibonacci number: compute $r(x)$, and find whether $$ x=round\left(\frac1{\sqrt5} \left(\frac{1+\sqrt5}2\right)^{round(r(x))}\right). $$