DSPy a system for AI to Write Prompts and Do Fine Tuning
Semi-Magic Squares From Snake-Shaped Matrices
1. Semi-Magic Squares From
Snake-Shaped Matrices
Lohans de OLiveira Miranda, Instituto Antoine Lavoisier de Ensino,
Teresina-PI, Brasil
Lossian Barbosa Bacelar Miranda, Instituto Federal de Educa¸˜o Ciˆncia e
ca e
Tecnologia do Piaui, Brasil
Abstract. Using snake-shaped matrices and reflections on their columns of
even order we present a method that generates a large class of semi-magic
squares.
Keywords: semi-magic squares, snake-shaped matrices, arithmetic progres-
sions.
1. Introduction
Methods have been developed for the construction of magic rectangles
from snake-shaped matrices (see reference [1]), which consist of two steps.
In this paper we present an alternative method, which also makes use of
snake-shaped matrices, consisting of three steps. The first step is the same
as established in the literature and the second, slightly different. The third
is a problem of combining the solution of which provides a variety of semi-
magic squares. Our approach is restricted to the squares of even order, but
applies to any rectangles with even numbers of rows and columns. To make
the construction three procedures (steps) can be used on the lines instead
of columns. Similar result is achieved by making it the second procedure
(reflection) on the columns of odd order.
2. Definitions and notations
Consider a square matrix of even order A = (aij ) , n > 2, with aij ∈
In2 = {1, 2, 3, ..., n2 } and such that aij = akl ⇔ i = k ∧ j = l. The aij
elements are called entries. We denote the row of order k by (akj )j=1,2,...,n =
[ak1 , ak2 , ..., akn ] and the column of order k by (ajk )j=1,2,...,n = [a1k , a2k , ..., ank ]t .
n n n(n2 +1)
If j=1 akj = i=1 ail = 2
, ∀k, l ∈ In2 , we say that A is a semi-magic
n(n2 +1)
square with the magic constant c(n) = 2
. The columns [a1k , a2k , ..., ank ]t
1
2. t
and ank , a(n−1)k , ..., a1k are said reflected from each other and we call re-
flection the procedure for changing aik by a(n−i+1)k for any i ∈ I n . We call
2
the snake-shaped matrix the square matrix A = (aij )n×n defined by
n(i − 1) + j if i = 1, 3, 5, ..., (n − 1)
aij = (1)
ni − (j − 1) if i = 2, 4, 6, ..., n
Using (1) it is noticed that the sum of all the elements of any column of
a snake-shaped matrix is equal to the magic constant. If all n columns of
2
an even order snake-shaped matrix suffer a reflection, we will have a snake-
shaped matrix with reflected columns of even orders.
3. Main Results
The following are the main results.
PROPOSITION 1. If A = (aij )n×n , n > 2 , is snake-shaped matrix with re-
flected columns of even orders, then: (i) n a[(2k−1)+2s]j = n a(2k−1)j =
j=1 j=1
c(n) − n , k ∈ I( n −1) , s ∈ I( n −k) ; (ii) n a(2k+2s)j = n a(2k)j =
2 2 2 j=1 j=1
c(n) + n , k ∈ I( n −1) , s ∈ I( n −k) .
2 2 2
Proof (i): consider the snake-shaped matrix A = (aij )n×n that generates
A from the reflections of its n columns of even order. To this matrix we
2
have,
a[(2k−1)+2s] − a(2k−1)j = 2sn = a(2k+2s)j − a(2k)j , k ∈ I( n −1) , s ∈ I( n −k)
2 2
(2).
If j ∈ In is an odd number, its follows from (2):
a[(2k−1)+2s]j = a(2k−1)j + 2sn (3).
After the reflection of the column of order j + 1 of A results:
a(2k−1)(j+1) = a[(2k−1)+2s](j+1) + 2sn (4).
Therefore, after reflection of the column of order j + 1, (3) and
(4) provide a(2k−1)j + a(2k−1)(j+1) = a[(2k−1)+2s]j + a[(2k+1)+2s](j+1) , j =
1, 3, 5, ..., (n−1). Since the columns of odd order are not altered by the reflec-
tions of columns of even order results a(2k−1)j + a(2k−1)(j+1) = a[(2k−1)+2s]j +
a[(2k−1)+2s](j+1) , j = 1, 3, 5, ..., (n−1), k ∈ I( n −1) , s ∈ I( n −k) from which follows
2 2
n n
+1 +1
2
m=1 a(2k−1)(2m−1) + a(2k−1)2m = 2
m=1 a[(2k−1)+2s](2m−1) + a[(2k−1)+2s]2m
2
3. n n
and then j=1 a[(2k−1)+2s]j = j=1 a(2k−1)j . Similarly proves (ii).
n
Sums of arithmetic progressions directly provide the identities 2
j=1 a1j =
n n n
2 n3 n
s=1 [1
2
+ 2(s − 1)] + s=1 [n
2
+ (2s − 1)] = 2
= c(n) − 2
and 2
j=1 a2j =
n n
n3 n
s=1 [2n
2
− 2(s − 1)] + s=1 [(n
2
− 2)n + 2s] + n = 2
= c(n) + 2
.
PROPOSITION 2. Every snake-shaped matrix with reflected columns of
even orders A = (aij )n×n can be transformed into a semi-magic square from
the swap of entries with the forms a(2k−1)j and a(2k)j , k ∈ I n , j ∈ In .
2
Proof. Direct observation provides a(2k−1)(n−s) −a(2k)(n−s) = (−1)s (2s−1), k ∈
I n , j ∈ In . From the Proposition 1 results n a(2k)j − n a(2k−1)j = n
2 j=1 j=1
and, therefore, to transform A into semi-magic square is sufficient swap el-
n
ements with forms a(2k−1)j and a(2k)j , transferring n units of
2 j=1 a(2k)j
n
for the sum j=1 a(2k−1)j . This is equivalent to finding different numbers
n
x1 , x2 , ..., xr ∈ Ωn = 1 + 4s; 0 ≤ s < and diferents numbers y1 , ..., yk ∈
2
n
Bn = 3 + 4s; 0 ≤ s < such that (eventually there may be only elements
2
of Bn ):
k r
n
yi − xi = ; 0<r+k ≤n (5)
i=1 i=1
2
Let ξ(n) the number of different solutions for (5). The above method
n
provides ξ(n) 2 semi-magic squares. The following, we show that in any sit-
uation, (5) does not have empty solution.
s
Situation 1 ( n is odd). Direct observation gives us:
2 i=2 [3 + 4(i − 1)] −
n
s +3
i=1 [1 + 4(i − 1)] = 2s − 3, s ∈ {1, 2 }; 7 − (1 + 5) = 1. If s =
/ , then
2
2
2s − 3 = n . The largest summand of the sum is 3 + 4(s − 1) = n + 5, which
2
is less than 2n.
s
Situation 2 ( n is even). Direct observation gives us: 2s =
2 i=1 [3 + 4(i −
n
s n
1)] − i=1 [1 + 4(i − 1)], s = 0. Since 2
is even, we have n =
2 i=1 [3
4
+
n
4(i − 1)] − i=1 [1 + 4(i − 1)]. The largest summand is
4
3 + 4( n −
4
1), which
is smaller than 2n.
Observation. The following list show ξ(n) and swaps for some values of
n.
3
6. Acknowledgments
We thank the students Oannes de Oliveira Miranda and Liuhan Oliveira
de Miranda for discussions and suggestions.
References
[1] J. P. De Los Reyes, Ashish Das, Chand K. Midha and P. Vellaisamy.
On a method to construct magic Rectangles of even order. New
Delhi: Indian Statistical Institute, Delhi Centre, 2007. Available at
http://www.isid.ac.in/∼statmath/2007/isid200709.pdf. 17/02/2012.
[2] Leonhard Euler. On magic squares. Originally published as De
quadratis magicis, Commentationes arithmeticae 2 (1849), 593-602.
Translated from the Latin by Jordan Bell, 2004. Available at
http://arxiv.org/pdf/math/0408230.pdf. 18/02/2012.
[3] La Loubere, Simon de. A new historical relation of the king-
dom of Siam. Ithaca, New York: Cornell University Li-
brary. Print source: London, Tho. Horne. . . [and 2 others],
1693. Available at http://dlxs.library.cornell.edu/cgi/t/text/text-
idx?c=sea;idno=sea130;view=toc;cc=sea. 29/2/2012.
6