Tupper’s self-referential formula

\displaystyle{1\over 2} < \left\lfloor \mathrm{mod}\left(\left\lfloor {y \over 17} \right\rfloor 2^{-17 \lfloor x \rfloor - \mathrm{mod}(\lfloor y\rfloor, 17)},2\right)\right\rfloor

Tupper’s self-referential formula is a neat little math formula that when graphed over a certain (x, y) range will produce a graph that visually looks like the formula itself. To be specific, graphing the points (x, y-n) for all points that satisfy the inequality in the range of 0 \le x \le 106 and n \le y \le n+16 where n is equal to:


will result in the image:

Tupper's self-referential formula

While at first this sounds quite spectacular, it’s actually a bit of a trick: the formula itself is a general purpose method of graphing a monochromatic (two color) bitmap (specifically a bitmap that is 17 pixels in height). The range of y values start at a very large integer – an integer that is actually a representation of a bitmap of the formula.

I wrote a program using OCaml that can graph Tupper’s self-referential formula. I generalized it so that you can specify the integer-bitmap and the width and height of the image. I also wrote a Perl script that will convert an image into an integer representation of the image. The image doesn’t have to be monochromatic, but the Perl script will treat all non-black colors as if they are white. Only pure black is considered. The script requires the PerlMagick library. The Perl script expects the location of the image as a command line argument.

To compile the OCaml program on GNU/Linux (or other POSIX OS) you just need to run make. If that doesn’t work, or you are on a non-POSIX OS you can try to run:

ocamlopt -o tupper graphics.cmxa nums.cmxa tupper.ml

The program optionally takes three command line arguments – a value for n (the integer-bitmap), the width and the height. As it so happens, the Perl script will output those three values to the standard output meaning you can run the program like this:

./tupper `perl img_to_tupper.pl example.png`

Without any arguments it defaults to displaying the formula.

Download the source