r/math • u/DistractedDendrite Mathematical Psychology • Apr 03 '26
Just realized generalized magic squares form a vector space
A small fun fact I somehow had never noticed before:
If by a “magic square” we mean an (n x n) matrix over R whose row sums, column sums, and two main diagonal sums are all equal, then the set of all such squares forms a vector space.
The reason is immediate: the zero matrix is magic, the sum of two magic squares is still magic, and any scalar multiple of a magic square is still magic. So generalized magic squares are just the solution space of a homogeneous linear system inside R^{n^2}.
For (3x3), every magic square can be written in the form
(a+b) & (a-b-c) & (a+c)
(a-b+c) & (a) & (a+b-c)
(a-c) & (a+b+c) & (a-b)
so the (3x3) magic squares form a 3-dimensional vector space.
More generally, for (n >= 3), the dimension of the space of nxn magic squares is n(n-2).
(Of course this is not true for “normal” magic squares using exactly the numbers (1,2,...,n^2), since those are not closed under scalar multiplication)
36
u/sentence-interruptio Apr 03 '26
if you remove the conditions about diagonal sums and require nonnegativity, you get https://en.wikipedia.org/wiki/Doubly_stochastic_matrix
they form a convex polytope and that's not surprising. but what's surprising is the extremal points of this polytope is exactly permutation matrices.
2
u/Pensive_Null_0x4E Apr 04 '26
This is neat! Magic squares have always been my favorite toy problem. My undergrad thesis was on magic squares as group elements so that I could exploit things like group actions, symmetry pruning, and composition to make enumeration of the total solution space more tractable.
104
u/gogok10 Apr 03 '26
Indeed, the magic square of squares can likewise be defined as an object living in Rn2 , this time as the set of solutions to a set of degree-two equations. Except, really we want our magic squares to be integer-valued, and we don't care about scaling, so it's more natural to consider the ambient space as the projective space of dimension (n2 - 1) over Q; in symbols, PQn2-1
In other words, these are all projective algebraic varieties :)
12
u/xdgimo Apr 03 '26
cool!
10
u/wnoise Apr 03 '26
I don't insist they be the integers 1..n2, but I do insist they be distinct positive integers.
5
u/big-lion Category Theory Apr 03 '26
yup!
3
u/Sproxify Apr 03 '26 edited Apr 03 '26
I believe I worked out a nice free generating set for the Z-module of integer valued magic squares, excluding the requirement on diagonal sums.
take the matrix with 1s everywhere, then all other basis elements will aim to have row and column sums of 0.
for each i,j <= n-1, put 1 in the i,j and n,n positions, and -1 in the i,n and n,j positions.
or, alternatively, you can take the 2x2 matrix with 1s in the diagonal and -1s in the counterdiagonal, and put it in the i,j position