Another formula I found out about:
$$f(n)=[\frac{\phi^n}{\sqrt5}]$$ (square brackets mean rounding down AKA truncation AKA conversion to int
).
from math import sqrt
root_five = sqrt(5)
phi = (root_five + 1) / 2
def fibonacci(n):
return int((phi ** n) / root_five)
Note: only supports the normal fibonacci sequence, may or may not work for negatives.