Stifel's odd magic squares of any size (Arithmetica Integra 1544)​
​by Oliver Seipel

Michael Stifel’s Arithmetica Integra 1544

References:
Original Book (University of Madrid)
https://archive.org/details/bub_gb_fndPsRv08R0C
Original Book (National Central Library of Rome)
https://archive.org/details/bub_gb_ywkW9hDd7IIC
Biography
https://en.wikipedia.org/wiki/Michael_Stifel
Magic square:
https://en.wikipedia.org/wiki/Magic_square

Mathematica code

In[]:=
MagicSum[n_]:=
1
2
n(1+
2
n
)
In[]:=
MagicSquareQ[m_?SquareMatrixQ]:=Equal@@Join[Apply[Plus,m,1],Apply[Plus,Transpose[m],1],{Tr[m],Tr[Reverse/@m]}]
In[]:=
EightSymmetries[m_?SquareMatrixQ,n_]:=Which[n1,m,n2,Reverse[Map[Reverse,m]],n3,m,n4,Map[Reverse,m],n5,Reverse[Map[Reverse,m]],n6,Reverse[m],n7,Map[Reverse,m],True,Reverse[m]];
In[]:=
AddOuterRingToMatrix[m_?SquareMatrixQ,left_List,right_List,top_List,down_List]:=​​Join[{top},Join[{left},m,{right}],{down}]
In[]:=
stifelOdd[m_?OddQ,kernel_?SquareMatrixQ]/;m≥3&&Length[kernel]m-2:=​​Module[{s=
2
m
+1,left,right,top,bottom,topmiddle},​​topmiddle=Join[Table[s-k,{k,1,m-2,2}],Table[k,{k,m+2,2m-3,2}]];​​top=Join[{2(m-1)},topmiddle,{2}];​​bottom=Join[{s-2},s-topmiddle,{s-(2(m-1))}];​​left=Join[Table[s-k,{k,4,m-1,2}],{m},Table[k,{k,m+1,2(m-2),2}]];​​right=s-left;​​AddOuterRingToMatrix[kernel+2m-2,left,right,top,bottom]]
In[]:=
StifelOddMagicSquare[n_?OddQ]:=Fold[stifelOdd[#2,#1]&,{{1}},Range[3,n,2]]

Michael Stifel’s odd magic squares:

Michael Stifel gives an algorithm to construct odd magic squares of any size:
De Progressionibus Arithmeticis, Cap. III.
We start with
n=1
:
Out[]=
1
In[]:=
MagicSum[1]
Out[]=
1
He puts the 1 on the right side of the left bottom corner and the 2 in the right top corner. the 3 in the middle of the left column and the 4 in the left top corner. Because of the magic sum all other values follow:
He puts the 1, 3 on the right side of the left bottom corner and the 2 in the right top corner and 4 below. the 5 in the middle of the left column, 6 below, the 7 is on the left side of the top right cirner and the 8 in the left top corner. Because of the magic sum all other values follow:
The numbers must be distributed so that the two outer rows and two columns have magic sum 65. The 4 corners contribute to the row sum and to the column sum.
Is it really magic?
Check the code from above:
Here is Stifel’s 9x9 example from his “Arithmetica Integra”:
The reconstruction is exactly the same:
And it’s magic of course:

Appendix:

Stifel’s construction principle can be extended with permutations of the outer rows and columns and 8 symmetrie operations:
This is the original Stifel magic square of order 7:
Test for magicness:
The outer ring can additionally be put in one of the 8 symmetrie forms:
Test for magicness:
How many such variations are there?
What does the closed form look like?
And here is the discrete asymptotic:
And the numeric value for k=3, m=2k+1=7:
Which is pretty close to the exact value.
And here is Stifel’s odd magic square with maximal randomness: