The rows, columns, diagonals, and other "magic" features of Dürer's square
can be seen to be affine subspaces or ** "flats"**, naturally
sorted into groups of four parallels.
It is not surprising that the rows and columns are two groups of parallel flats.
One may feel surprised that the two diagonals are parallel, and that the other two flats parallel to them are what we
usually call the "short broken diagonals."
The "long broken diagonals" are another family of parallel flats.

A magic square is called"pandiagonal" if each of its broken diagonals adds up to the magic sum. If a 4x4 magic square is magic on short broken diagonals but not on the long broken diagonals, it is called "semi-pandiagonal." The 4x4 magic squares that are pandiagonal or semi-pandiagonal are an interesting set; following Kraitchik (p. 187), I will call them "algebraic magic squares."

In a square modeled by **F**_{p}^{2m} , the diagonals have a different
structure depending on whether *p* is *2* or an odd prime.
In the case *p=2*, as we have seen, the two diagonals are parallel flats.
If *p* is odd, however, they are flats but they are not parallel.
Indeed, they intersect at the central cell of the square.
We shall see that this has a mixed effect on the construction of affine magic squares.

Looking at the Dürer square, we see that each base-*p* digit is
determined by an affine function, which is non-constant on the first row,
the first column, and the main diagonal.
This fact is what makes the Dürer square magic.
Why? Because an affine function which is non-constant on a linear subspace must take every possible value equally often on
that subspace; in this case, it takes the values *0* and *1* two times each.
Moreover, it has the same distribution of values on every parallel flat.
Therefore, it makes a uniform contribution to the sums over all of those parallel flats.

For a magic square, we want the values in the square to include *0*, ..., *p ^{2m}-1*, without
omissions or repetition.
We can have this, if the linear parts of the digit coordinates are linearly independent.
So we make this definition:

An affine map on **F**_{p}^{2m} is nonsingular if and only if it maps
**F**_{p}^{2m} onto itself in a one-to-one way.

As we saw from the example of the Dürer square, we achieve the magic uniformity of sums of values over parallel subspaces by making the affine functions non-constant on those subspaces. Therefore we make this definition:

Note that if an affine map is uniform on **E** then, on every affine subspace parallel to
**E**, every component of the map takes each of the values
0, ..., p-1 equally often.

The first column of the square corresponds to the linear subspace spanned by
{e_{0} ,..., e_{m-1}},
and the first row corresponds to the linear subspace spanned by
{e_{m} ,..., e_{2m-1}}.
The main diagonal corresponds to the linear subspace spanned by
{e_{0}+e_{m} ,...,
e_{m-1}+e_{2m-1}}.
The other diagonal does not correspond to a linear subspace, but to an affine subspace which is parallel to the linear
subspace spanned by {e_{0}-e_{m}
,..., e_{m-1}-e_{2m-1}}.
Here we find a considerable difference between the cases *p = 2* and * p > 2*.
When *p = 2*, the secondary diagonal is parallel to the main diagonal.
When *p > 2*, however, the diagonals are not parallel; indeed, they intersect.
Thus the definition of an affine magic square imposes four conditions on each content coordinate when *p > 2*, but
only three conditions when *p = 2*.
This makes the construction of affine magic squares more difficult when *p > 2*.

When *p > 2*, we can impose a looser condition on the digit coordinates and still construct magic squares.
If a digit function is constant on a diagonal subspace, then it will have different sums on the different affine subspaces
parallel to that subspace.
But we can choose the constant part of the affine function so that the digit coordinate will have the value
(p - 1)/2 at the central position; then this digit coordinate will contribute just the right
amount to the sum along each diagonal.
This leads us to the following definition.

(a) it is nonconstant on the linear subspace corresponding to the main diagonal, or

(b) *p > 2* and A_{i} takes the value (p - 1)/2 at
the vector ((p-1)/2 ,..., (p-1)/2), which corresponds to the central cell of the square.

Below is an interactive display to construct affine squares.
At the top are controls to select the values of *p* and *m*, as for the displays on the
Finite Vector Spaces page.
These will affect the size of a rectangular array in which you can specify the content coordinates.
The square will be filled in whenever the content coordinates are completely specified.

Each content coordinate is controlled by a column in the array. It presents controls in which you can select the constant
part and the value of the linear part at each of the basis vectors
{e_{0} ,..., e_{2m-1}}.
Initially each of these values is indeterminate, represented by a dash.

If there is a linear relation between the linear parts of the content coordinates, then the affine square is singular. The display will warn you of this by reddening the labels of a set of coordinates that are related. In general, there might be several such sets; the display finds one whose rightmost member is as far to the left as possible.

If the linear part of a content coordinate is zero on either {e_{0} ,...,
e_{m-1}} or {e_{m} ,...,
e_{2m-1}}, then the display puts a pale yellow background on that part of the array
for this coordinate.
Below the array of controls, there is an array of cells which show the values of the linear parts on
{e_{0}+e_{m-1} ,...,
e_{m}+e_{2m-1}},
and light these up if they are all zero for a content coordinate.
If *p > 2*, then there is a similar array for {e_{0}-
e_{m-1} ,..., e_{m}-
e_{2m-1}}.

If *p > 2*, then one may choose the constant part of a content coordinate so as to give the function the value
(p - 1)/2 at the central cell of the square.
The display provides for this option by a "*" in the control corresponding to the constant part of the coordinate.
When you choose the "*", and the linear part is fully determined, then the appropriate value is filled in, with a pale
green background.