\myheading{A simple Latin Square}

\renewcommand{\CURPATH}{latin/simple}

A popular way of representing \ac{LS} as cube.
Third dimension is added: symbol (number).

Sometimes also called ``incidence cube''
[see: Mark T. Jacobson, Peter Matthews -- Generating Uniformly Distributed Random Latin Squares (1996)].

For example, this is the normalized \ac{LS}
\footnote{
A \textit{Normalized/reduced} Latin square has first row and column consisting of ascending numbers/symbols (0,1,2,3...)
}
I visualized using matplotlib:

\begin{lstlisting}
012345
154230
245013
301524
430152
523401
\end{lstlisting}

% TODO side by side
\begin{figure}[H]
\centering
\myfbox{\includegraphics[scale=0.7]{\CURPATH/L6_cube/cube_00780_060_060.png}}
\end{figure}

\begin{figure}[H]
\centering
\myfbox{\includegraphics[scale=0.7]{\CURPATH/L6_cube/cube_00765_045_045.png}}
\end{figure}

By looking from all three sides, you'll see all $6 \cdot 6=36$ cubelets, but only one in each \emph{slot}:

% TODO side by side
\begin{figure}[H]
\centering
\myfbox{\includegraphics[scale=0.7]{\CURPATH/L6_cube/cube_00000_000_000.png}}
\end{figure}

\begin{figure}[H]
\centering
\myfbox{\includegraphics[scale=0.7]{\CURPATH/L6_cube/cube_00090_000_090.png}}
\end{figure}

\begin{figure}[H]
\centering
\myfbox{\includegraphics[scale=0.7]{\CURPATH/L6_cube/cube_00450_090_000.png}}
\end{figure}

Also, see the video for L(6) \ac{LS}: \url{https://www.youtube.com/watch?v=Fk-ysMqcO98}

See the video for L(10): \url{https://www.youtube.com/watch?v=zT04G60VKD8}.
Notice the distinctive ``V'' shape, which is the result of normalization (\verb|0..9| in first row and column).

Also L(16): \url{https://www.youtube.com/watch?v=Lovt41KVkwM},
L(25): \url{https://www.youtube.com/watch?v=1eVsFy_gLaY},
L(36): \url{https://www.youtube.com/watch?v=IgYuqRXry0A}.

Adding constraints for such a \emph{cube} is easy:

\begin{lstlisting}[style=custompy]
def latin_add_constraints(SIZE, s, ar):
    # 'cube'

    # one hot for each r, c.
    for r in range(SIZE):
        for c in range(SIZE):
            tmp=[ar[r][c][n] for n in range(SIZE)]
            s.make_one_hot(tmp)

    # one hot for each r, n
    for r in range(SIZE):
        for n in range(SIZE):
            tmp=[ar[r][c][n] for c in range(SIZE)]
            s.make_one_hot(tmp)

    # one hot for each c, n
    for c in range(SIZE):
        for n in range(SIZE):
            tmp=[ar[r][c][n] for r in range(SIZE)]
            s.make_one_hot(tmp)
\end{lstlisting}
( The full file: \url{\RepoURL/latin/latin_utils.py} )

Adding ormalization constraints are also easy:

\begin{lstlisting}[style=custompy]
def fix_first_row_increasing(s, a, SIZE):
    # setting first row of $a$ to [0..SIZE-1]
    for _c in range(SIZE):
        _r=0
        tmp=SAT_lib.n_to_BV(1 << _c, SIZE)
        s.fix_BV(a[_r][_c], tmp)

def fix_first_col_increasing(s, a, SIZE):
    # setting all columns to [0..SIZE-1]
    for _r in range(SIZE):
        _c=0
        tmp=SAT_lib.n_to_BV(1 << _r, SIZE)
        s.fix_BV(a[_r][_c], tmp)
\end{lstlisting}
( The full file: \url{\RepoURL/latin/latin_utils.py} )

Generating small \ac{LS} is easy, see source code: \url{\RepoURL/latin/simple/LS.py}.

The largest \ac{LS} I could generate is of order 180 -- ~8 hours on AMD Ryzen 5 3600 6-Core Processor using the Gimsatul
parallel SAT solver running on 6 threads: \url{\RepoURL/latin/simple/L180.txt}.

An important note: forcing a Latin square to be \textit{normalized} makes search space much smaller.
Obviously, there are much less \textit{normalized} squares than \textit{usual} ones.

See a number of Latin squares in \ac{OEIS}:

\begin{lstlisting}[basicstyle=\ttfamily\footnotesize]
A002860 Number of Latin squares of order n; or labeled quasigroups.
1, 2, 12, 576, 161280, 812851200, 61479419904000, ...
\end{lstlisting}
( \url{https://oeis.org/A002860} )

A number of \textit{normalized/reduced} Latin squares:

\begin{lstlisting}
A000315 Number of reduced Latin squares of order n;
also number of labeled loops (quasigroups with an identity element)
with a fixed identity element.
1, 1, 1, 4, 56, 9408, 16942080, 535281401856, ...
\end{lstlisting}
( \url{https://oeis.org/A000315} )

And these is \textit{symmetry breaking} constraints that makes Latin square to be \textit{normalized/reduced}.
Sometimes they make SAT solver work faster, but sometimes not.
As they say, \textit{your mileage may vary}, they can help for your specific problem, or may not.

