User talk:Gangleri/tests/sandbox/squares

21572 save referencing the newest version of page using one of its history id

&rarr; help:Displaying a formula

&rarr; prime signature

Construction
If $$ n \, $$ is the order of a most-perfect magic square then $$ n = 4 \cdot n^' $$. Assuming the prime decomposition of $$ n \, $$ is

$$ n = p_1^{e_1} \cdot \ldots \cdot p_M^{e_M} = \prod_{k=1}^{M} p_k^{e_k} $$ where $$ p_i < p_j \, $$ for $$ i < j \, $$ and $$ p_1 = 2 \, $$

Let $$ e_{total} \, $$ be the the sum of the exponents: $$ e_{total} = \sum_{k=1}^{M} {e_k} $$.

Let $$ B \, $$ be the canonical base for the representation of the integer numbers from $$ 0 \, $$ to $$ n - 1 \, $$ in a positional numeral system based on a mixture of prime numbers. It will contain $$ e_{total} \, $$ $$ 2 \, $$ -tuples:

$$ B = \left ( \underbrace{ \underbrace{ \left ( p_1,1 \right ), \dots, \left ( p_1,e_1 \right ) }_{e_1}, \dots, \underbrace{ \left ( p_M,1 \right ), \dots, \left ( p_M,e_M \right ) }_{e_M} }_{M} \right ) $$

$$ C = \left ( 1, p_1, \dots, \prod_{m=1}^{pos - 1} {p_k}, \dots, \prod_{m=1}^{e_{total} - 1} {p_k} \right ) $$

is the weight of the canonical base $$ B \, $$. Both define together the positional numeral system.

The algorithm to find the representation of an integer $$ a \, $$ between $$ 1 \, $$ and $$ n \, $$ is as follows:


 * initialisation
 * $$ k := 1 \, $$
 * $$ a := a - 1 \, $$
 * $$ c := 1 \, $$
 * $$ e_{total} \, $$ computations
 * $$ b_k := a\,\bmod\,p_k\, $$, where $$ p_k \, $$ is the first value of the $$ k \, $$ -th 2-tuple in $$ B \, $$
 * $$ a := \frac{\left ( a - b_k \right )}{p_k} \,$$
 * $$ c_k := c \, $$, this is the computation of $$ C \, $$
 * $$ c := c \cdot p_k \, $$
 * $$ k := k + 1 \, $$

Any number $$ a \, $$ between $$ 1 \, $$ and $$ n \, $$ can now be written as

$$ a = 1 + \sum_{k=1}^{e_{total}} {b_k} \cdot {c_k} $$ where $$ 0 \le b_k \le p_k - 1 $$ and $$ b_k \, $$ ∈ $$ \mathbb{N}_0 $$

In the following the $$ e_{total} \, $$ -tuple formed by the values $$ b_k \, $$ is called coefficients in the positional numeral system defined by $$ B \, $$ and $$ C \, $$.

Constructing auxiliary squares
Let $$ S \, $$ be the set of the integer numbers from $$ 1 \, $$ and $$ n \, $$. It is possible to choose a random $$ n \, $$ -tuple named $$ S_r \, $$ as follows:


 * initialisation
 * $$ k := 1 \, $$
 * $$ S := S \, $$
 * $$ c := 1 \, $$
 * $$ \frac{n}{2} \, $$ computations
 * a random element $$ n_k \, $$ of $$ S \, $$ is assigned to the the $$ k \, $$ -th element of $$ S_r \, $$
 * $$ S := S \setminus \{ n_k \} \, $$
 * $$ S := S \setminus \{ n + 1 - n_k \} \, $$
 * $$ k := k + 1 \, $$

Now it is possible to decompose each element of the $$ n \, $$ -tuple $$ S_r \, $$ in the positional numeral system defined by $$ B \, $$ and $$ C \, $$ calculating the coefficients for each element. Regrouping the appropriate coefficients it is possible to compute $$ e_{total} \, $$ different $$ n \, $$ -tuples $$ S_{r,k} \, $$ where $$ S_{r,k} \, $$ relates to the $$ m \, $$ -th occurence of the prime number $$ p_{k^'} \, $$.

Each $$ n \, $$ -tuple $$ S_{r,k} \, $$ is used to construct an auxiliary square $$ A_{r,k} \, $$ of order $$ n \, $$ as follows:


 * the rows of $$ A_{r,k} \, $$ with an odd number consist of the $$ n \, $$ -tuples $$ S_{r,k} \, $$
 * the rows of $$ A_{r,k} \, $$ with an even number consist of the prime number $$ p_{k^'} \, $$ -complements of $$ n \, $$ -tuples $$ S_{r,k} \, $$
 * for any value $$ 0 \le b_{k^{}} \le p_{k^'} - 1 $$ and $$ b_{k^{}} \, $$ ∈ $$ \mathbb{N}_0 $$ its complement is $$ p_{k^'} - 1 - b_{k^{''}} \, $$

All steps from above can be repeated for columns. This is how a random $$ n \, $$ -tuple named $$ S_c \, $$ is choosen which will drive the computation of $$ e_{total} \, $$ different $$ n \, $$ -tuples $$ S_{c,k} \, $$ where $$ S_{c,k} \, $$ relates to the $$ m \, $$ -th occurence of the prime number $$ p_{k^'} \, $$.

Finaly $$ e_{total} \, $$ different auxiliary squares $$ A_{c,k} \, $$ of order $$ n \, $$ are generated as follows:


 * the columns of $$ A_{c,k} \, $$ with an odd number consist of the transpose of the $$ n \, $$ -tuples $$ S_{c,k} \, $$
 * the columns of $$ A_{c,k} \, $$ with an even number consist of the prime number $$ p_{k^'} \, $$ -complements of the transpose of the $$ n \, $$ -tuples $$ S_{c,k} \, $$

The set of auxiliary squares $$ \{ A_{r,k} \mid 1 \le k \le e_{total} \} \cup \{ A_{c,k} \mid 1 \le k \le  e_{total} \} \, $$ has many interesting properties:


 * the sum of any 2×2 subsquare is constant inside a particular square
 * the sum of two cells with a distance of n/2 along a (major) diagonal is constant inside a particular square
 * choosing an ordered subset of $$ m \, $$ auxiliary squares one can generate $$ n^2 \, $$ (one for each element) $$ m \, $$ -tuples ; counting all different kind of $$ m \, $$ -tuples show an equal distribution of these tuples

Parameterizing of the auxiliary squares
Magic squares of order $$ n \, $$ contain all values from $$ 1 \, $$ to $$ n^2 \, $$.

$$ n^2 = p_1^{2 \cdot e_1} \cdot \ldots \cdot p_M^{2 \cdot e_M} = \prod_{k=1}^{M} p_k^{2 \cdot e_k} $$ where $$ p_i < p_j \, $$ for $$ i < j \, $$ and $$ p_1 = 2 \, $$

In order to represent the integer numbers from $$ 1 \, $$ to $$ n^2 \, $$ in a positional numeral system any base similar to the ones already used above needs to have $$ 2 \cdot e_{total} \, $$ tuples. Below a noncanocal base is presented::

$$ B^{'} = \left ( \underbrace{ \underbrace{ \left ( p_1,r \right ), \dots, \left ( p_1,r \right ) }_{e_1}, \dots, \underbrace{ \left ( p_M,r \right ), \dots, \left ( p_M,r \right ) }_{e_M}, }_{M} \underbrace{ \underbrace{ \left ( p_1,c \right ), \dots, \left ( p_1,c \right ) }_{e_1}, \dots, \underbrace{ \left ( p_M,c \right ), \dots, \left ( p_M,c \right ) }_{e_M} }_{M} \right ) $$

Let $$ B^{''} \, $$ be a permutation of the $$ 2 \cdot e_{total} \, $$ $$ 2 \, $$ -tuples of $$ B^{'} \, $$ where for two consecutive $$ 2 \, $$ -tuples $$ \left ( p_i,x_i \right ) $$ and $$ \left ( p_{i + 1},x_{i + 1} \right ) $$

$$ x_i = x_{i + 1} \, $$ implies $$ p_i \le p_{i + 1} \, $$

Let $$ P \, $$ be the set of all permutations $$ B^{''} \, $$ of $$ B^{'} \, $$ as described above. The question is what is the number of elements of $$ P \, $$. The requested number can be calculated with a function named $$ \beth \, $$ which depends only on the number and values of the prime decomposition of $$ n \, $$ ; i.e. $$ \beth \left ( {e_1}, \ldots {e_M} \right ) \, $$. Examples of its calculation are given here.

Description about the calculation of $$ \beth \, $$ will follow. One can see that

$$ \beth \left ( {e_1}, \ldots {e_r}, \ldots {e_s}, \ldots {e_M} \right ) = \beth \left ( {e_1}, \ldots {e_s}, \ldots {e_s}, \ldots {e_M} \right ) \, $$ if $$ r = s \, $$

From the construction one can see that this method allows the construction of

$$ 2^n \cdot (\frac{n}{2}!)^2 \cdot \beth(e_1,..., e_M) \, $$ different squares. See matching A051235.

If $$ n = 2^{m} \, $$ where $$ m \ge 2 \, $$ the function $$ \beth(m) \, $$ simplifies to $$ \beth(m) = \binom {2 \cdot m}{m} \, $$ and the number of most-perfect magic squares of order is

$$ 2^{2^m} \cdot (\frac{2^m}{2}!)^2 \cdot \binom {2 \cdot m}{m} \, $$ ( partialy matching A151932 )

To be continued.