Happy Birthday!


Real-time refresh

Let the number above be k, plot the graph for in the range x = [0, 106) and y = [k, k+17), and you have your birthday wishes!

This is called Tupper’s self-referential formula. You may copy the original k that I put below to see why it is called a self-referntial formula. As a matter of fact, if you plot the graph for y = [0, ∞), you will get every 17 by 106 pixel map possible.

Some constants…

Tupper's Self-Referential Formula


Happy Birthday


How it works

Actually, the plotting code doesn’t really evaluate that inequality. Since and are real numbers, it is impossible for computers to plot the graph directly. (There are workarounds though, read till the end.) However, firstly we can observe that and are floored so that you may choose and as integers, reducing the computation to 1926 times.

Still, this doesn’t explain why this formula maps a pixel map to an integer. We should look into the formula’s true intention.

Step 1: Simplify the formula

${1 \over 2} < {\lfloor x \rfloor}$ is the same as $1 <= {\lfloor x \rfloor}$ since the floor function returns only integers.

Let $y=17m+n$ so that we can simplify $\lfloor {y \over 17} \rfloor$ as $m$, rewrite the formula as

Step 2: Get the idea

  1. If we take a binary number $b$, divide it by $2^e$, we basically moved $b$ to the right by $e$ bits. (See Bitwise Operation)

  2. If we take a binary number $b$, mod it by $k$, we obtain its rightmost digit, which is either 0 or 1 by the definition of binary representation.

Observe $\mathrm{mod} \left(\frac{m}{2^{17x+n}}, 2 \right)$, based on the two conclusions above, it is equivalent to retrieving the $(17x+n)^{th}$ bit of $m$ (counting from the rightmost digit).

Step 3: Conclude

Then the formula means the $(17x+n)^{th}$ bit of $m$ is 1 (binary digits can only be 0 or 1). If we want to make $(x,n)$ a black pixel in the graph, we put a 1 on the $(17x+n)^{th}$ bit of $m$, do the same thing for all combinations of $(x,n)$ to come up with an $m$.

In human language Draw a grid of 18*107, read vertically from bottom to top, from left to right. If you meet a black pixel, put a 1 to the left of your number, otherwise put a 0.

The $K$ that you want is $m * 17$. (Why?)

Hint How do we define $m$? If $i$ is a multiple of 17, does $j \in [0, 17)$ change the value of $\lfloor{ {i+j} \over 17 }\rfloor$?

This is the original paper Reliable Two-Dimensional Graphing Methods for Mathematical Formulae with Two Free Variables written by Jeff Tupper. He proposed this formula to validate a plotting technique to handle flooring and ceiling operations in functions. You may check it out.

Making of this post

This post is made possible with the help these resources:

Tupper’s Formula Tools: helped me understand how the formula works, and how to plot it with respect to K.

MathJax: use this to render beautiful math expressions on any browser.

Confetti.js: made the confetti effect on the top^^