On Computing the Number of Latin Rectangles

Doyle (circa 1980) found a formula for the number of k×n\documentclass[12pt]{minimal} \usepackage{amsmath} \usepackage{wasysym} \usepackage{amsfonts} \usepackage{amssymb} \usepackage{amsbsy} \usepackage{mathrsfs} \usepackage{upgreek} \setlength{\oddsidemargin}{-69pt} \begin{document}$$k \times n$$\end{document} Latin rectangles Lk,n\documentclass[12pt]{minimal} \usepackage{amsmath} \usepackage{wasysym} \usepackage{amsfonts} \usepackage{amssymb} \usepackage{amsbsy} \usepackage{mathrsfs} \usepackage{upgreek} \setlength{\oddsidemargin}{-69pt} \begin{document}$$L_{k,n}$$\end{document}. This formula remained dormant until it was recently used for counting k×n\documentclass[12pt]{minimal} \usepackage{amsmath} \usepackage{wasysym} \usepackage{amsfonts} \usepackage{amssymb} \usepackage{amsbsy} \usepackage{mathrsfs} \usepackage{upgreek} \setlength{\oddsidemargin}{-69pt} \begin{document}$$k \times n$$\end{document} Latin rectangles, where k∈{4,5,6}\documentclass[12pt]{minimal} \usepackage{amsmath} \usepackage{wasysym} \usepackage{amsfonts} \usepackage{amssymb} \usepackage{amsbsy} \usepackage{mathrsfs} \usepackage{upgreek} \setlength{\oddsidemargin}{-69pt} \begin{document}$$k \in \{4,5,6\}$$\end{document}. We give a formal proof of Doyle’s formula for arbitrary k. We also improve a previous implementation of this formula, which we use to find Lk,n\documentclass[12pt]{minimal} \usepackage{amsmath} \usepackage{wasysym} \usepackage{amsfonts} \usepackage{amssymb} \usepackage{amsbsy} \usepackage{mathrsfs} \usepackage{upgreek} \setlength{\oddsidemargin}{-69pt} \begin{document}$$L_{k,n}$$\end{document} when k=4\documentclass[12pt]{minimal} \usepackage{amsmath} \usepackage{wasysym} \usepackage{amsfonts} \usepackage{amssymb} \usepackage{amsbsy} \usepackage{mathrsfs} \usepackage{upgreek} \setlength{\oddsidemargin}{-69pt} \begin{document}$$k=4$$\end{document} and n≤150\documentclass[12pt]{minimal} \usepackage{amsmath} \usepackage{wasysym} \usepackage{amsfonts} \usepackage{amssymb} \usepackage{amsbsy} \usepackage{mathrsfs} \usepackage{upgreek} \setlength{\oddsidemargin}{-69pt} \begin{document}$$n \le 150$$\end{document}, when k=5\documentclass[12pt]{minimal} \usepackage{amsmath} \usepackage{wasysym} \usepackage{amsfonts} \usepackage{amssymb} \usepackage{amsbsy} \usepackage{mathrsfs} \usepackage{upgreek} \setlength{\oddsidemargin}{-69pt} \begin{document}$$k=5$$\end{document} and n≤40\documentclass[12pt]{minimal} \usepackage{amsmath} \usepackage{wasysym} \usepackage{amsfonts} \usepackage{amssymb} \usepackage{amsbsy} \usepackage{mathrsfs} \usepackage{upgreek} \setlength{\oddsidemargin}{-69pt} \begin{document}$$n \le 40$$\end{document} and when k=6\documentclass[12pt]{minimal} \usepackage{amsmath} \usepackage{wasysym} \usepackage{amsfonts} \usepackage{amssymb} \usepackage{amsbsy} \usepackage{mathrsfs} \usepackage{upgreek} \setlength{\oddsidemargin}{-69pt} \begin{document}$$k=6$$\end{document} and n≤15\documentclass[12pt]{minimal} \usepackage{amsmath} \usepackage{wasysym} \usepackage{amsfonts} \usepackage{amssymb} \usepackage{amsbsy} \usepackage{mathrsfs} \usepackage{upgreek} \setlength{\oddsidemargin}{-69pt} \begin{document}$$n \le 15$$\end{document}. Motivated by computational data for 3≤k≤6\documentclass[12pt]{minimal} \usepackage{amsmath} \usepackage{wasysym} \usepackage{amsfonts} \usepackage{amssymb} \usepackage{amsbsy} \usepackage{mathrsfs} \usepackage{upgreek} \setlength{\oddsidemargin}{-69pt} \begin{document}$$3 \le k \le 6$$\end{document}, some research problems and conjectures about the divisors of Lk,n\documentclass[12pt]{minimal} \usepackage{amsmath} \usepackage{wasysym} \usepackage{amsfonts} \usepackage{amssymb} \usepackage{amsbsy} \usepackage{mathrsfs} \usepackage{upgreek} \setlength{\oddsidemargin}{-69pt} \begin{document}$$L_{k,n}$$\end{document} are presented.


Introduction
A k × n Latin rectangle is a k × n matrix L, with symbols from {1, 2, . . . , n}, such that each row and each column contains only distinct symbols. If k = n then L is a Latin square of order n. Let L k,n be the number of k × n Latin rectangles.
The main purpose of this article is to report the computation of previously unknown values of L k,n (for 4 ≤ k ≤ 6). To the end, we use a formula by Doyle, for which we give a proof for in Sect. 3. We use these values to provide evidentiary support for a question we pose regarding the divisors of L k,n (Question 4). We also present conjectures about divisors of K 3,n (Conjecture 5). Questions about divisors of L n,n were previously raised by Alter [1] and about divisors of L k,n in [35].
A Latin rectangle is called normalised if the first row is (1, 2, . . . , n), and reduced if the first row is (1, 2, . . . , n) and the first column is (1, 2, . . . , k) T . Let K k,n denote the number of normalised k × n Latin rectangles and let R k,n denote the number of reduced k × n Latin rectangles. In the case of Latin squares, the numbers L n,n , K n,n and R n,n will be denoted L n , K n and R n , respectively. The three numbers L k,n , K k,n and R k,n are related by L k,n = n!K k,n = n!(n − 1)! (n − k)! R k,n .
In particular L n = n!K n = n!(n − 1)!R n .
So finding the value of L k,n is essentially the same as finding the value of R k,n or K k,n . McKay and Wanless [23] published a table of values for R k,n when 2 ≤ k ≤ n ≤ 11, which were obtained by lengthy computer enumerations. Some values of R k,n for k ∈ {4, 5, 6} were reported in [36]. Also see [36] for a survey of the formulae involving the number of Latin rectangles. Gessel [15] proved that for every k ≥ 1, there exists a finite M = M(k) such that there exists M + 1 polynomials c i (n) such that 0≤i≤M c i (n)L k,n+i = 0 for all n ≥ k (other than when each c i (n) = 0). So recurrence relations theoretically exist for L k,n for any fixed k. For example, we know that (n + 1)L 1,n − L 1,n+1 = 0 since L 1,n = n! and (n + 2)(n + 1) 2 L 2,n + (n + 2)(n + 1)L 2,n+1 − L 2,n+2 = 0 since L 2,n = n!d n where d n is the number of derangements of n elements, and d n satisfies the well-known recurrence d n = (n − 1)(d n−1 + d n−2 ) where d 0 = 1 and d 1 = 0. Theorem 1 (in the next section) gives such a recurrence for k = 3.
In the next section we give an historical survey of the formulae for R 3,n , the case of three-line Latin rectangles. Despite the numerous formulae for R 3,n , we are still unable to fully explain the growth in the largest power of 2 that divides R 3,n . Afterwards, we use a formula by Doyle (improving on the implementation used in [35]) to compute values of R k,n when 4 ≤ k ≤ 6. We give a proof of this formula in Sect. 3. We find that the divisors of R k,n with k ∈ {4, 5, 6} display similar behaviour to that of R 3,n . Based on this data, in Sect. 5 we discuss the asymptotic behaviour of the divisors of R k,n for fixed k and present some conjectures about the divisors of R 3,n .

Three-line Latin Rectangles
The enumeration of three-line Latin rectangles has a long history, which we will now review in detail. We also direct the reader to [36], which gives a survey of formulae for L k,n for general k, but does not go into detail about the three-line case. We list the first few non-zero values of L 3,n , K 3,n and R 3,n in Table 1.
There are many known general formulae for L k,n (see [36]), of which L 3,n is a special case. For example, the following result originated with MacMahon [22] in 1898. Let X = (x i j ) be a k ×n matrix whose symbols are the kn variables x i j . We index the rows of X by [k] := {1, 2, . . . , k} and the columns of X by [n] := {1, 2, . . . , n}. Let S k,n be the set of injections σ : [k] → [n]. We define the permanent of the rectangular matrix X to be Then L k,n is the coefficient of k i=1 n j=1 x i j in per(X ) n . Let B k,n be the set of k × n (0, 1)-matrices. Fu [13] and Shao and Wei [31] gave the formula where σ 0 (A) is the number of 0 elements in A, which was generalised in [36] (see also [23]).
The first published formula specifically for L 3,n seems to be by Jacob [19] in 1930, although some errors in [19] were later rectified by Kerawala [20] to give the following theorem.
Riordan [26] proved that K 3,n ∼ n! 2 exp(−3), which he described as "a result which Kerawala surmised but failed to prove, though his numerical evidence was practically conclusive (agreeing with exp(−3) to seven decimal places)." Jacob [19] also mentioned the possibility of n! 2 /K 3,n → exp(3), but it was subsequently abandoned. This asymptotic formula was generalised by Erdős and Kaplansky [11], who found that L k,n ∼ n! k exp − k(k − 1)/2 for k = O (log n) 3/2− , which has since been extended (see [36] for an history). The most up-to-date asymptotic enumeration is by Godsil and McKay [17], who proved L k,n ∼ n! k n(n − 1) · · · (n − k + 1)/n k n (1 − k/n) −n/2 exp(−k/2) as n → ∞ with k = o(n 6/7 ). In [27] (see also [29]), Riordan gave a formula for K 3,n that involves the problème de ménages. Specifically where d n is the number of derangements of n elements (Sloane's [34] A000166) and u n is given by where u 0 = 1. The numbers u n for n ≥ 2 are the ménages numbers (Sloane's A000179). The ménages numbers can also be defined as the number of permutations σ of [n] such that σ (i) ≡ i (mod n) and σ (i) ≡ i + 1 (mod n) for all i ∈ [n]. However, for (1) to be valid, we require u 1 = −1, which is inconsistent with the "number of σ " definition, but is consistent with (2) (this issue was raised by Vladimir Shevelev on Sloane's A000186). Riordan's formula (1) was generalised by Moser [24] to count normalised three-line Latin rectangles where the derangement defined by the second row does not have cycle lengths belonging to some set S. A related generalisation was given by Shevelev [32] where instead the cycle lengths belong to S. Riordan [28] also gave the recurrence equation where and s 0 = 1. We find that using (3)-(4) is the fastest way to compute K 3,n in practice. This is unsurprising as it requires only a finite number of arithmetic operations to compute K k,n (from previous terms and the auxiliary function s n ). With the exception of Kerawala's recurrence (Theorem 1), all other formulae for L k,n we survey require a number of arithmetic operations which grows with n. Dulmage [9] posed an "explicit (though complicated)" formula for L 3,n as a problem, which was later refined by Dulmage and McMaster [10] who gave which they used to compute K 3,n for n ≤ 40 on an IBM 370/158 in approximately five seconds. Bogart and Longyear [3] gave where the sum is over all non-negative integers p, q, r , s and d which sum to n. Bogart and Longyear used their formula to find L 3,n for n ≤ 11 (although some typographical errors were pointed out in [39]) and gave an approximation of L 3,n for n ≤ 20. Riordan [28] said Yamamoto [44] found the equation where the sum is over all non-negative integers a, b and c which sum to n.
Goulden and Jackson [18] showed that K 3,n is the coefficient of x n /n! in the series expansion of This was generalised by Gessel [14] to count pairs of discordant derangements. Specifically, the number of pairs (π, σ ) of derangements of [n] such that πσ −1 is also a derangement, π has a cycles and σ has b cycles is the coefficient of Riordan [28] gave the recurrence congruence R 3,n+ p ≡ 2R 3,n (mod p) for all odd primes p, provided n ≥ 3, which was generalised by Carlitz [5] to R 3,n+t ≡ 2 t R 3,n (mod t) for all t ≥ 1. This was generalised to k-line Latin rectangles in [39], who gave for all k ≥ 1 and t ≥ 1 provided n ≥ k. It was also noted in [39] that some primes p do not divide R 3,n for any n ≥ 3. For example, any prime p ∈ {3, 5, 11, 29, 37, 41, 43, 53, 67, 79, 83, 97} does not divide R 3,n for all n ≥ 3 (see [36,39]). There are also published formulae for four-line Latin rectangles by Light Jr. [21], Pranesachar et al. [2,25] and Doyle [6]. We will discuss Doyle's formula in the next section, which is, by far, the best method for finding the exact value of R k,n for 4 ≤ k ≤ 6.

Doyle's Formula
The computation of L k,n for k ∈ {1, 2, 3} can be considered as effectively "solved": we have L 1,n = n!, and L 2,n can be found by computing the number of derangements d n . For n = 3, using Riordan's recurrence (i.e., (3)-(4)), we computed L 3,n for all n ≤ 2 21 ≈ 2 × 10 6 on a desktop computer in under 38 hours (we use these results in Section 5). As we will see, computing L k,n for k ≥ 4 is much more difficult practically.
Exact enumeration is difficult for k > 3. -Skau [33] In [6], Doyle gave formulae for K k,n for k ≤ 4 and indicated how they could be generalised to arbitrary k. This generalisation was subsequently used in [36] to find values K k,n when k ≤ 6 (although a proof was not given). For the sake of rigour, we will give a proof of Doyle's generalised formula. The overall idea of the formula is to use Inclusion-Exclusion on ordered n-tuples of columns. We include all such n-tuples, then exclude those that clash. To count the number of n-tuples that clash, Möbius Inversion is used on each column, counting the number of arrangements that "avoid" a certain substructure (e.g. symbol 1 in row 2).
Let R be the set of non-negative integer vectors s = ( Let L = (l i j ) be a normalised k × n Latin rectangle. From L we can construct a k × n × n (0, 1)-array P = ( p i jr ) where p i jr = 1 whenever l i j = r . We will find it helpful to think of P as an ordered n-tuple of n × jr . An example of this equivalence is given in Fig. 1; the shaded entries must be zero since L is normalised.
For 1 ≤ j ≤ n, and D ∈ S, let D j be the matrix formed from D after the j-th row has been converted to a row of ones. By Inclusion-Exclusion Then this would imply that symbol r does not appear in row i + 1 of L, giving rise to a clash. Therefore, we then exclude all such n-tuples for which there exists some D ∈ S containing a 1 for which every M j avoids D.
From any D ∈ S we construct a vector s = (s 1 , s 2 , . . . , s 2 k−1 ) in the following way. Each row of D can be considered the binary digits of some number between 0 and 2 k−1 − 1 (inclusive). Let s t be the number of rows in D that are the binary digits of t. To be consistent with [36], we use s 2 k−1 = s 0 in the statement of the theorem. This does not affect the proof since the first k − 1 binary digits of both 0 and 2 k−1 are zero. Hence σ (D) = ||s||. This process is depicted in an example in Fig. 2.
The number of D ∈ S that give rise to a given s ∈ R is given by the multinomial coefficient n s 1 , s 2 , . . . , s 2 k−1 .
We can partition S according to s ∈ R, whence two matrices D and D in the same part have |X (D)| = |X (D )|. For each s ∈ R, choose a representative D * = D * (s).
We can decompose any N ∈ Y P into |P| submatrices N p for each p ∈ P. An example of this decomposition is given in Fig. 3; we shade the entries that N and the N p avoid. For a given D ∈ S, the number of possible submatrices N p is equal to the number of rows of D that map to a number t for which the j-th binary digit of t is zero for all j ∈ p (informally, we can choose a single row of ones in N p that avoids the ones in D); this number is given by (8). Therefore |Y P | = p∈P f p (a). It is now sufficient to show that g(a) If P, Q ∈ P k−1 and P is a refinement of Q, then we write P Q and Q P. If additionally P = Q, then we write P Q and Q P. For the remainder of this proof, P ∈ P k−1 will be the partition of cardinality k − 1, i.e., we will henceforth assume P = {{1}, {2}, . . . , {k − 1}}.
By Inclusion-Exclusion, for some integer coefficients μ(P, Q), where μ(P, P) = 1. To ensure the matrices M ∈ Y P with some duplicated columns are counted 0 times overall, the coefficients μ(P, Q) must satisfy P R Q μ(P, R) = 0, whenever P Q. Therefore μ(P, Q) = − P R Q μ(P, R). Hence μ is the Möbius Function for the lattice of partitions P k−1 (see [30, pp. 359-360] or [43, pp. 333-336] for example). Since P is the partition of cardinality k − 1, we find μ(P, Doyle's equation for K k,n might seem intimidating at first, but if we fix a value of k, then g(a) and the f p (a) are fixed multivariate polynomials. Afterwards, for each vector s ∈ R, computing its contribution to (6) is a straightforward task.
Doyle's formula was used in [36] to find R 4,n for n ≤ 80, R 5,n for n ≤ 28 and R 6,n for n ≤ 13. Motivation for finding more of these numbers comes from the following question in [35], which was posed after considering the data for R 4,n and R 5,n in [36].

Question 3 How do the prime power divisors p a of R k,n behave asymptotically for a fixed k > p as n → ∞ or as both k → ∞ and n → ∞?
Some general results concerning the divisors of R k,n were given by [39]. For example, we know that p n/ p divides R k,n+d and K k,n when p is a prime and d ≥ k > p.

Implementation
The first author gave a basic implementation of Doyle's formula in C available from http://code.google.com/p/latinrectangles/downloads/list (12) which was used in [36] to find R 4,n , R 5,n and R 6,n for n ≤ 80, n ≤ 28 and n ≤ 13, respectively. Some basic, but significant improvements to the code were made, most notably: 1. Parallelisation. In order to implement Doyle's formula in parallel, we partition R into x parts, where x is the number of processes to be run in parallel. Using lexicographic ordering on R, we find x − 1 vectors z 1 , z 2 , . . . , z x−1 , such that the x sets have roughly the same cardinality. The Maple code used to find the vectors z i is also available from (12). 2. Symmetry. We identify a group G that acts on R such that the contribution to (6)  Using the aforementioned improvements, we were able to find R k,n when k = 4 and n ≤ 150, as at Sloane's [34] A000573, k = 5 and n ≤ 40, as in Fig. 4 (Fig. 5 gives the prime factorisations), k = 6 and n ≤ 15, as in Fig. 6.
The improved version of the code can also be downloaded from (12). Theoretically, if we found enough values of R 4,n , we could use Sister Celine's technique [45] to propose a recurrence for R 4,n . However, it seems that very many values of R 4,n would be required to find the recurrence, well beyond the values for n ≤ 150 we currently have.
We can use (5) to check that the values are indeed correct. It is highly unlikely that an erroneous implementation would still return numbers that satisfy all of the recurrences implied by (5). We can also check that the number of digits is roughly what we expect based on the asymptotic formula and neighbouring data points.
Doyle's formula iterates through each s ∈ R = R(k, n); a "stars and bars" argument gives  although we do reduce the number of required iterations by a factor of (k −1)! through symmetry. For the purpose of inspecting the divisors of R k,n , we are particularly interested in finding more values of R 5,n . We can estimate how many times longer it would take to compute R k,n+1 than R k,n with the ratio r k,n := |R(k, n + 1)| |R(k, n)| = n + 2 k−1 n + 1 , which is close to 1 when n is much larger than 2 k−1 . For example, r 4,150 ≈ 1.1, r 5,40 ≈ 1.4 and r 6,15 ≈ 2.9. So it would be possible to find more values of R 4,n , but we had to stop somewhere.

Divisors
The question of divisors of R n , and in particular powers of 2 and 3, was originally raised by Alter [1] about Latin squares. This question, along with analogous questions for Latin rectangles, has been a hot research topic for Stones [35], and is linked to the autotopisms and automorphisms of Latin rectangles [4,39] (see also [12,38]), and orthomorphisms and partial orthomorphisms of finite cyclic groups [40,41]. Divisors for the number of even/odd Latin squares have been used in proving special cases of the Alon-Tarsi Conjecture [7] (see also [8,16,37,42]). For any prime p, let ω p (n) be the largest non-negative integer such that p ω p (n) divides n, that is the p-adic valuation of n. In Fig. 7, we plot ω 2 (R k,n ) for k ∈ {3, 4, 5, 6} and small n. In Fig. 8, we plot ω 3 (R k,n ) for k ∈ {4, 5} and small n. This data leads us to the following question. The gradients implied by Question 4 match those in Fig. 9, which are suggested by the empirical data.
The divisors of R k,n for primes p ≥ k do not display the same characteristics as when p < k. For example, 3 does not divide R 3,n for any n ≥ 3, whereas a growing power of 3 divides R 4,n [39].
Conjecture 5 implies that ω 2 (K 3,n ) is not bounded below by n−c for any constant c. Furthermore, Conjecture 5 implies that the error term for the first order approximation in Question 4 is at least O(log n).