Tupper's self-referential formula
Tags: #calc #commonlisp #elisp #math
Tupper’s self-referential formula plots itself. On a 106×17 screen, blackening the pixels (x,y) that satisfy the inequality below traces… the same inequality.


The trick hides in the lower bound of y — a 540-digit integer k that encodes the picture.
The only real difficulty of a Tupper implementation is therefore handling a 540-digit integer. Any language with native bignums reduces the program to a direct transcription of the inequality. That is what we did in Common Lisp, Emacs Lisp and GNU Emacs Calc.
cl-problem-solving — SBCL’s native bignums make the formula a twelve-line loop:
(defun tupper ()
(loop with n = 96093937991895888... ; 540 digits
for y from n below (+ n 17)
do (loop for x from (- 106 1) downto 0
do (if (< 0.5 (floor (mod (/ (floor y 17)
(expt 2 (+ (* 17 x) (mod y 17))))
2)))
(write-char #\#)
(write-char #\Space)))
(write-char #\Newline)))The version is also published on Rosetta Code.
elisp-problem-solving — Emacs has had built-in bignums since version 27, so the Elisp version reads almost identically. M-x tupper paints the picture into the current buffer at point, with insert in place of write-char.
calc-problem-solving — Emacs Calc also supports arbitrary-precision integers, but inside a very different programming model. No defun, no named variables — the formula becomes a keystroke macro operating on a stack, with Z{ ... Z} for loops. The same inequality comes out, only written in a notation that a 1980s RPN calculator would recognize.