fib
Three implementations of Fibonacci, side by side. The invariant is definitional: fib(n) is the same value regardless of which algorithm computes it, so the three columns must always agree.
- iterative – bottom-up, O(n) time, O(1) space. The one to use.
- recursive – naive top-down; O(phi^n). Capped at n=35 to avoid burning the browser tab. Useful only for showing the cost of the wrong algorithm.
- matrix – fast exponentiation of [[1 1] [1 0]]. O(log n) via divide-and-conquer.
The pure transforms live in wal-sh.tools.fib.core (host-neutral
.cljc). The browser adapter is wal-sh.tools.fib.browser. Build:
gmake tools-cljs; debug in isolation: gmake dev-tool TOOL=fib.