Im trying to make a function that finds the length of a fibonacci sequence based upon its sum
I know $\sum f_n = f_{n+2} + f_2$
I know $f_n = \cfrac{\varphi^n-({-\varphi})^n}{\sqrt 5}$
so, $\sum f_n = \cfrac{\varphi^{n+2}-({-\varphi})^{-(n+2)}}{\sqrt 5}+1$
but, I need to rearrange it to isolate $n$
or, more generally, solve for $x$ in $z = p^x - ({-p})^{-x}$
also would this be computationally sound compared to generating the fib sequence until its total exceeds the target sum?
ie
def findTerm(sum):
lastlast = 1
last = 0
n = 0
while 0 <= lamb:
next = last + lastlast
lastlast = last
last = next
sum -= next
n += 1
return n - 1