Latin Square

DOWNLOAD Mathematica Notebook

An n×n Latin square is a Latin rectangle with k=n. Specifically, a Latin square consists of n sets of the numbers 1 to n arranged in such a way that no orthogonal (row or column) contains the same number twice. For example, the two Latin squares of order two are given by

 [1 2; 2 1],[2 1; 1 2],
(1)

the 12 Latin squares of order three are given by

  [1 2 3; 2 3 1; 3 1 2],[1 2 3; 3 1 2; 2 3 1],[1 3 2; 2 1 3; 3 2 1],[1 3 2; 3 2 1; 2 1 3], 
 [2 1 3; 1 3 2; 3 2 1],[2 1 3; 3 2 1; 1 3 2],[2 3 1; 1 2 3; 3 1 2],[2 3 1; 3 1 2; 1 2 3], 
 [3 2 1; 1 3 2; 2 1 3],[3 2 1; 2 1 3; 1 3 2],[3 1 2; 1 2 3; 2 3 1],[3 1 2; 2 3 1; 1 2 3],
(2)

and two of the whopping 576 Latin squares of order 4 are given by

 [1 2 3 4; 2 1 4 3; 3 4 1 2; 4 3 2 1]  and  [1 2 3 4; 3 4 1 2; 4 3 2 1; 2 1 4 3].
(3)

The numbers N(n,n) of Latin squares of order n=1, 2, ... are 1, 2, 12, 576, 161280, ... (OEIS A002860). The number L(n,n) of isotopically distinct Latin squares of order n=1, 2, ... are 1, 1, 1, 2, 2, 22, 564, 1676267, ... (OEIS A040082).

A pair of Latin squares is said to be orthogonal if the n^2 pairs formed by juxtaposing the two arrays are all distinct. For example, the two Latin squares

 [3 2 1; 2 1 3; 1 3 2]    [2 3 1; 1 2 3; 3 1 2]
(4)

are orthogonal. The number of pairs of orthogonal Latin squares of order n=1, 2, ... are 0, 0, 36, 3456, ... (OEIS A072377).

The number of Latin squares of order n with first row given by {1,2,...,n} is the same as the number of fixed diagonal Latin squares of order n (i.e., the number of Latin squares of order n having all 1s along their main diagonals). For n=1, 2, ..., the numbers of such matrices are 1, 1, 2, 24, 1344, 1128960, ... (OEIS A000479) and the total number of Latin squares of order n is equal to this number times n!.

A normalized, or reduced, Latin square is a Latin square with the first row and column given by {1,2,...,n}. General formulas for the number of normalized n×n Latin squares L(n,n) are given by Nechvatal (1981), Gessel (1987), and Shao and Wei (1992), but the asymptotic value of L(n,n) is not known (MacKay and Wanless 2005). The total number of Latin squares N(n,n) of order n can then be computed from

 N(n,n)=n!(n-1)!L(n,n).
(5)

The numbers of normalized Latin squares of order n=1, 2, ..., are summarized in the following table (OEIS A000315).

nL(n,n)reference
11
21
31
44
556Euler (1782), Cayley (1890), MacMahon (1915; incorrect value)
69408Frolov (1890) and Tarry (1900)
716942080Frolov (1890; incorrect), Norton (1939; incomplete), Sade (1948), Saxena (1951)
8535281401856Wells (1967)
9377597570964258816Bammel and Rothstein (1975)
107580721483160132811489280McKay and Rogoyski (1995)
115363937773277371298119673540771840McKay and Wanless (2005)
121.62×10^(44)McKay and Rogoyski (1995)
132.51×10^(56)McKay and Rogoyski (1995)
142.33×10^(70)McKay and Rogoyski (1995)
151.5×10^(86)McKay and Rogoyski (1995)

Sudoku is a special case of a Latin square.

Wolfram Web Resources

Mathematica »

The #1 tool for creating Demonstrations and anything technical.

Wolfram|Alpha »

Explore anything with the first computational knowledge engine.

Wolfram Demonstrations Project »

Explore thousands of free applications across science, mathematics, engineering, technology, business, art, finance, social sciences, and more.

Computerbasedmath.org »

Join the initiative for modernizing math education.

Online Integral Calculator »

Solve integrals with Wolfram|Alpha.

Step-by-step Solutions »

Walk through homework problems step-by-step from beginning to end. Hints help you try the next step on your own.

Wolfram Problem Generator »

Unlimited random practice problems and answers with built-in Step-by-step solutions. Practice online or make a printable study sheet.

Wolfram Education Portal »

Collection of teaching and learning tools built by Wolfram education experts: dynamic textbook, lesson plans, widgets, interactive Demonstrations, and more.

Wolfram Language »

Knowledge-based programming for everyone.