Magical Fibonacci Formulae

This web content presents a Python function that computes the Fibonacci sequence without using loops, recursion, or floating point arithmetic. The function f=lambda n:(b:=2<<n)**n*b//(b*b-b-1)%b is provided as an example and indeed generates the correct Fibonacci sequence. The content then delves into the concept of generating functions and how they can be used to represent the Fibonacci sequence. A closed form expression for the Fibonacci numbers, known as Binet's formula, is derived and presented using the golden ratio. The use of generating functions to evaluate the Fibonacci numbers is discussed, and a method involving flooring and modulo operations is proposed to extract the Fibonacci numbers from the generating function. Finally, a closed form expression for computing the Fibonacci numbers using the base of a chosen number is introduced, and a golfed version of the function is provided using Python's "walrus operator." The content concludes with the demonstration of the function's ability to generate the Fibonacci sequence.

https://orlp.net/blog/magical-fibonacci-formulae/

To top