Dürer's engraving titled *Melencolia* or *Melancholia* is one of his best-known, and most enigmatic,
works.

Part of this picture is the 4-by-4 square on the wall behind the angel.

In the first display, these numbers are reproduced in more modern style. Each row, each column, and each diagonal adds up to 34; these are the traditional magic properties. But there is more magic to be found here. There are actually thirteen different ways of dividing this square into four groups of four cells, with each group of four cells adding to 34. The control in the display can be used to select among these. If you press the mouse button on one of the cells, then the numbers in its group will be enlarged and highlighted in red. The highlighting goes away when the button is lifted.

These groupings of cells are not arbitrary. The positions in the Dürer square can be seen as a finite vector space, in which each set of four groups of four cells is a set of parallel affine subspaces.

The contents of the cells are also related to the vector-space structure.
To make this relationship explicit, we take three steps:

- subtract 1 from each number, so that the square is filled with numbers in the range 0 .. 15;
- represent each number in base 2 or "binary" form;
- consider the respective positions in the binary representations independently of one another.

At the upper right is a control with which you can choose to view the square as decimal numbers from 1 to 16, decimal numbers from 0 to 15, or binary numbers from 0000 to 1111. When you make the third choice, you can also view the bits at a particular position in each binary number; for instance, the 8's bits in each cell. When you choose a position, the bits in that position are enlarged and highlighted in red, and a copy of them is shown in a smaller square.

For each bit position, there is a different distribution of 0's and 1's.
Each distribution has the "magic" property, that it gives the same sum (namely, 2) on each of the rows, columns,
diagonals, and other groupings that we saw in the previous applet.
Because the sums are equal for each bit position, the sums are equal for the numbers in the original square.
The distributions of 0's and 1's are of a very particular kind.
In fact, each one is an *affine function* on the vector space of positions.
On other pages are an explanation and demonstration of
affine functions, and an explanation of how they can be used to make
magic squares.