1991 Mathematics Subject Classification. Primary 13P99, 13D40, 05C69, 05C38.
<ph f="cmbx">Counting monomials</ph>

Mordechai Katzman

Department of Pure Mathematics, University of Sheffield, Hicks Building, Sheffield S3 7RH, United Kingdom, Fax number: 0044-114-222-3769 E-mail address : M.Katzman@sheffield.ac.uk

1 Introduction and preliminaries.

The purpose of this note is to illustrate two powerful enumeration techniques based on computational Commutative Algebra methods.
By way of illustration I chose to apply these methods to the following two elementary problems:
  • (1) Consider a n × n   chessboard. What is the maximal number of unattacked squares in the board after placing on it k   queens? More generally, in how many ways can we place k   queens on a chess board to obtain exactly u   unattacked squares?
  • (2) Consider an infinite chessboard. How many squares can a knight reach in d   moves? How many squares can be reached in d   moves and no less?
Although these problems are phrased in the language of chess, they are specific instances of more general graph-theoretical problems. The enumeration techniques presented here answer these more general problems.
At the heart of the methods presented in this paper are the notions of graded modules and their Hilbert functions. In essence, we will reduce each of the problems above to a problem about the enumeration of sets of monomials, and this enumeration will be achieved using Hilbert functions.
While the application of Hilbert functions to the problems presented in this paper is new, the use of Hilbert functions in combinatorics is not. The solution of some simple enumeration problems using Hilbert functions, such as finding the independence number of a graph, has long been part of the folklore of computational commutative algebra experts. An early and striking example of the use Hilbert functions in combinatorics is Richard P. Stanley's work on magic squares (I refer the reader to [8for an accessible and thoroughly enjoyable account of this work.) We now review graded modules and Hilbert functions. Throughout this paper, all rings are commutative and with 1   ; K   will always denote a field.
A K   -algebra R   is N N   -graded if we can write R = a N N R a ,   a direct sum of abelian groups, and the direct summands satisfy R a R b R a + b   for all a , b N N   . Henceforth we shall also impose the condition R 0 = K   , which implies that each R a   is a K   -vector space and that, if R   is a finitely generated K   -algebra, each R a   is a finite dimensional K   -vector space. For each a N N   we shall refer to the elements of R a   as being homogeneous of degree a   .
A fundamental example of such a graded K   -algebra is the ring of polynomials R = K [ x 1 , . . . , x n ]   .
We can endow R   with different graded structures. We are all familiar with the N   -grading R = a N R a   in which each R a   consists of the homogeneous polynomials of degree a   . We can define another grading as follows: let d 1 , . . . , d n N N   and define the degree of a monomial x 1 α 1 . . . x n α n   to be α 1 d 1 + . . . α n d n   . We can now write R = a N N R a ,   where each R a   is the K   -vector space spanned by all monomials of degree a N N   .
Let R   be a N N   -graded K   -algebra. An R   -module M   is graded if it has a N N   -grading compatible with that of R   , i.e., if we can write M = a N N M a ,   a direct sum of abelian groups, and the direct summands satisfy R a M b M a + b   for all a , b N N   .
If R   is a polynomial ring as in the examples above and I R   is a homogeneous ideal, i.e., an ideal generated by homogeneous elements, then R / I   has a natural structure of a graded R   -module. Let R   be a N N   -graded K   -algebra and let M   be a graded R   -module. We define the Hilbert function HF M   of M   to be the function HF M : N N N   defined by HF M ( a ) = dim K M a   . The Hilbert series HS M ( t 1 , . . . , t N )   of M   is the generating function of the Hilbert function, i.e., HS M ( t 1 , . . . , t N ) = a N N HF M ( a ) t 1 a 1 . . . t N a N .   If R   is a polynomial ring as in the examples above with its familiar N   -grading, and if we view R   as a graded R   -module, then HF R ( a )   is just the number of monomials of degree a   in n   variables, i.e., HF R ( a ) = ( a + n 1 a )   , and HS R ( t ) = 1 / ( 1 t ) n   . If we were to assign degrees d 1 , . . . , d n N N   to x 1 , . . . , x n   we would obtain HS R ( t 1 , . . . , t N ) = 1 i = 1 n 1 t 1 d i 1 . . . t N d i N .   Take R   to be a polynomial ring with its familiar N   -grading, let I R   be a homogeneous ideal and write S = R / I   . One can show that HF S ( a )   is of polynomial type, i.e., it agrees with a polynomial, the Hilbert polynomial HP S ( a )   of S   , for all a 0   . The degree of HP S   is one less than the Krull dimension of S   . Also, one can write HS S ( t ) = P ( t ) ( 1 t ) d   where P ( t )   is a polynomial which does not vanish at t = 1   and d   is the Krull dimension of S   .

2 Unattacked squares

We now consider the first question mentioned in the introduction. We naturally identify the squares of the n × n   chessboard with pairs ( i , j )   where 1 i , j n   .
We fix n   , the size of the board. Let K   be any field and define R   to be the polynomial ring in 2 n 2   variables R = K [ x 11 , . . . , x n n , y 11 , . . . , y n n ] .   We assign degree ( 1 , 0 )   to all the x   variables and degree ( 0 , 1 )   to all the y   variables.
Roughly, the x   variables will correspond to squares in our n × n   chessboard which are occupied by queens while the y   variables will correspond to unattacked squares on the board.
We define I   to be the ideal of R   generated by the squares of all variables together with { x i j y l m | a q u e e n c a n m o v e f r o m s q u a r e ( i , j ) t o s q u a r e ( l , m ) } .   Notice that I   , as any other ideal generated by monomials, is homogeneous with respect to the N 2   -grading of R   .
For any k > 0   define μ ( k ) = max { μ N | dim K ( R / I ) ( k , μ ) > 0 } .  
Proposition 2.1. μ ( k )   is the maximal number of squares on the n × n   chessboard which can remain unattacked after placing on it k   queens.
  • Proof. Consider any monomial M = x α y β   in R   whose image in R / I   is not zero. Since I   contains the squares of all the variables, M   must be square-free and we may write M = x i 1 , j 1 x i λ , j λ y l 1 , m 1 y l ν , m ν .   where all the variables in this expression are distinct. We next observe that for any 1 ξ λ   and 1 ζ ν   , a queen cannot move from square ( i ξ , j ξ )   to square ( l ζ , m ζ )   , otherwise, x i ξ , j ξ y l ζ , m ζ   wouldbe one of the generators of I   and M   would be zero modulo I   . We showed that every monomial of degree ( λ , μ )   whose image in R / I   is not zero corresponds to a configuration on the chessboard where the squares ( i 1 , j 1 ) , . . . , ( i λ , j λ )   are occupied by queens and the squares ( l 1 , m 1 ) , . . . , ( l ν , m ν )   are not attacked by any of these queens.
    It is easy to see that the converse is also true and so we have established a bijection between the configurations of λ   queens and ν   unattacked squares and the set of monomials of degree ( λ , ν )   which are not zero modulo I   .
    Notice that all the graded components ( R / I ) ( λ , ν )   are spanned as K   -vector spaces by monomials of degree ( λ , ν )   , and that a basis for ( R / I ) ( λ , ν )   is given by the set of all such monomials whose images in R / I   are not zero. So now we can see that the condition dim K ( R / I ) ( k , μ ) > 0 , dim K ( R / I ) ( k , μ + 1 ) = 0   can be translated using the bijection established above to the statement that it is possible to place k   queens on the chessboard so that one can find μ   unattacked squares but not μ + 1   unattacked squares.
We now address the more general question: in how many ways Φ ( k , u )   can we place k   queens on a chessboard to obtain exactly u   unattacked squares?
Proposition 2.2. For any 0 u μ ( k )   Φ ( k , u ) = HF R / I ( k , u ) v = u + 1 μ ( k ) ( v u ) Φ ( k , v ) .  
  • Proof. We proceed to prove this by reverse induction of u   . When u = μ ( k )   the equality Φ ( k , μ ( u ) ) = HF R / I ( k , μ ( u ) )   follows easily from the discussion in the proof of the previous proposition.
    Pick now any 0 u < μ ( k )   . HF R / I ( k , u )   is the number of ways one can choose the position of k   queens and u   squares unattacked by these queens. For each such choice, one can extend the set of u   unattacked squares to a maximal set of v   unattacked squares by the same k   queens. To obtain Φ ( k , u )   we need to count only those choices for which u = v   or, equivalently, we need to subtract from HF R / I ( k , u )   the number of configurations which which extend to a maximal one with v > u   unattacked squares. The induction hypothesis implies that there are exactly Φ ( k , v )   configurationswith k   queens and a maximal set of v   unattacked squares, and each one of these produces ( v u )   configurations with k   queens and u   unattacked squares which can be extended to a maximal set of v   unattacked squares. Subtracting all these, we get the desired result.
Table 1 lists the values of Φ ( k , u )   when n = 8   for 3 k 43   and 1 u 25   (blank entries are zero.) For example, the table shows that μ ( 8 ) = 11   and that Φ ( 8 , μ ( 8 ) ) = 48   , which means that the largest number of unattacked squares one can have when 8 queens are placed on a regular chessboard is 11, and that there are 48 such configurations. This is the answer to a question originally published by W. W. Rouse Ball in 1896 [2(see also chapter 34 in [3.) This calculation was produced by FreeSquares, a C++ program which can be found in [5. (There are several widely used computer packages which can compute multi-graded Hilbert series, but unfortunately they are not very efficient.)

UnattackedSquares8

The method introduced in this section generalizes naturally to deal with graph-theoretical problems which we now describe. Let G   be a finite graph. If U   and W   are disjoint sets of vertices of G   we say that U   and W   are independent if there is no edge connecting a vertex in W   with a vertex in U   . For a given k   what is the maximal size of a set of vertices which is independent of a set of k   vertices?
In how many ways can one choose independent U   and W   with given size?
Let { v 1 , . . . , v N }   be the vertices of G   . One obtains the solution to this more general problem by replacing the ring R   with K [ x 1 , . . . , x N , y 1 , . . . , y N ]   and the ideal I   above with the ideal generated by the squares of all the variables and { x i y j | ( v i , v j ) i s a n e d g e i n G } .  

3 Knight moves in an infinite chessboard.

We now consider the second set of questions mentioned in the introduction: How many squares can a knight in an infinite chessboard reach in d   moves? How many squares can be reached in d   moves and no less moves? We will denote the first number with f ( d )   and the second with g ( d )   .
The implementation of the results in this section relies on Gröbner bases techniques– the reader may want to consult [1for an introduction to Gröbner bases. However, to appreciate the general ideas behind the approach of this section no knowledge of Gröbner bases is needed.
We again let K   be any field and let R   be the K   -subalgebra of K [ x 1 , x 2 , x 1 1 , x 2 1 ]   generated by M = { x 1 x 2 2 , x 1 2 x 2 , x 1 1 x 2 2 , x 1 2 x 2 , x 1 x 2 2 , x 1 2 x 2 1 , x 1 1 x 2 2 , x 1 2 x 2 1 } .   The first step towards the solution of this problem is to realize that f ( d )   is the cardinality of M d : = { a 1 . . . a d | a 1 , . . . , a d M }   while g ( d )   is the number of elements in M d   but not in any M i   for i < d   .
We can produce a presentation for R   by mapping a polynomial ring S = K [ y 1 , . . . , y 8 ]   to R   by y i m i   where m i   is the i   th element of M   . We denote this mapping with Ψ   . Notice that the restriction of Ψ   to the set of degree- d   monomials in S   gives a surjection onto the elements of M d   .
Let κ   be the kernel of the map above. This kernel can be computed effectively using Gröbner bases techniques as follows: let I   be the ideal of k [ u , x 1 , x 2 , y 1 , . . . , y 8 ]   generated by
{ u x 1 x 2 1 , y 1 x 1 x 2 2 , y 2 x 1 2 x 2 , y 3 x 1 x 2 2 , y 4 x 1 2 x 2 , y 5 x 2 2 x 1 , y 6 x 2 x 1 2 , y 7 x 1 x 2 2 1 , y 8 x 1 2 x 2 1 }  
and fix an elimination order where u , x 1 , x 2   are the largest variables. Then κ   is generated by the elements of a Gröbner basis for I   which do not contain the variables u , x 1 , x 2   (cf. chapter 1 of [7.) Recall also that κ   is a binomial ideal.
Notice that the ring R   is not very interesting: it is in fact identical to K [ x 1 , x 1 1 , x 2 , x 2 1 ]   (here is a chess proof: x 1 R   because a knight can move one square to the right in three moves. By symmetry also x 1 1 , x 2 , x 2 1 R   .) However, S / κ   is far more interesting for reasons explained below.
Since the restriction of Ψ   to the set of degree- d   monomials in S   is a surjection onto M d   , to find f ( d )   we need to find the size of a maximal set of degree- d   monomials in S   which are distinct modulo κ   . Two such monomials y α   and y β   are distinct modulo κ   if and only if y α y β   is not in the largest homogeneous sub-ideal H   of κ   . It is easy to compute H   : the elements of H   are the elements of the homogenization of κ   with respect to a new variable, say t   , which do not involve t   , thus we can compute H   by homogenizing a Gröbner basis for K   using a graded lexicographic order (cf. exercise 1.6.19 in [1) and eliminating the variable t   . We notice that this Gröbner basis can be chosen to consist of binomials, and so H   is also a binomial ideal.
So we have reduced the problem of computing f ( d )   to the problem of finding the size of a maximal set of degree- d   monomials in S   which are distinct modulo H   . Fix any term ordering in S   and let   be a Gröbner basis for H   consisting of binomials. Now for any two monomials y α > y β   of the same degree, y α y β   modulo H   if and only if y α   reduces to y β   with respect to   . Since each reduction of a monomial with respect to   produces a new monomial (of same degree), to produce a maximal set of degree- d   monomials in S   which are distinct modulo H   we may pick all monomials of degree d   which are non-zero modulo in ( H )   , i.e., f ( d ) = dim K ( S / in ( H ) ) d = dim K ( S / H ) d = HF S / H ( d )   where the second equality is a celebrated theorem proved by F. S. Macaulay in [6.
An easy computation with Macaulay2 ([4) shows that HS S / H ( t ) = 1 + 5 t + 12 t 2 8 t 4 + 4 t 5 ( 1 t ) 3   and that the Hilbert polynomial of S / H   is 1 + 4 d + 7 d 2   . Since HS S / H ( t ) d = 0 ( 1 + 4 d + 7 d 2 ) t d = 4 t 2 4 t   we obtain f ( d ) = { 1 d = 0 8 d = 1 33 d = 2 1 + 4 d + 7 d 2 d 3   We now proceed to compute g ( d )   . We again fix a monomial ordering in S   which refines the total degree ordering. List all the monomials in S   in ascending order, and let B   be the set of all degree- d   monomials in S   which are not congruent modulo κ   to a monomial appearing earlier in the list. We now show that g ( d ) = # B   .
If for two distinct degree- d   monomials y α > y β   we have Ψ ( y α ) = Ψ ( y β )   then y α y β κ   contradicting the choice of B   . Hence the restriction of Ψ   to B   is injective. Similarly, if for some degree- d   monomial y α   there exist a monomial y β   of degree i < d   so that Ψ ( y α ) = Ψ ( y β )   then y α y β κ   and since y α > y β   we get a contradiction to the choice of B   . Hence the restriction of Ψ   to B   is a surjection onto M d \ i < d M i   .
Using the fact that κ   has a Gröbner basis generated by binomials we may deduce that B   is the set of all monomials which are not in in κ   and so g ( d ) = dim K ( S / in ( κ ) ) d = HF ( S / in ( κ ) ) ( d ) .   Another straightforward computation with Macaulay2 shows that HS ( S / in ( κ ) ) ( t ) = 1 + 6 t + 17 t 2 + 12 t 3 8 t 4 4 t 5 + 4 t 6 ( 1 t ) 2   and that the Hilbert polynomial of S / in ( κ )   is 28 d 20   . Since HS ( S / in ( κ ) ) ( t ) d = 0 ( 28 d 20 ) t d = 4 t 4 + 4 t 3 4 t 2 + 21   we obtain g ( d ) = { 1 d = 0 8 d = 1 32 d = 2 68 d = 3 96 d = 4 28 d 20 d 5   The methods of this section also generalize in a natural way. Let W = { ( w 11 . . . w 1 m ) , . . . , ( w N 1 . . . w N m ) } Z m   be a finite set and consider an infinite directed graph G   whose vertex set is Z m   and for any u , v Z m   , ( u , v )   is a directed edge if and only if v u W   .
By replacing R   above and its presentation S R   with the presentation K [ y 1 , . . . , y N ] K [ x 1 w 11 x m w 1 m , . . . , x 1 w N 1 x m w N m ]   which maps y i   to x 1 w i 1 x m w i m   for all 1 i N   , we can, by following exactly the same procedures as before, produce closed formulas for the functions f ( d )   which count how many endpoints all length d   paths starting at a fix vertex have, and closed formulas for the functions g ( d )   which count how many vertices are at a distance of d   from a fixed vertex.
Theorem 3.1. For any directed graph G   as above, there exist polynomials P ( d )   and Q ( d )   so that f ( d ) = P ( d )   and g ( d ) = Q ( d )   for all d 0   .
  • Proof. This is an immediate consequence of the fact that Hilbert functions are of polynomial type.

Appendix: A Macaulay2 implementation.

All the methods in this paper are easy to implement with existing computer systems. As an example aimed to tempt the reader to experiment with these systems we present a Macaulay2 program for the solution of the enumeration problem in the previous section:
R=ZZ/101[u,a,b,y˙–1˝..y˙–8˝,MonomialOrder=>Lex]; I=–u*a*b-1˙R,y˙–1˝-a*b^2,y˙–2˝-a^2*b,y˙–3˝*a-b^2,y˙–4˝*a^2-b, y˙–5˝*b^2-a,y˙–6˝*b-a^2,y˙–7˝*a*b^2-1˙R,y˙–8˝*a^2*b-1˙R˝; G=gens gb ideal I; J=selectInSubring(3,G); S1=ZZ/101[y˙–1˝..y˙–8˝,t]; J=substitute(J,S1); H0=homogenize(gens gb J,t); S2=ZZ/101[t,y˙–1˝..y˙–8˝,MonomialOrder=>Lex]; H0=substitute(H0,S2); G=gens gb ideal H0; H=selectInSubring(1,G); S=ZZ/101[y˙–1˝..y˙–8˝]; J=substitute(J,S); H=substitute(H,S); print(hilbertSeries coker J); print(hilbertPolynomial(coker J, Projective=>false)); print(hilbertSeries coker H); print(hilbertPolynomial(coker H, Projective=>false));
This produces the following output:
6 5 4 3 2 4$T -4$T -8$T +12$T +17$T +6$T+1 -------------------------------2 (-$T+1) 28$i-20 5 4 2 4$T -8$T +12$T +5$T+1 --------------------3 (-$T+1) 2 7$i +4$i+1
References

  1. W. W. Adams and P. Loustaunau. An Introduction to Gröbner Bases, Graduate Studies in Mathematics, 3, American Mathematical Society, Providence, RI (1994)
  2. W. W. Rouse Ball. Mathematical recreations & essays. Macmillan, London (1940)
  3. M. Gardner, A Gardner's workout. A K Peters, Ltd., Natick, MA, (2001)
  4. D. Grayson and M. Stillman: Macaulay 2 – a software system for algebraic geometry and commutative algebra, available at http://www.math.uiuc.edu/Macaulay2.
  5. M. Katzman. FreeSquares Available from http://www.shef.ac.uk/katzman/ComputerAlgebra/ComputerAlgebra.html
  6. F. S. Macaulay, Some properties of enumeration in the theory of modular systems. Proceedings of the London Mathematical Society 26, pp. 531–555.
  7. B. Sturmfels. Gröbner bases and convex polytopes, University Lecture Series, 8. American Mathematical Society, Providence, RI (1996)
  8. Richard P. Stanley. Combinatorics and commutative algebra. Second edition. Progress in Mathematics, 41. Birkhuser Boston, Inc., Boston, MA, 1996.

Department of Pure Mathematics, University of Sheffield, Hicks Building, Sheffield S3 7RH, United Kingdom, Fax number: 0044-114-222-3769 E-mail address : M.Katzman@sheffield.ac.uk