Uniform step magic hyper-squares

Livinus U. Uko1
1Mathematics Department, Georgia Gwinnett College, Lawrenceville, GA, USA

Abstract

Given any integers \(q\ge 2\) and \(p\ge 3\), a multidimensional array \[[m(i_1,i_2, \dots, i_q)\colon 1\le i_1\le p, \dots , 1\le i_q\le p],\] with non-repeated entries from the set \(\{1,2,\dots, p^q\}\) will be called a \(q\) dimensional magic hyper-square of order \(p\) if the sum of the numbers in any of its axes or diagonals is \(p(p^q+1)/2\). In this paper, we study odd-order uniform step magic hyper-squares of the form \[m(i_1, \dots, i_q)=1+\sum\limits_{j=1}^{q} p^{j-1}\left[\left(\sum\limits_{k=1}^qa_{j,k} i_k+d_j\right) \bmod p \right] .\] We derive necessary and sufficient conditions for these coefficients to generate magic hyper-squares and use a specific choice of coefficients to get new formula that generates magic hyper-squares of all odd orders greater than two.

Keywords: magic square, magic cube, magic hypercube, magic p-dimensional cube, magic tesseract, multi-dimensional magic cube, magic hyper-square, generalized vector product

1. Introduction

Given whole numbers \(q\ge 2\) and \(p\ge 3\) and a \(q\) dimensional integer array \[M=[m(i_1, \dots, i_q)\colon i_1=1,\dots,p, \dots , i_q=1,\dots, p] \label{m}, \tag{1}\] of degree \(p\), an axis of \(M\) is a one-dimensional sub-array consisting of \(p\) entries of \(M\) with identical coordinates in \(q-1\) places, and a diagonal of \(M\) is a sub-array of the form \[[m(n_1(i), \dots, n_q(i))\colon i=1,\dots, p],\] where \[n_r(i)\stackrel{\rm def}{=}\begin{cases}i, & {\rm\ if \ }r\in S {\rm\ or \ }r=1, \\ p+1-i,& {\rm\ if \ }r\not \in S ,\end{cases}\label{nr} \tag{2}\] and \(S\) is a subset of the set \(\{2,\dots, q\}\). The array will be called a \(q\) dimensional magic hyper-square of order \(p\) if it has non-repeated entries from the set \(\{1,2,\dots, p^q\}\) and the sum of the numbers in any of its \(qp^{q-1}\) axes or \(2^{q-1}\) diagonals is \(p(p^q+1)/2\). Arrays of this kind are usually referred to (cf. [1, 3, 5, 6, 12, 17, 18, 19]) as \(q\)-dimensional magic cubes of order \(p\). However, since these are generalizations of the basic concept of magic square, we prefer to call them magic hyper-squares, to avoid the oddity of regarding squares as two-dimensional cubes.

Magic hyper-squares of dimensions 2, 3 or 4 are called, respectively, magic squares, magic cubes or magic tesseracts. Magic squares originated from China and appear in post 2100 BC Chinese texts, post 8\({}^{\rm th}\) century AD Islamic texts, and post renaissance European texts. They, together with magic cubes and magic tesseracts have, for several centuries, been sources of mathematical recreations and challenges for large numbers of math enthusiasts. Different types of magic hyper-squares and some methods for constructing them can be found in the publications [2, 3, 4, 8, 9, 10, 11, 12, 13, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24].

In the sequel, for any \(k\in \{2,3,4, \dots \}\), we will adopt the notations \[\begin{aligned} \mathbb{N}_k&\stackrel{\rm def}{=}\{1,2,\dots, k\}, \\ \mathbb{Z}_k&\stackrel{\rm def}{=}\{0,1,\dots, k-1\}, \\ \mathbb{W}_k&\stackrel{\rm def}{=}\{2,\dots, k\}. \end{aligned}\]

Given integers \(a\) and \(b\), \(a\) mod \(b\) and \((a,b)\) will designate, respectively, the remainder when \(b\) divides \(a\), and the greatest common factor of \(a\) and \(b\).

By an analogy with the magic squares correspondences established in [22], we will say that the \(q\) dimensional magic hyper-square (1) of order \(p\) is of the uniform step kind if its entries can be expressed in the form \[m(i_1, \dots, i_q)=1+\sum\limits_{j=1}^{q} p^{j-1}\left[\left(\sum\limits_{k=1}^qa_{j,k} i_k+d_j\right) mod p \right], \label{mhypersquare} \tag{3}\] with coefficients \(\{a_{j,k}\colon j,\, k\in\mathbb{N}_q\}\subseteq \mathbb{N}_p\) and \(\{d_j\colon j\in\mathbb{N}_q\}\subseteq\mathbb{Z}\). In Section 3 below we will derive necessary and sufficient conditions for these coefficients to generate magic hyper-squares, and use a specific choice of coefficients to derive a new magic hyper-squares generation formula. Section 2 contains prerequisite concepts and results which will be used in Section 3.

2. Auxiliary concepts and results

Let \(\mathbb{R}^q\) be the set of \(q\)-tuples of row vectors of real numbers, and for \(i\in \mathbb{N}_q\), let \( {e}_i\) be the standard basis vector in \(\mathbb{R}^q\) with 1 on its \(i\)-th coordinate and zeros elsewhere. Given any collection \( {b}_1\), …, \( {b}_s\) of vectors in \(\mathbb{R}^s\), let \(g( {b}_1, … , {b}_s)\) designate the determinant of their \(s\times s\) Gramian matrix \(G\) having \( {b}_i\cdot {b}_j\) as its \(i\)\(j\)th entry, and let \(\Delta ( {b}_1, … , {b}_s)\) denote the determinant of the \(s\times s\) matrix \(B\) having \( {b}_i\cdot {e}_j\) as its \(i\)\(j\)th entry. The following well known result relates the two concepts and will be useful in the sequel.

Lemma 2.1. The equation \[g( {b}_1, … , {b}_s)=\Delta ( {b}_1, … , {b}_s)^2,\label{g=d^2} \tag{4}\] holds for all \(( {b}_1, \dots, {b}_s)\) in \(\mathbb{R}^s\).

Proof. If we set \( {b}_i=\sum\limits_{k=1}^sb_{i,k} {e}_k\), we see that \[ {b}_i\cdot {b}_j= \sum\limits_{k=1}^s\sum\limits_{r=1}^s b_{i,k}b_{j,r} {e}_k\cdot {e}_r =\sum\limits_{k=1}^sb_{i,k}b_{j,k},\] and hence that \(G=BB^{\text{T}}\) and \[g( {b}_1, … , {b}_s)=\det(G)=\det (BB^{\text{T}})=(\det B)^2=\Delta ( {b}_1, … , {b}_s)^2.\] ◻

The generalized vector product was defined and analyzed in [14] using the concepts of exterior products and duality. We adopt a more elementary definition of the product here and supply simpler proofs of the properties that are used in this paper.

Given a vector \( {a}\) in \(\mathbb{R}^2\), we define its crossed vector in the form: \[ {a}^\times \stackrel{\rm def}{=}\begin{vmatrix} {e}_1\cdot {a}& {e}_2\cdot {a}\\ {e}_1& {e}_2 \end{vmatrix}= ( {e}_1\cdot {a}) {e}_2-( {e}_2\cdot {a}) {e}_1.\]

The basic properties of this operator are the identities \( {a}^{\times} \cdot {a}={ 0}\), \(\| {a}^{\times}\|=\| {a}\|\) and \(( {a}^{\times} )^{\times }= – {a}\).

In the case with \(q>2\), we define the vector product of \(q-1\) vectors in \(\mathbb{R}^q\) with the formula \[ {a}_1\times … \times {a}_{q-1}\stackrel{\rm def}{=} \begin{vmatrix} {e}_1\cdot {a}_1 & … & {e}_q\cdot {a}_1\\ \vdots & \vdots& \vdots \\ {e}_1\cdot {a}_{q-1}& … & {e}_q\cdot {a}_{q-1}\\ {e}_1 & … & {e}_q\end{vmatrix}.\]

We observe that \( {a}_k\cdot ( {a}_1\times … \times {a}_{q-1})=0\) for \(k\)=1, …, \(q-1\), and that this vector product coincides with the usual three dimensional vector product when \(q=3\).

The following result follows directly from these definitions.

Lemma 2.2.The equations>

\[ \begin{align} a_1\times … \times a_{q-1}\cdot a_q&=\Delta(a_1,\dots,a_q),\label{p1}\\ a_1\times\dots\xcancel{a_i} \dots\times a_q \cdot a_i &=(-1)^{q-i} \Delta(a_1,\dots,a_q),\label{p2} \end{align}\]

hold for all \( {a}_1, \dots, {a}_q\) in \(\mathbb{R}^q\) and \(i\in \mathbb{N}_q\), with the cancellation indicating an omitted vector.

Proof. It follows from the definition of the vector product that \[\begin{aligned} {a}_1\times … \times {a}_{q-1}\cdot {a}_q &=\begin{vmatrix} {e}_1\cdot {a}_1 & … & {e}_q\cdot {a}_1\\ \vdots & \vdots& \vdots \\ {e}_1\cdot {a}_{q-1}& … & {e}_q\cdot {a}_{q-1}\\ {e}_1 & … & {e}_q \end{vmatrix} \cdot {a}_q\\ &=\begin{vmatrix} {e}_1\cdot {a}_1 & … & {e}_q\cdot {a}_1\\ \vdots & \vdots& \vdots \\ {e}_1\cdot {a}_{q-1}& … & {e}_n\cdot {a}_{q-1}\\ {e}_1\cdot {a}_{q}& … & {e}_n\cdot {a}_{q}\\ \end{vmatrix} = \Delta( {a}_1,\dots, {a}_q) , \end{aligned}\] which proves Eq. (5).

Eq. (6) follows immediately from (5) on interchanging rows in the determinants above and changing signs accordingly. ◻

The next result relates the vector product and the Gramian determinant.

Lemma 2.3. The equation \[g( {a}_1,\dots, {a}_{q-1})= \| {a}_1\times … \times {a}_{q-1}\|^2, \label{eqn0} \tag{7}\] holds for all \(( {a}_1, \dots, {a}_{q-1})\) in \(\mathbb{R}^{q-1}\).

Proof. If the vectors \( {a}_1\), …, \( {a}_{q-1}\) are linearly dependent, then it follows from Lemma 2.1 and the definition of the vector product that both sides of Eq. (7) are zeros. The equation also holds trivially when \(q=2\) or \(q=3\). We therefore suppose in the rest of the proof that these vectors are linearly independent and that \(q\ge 3\).

If we set \( {a}_q= {a}_1\times … \times {a}_{q-1}\), then it follows from Lemmas 2.1 and 2.2 that \[\begin{aligned} \| {a}_q\|^4&=( {a}_1\times … \times {a}_{q-1}\cdot {a}_q)^2\\ &=\Delta( {a}_1,\dots, {a}_q)^2= g( {a}_1,\dots, {a}_q)\\ &= \begin{vmatrix} {a}_1\cdot {a}_1 & … & {a}_1\cdot {a}_{q-1} & {a}_1\cdot {a}_q\\ \vdots & \vdots& \vdots & \vdots \\ {a}_{q-1}\cdot {a}_1& … & {a}_{q-1}\cdot {a}_{q-1} & {a}_{q-1}\cdot {a}_q\\ {a}_q\cdot {a}_1& … & {a}_q\cdot {a}_{q-1} & {a}_{q}\cdot {a}_q\\ \end{vmatrix}\\ &= \begin{vmatrix} {a}_1\cdot {a}_1 & … & {a}_1\cdot {a}_{q-1} & 0\\ \vdots & \vdots& \vdots & \vdots \\ {a}_{q-1}\cdot {a}_1& … & {a}_{q-1}\cdot {a}_{q-1} &0\\ 0& … & 0 & {a}_{q}\cdot {a}_q\\ \\ \end{vmatrix} \\ &= \| {a}_q\|^2 g( {a}_1,\dots, {a}_{q-1}), \end{aligned}\] which implies Eq. (7). ◻

The next three results will be used in the sequel to derive conditions on the coefficients for the uniform step formula (3) to generate \(q\) dimensional magic hyper-squares of odd order \(p\).

Lemma 2.4(from [7]).Let \(\theta\in \mathbb{Z}\). Then the Diophantine equation \[\theta z\equiv b \pmod p,\] has one unique solution \(z\in \mathbb{N}_p\) associated with each integer \(b\) if and only if \((p,\theta)=1\).

Proposition 2.5. Let \(p\) be a positive odd number, let \(q\) and \(z\) be any integers and let \(alpha=(p,q)\) and \(u=z od alpha\). Then \[\displaystyle \sum\limits_{i=1}^p [(qi+z) mod p]=p\left(u+\frac{p-alpha}2\right).\label{eq0} \tag{8}\]

Proof. This results is contained in the proof of Proposition 2.1 of [22]. ◻

Lemma 2.6. Let \( {a}_i=[a_{i,1}, \dots,a_{i,q}]\in \mathbb{N}_p^q\), for \(i=1\), …, \(q\), and let \(\Delta( {a}_1,\dots, {a}_q)\) be written as \(\Delta\) for simplicity. Then the Diophantine system of simultaneous equations: \[\sum\limits_{j=1}^qa_{i,j}x_j\equiv f_i \pmod p, \quad i=1,\dots, q,\label{dioph} \tag{9}\] has one unique solution \([x_1, \dots,x_q]\in \mathbb{N}_p^q\) associated to each \( {f}=[f_1,\dots,f_q]\in \mathbb{Z}^q\), if and only if \((\Delta,p)=1\).

Proof. The system of Eqs. (9) can be written in the vector form: \[ {a}_1 x_1+\dots+ {a}_qx_q \equiv {f}\pmod p.\]

If we set \( {b}_i=(-1)^{q-i} {a}_1\times\dots\xcancel{ {a}_i} \dots\times {a}_q\) then we can rewrite the system in the form \[x_i( {a}_i \cdot {b}_i) \equiv \Delta_i \pmod p,\] with \(\Delta_i= {f}\cdot {b}_i\) for all \(i\in\mathbb{N}_q\). It follows from Eq. (6) in Lemma 2.2 that \( {a}_i \cdot {b}_i=\Delta\) and hence that this system can also be written in the form \[\Delta x_i\equiv \Delta_i \pmod p, \quad i=1,\dots, q.\]

Since \( {f}\) can be chosen to give \(\Delta_i\) arbitrary integer values, the conclusion follows immediately from Lemma 2.4. ◻

3. The main results

The next result gives necessary and sufficient conditions for the uniform step Eq. (3) to generate a \(q\) dimensional magic hyper-square of odd order \(p\).

Theorem 3.1. Given an odd integer \(p\ge 3\) and an integer \(q\ge 2\), let \(A=[a_{j,k} \colon j,k\in \mathbb{N}_q]\) be a \(q\times q\) matrix with entries from \(\mathbb{N}_p\), let \(\delta=\det(A)\), let \([d_j \colon j\in\mathbb{N}_q]\) be a vector with integer entries. For every subset \(S\) of the set \(\mathbb{W}_q= \{2, \dots, q\}\) and \(j\in\mathbb{N}_q\), let

\[ w_j(S) =a_{j,1}+\sum\limits_{k\in S}a_{j,k}- \sum\limits_{k\not \in S}a_{j,k},\label{w}\ \tag{10}\] \[z_j(S) =(p,w_j(S) ), \label{z}\ \tag{11}\] \[e_j(S) =d_j+\sum\limits_{k\not \in S}a_{j,k}.\label{e} \ \tag{12}\]

Then the array \(M\) defined with the uniform step formula (3) generates a \(q\) dimensional magic hyper-square of order \(p\) if and only if its coefficients satisfy the uniqueness condition \[(\delta,p)=1,\label{cond1} \tag{13}\] the axes conditions \[(p,a_{j,k})=1,\quad \forall j,\,k\in \mathbb{N}_q, \label{cond2} \tag{14}\] and the diagonal conditions \[e_j(S) od z_j(S)=(z_j(S)-1)/2,\quad\forall j\in \mathbb{N}_q,\,\, \forall S\subseteq \mathbb{W}_q. \label{cond3} \tag{15}\]

Proof. The uniform step Eq. (3) implies that the identity \[\{m(i_1, \dots, i_q) \colon (i_1,\dots i_q)\in \mathbb{N}_p\}= \{1, 2, \dots, p^q\},\] holds if and only if the equation \[\sum\limits_{j=1}^qp^{j-1}\left[\left(\sum\limits_{k=1}^qa_{j,k}i_k+d_j\right) od p\right] =\sum\limits_{j=1}^qp^{j-1}u_j,\] has a unique solution \([i_1, \dots, i_q]\in \mathbb{N}_p^q\), for any given \([u_1,\dots, u_q]\in \mathbb{Z}_p^q\). This is the case if and only if the Diophantine linear system \[\left(\sum\limits_{k=1}^qa_{j,k} i_k+d_j \right)\equiv u_j \!\!\!\! \pmod p,\quad j=1,\dots, q,\] has a unique solution \((i_1, \dots, i_q)\in \mathbb{N}_p^q\) for any given \((u_1,\dots, u_q)\in \mathbb{Z}_p^q\). By Lemma 2.6, this condition holds if and only if the uniqueness condition (13) holds.

Proposition 2.5 implies that every axes sum of \(M\) can be written in the form

\[\begin{align}\label{eq4} \sum\limits_{i_k=1}^pm(i_1,\dots,i_k,\dots,i_p)&=\sum\limits_{i_k=1}^p\left(1+\sum\limits_{j=1}^qp^{j-1}\left[\left( a_{j,k}i_k+\sum\limits_{r\ne k}^qa_{j,r}i_r+d_j\right) \bmod p \right]\right) \nonumber\\ &=p+\sum\limits_{j=1}^qp^{j-1}\sum\limits_{i_k=1}^p\left[\left( a_{j,k}i_k+\sum\limits_{r\ne k}^qa_{j,r}i_r+d_j\right) \bmod p \right]\nonumber\\ &=p+ \sum\limits_{j=1}^qp^{j-1}p(u_{j,k}(i_1,\dots,\xcancel{i_k},\dots, i_q)+\frac{p-alpha_{j,k}}2 ),\end{align}\tag{16}\]

with the coefficients:

\[alpha_{j,k}=(p,a_{j,k}),\tag{17}\] \[u_{j,k}(i_1,…,\xcancel{i_k},…,i_q)=(d_j+\sum\limits_{rk}^{q}a_{j,r}i_r)mod alpha_{j,k}\tag{18}\]

If condition (14) holds, then \(alpha_{j,k}=1\) and \(u_{j,k}(i_1,\dots,\xcancel{i_k},\dots, i_q)=0\), for all \(j\), \(k\in \mathbb{N}_q\), and Eq. (16) shows that the axes sum values are \[p+ \sum\limits_{j=1}^q\frac{p^j(p-1)}2=p+\frac{(p^{q+1}-p)}{(p-1)}\frac{(p-1)}2=\frac{p(p^q+1)}2.\]

Suppose, on the other hand, that the axes sums equations \[\sum\limits_{i_k=1}^pm(i_1,\dots,i_k,\dots,i_p)=p(p^q+1)/2, \label{eq14} \tag{19}\] hold for all \((i_i,\dots,\xcancel{i_k},\dots,i_q)\in \mathbb{N}_p^{q-1}\). Then it follows from (16) that \[\sum\limits_{j=1}^qp^j\left(u_{j,k}(i_1,\dots,\xcancel{i_k},\dots, i_q)+\frac{p-alpha_{j,k}}2 \right)=\frac{p(p^q+1)}2-p = \sum\limits_{j=1}^q\frac{p^j(p-1)}2,\] and hence that \[\sum\limits_{j=1}^qp^{j-1}\left(u_{j,k}(i_1,\dots,\xcancel{i_k},\dots, i_q)+\frac{1-alpha_{j,k}}2\right)=0.\label{sm} \tag{20}\]

This implies that \(u_{1,k}(i_1,\dots,\xcancel{i_k},\dots, i_q)+\frac{1-alpha_{1,k}}2\) is divisible by \(p\). However, definitions (17) and (18) imply that \[\begin{aligned} \frac{1-alpha_{1,k}}2&\le u_{1,k}(i_1,\dots,\xcancel{i_k},\dots, i_q)+\frac{1-alpha_{1,k}}2\\ &\le alpha_{1,k}-1+\frac{1-alpha_{1,k}}2=\frac{alpha_{1,k}-1}2, \end{aligned}\] and therefore that \[\left|u_{1,k}(i_1,\dots,\xcancel{i_k},\dots, i_q)+\frac{1-alpha_{1,k}}2\right|\le \frac{alpha_{1,k}-1}2 \le \frac{p-1}2.\]

Therefore we must have \(u_{1,k}(i_1,\dots,\xcancel{i_k},\dots, i_q)+\frac{1-alpha_{1,k}}2=0\) for \(k=1\), …, \(q\).

On deleting the term with \(j=1\) from the sum (20) and dividing that sum with \(p\), and inductively repeating the previous argument, we see that the equations \[u_{j,k}(i_1,\dots,\xcancel{i_k},\dots, i_q)+\frac{1-alpha_{j,k}}2=0, \label{sn} \tag{21}\] hold for all \(j\), \(k\in \mathbb{N}_q\) and all \((i_1,\dots,\xcancel{i_k},\dots, i_q)\in \mathbb{N}_p^{q-1}\).

Now, condition (13) implies that there exists \([i_1^*,\dots,i_q^*]\in \mathbb{N}_p^q\) such that \[\left(d_j+\sum\limits_{k=1}^q a_{j,k}i_k^*\right) od p=0.\]

Therefore there exists \(r_{j,k}\in \mathbb{N}\) such that \(d_j+\sum\limits_{k=1}^q a_{j,k}i_k^* =pr_{j,k}\). On the other hand, it follows from definition (17) that there exist \(s_{j,k}\), \(v_{j,k}\in \mathbb{N}\) such that \(p=alpha_{j,k}s_{j,k}\) and \(a_{j,k}=alpha_{j,k}v_{j,k}\). Therefore \[\begin{aligned} u_{j,k}(i_1^*,\dots,\xcancel{i_k^*},\dots, i_q^*)&=\left(d_j+\sum\limits_{r\ne k}^qa_{j,r}i_r^*\right) od alpha_{j,k}\\ &=(pr_{j,k}-a_{j,k}i_k^*) od alpha_{j,k}\\ &=alpha_{j,k}(s_{j,k}r_{j,k}-v_{j,k}i_k^* ) od alpha_{j,k} =0. \end{aligned}\]

On setting \([i_1,\dots,\xcancel{i_k},\dots, i_q]=[i_1^*,\dots,\xcancel{i_k^*},\dots, i_q^*]\) in (21), we see that \(\frac{1-alpha_{j,k}}2=0\) and hence the equations \(alpha_{j,k}= 1\) hold for all \(j\), \(k\in \mathbb{N}_p\). Therefore condition (14) holds.

We conclude that if condition (13) holds, then all axes sums of \(M\) have the value \(p(p^q+1)/2\) if and only if condition (14) holds.

Proposition 2.5 implies that every diagonal sum of \(M\) is equal to

\[\begin{align} \sum\limits_{i=1}^pm&(n_1(i),\dots,n_q(i))= \sum\limits_{i=1}^p1+\sum\limits_{j=1}^qp^{j-1}\left(\left[\left(\sum\limits_{r=1}^q a_{j,r}n_r(i)+d_j\right) \bmod p \right] \right)\nonumber\\ &=p+\sum\limits_{i=1}^p\sum\limits_{j=1}^qp^{j-1}\left[\left(a_{j,1}i+\sum\limits_{r=2}^q a_{j,r}n_r(i)+d_j\right) \bmod p \right] \nonumber\\ &=p+ \sum\limits_{j=1}^qp^{j-1} \sum\limits_{i=1}^p\left[\left(a_{j,1}i+\sum\limits_{r\in S}a_{j,r}i+\sum\limits_{r\not \in S}a_{j,r}(p+1-i)+d_j\right) \bmod p \right] \nonumber\\ &=p+ \sum\limits_{j=1}^qp^{j-1} \sum\limits_{i=1}^p\left[\left(\left(a_{j,1}+\sum\limits_{r\in S}a_{j,r}-\sum\limits_{r\not \in S}a_{j,r}\right)i+\sum\limits_{r\not \in S}a_{j,r}+d_j\right) \bmod p \right] \nonumber\\ &=p+ \sum\limits_{j=1}^qp^{j-1}\sum\limits_{i=1}^p\left[(w_j(S)i +e_j(S)) \bmod p \right] \nonumber\\ &=p+\sum\limits_{j=1}^qp^{j-1}p\left(x_j(S)+\frac{ p-z_j(S)}2 \right), \end{align} \tag{22}\]

where \(n_r\) is defined in (2) and \(x_j(S)= e_j(S) od z_j(S)\) and \(S\) is a subset of the set \(\mathbb{W}_q=\{2,\dots,q\}\).

Suppose that all diagonal sums of \(M\) are equal to \(p(p^q+1)/2\). Then Eq. (22) implies (with \(x_j(S)\) written as \(x_j\) and \(z_j(S)\) as \(z_j\)) that \[\sum\limits_{j=1}^qp^j\left(x_j+\frac{p-z_j}2 \right)=\frac{p(p^q+1)}2-p=\sum\limits_{j=1}^q\frac{p^j(p-1)}2,\] and hence that \[\sum\limits_{j=1}^qp^{j-1}\left(x_j+\frac{1-z_j}2\right)=0.\label{eq5} \tag{23}\]

The inequalities \(\frac{1-z_j}2\le x_j+\frac{1-z_j}2\le z_j-1+\frac{1-z_j}2=\frac{z_j-1}2\) imply that \[\left|x_j+\frac{1-z_j}2\right|\le \frac{z_j-1}2\le \frac{p-1}2{\rm\ for\ } j=1, \dots, q.\]

It follows from (23) that \(x_1+\frac{1-z_1}2\) is divisible by \(p\), which implies, since \(|x_1+\frac{1-z_1}2|\le \frac{p-1}2\), that \(x_1+\frac{1-z_1}2=0\). By deleting the term corresponding to \(j=1\) from the sum (23), and dividing that sum with \(p\), and inductively repeating the previous argument, we conclude that the equation \(x_j=\frac{z_j-1}2\) holds for all \(j\in \mathbb{N}_p\), and hence that condition (15) holds.

On the other hand, if condition (15) holds, then Eq. (22) implies that all diagonal sums of \(M\) have the value \(p+ \sum\limits_{j=1}^q \frac{p^j(p-1)}2=\frac{p(p^q+1)}2\).

We conclude that the uniform step Eq. (3) generates a \(q\) dimensional magic hyper-square of order \(p\) if and only if conditions (13)–(15) hold. ◻

Remark 3.2. The verification of condition (15) of Theorem 3.1 for all \(2^{q-1}\) diagonals is computationally intensive for large \(q\). The next results eliminates the need to verify that condition for uniform step hyper-squares with a special structure.

Theorem 3.3. Given an odd number \(p\ge 3\), a whole number \(q\ge 2\), and a \(q\times q\) matrix \(A=[a_{j,k}]\) with entries in \(\mathbb{N}_p\), let \(\delta=\det(A)\) and suppose that conditions (13)–(14) hold. If we set \[d_j=(p-1)/2-(p+1)\left(\sum\limits_{k=1}^qa_{j,k}\right)/2,\, {\rm \ for \ } j=1,\dots, q,\label{d} \tag{24}\] then the array \(M\) defined with the uniform step formula (3) is a \(q\) dimensional magic hyper-square of order \(p\).

Proof. Since conditions (13)–(14) of Theorem 3.1 are included in the hypotheses, we only have to verify condition (15) of that Theorem.

For fixed \(j\) and a fixed subset \(S\) of \(\mathbb{W}_q\), let \(z=z_j(S)\), \(w=w_j(S)\), \(e=e_j(S)\), \(d=d_j\), \(s=\sum\limits_{k=1}^qa_{j,k}\) and \(t=\sum\limits_{k\not\in S}a_{j,k}\). Then Eqs. (10)–(12) and (24) imply that \(w=s-2t\), \(z=(p,w)\), \(d=(p-1-(p+1)s)/2\) and \(e=d+t\). Since \(z\ge 1\), we must have \(0\le (z-1)/2<z\).

The definition of the greatest common factor \(z=(p,w)\) shows that there exist an odd integer \(u\) and an integer \(v\) such that \(p=zu\) and \(w=zv\), and hence that \[\begin{aligned} e&=d+t=(p-1-(p+1)s+2t)/2\\ &=(p-1-(p+1)(w+2t)+2t)/2\\ &=(p-z-pw-2pt-w)/2+(z-1)/2\\ &=(zu-z-pzv-2zut-zv)/2+(z-1)/2\\ &=z((u-1)/2-v(p+1)/2-ut)+(z-1)/2. \end{aligned}\]

Since and \(z\) and \(u\) (factors of the odd number \(p\)) are odd, we conclude that \[e od z=(z-1)/2.\]

This shows that condition (15) of Theorem 3.1 holds, which completes the proof. ◻

Remark 3.4. In the sequel, we will refer to any uniform step magic hyper-square (3) in which the coefficients \(\{d_j\}\) are defined as in (24) as a restricted uniform step magic hyper-square. The entries of such a hyper-square are given by the expressions

\[\begin{align} \label{restricted_eqn} m(i_1,\dots, i_q)&=1+ \sum\limits_{j=1}^qp^{j-1}\left[\left(\sum\limits_{k=1}^qa_{j,k}i_k+d_j\right)\bmod p \right]\nonumber \\ &=1+ \sum\limits_{j=1}^qp^{j-1}\left[\left(\sum\limits_{k=1}^qa_{j,k}(i_k-(p+1)/2)+(p-1)/2\right) \bmod p \right] , \end{align} \tag{25}\]

and its center cell, with the constant coordinates \(c=(p+1)/2\), has the value \[m(c,\dots, c)=1+\sum\limits_{j=1}^qp^{j-1}(p-1)/2= 1+(p^q-1)/2=(p^q+1)/2.\label{ctr} \tag{26}\]

Remark 3.5. Theorem 3.3 gives sufficient conditions for the uniform step rule (3) to generate \(q\)-dimensional magic hyper-squares of order \(p\). However, these conditions are not necessary as can be seen from the uniform step formula \[m(i,j)=1+[(p-i+2j+p-1) od p+p[(i+2j+1) od p],\] which in the case \(p=5\) generates the \(2\)-dimensional magic hyper-square (a magic square) \[\begin{array}{lllll} 21 & 8 & 20 & 2 & 14\\ 5 & 12 & 24 & 6 & 18\\ 9 & 16 & 3 & 15 & 22\\ 13 & 25 & 7 & 19 & 1\\ 17 & 4 & 11 & 23 & 10 \end{array}\]

It is easy to verify that all row, column and diagonal sums of this magic square are \(65=5(5^2+1)/2\), as expected. However, the restricted uniform step center cell necessary condition (26) does not hold.

Example 3.6. The determinant \(\Delta_q\) of the \(q\times q\) matrix \[A=[a_{j,k}\colon j,\,k\in \mathbb{N}_q] = \left \{ \begin{array}{rr} 2, \, & {\rm\ if\ } j<k,\\ 1, \, & {\rm\ if\ } j\ge k,\end{array} \right . \label{aa} \tag{27}\] satisfies the equations \(\Delta_2=-1\), \(\Delta_3=1\), \(\Delta_4=-1\), \(\Delta_5=1\) and, for \(q\ge 6\), the recurrence \[\Delta_q=\begin{vmatrix} 1 & 2 & … & 2& 2\\ 1 & 1 & \ddots & 2 & 2 \\ \vdots & \ddots & \ddots & \ddots & \vdots \\ 1 & 1 & \ddots &1 &2 \\[1ex] 1 & 1 & \dots & 1 & 1 \end{vmatrix} =\begin{vmatrix} -1 & 0 & 0 & … & 0 & 0\\ 1&1 & 2 & … & 2& 2\\ 1&1 & 1 & \ddots & 2& 2 \\ \vdots& \vdots & \ddots & \ddots & \ddots & \vdots \\ 1&1 & 1 & \ddots &1 &2 \\[1ex] 1&1 & 1 & \dots & 1 & 1 \end{vmatrix} =(-1)\Delta_{q-1} ,\] obtained by multiplying the last row with \((-2)\) and adding it to row 1. Hence \(\Delta_q=(-1)^q\).

The array \(A\) is an interesting example of a full uni-modal matrix. Since its entries are 1’s and 2’s, and \(p\) is odd and greater than 3, the sufficient conditions (13)–(14) of Theorems 3.1 and 3.3 hold. Since \(\sum\limits_{k=1}^qa_{j,k}=2q-j\), it follows from (25) that the entries of the resulting novel restricted uniform step magic hyper-square of dimension \(q\ge 2\) and odd order \(p\) are \[\begin{aligned} m(i_1, \dots, i_q)&=1+ \sum\limits_{j=1}^qp^{j-1}\left[\left(\sum\limits_{k=1}^qa_{j,k}(i_k-(p+1)/2)+(p-1)/2\right) od p \right]\\ &=1+ \sum\limits_{j=1}^qp^{j-1}\left[\left(\sum\limits_{k=1}^qa_{j,k}i_k-\sum\limits_{k=1}^qa_{j,k}(p+1)/2+(p-1)/2\right) od p \right]\\ &=1+ \sum\limits_{j=1}^qp^{j-1}\left[\left(\sum\limits_{k=1}^qa_{j,k}i_k-(2q-j)(p+1)/2+(p-1)/2\right) od p \right]\\ &=1+ \sum\limits_{j=1}^qp^{j-1}\left[\left(\sum\limits_{k=1}^qa_{j,k}i_k+j(p+1)/2-qp-q+(p-1)/2\right) od p \right]\\ &=1+ \sum\limits_{j=1}^qp^{j-1}\left[\left(\sum\limits_{k=1}^qa_{j,k}i_k+j(p+1)/2-q+(p-1)/2\right) od p \right]\\ &=1+ \sum\limits_{j=1}^qp^{j-1}\left[\left(\sum\limits_{k=1}^qa_{j,k}i_k+(j+1)(p+1)/2-q-1\right) od p \right]\\ &=1+\sum\limits_{j=1}^q p^{j-1}\left[\left( \sum\limits_{k=1}^qi_k+\sum\limits_{k=j+1}^q i_k +(j+1)(p+1)/2-q-1\right) od p \right]. \end{aligned}\]

For example, if we set \(q=4\) in this formula we obtain the novel magic tesseract formula \[\begin{aligned} m(i,j,k,r)=&1+[(i+2j+2k+2r+p+1-5 ) od p] \\ &+ p [( i+j+2k+2r+3(p+1)/2-5) od p ]\\&+p^2[( i+j+k+2r+2(p+1)-5) od p ]\\ &+p^3[( i+j+k+r+5(p+1)/2-5) od p ]. \end{aligned}\]

In this case, if we set \(\bar i=p+1-i\), then it is easy to verify that each of the diagonal sums \(\sum\limits_{i=1}^p m(i,i,i,i)\), \(\sum\limits_{i=1}^p m(i,\bar i,i,i)\), \(\sum\limits_{i=1}^p m(i,i,\bar i,i)\), \(\sum\limits_{i=1}^p m(i,i,i,\bar i)\), \(\sum\limits_{i=1}^p m(\bar i,\bar i,i,i)\), \(\sum\limits_{i=1}^p m(\bar i,i,\bar i,i)\), \(\sum\limits_{i=1}^p m(\bar i,i,i,\bar i)\), \(\sum\limits_{i=1}^p m(i,\bar i,\bar i,i)\), and each of the axes sums \(\sum\limits_{r=1}^p m(r,i,j,k),\) \(\sum\limits_{r=1}^p m(i,r,j,k),\)\(\sum\limits_{r=1}^p m(i,j,r,k)\), \(\sum\limits_{r=1}^p m(i,j,k,r),\) has the value \(p(p^4+1)/2\) for all \((i,j,k)\in \mathbb{N}_p^3.\)

If we set \(q=3\), we obtain the magic cube formula \[\begin{aligned} m(i,j,k) =&1 +[(i+2j+2k+p-3) od p ]\\ &+ p [(i+j+2k+3(p+1)/2-4) od p]\\ &+ p^{2}[(i+j+k+2p-2) od p]. \end{aligned}\]

In the case \(p=3\), the slices of this magic cube are the arrays

\(M_{\colon \colon 1}\)
12 23 7
22 9 11
8 10 24
\(M_{\colon \colon 2}\)
26 1 15
3 14 25
13 27 2
\(M_{\colon \colon 3}\)
4 18 20
17 19 6
21 5 16

where \(M_{\colon\colon k}\stackrel{\rm def}{=}\{m(i,j,k)\colon i,j\in \mathbb{N}_p\}\). It is easy to verify that all axes and diagonal sums of this magic cube are \(42=3(3^3+1)/2\), as expected.

Example 3.7. Another interesting choice of coefficients is the matrix \[A= [a_{j,k} \colon j,\,k\in \mathbb{N}_q] = \left \{ \begin{array}{rr} -1, \, & {\rm\ if\ } j<k,\\ 1, \, & {\rm\ if\ } j\ge k,\end{array} \right .\] which has the determinant \(\Delta_q=2^{q-1}\) (as is easily verified) and for which the sufficient conditions (13)–(14) of Theorem 3.8 also hold. This matrix was introduced and used by Trenkler [16] to establish for the first time the existence of \(q\ge 2\) dimensional magic hyper-squares for every odd order \(p\ge 3\).

Let \(M(A, {d})\) designate the \(q\)-dimensional magic hyper-square of order \(p\) generated via Eq. (3) from a \(q\times q\) matrix \(A=[a_{j,k}]\) of whole numbers and a \(q\) dimensional vector \( {d}=[d_j]\) of integers. The next result shows that \(M(A, {d})\) is is uniquely defined by the coefficients \(A\) and \( {d}\).

Theorem 3.8. If \(M(A, {d})=M(A', {d}')\), then \((A, {d})=(A', {d}')\).

Proof. For all \(i\in \mathbb{N}_p\) and \(n_i=1\), 2, …, \(p\), we have \[\sum\limits_{j=0}^{q-1}p^j \left[\left(\sum\limits_{k=1}^qa'_{j,k} n_k+d'_j\right) od p \right]= \sum\limits_{j=0}^{q-1}p^j \left[\left(\sum\limits_{k=1}^qa_{j,k} n_k+d_j\right) od p \right].\]

Hence \[\left(\sum\limits_{k=1}^q(a'_{j,k}-a_{j,k}\right) n_k+(d'_j-d_j) \equiv 0 \pmod p,\] for \(j=1\), …, \(q\).

On setting \(n_k=p\) for \(k=1\), …, \(q\), we obtain the relations \(|d_j'-d_j| \equiv 0 \pmod p\), which imply (since the \(|d_j'-d_j|\) are elements of \(\mathbb{Z}_p\)) that \(d_j'=d_j\) for \(j=1\), …, \(q\).

If we set \(n_k=1\), and set \(n_j=p\) whenever \(j\ne k\) we obtain the relations \(|a_{j,k}'-a_{j,k}| \equiv 0 \pmod p\), which imply that \(a_{j,k}'=a_{j,k}\) for \(i\), \(j=1\), 2, …, \(q\). That shows that \((A, {d})=(A', {d}')\) and concludes the proof. ◻

References:

  1. W. S. Andrews. Magic Squares and Cubes. Dover, New York, 1960.
  2. W. H. Benson and O. Jacoby. Magic Cubes: New Creations. Dover, New York, 1981.
  3. L. E. Dickson. Introduction to the Theory of Numbers. Dover, New York, 1950.
  4. J. D. O’Keeffe. A generalization of the vector product. International Journal of Mathematical Education in Science and Technology, 12:541–547, 1981. https://doi.org/10.1080/0020739810120505.
  5. M. Trenkler. Magic cubes. The Mathematical Gazette, 82:56–61, 1998. https://doi.org/10.2307/3620151.
  6. M. Trenkler. A construction of magic cubes. The Mathematical Gazette, 84:36–41, 2000. https://doi.org/10.2307/3621472.
  7. M. Trenkler. Magic p-dimensional cubes of order n ≠ 2 (mod 4). Acta Arithmetica, 92(4):189–194, 2000. https://doi.org/10.4064/aa-92-2-189-194.
  8. M. Trenkler. Magic p-dimensional cubes. Acta Arithmetica, 96:361–364, 2001. https://doi.org/10.4064/AA96-4-5.
  9. L. U. Uko. The anatomy of magic squares. Ars Combinatoria, 67:115–128, 2003.
  10. L. U. Uko. Uniform step magic squares revisited. Ars Combinatoria, 71:109–123, 2004.
  11. L. U. Uko and T. L. Barron. A generalization of Trenkler’s magic cubes formula. Recreational Mathematics Magazine, 8:39–45, 2018. https://doi.org/10.1515/rmm-2017-0019.
  12. L. U. Uko and J. L. Sinclair. A simple formula for de la loubere’s magic square method. The Mathematical Scientist, 38(1):1–6, 2013.