this post was submitted on 09 Nov 2025
493 points (97.1% liked)

Lifehacks

206 readers
271 users here now

Efficiency in all walks of life.

founded 1 year ago
MODERATORS
you are viewing a single comment's thread
view the rest of the comments
[–] ExperimentalGuy@programming.dev 20 points 1 day ago (1 children)

This is such a cool example of how some recursive algorithms have a closed form. We all know that there's a simple equation to plug miles into to get kilometers, but we don't talk about how the Fibonacci sequence has a closed form. This is so cool.

[–] angrystego@lemmy.world 6 points 16 hours ago (1 children)

Wjat does closed form mean? Asking as a stupid botanist, sorry.

[–] WolfLink@sh.itjust.works 5 points 12 hours ago* (last edited 12 hours ago)

Closed form means it can be written out as a specific, finite set of instructions that work the same regardless of what the input to your function is.

For Fibonacci, it is most commonly defined in its recursive form:

f(0) = 0
f(1) = 1
f(x) = f(x-1) + f(x-2) for integer x > 1

But using this form, computing a very large Fibonacci number requires computing all the numbers before it, so it’s not the same finite set of instructions for every number, it takes more computation to generate larger numbers.

However, there is a closed form formula for generating Fibonacci numbers. Using this formula, you can directly compute any large Fibonacci number without having to compute all those intermediate steps. It takes the same amount of work to compute any Fibonacci number.

f(x) = (a^x - b^x)/√5
a = (1+√5)/2
b = (1-√5)/2

(Note that a and b here are constants; I only wrote them separately to avoid a mess of nested parenthesis)

For an example of something that doesn’t have a closed form, we do not know of a closed form for generating prime numbers. There are several known algorithms for generating the nth prime number, but they all depend on computing all the previous prime numbers, making it very difficult to compute very large prime numbers (in fact, how generating large primes is actually done is by making an educated guess and then checking that it’s actually prime). Discovering a closed form formula for prime numbers would have a huge impact on mathematics and cryptography.