fibonacci sock almost ruined my date

APR 05, 2026

inkhaven


click here to skip to the math.

finding the sock


My partner and I were on a date in Sausalito, a quiet seaside town north of the Bay, when we came across this sock (at a sock store).

fibonacci sock
we may have gotten extremely distracted and forgotten to take a photo of the sock in the store. please accept this stock photo instead.1

I personally assume that all code on clothing is nonsense until proven otherwise, so I got ready to make a joke about it, except that this program…actually does something.

Here, take a look:

1fn main() {
2	let root = 5_F32.0;
3	let phi = (1.0 + root)/2;
4	for n in 0.16 {
5		print!('{}', (phi.pow(n)/root).round());
6	}
7}
8

As we've hinted at in the title, this program computes the first 16 Fibonacci numbers (in Rust!). These are the numbers you get when you start with terms 11 and 11 (or sometimes 00 and 11) and add the previous two terms to get the next term. You can see that the program output across the back of the ankle,

1,1,2,3,5,81, 1, 2, 3, 5, 8\dots

is indeed the first couple of terms of the Fibonacci sequence.

To compute these numbers, the program is using something called Binet's formula.2 Binet's formula says that the nnth Fibonacci number is

Fn=ϕnϕˉn5,F_{n}=\frac{\phi^n-\bar\phi^n}{\sqrt{5}},

where

ϕ=1+52,ϕˉ=152.\phi = \frac{1+\sqrt{5}}{2}, \quad \bar\phi=\frac{1-\sqrt{5}}{2}.

It was pretty easy to get here with a quick Wikipedia search, after which I tried very hard to be like "well, that's cool and all, I guess I'll update my priors about code on apparel, but now we can move on…"

except that my brain was like...!!! where does this formula come from???? what does it all mean???? And despite the romantic vibe and beautiful seaside view, I was not able to let it go.

nerd-sniped


The idea goes something like this: we know that the Fibonacci numbers F0,F1,F2F_{0}, F_{1},F_2\dots satisfy the recurrence relation

Fn=Fn1+Fn2()F_{n}= F_{n-1} + F_{n-2} \quad({\color{red}{*}})

with the initial conditions

F0=0,F1=1.()F_{0}= 0, \quad F_{1}= 1. \quad({\color{blue}\star})

Here's the general plan:

  1. Do some guessing to find a family of sequences that satisfies the recurrence relation in ()({\color{red}{*}}).
  2. Hope that one of them satisfies the initial conditions in ()({\color{blue}\star}).

We know that the Fibonacci sequence grows at least exponentially, since the sequence more than doubles every two terms. So let's try guessing3 that some exponential sequence satisfies the relation in ()({\color{red}{*}}), say sn=cxns_{n}= cx^n where cc and xx are fixed real numbers. Then ()({\color{red}{*}}) says that

sn=sn1+sn2,s_{n}= s_{n-1} + s_{n-2},

which means that

cxn=cxn1+cxn2.cx^{n}=cx^{n-1}+cx^{n-2}.

Then we know that either c=0c=0, or

x2x1=0.x^{2}-x-1=0.

This polynomial4 might look familiar to you. Indeed,

ϕ=1+52,ϕˉ=152\phi = \frac{1+\sqrt{5}}{2}, \quad \bar\phi=\frac{1-\sqrt{5}}{2}

are its roots! This means we actually have two families of sequences satisfy the Fibonacci relation in ()({\color{red}{*}}). These are

tn=c1ϕn and tˉn=c2ϕˉn,t_{n}= c_{1}\phi^{n} \quad \text{ and } \quad \bar t_{n}=c_2\bar\phi^n,

where c1,c2c_{1},c_2 are some constants.

We also easily check that the sum of the two,

fn=tn+tˉn=c1ϕn+c2ϕˉnf_{n}= t_{n}+\bar t_{n} = c_{1}\phi^{n} + c_{2}\bar \phi^{n}

also satisfies the relation in ()({\color{red}{*}}).

Now that we've got a nice family of sequences that satisfy ()({\color{red}{*}}), let's see if any of them satisfy the initial conditions in ()({\color{blue}\star}). We should have that

f0=c1ϕ0+c2ϕˉ0=0f_{0}=c_{1}\phi^0+c_2\bar{\phi}^{0}= 0

and

f1=c1ϕ1+c2ϕˉ1=1.f_1=c_1\phi^1+c_2\bar{\phi}^{1}= 1.

Simplifying a bit, we see that

c1+c2=0c_1+c_{2}=0

and

c1ϕ+c2ϕˉ=1.c_{1}\phi+ c_{2}\bar \phi =1.

We can solve this system of equations, and we get that

c1=15,c2=15.c_{1}= \frac{1}{\sqrt{5}}, \quad c_{2}= -\frac{1}{\sqrt{5}}.

Plugging it all back in, we see that the sequence

fn=15ϕn15ϕˉn=ϕnϕˉn5f_{n}= \frac{1}{\sqrt{5}}\phi^{n}-\frac{1}{\sqrt{5}} \bar\phi^{n}= \frac{\phi^{n}- \bar{\phi}^n}{\sqrt 5}

satisfies the recurrence relation in ()({\color{red}{*}}) and the initial conditions in ()({\color{blue}\star}). That means that this sequence is the sequence of Fibonacci numbers! So we win, and this is why Binet's formula works!5

Getting here took a lot of animated yapping, and I imagine that everyone around thought that we were crazy. But hey, I understood it eventually, and the date wasn't even ruined! We got some ice cream, watched some boats, and managed not to miss the sunset.

e, thanks for telling me to write this.

footnotes


  1. I spent far too long finding this photo because it turns out that searching "Binet's formula code sock" doesn't exactly work. I went to the sock store's Google Maps page and found the name of a company that make these novelty socks (it was the wrong one), realized I could google "novelty socks" and visited a couple novelty sock websites, continued looking until I realized that I probably should have tried "Fibonacci code sock", and finally tracked it down.

  2. Though, the program ignores the ϕˉn\bar\phi^n term because ϕˉ0.618\bar\phi\approx -0.618 is small enough to safely ignore if you're rounding to the nearest integer.

  3. à la solving differential equations

  4. This polynomial is called the characteristic polynomial of the linear recurrence relation.

  5. Of course, this is not the only way to get to Binet's formula. I personally like the linear algebra approach better, where you can see that ϕ\phi and ϕˉ\bar{\phi} are the eigenvalues of the matrix corresponding to the recurrence relation.

kaylee kim


made with


back to top