This Thursday, while solving Polish 2018 P6, I remembered the well-known fact that a complete graph on an odd number of vertices can be decomposed into Hamiltonian cycles, which led me to wonder how many such decompositions there are. After asking Gemini, I was informed that this is an open problem where the lower and upper bounds are quite far apart from each other. I jokingly told my friend “there ain’t nothing a Devin Max subscription can’t beat” and decided to just have Devin Ultra try to come up with a better bound. After around an hour of thinking it came back with (a claim that has not been formally verified). It then claimed that the method could be used to improve the asymptotics for Latin squares, and several days and a lot of prompting later it had produced improved bounds on the number of Latin squares, together with a Lean formalization.
Let be the number of Latin squares of order
. The classical bounds, from the van der Waerden permanent bound
and Brégman’s theorem, determine
up to a factor
. We prove
for an explicit constant , so
, and then that the lower bound gives the right coefficient,
Both statements are formally verified in Lean 4. Finally we describe a claimed explicit rate, which is not formalized:
Section 1 gives the proof of the gap in full. Sections 2 and 3 are overviews: they state the key theorems
behind the two sharper results and show how they combine; the proofs of these theorems are in the accompanying
papers [1, 2].
The result extends to Latin rectangles. Let be the number of
Latin rectangles. For every
,
so the formula of Godsil and McKay, known to be asymptotically exact for , gives
up to a factor
for every number of rows. Away from squares the error is smaller: for all
the two sides differ by at
most
, so for
the formula gives
up to a factor
. Both statements are also
formally verified in Lean 4; they are described in Section 5 and proved in [3].
Authorship. This overview was written with AI assistance (Devin, an AI system built by Cognition AI). The author
has worked through only the proof of the gap in Section 1; Sections 2 and 3 summarize results produced
by the AI system, which the author has not verified. The same holds for Section 5. The
theorem and the two rectangle theorems are certified by the Lean proof.
This paper will take the entropy-based perspective on Latin squares, redefining it as a collection of bijections from
to
(finite sets, both of size
) such that
for any
, where each
represents the
th row as a
bijection between the numbers
and the columns! Choosing an arbitrary Latin square
uniformly at random gives
that,
where denotes the Shannon entropy of the random variable. Observe that
since the last color
is forced. The
may be bounded by using that
is a
-regular bipartite graph, thus it consists of at
most
even cycles and consequently
.
This section will focus on the following proving the following result,
The theorem is unconditional and has been formally verified in Lean 4. The constant is unoptimized, in fact it can be
improved quite substantially with a number of different techniques, however since the next section is focused on showing that it
may be optimized to
I see no reason to overcomplicate the proof.
Throughout the proof many constants are used, this is a quick table reference to them. Let denote a
random
variable.
Let us define (a bipartite graph with
) as the available option graph after
steps, or more formally
, where one interprets each
as a perfect matching from
to
.
The idea of counting the number of matchings through the following two quantities,
Proposition 1 (Row Bound). Let be jointly distributed, with
a function of
, where
is a
-regular
bipartite graph on
,
, and
is a perfect matching of
. Then
Proposition 2 (Exchangeability). Let be a uniformly random Latin square. For the row
, with
,
Moreover for every
-regular
and perfect matching
of
.
Thus, letting (where
) the main inequality used in this section is,
This constant inequality (Lemma 1) is nothing particularly interesting and for the exact proof refer to the AI generated writeup in the accompanying files.
These inequalities together produce a tighter gap,
Let be some ordering then
and let
. The idea is to
select a value based on its popularity among other still searching columns, this is done by taking the probability distribution
where
and
(where
is the set of available values) is a normalization
constant. By Gibb’s inequality (let
),
| (1) |
Proof. Let . Observe that one may write
in terms of indicator functions as
where
and
. A similar rewrite may be done with
,
Thus, is the sum a constant and
i.i.d. Bernoulli random variables and thus,
where (
is the probability that
is
). Thus,
where per definition has an expectation of
. □
Let us fix ,
and
, then since
(because
) a bound on
may be obtained with
(where
),
| (2) |
Observe that . Let us bound the terms independently,
Let and
then by the Covariance Bound (Proposition 5),
The other terms are bounded similarly using the Covariance Bound (Proposition 5),
Thus, (using )
The value of in Equation 2 is simply
(since
is the sum of Bernoulli variables) and thus,
Thus, looking back at Equation 1 one is left with the task of integration over and taking the expectation.
Recall that everything above was computed for fixed ,
,
and conditionally on
, so that the indicators
,
, are i.i.d. Bernoulli
. Since
has the same distribution as
, we have
as well, and therefore
| (3) |
The time is uniform on
, hence so is
, and integrating (3) over
gives
Now sum over . By definition
and
,
so
where is the number of triples
with
,
,
, and
is the number of pairs
with
,
. Hence, for fixed
and
,
Finally take the expectation over in (1) to obtain Proposition 1!
Let us split Proposition 2 into two parts,
Proof. Since for there are no more than
values
with
, thus giving the trivial bound of
! □
Proof. Let a row be late if it comes after . Write
and
. Then, there are two options either all the
edges
,
and
are in different matchings, or
and
are in the same matching.
Since doesn’t depend on the order,
can be generated by first choosing the unordered set
of its
rows and then
putting them in a uniformly random order. For a row
and
distinct rows
,
| (4) |
The inequality holds because for
. Observe,
So it remains to bound the probability of each configuration by (4), and to count the configurations.
Type (a): lie in three distinct rows. These three rows must all be late, so by (4) with
each such configuration
has probability at most
. There are at most
configurations in total (
choices for each of
), so type (a)
contributes at most
Type (b): and
lie in the same row
. Now only two distinct rows must be late (
and the row of
), so by
(4) with
each such configuration has probability at most
, which is larger than in type (a). There
are at most
(since one needs to only fix
,
and
) configurations of type (b), and they contribute at
most
Adding the two contributions, for every
, and averaging over
gives the claim.
□
Thus Lemma 3 and Lemma 4 give Proposition 2!
This section is an overview of the proof of
The theorem has been formally verified in Lean 4 with no hypothesis (theorem mainStatement, for the count Erdos725.L n n of the library formal-conjectures). The full written proof is in [1]; here only the key theorems are stated, with a few words on why each holds, followed by the calculation that combines them.
The lower bound follows from the permanent inequality of Gurvits [11] applied row by row.
So everything is about the upper bound. The bound used in the previous section was,
and its three terms sum to ,
and
. To reach
two things must be improved: the term
must
become
on most rows, and the constant
must be brought down to
. The first is done by Theorem A below,
the second by Theorems B, C and D:
For rows with a different predictor is used (guess
with probability proportional to
instead of
).
The constant of
is far worse than in Proposition 1, which is why this bound is only used for
, where
.
An intercalate of a Latin square is a Latin subsquare, i.e. two rows and two columns whose four cells contain only two
symbols. Let
be their number. In Section 1 the quantity
was bounded trivially by
. In fact
by the argument of Lemma 4, where the second term comes from the configurations in which the two late
edges lie in the same row. The same configurations appear in every pattern count of Theorem C, so a bound on
is
needed.
The proof is independent of everything else and has three steps.
The factor is harmless: it only enters the row bounds through
, and
.
Remark. Kwan, Sah and Sawhney [10] proved a large deviation bound which gives for all large
. With their
theorem, Theorem B is not needed and the factor
disappears from all calculations. Their theorem is not used here, so that the
proof (and its Lean verification) rests on no result outside the standard library.
For rows with the columns are revealed in a random order as in Proposition 1; a column revealed at time
sees about
available symbols. The interval of
is cut in three, for constants
:
Let be the following random rooted tree with a perfect matching. The root (a column) is matched to one marked child and
has
further children; a vertex matched to its parent has
children; any other vertex is matched to one of its children
and has
further children. The cost of a local rule
on the tree is
, and we
put
where is a Poisson variable of mean
and
is the limit of
as
with
. The term
is what is saved by not using the rule
for
, and the integral is what the local rule costs
instead.
The proof couples the ball around in the leftover graph of a random Latin square with
. The two differ only when the
exploration of the ball meets a vertex twice, and the expected number of such repeats is bounded by counting patterns in a
random Latin square, as in Proposition 2. The patterns that contain two edges of the same row are controlled
by Theorem B. The
comes from mixing
with the uniform guess, so that the cost of a wrong prediction is
bounded.
The best rule of radius (the cavity rule) guesses the conditional law of the marked child given the tree up to depth
. Its cost
decreases in
, to a limit
, so
By the lower bound and Theorem C, for every local rule, so Theorem D is sharp. It rests on three facts about
. Let
be independent copies of the likelihood ratio of the subtree below a child of the root,
and
Together,
and one takes ,
small and
large. Note where the
comes from: it is the term
in fact 3, multiplied by
.
Fix and take
from Theorem 5, then
small. Use Proposition 3 for
, Theorem 4 (with
) for
, and the trivial bound
for the
rows with
:
So the three halves are: from Stirling’s formula in the main term,
from the tree constant (Theorems B, C, D), and
from
on the dense rows (Theorem A).
The proof of the previous section gives no rate for the : in Theorem D the radius of the rule
is not controlled as
,
because
is only known as a limit, and the constants of Theorem C depend on
in an unspecified way. The note [2]
makes both quantitative.
Status. Unlike Theorems 1 and 2, this theorem is not formalized in Lean, and its proof has not been checked independently. It should be read as a claim.
The lower bound already has the error , so again only the upper bound matters. Theorems A and B are used
unchanged; Theorems D and C are replaced by the following two.
Theorem 7 (Theorem D, Bethe inequality at finite depth). There is a constant
such that for every integer
, with
and
, the cavity rule of radius
satisfies
This is Theorem D with a rate. It is not obtained from a rate for , which is not known. Instead the proof of the Bethe
inequality is repeated at finite depth, where the laws of the likelihood ratio at depth
are no longer a fixed point of the recursion.
The amount
by which they fail to be one is a difference of a bounded monotone sequence, so
, and among the
depths
there is one with defect at most of order
. Since
is non-increasing in
, that depth suffices. Balancing
the resulting error
against the other small parameters of the Bethe inequality gives the exponent
.
Proposition 4 (Theorem C, transfer with explicit constants). There are constants
such that for every row with
, every integer
, all
,
with
,
and every local rule
of radius
,
This is Theorem C with the dependence on the rule made explicit: the number of patterns that can occur in a ball of radius is
, and this is the factor
. It multiplies
, which is small compared with
when both
and
are
large. So the radius may grow with
, and may depend on the row.
Let .
Sparse rows, . Let
and use the cavity rule of radius
This choice makes , so by Theorems C
and D
Summing over the sparse rows, ,
, all terms inside the
sum to
, and the
remaining term is
after substituting for
and
for
. With
this gives
The only term that is not is the one with
, so the rate is decided by the exponent in Theorem D
.
Proposition 5 (Covariance Bound). Let be i.i.d. Bernoulli
, let
be index sets with
and
, let
, and let
. With
,
Proof. Let , let
be independent copies of the
, and let
be
with
replaced by
. Then
, and
is independent of
and distributed
as
. So the left side equals
. Fix
and write
,
,
, where
is independent of
and
,
are each distributed as
. Then
and
. Since
and
,
Apply the Cauchy–Schwarz inequality to each of the terms. □
A Latin rectangle is a
array with entries in
and no repeated symbol in a row or a column;
is
their number, so
. Erdős Problem 725 [14] asks for a formula
with
for all
.
Known results.
With , Godsil and McKay [15] proved for
that
and Li [16] extended this to all . For
proportional to
we found only the classical bounds from the van der
Waerden and Brègman theorems,
whose logarithms differ by for
, and by
for
.
The new results. They are proved in [3] and formalized in Lean.
So the formula of Godsil and McKay gives up to a factor
for every number of rows. For
this
determines the coefficient of
in
: the classical lower bound is correct up to
. For
the
theorem is much weaker than [15, 16], and in no range does it give the factor
that Problem 725 asks
for.
So for proportional to
the formula of Godsil and McKay gives
up to a factor
, where the classical bounds
differ by
. This is still far from the factor
of Problem 725, and an error of order
in
is the limit of
the method, because the lower and upper bounds for one row differ by a constant factor. Theorem 9 is the stronger of the two
when
and Theorem 8 when
.
Proof of Theorem 8.
Let . By the permanent inequality of Gurvits [11], every Latin rectangle with
unused symbols in
each column can be extended by one row in at least
ways, so
. Using this for the first
rows and
for the last
rows,
The right side does not depend on , and it is
: this is the theorem for squares together with
, which is how the lower bound for squares is proved. Finally
uniformly in
, by Stirling’s formula. Any sharper bound for squares, such as the
one of [2], carries over to all rectangles in the same way.
Proof of Theorem 9.
Here the upper bound is also obtained row by row. Let . The lower bound for one row is
as above. For the upper bound, the entropy bound for rows with many free symbols (the dense row
bound of [1]) is applied to the last row
of a uniformly random
Latin rectangle, given the first
rows:
The proof of that bound uses the Latin square only through one estimate: the expected number of triples
, with
columns and
a symbol, such that
is unused in
and in
and
is unused in
, must be at
most about
. For squares this came from the symmetry between all
rows. For rectangles it follows from
the Cauchy–Schwarz inequality. Let
be an
Latin rectangle,
, and
the number of
symbols unused in both columns
and
. Summing
over the choice of the row
among the
rows of
gives
because and so
. The rows of a uniformly random rectangle can be permuted, so the
expectation of
for the last row is at most
. Finally both one-row bounds differ from
by at
most
, and
.
[1] The number of Latin squares: , accompanying paper
(latin_squares.pdf), with the Lean formalization in the repository.
[2] An explicit error term for the number of Latin squares, accompanying note (latin_rate.pdf).
[3] The number of Latin rectangles: the Godsil–McKay formula for every number of rows, accompanying note (latin_rectangles.pdf).
[4] J. H. van Lint, R. M. Wilson, A Course in Combinatorics, Cambridge University Press, 1992, Chapter 17.
[5] L. Kopfová, M. Kwan, R. Montgomery, K. Petrova, Asymptotic probabilities in random Latin squares, arXiv:2611.24564 (2026).
[6] J. Radhakrishnan, An entropy proof of Bregman’s theorem, J. Combin. Theory Ser. A 77 (1997), 161–164.
[7] L. M. Brègman, Certain properties of nonnegative matrices and their permanents, Dokl. Akad. Nauk SSSR 211 (1973), 27–30.
[8] G. P. Egorychev, The solution of van der Waerden’s problem for permanents, Adv. Math. 42 (1981), 299–305.
[9] D. I. Falikman, Proof of the van der Waerden conjecture regarding the permanent of a doubly stochastic matrix, Mat. Zametki 29 (1981), 931–938.
[10] M. Kwan, A. Sah, M. Sawhney, Large deviations in random Latin squares, Bull. Lond. Math. Soc. 54 (2022), 1420–1438; arXiv:2106.11932.
[11] M. Laurent, A. Schrijver, On Leonid Gurvits’s proof for permanents, Amer. Math. Monthly 117 (2010), 903–911.
[12] N. Alon, S. Friedland, The maximum number of perfect matchings in graphs with a given degree sequence, Electron. J. Combin. 15 (2008), Note 13.
[13] A. Ferber, V. Jain, B. Sudakov, Number of -factorizations of regular high-degree graphs, Combinatorica 40
(2020), 315–344; arXiv:1803.10360.
[14] T. F. Bloom, Erdős Problem #725, https://www.erdosproblems.com/725.
[15] C. D. Godsil, B. D. McKay, Asymptotic enumeration of Latin rectangles, J. Combin. Theory Ser. B 48 (1990), 19–44.
[16] E. Li, The Godsil–McKay asymptotic for Latin rectangles in the sublinear range of Erdős Problem 725, arXiv:2608.01671 (2026).