How can we determine the number of magic squares with magic constant 0?
-
5$\begingroup$ What's the range, from which the square entries are taken? $\endgroup$– GamowMar 2, 2016 at 10:41
-
4$\begingroup$ Can you specify the properties you want your squares to have? Must the numbers be consecutive, what size may the squares be? $\endgroup$– frodoskywalkerMar 2, 2016 at 14:47
-
1$\begingroup$ Any odd order $n$ magic square using entries $1,2,3,\dots n^2$ can be adapted by subtracting $(n^2+1)/2$ from all entries to make a sum of $0$. There are many of them of any size greater than $3 \times 3$, even if you remove ones related by reflection/rotation. Please think about your question. $\endgroup$– Ross MillikanMar 3, 2016 at 0:25
2 Answers
There are an infinite number of such squares
Take the example square below:
-3 2 1
4 0 -4
-1 -2 3
To generate a new square, simply multiply each element of this square by any positive integer. As there are an infinite number of positive integers, there are an infinite number of possible squares.
-
1$\begingroup$ The same is true about negative numbers since you'd be just switching parity. Because there is a requirement that magic squares be comprised of unique numbers, you can't use
0
, but any non-zero integer would work. $\endgroup$ Mar 2, 2016 at 14:13 -
1$\begingroup$ To my knowledge, a magic square has to use the numbers n,n+1,...,m-1,m. For some integers n < m. This answer only works if you allow non-sequential numbers. $\endgroup$– LacklubMar 2, 2016 at 14:29
-
$\begingroup$ @Lacklub good point, I've asked for clarification. $\endgroup$ Mar 2, 2016 at 14:48
-
$\begingroup$ "a square that is divided into smaller squares, each containing a number, such that the figures in each vertical, horizontal, and diagonal row add up to the same value." There is no stipulation in any definition that I have seen that the entries must be sequential. $\endgroup$ Mar 2, 2016 at 15:00
-
$\begingroup$ @IanMacDonald Each containing a distinct number, right? Otherwise it's trivial. $\endgroup$ Mar 2, 2016 at 22:54
If you add a number $k$ to every element of a magic square, you get another magic square whose magic constant is the original constant plus $3k$. In particular, if you set $k$ to $-\frac 13$ of the original constant, you get a magic square whose constant is $0$. Thus every magic square induces one whose constant is $0$.
Now, for a square with constant $0$, if we name the following elements, $$\begin{matrix}x & y & \cdot\\\cdot & z & \cdot\\\cdot & \cdot & \cdot\end{matrix}$$ we can start filling in the other elements from the requirement all columns, rows and diagonals sum to $0$.
$$\begin{matrix}x & y & -x-y\\\cdot & z & \cdot\\\color{red}{w} & -y-z & -x-z\end{matrix}$$ With $w$, we run into an impasse: to make the diagonal $0$, we must have $w = x + y - z$, and to make the bottom row $0$, we must have $w = x + y + 2z$. These can both be realized only if $z = 0$. With that change, we can complete the pattern: $$\begin{matrix}x & y & -x-y\\-2x -y & 0 & 2x+y\\x + y & -y & -x\end{matrix}$$ By the definition quoted by Ian MacDonald, any $x$ and $y$ would work. But I've always understood that the numbers in a magic square should also be distinct (Wikipedia agrees). If we add that condition then we have a list of restrictions on the values of $x$ and $y$: $$x \ne 0, y \ne 0, y \ne kx\text{ for }k \in \{1, -\frac 12, -1, -\frac 32, -2, -3\}$$
If we do not consider rotations/reflections as separate squares, then these restrictions allow only one magic square that consists of consecutive integers, the one that frodoskywalker has already produced: $$\begin{matrix}1 & 2 & -3\\-4 & 0 & 4\\3 & -2 & -1\end{matrix}$$
If you do consider rotations and reflections as separate squares, then there are 8 possible squares, depending on which of the 4 corners the $1$ is in, and whether the $2$ is clockwise or counter-clockwise from it.
If you allow non-consecutive integers, or non-integers, then there are infinitely many solutions, even if you don't allow multiples like frodoskywalker mentions. Just choose a non-zero $x$, then choose any value for $y$ other than the 7 that are restricted (and also relatively prime to $x$, if you want to avoid multiples of other squares).
Addendum: why there is only one magic square with consecutive integers.
Any pattern with $x < 0$ is a rotation of $180^\circ$ from one with positive $x$, so we can assume $x > 0$. Further, if $|y| < x$, then $-x < y$, so $x < 2x + y = |-2x - y|$. So by flipping the square if needed, we can also assume $|y| > x$.
Now, the sum of all the numbers in a magic square is the sum of the values of all three rows, and therefore is 3 times the magic number, which in this case is $0$. The only 9 consecutive integers that sum up to $0$ are those between $-4$ and $4$. So all the elements in our square need to be in this range. In particular $|2x + y| \le 4$. Consider the cases:
- $x = 1$: $y \ne -2, -3$ by the restrictions, and $2x + y < 4$ gives $y \le 2$. So $y = 2$ and $y = -4$ are the only choices, and both give the same square.
- $x = 2$: $y \ne -1, -2, -3, -4$ by the restrictions, and $2x + y < 4$ gives $y < 0$, so there is no solution.
- $x = 3$: Since $|y| > x$, the only possibilities are $-4$ and $4$, but $2\cdot 1 + 4 > 4$, so it must be that $y = -4$, which gives the same pattern again.
- $x = 4$: $|y| > x$ cannot be satisfied.
Which exhausts all possibilities.
-
$\begingroup$ Here is magic square with 25 fields and a sum of 0: -2 11 -6 7 -10 -9 -1 12 -5 3 4 -8 0 8 -4 -3 5 -12 1 9 10 -7 6 -11 2 But I agree with your calculation for 3x3 squares $\endgroup$– EtoplayMar 3, 2016 at 13:01