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
• Abstract. This paper presents two enumeration techniques based on Hilbert functions. The paper illustrates these techniques by solving two chessboard problems.

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 ${\mathbb{N}}^{N}$  -graded if we can write $R={\oplus }_{\mathbf{a}\in {\mathbb{N}}^{N}}{R}_{\mathbf{a}},$  a direct sum of abelian groups, and the direct summands satisfy ${R}_{\mathbf{a}}{R}_{\mathbf{b}}\subseteq {R}_{\mathbf{a}+\mathbf{b}}$  for all $\mathbf{a},\mathbf{b}\in {\mathbb{N}}^{N}$  . Henceforth we shall also impose the condition ${R}_{0}=K$  , which implies that each ${R}_{\mathbf{a}}$  is a $K$  -vector space and that, if $R$  is a finitely generated $K$  -algebra, each ${R}_{\mathbf{a}}$  is a finite dimensional $K$  -vector space. For each $\mathbf{a}\in {\mathbb{N}}^{N}$  we shall refer to the elements of ${R}_{\mathbf{a}}$  as being homogeneous of degree $\mathbf{a}$  .
A fundamental example of such a graded $K$  -algebra is the ring of polynomials $R=K\left[{x}_{1},...,{x}_{n}\right]$  .
We can endow $R$  with different graded structures. We are all familiar with the $\mathbb{N}$  -grading $R={\oplus }_{a\in \mathbb{N}}{R}_{a}$  in which each ${R}_{a}$  consists of the homogeneous polynomials of degree $a$  . We can define another grading as follows: let ${\mathbf{d}}_{1},...,{\mathbf{d}}_{n}\in {\mathbb{N}}^{N}$  and define the degree of a monomial ${x}_{1}^{{\alpha }_{1}}...{x}_{n}^{{\alpha }_{n}}$  to be ${\alpha }_{1}{\mathbf{d}}_{1}+...{\alpha }_{n}{\mathbf{d}}_{n}$  . We can now write $R={\oplus }_{\mathbf{a}\in {\mathbb{N}}^{N}}{R}_{\mathbf{a}},$  where each ${\mathbb{R}}_{\mathbf{a}}$  is the $K$  -vector space spanned by all monomials of degree $\mathbf{a}\in {\mathbb{N}}^{N}$  .
Let $R$  be a ${\mathbb{N}}^{N}$  -graded $K$  -algebra. An $R$  -module $M$  is graded if it has a ${\mathbb{N}}^{N}$  -grading compatible with that of $R$  , i.e., if we can write $M={\oplus }_{\mathbf{a}\in {\mathbb{N}}^{N}}{M}_{\mathbf{a}},$  a direct sum of abelian groups, and the direct summands satisfy ${R}_{\mathbf{a}}{M}_{\mathbf{b}}\subseteq {M}_{\mathbf{a}+\mathbf{b}}$  for all $\mathbf{a},\mathbf{b}\in {\mathbb{N}}^{N}$  .
If $R$  is a polynomial ring as in the examples above and $I\subset 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 ${\mathbb{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}:{\mathbb{N}}^{N}\to \mathbb{N}$  defined by ${HF}_{M}\left(\mathbf{a}\right)={dim}_{K}{M}_{\mathbf{a}}$  . The Hilbert series ${HS}_{M}\left({t}_{1},...,{t}_{N}\right)$  of $M$  is the generating function of the Hilbert function, i.e., ${HS}_{M}\left({t}_{1},...,{t}_{N}\right)={\sum }_{\mathbf{a}\in {\mathbb{N}}^{N}}{HF}_{M}\left(\mathbf{a}\right){t}_{1}^{{a}_{1}}...{t}_{N}^{{a}_{N}}.$  If $R$  is a polynomial ring as in the examples above with its familiar $\mathbb{N}$  -grading, and if we view $R$  as a graded $R$  -module, then ${HF}_{R}\left(a\right)$  is just the number of monomials of degree $a$  in $n$  variables, i.e., ${HF}_{R}\left(a\right)=\left(\genfrac{}{}{0}{}{a+n-1}{a}\right)$  , and ${HS}_{R}\left(t\right)=1/\left(1-t{\right)}^{n}$  . If we were to assign degrees ${\mathbf{d}}_{1},...,{\mathbf{d}}_{n}\in {\mathbb{N}}^{N}$  to ${x}_{1},...,{x}_{n}$  we would obtain ${HS}_{R}\left({t}_{1},...,{t}_{N}\right)=\frac{1}{{\prod }_{i=1}^{n}1-{t}_{1}^{{\mathbf{d}}_{i1}}...{t}_{N}^{{\mathbf{d}}_{iN}}}.$  Take $R$  to be a polynomial ring with its familiar $\mathbb{N}$  -grading, let $I\subset R$  be a homogeneous ideal and write $S=R/I$  . One can show that ${HF}_{S}\left(a\right)$  is of polynomial type, i.e., it agrees with a polynomial, the Hilbert polynomial ${HP}_{S}\left(a\right)$  of $S$  , for all $a\gg 0$  . The degree of ${HP}_{S}$  is one less than the Krull dimension of $S$  . Also, one can write ${HS}_{S}\left(t\right)=\frac{P\left(t\right)}{\left(1-t{\right)}^{d}}$  where $P\left(t\right)$  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 $\left(i,j\right)$  where $1\le i,j\le 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\left[{x}_{11},...,{x}_{nn},{y}_{11},...,{y}_{nn}\right].$  We assign degree $\left(1,0\right)$  to all the $x$  variables and degree $\left(0,1\right)$  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 $\left\{{x}_{ij}{y}_{lm}|aqueencanmovefromsquare\left(i,j\right)tosquare\left(l,m\right)\right\}.$  Notice that $I$  , as any other ideal generated by monomials, is homogeneous with respect to the ${\mathbb{N}}^{2}$  -grading of $R$  .
For any $k>0$  define $\mu \left(k\right)=max\left\{\mu \in \mathbb{N}|{dim}_{K}{\left(R/I\right)}_{\left(k,\mu \right)}>0\right\}.$
Proposition 2.1. $\mu \left(k\right)$  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={\mathbf{x}}^{\alpha }{\mathbf{y}}^{\beta }$  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}}\cdot \dots \cdot {x}_{{i}_{\lambda },{j}_{\lambda }}{y}_{{l}_{1},{m}_{1}}\cdot \dots \cdot {y}_{{l}_{\nu },{m}_{\nu }}.$  where all the variables in this expression are distinct. We next observe that for any $1\le \xi \le \lambda$  and $1\le \zeta \le \nu$  , a queen cannot move from square $\left({i}_{\xi },{j}_{\xi }\right)$  to square $\left({l}_{\zeta },{m}_{\zeta }\right)$  , otherwise, ${x}_{{i}_{\xi },{j}_{\xi }}{y}_{{l}_{\zeta },{m}_{\zeta }}$  wouldbe one of the generators of $I$  and $M$  would be zero modulo $I$  . We showed that every monomial of degree $\left(\lambda ,\mu \right)$  whose image in $R/I$  is not zero corresponds to a configuration on the chessboard where the squares $\left({i}_{1},{j}_{1}\right),...,\left({i}_{\lambda },{j}_{\lambda }\right)$  are occupied by queens and the squares $\left({l}_{1},{m}_{1}\right),...,\left({l}_{\nu },{m}_{\nu }\right)$  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 $\lambda$  queens and $\nu$  unattacked squares and the set of monomials of degree $\left(\lambda ,\nu \right)$  which are not zero modulo $I$  .
Notice that all the graded components ${\left(R/I\right)}_{\left(\lambda ,\nu \right)}$  are spanned as $K$  -vector spaces by monomials of degree $\left(\lambda ,\nu \right)$  , and that a basis for ${\left(R/I\right)}_{\left(\lambda ,\nu \right)}$  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}{\left(R/I\right)}_{\left(k,\mu \right)}>0,{dim}_{K}{\left(R/I\right)}_{\left(k,\mu +1\right)}=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 $\mu$  unattacked squares but not $\mu +1$  unattacked squares.
We now address the more general question: in how many ways $\Phi \left(k,u\right)$  can we place $k$  queens on a chessboard to obtain exactly $u$  unattacked squares?
Proposition 2.2. For any $0\le u\le \mu \left(k\right)$  $\Phi \left(k,u\right)={HF}_{R/I}\left(k,u\right)-{\sum }_{v=u+1}^{\mu \left(k\right)}\left(\genfrac{}{}{0}{}{v}{u}\right)\Phi \left(k,v\right).$
• Proof. We proceed to prove this by reverse induction of $u$  . When $u=\mu \left(k\right)$  the equality $\Phi \left(k,\mu \left(u\right)\right)={HF}_{R/I}\left(k,\mu \left(u\right)\right)$  follows easily from the discussion in the proof of the previous proposition.
Pick now any $0\le u<\mu \left(k\right)$  . ${HF}_{R/I}\left(k,u\right)$  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 $\Phi \left(k,u\right)$  we need to count only those choices for which $u=v$  or, equivalently, we need to subtract from ${HF}_{R/I}\left(k,u\right)$  the number of configurations which which extend to a maximal one with $v>u$  unattacked squares. The induction hypothesis implies that there are exactly $\Phi \left(k,v\right)$  configurationswith $k$  queens and a maximal set of $v$  unattacked squares, and each one of these produces $\left(\genfrac{}{}{0}{}{v}{u}\right)$  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 $\Phi \left(k,u\right)$  when $n=8$  for $3\le k\le 43$  and $1\le u\le 25$  (blank entries are zero.) For example, the table shows that $\mu \left(8\right)=11$  and that $\Phi \left(8,\mu \left(8\right)\right)=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.)

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 $\left\{{v}_{1},...,{v}_{N}\right\}$  be the vertices of $G$  . One obtains the solution to this more general problem by replacing the ring $R$  with $K\left[{x}_{1},...,{x}_{N},{y}_{1},...,{y}_{N}\right]$  and the ideal $I$  above with the ideal generated by the squares of all the variables and $\left\{{x}_{i}{y}_{j}|\left({v}_{i},{v}_{j}\right)isanedgeinG\right\}.$

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\left(d\right)$  and the second with $g\left(d\right)$  .
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\left[{x}_{1},{x}_{2},{x}_{1}^{-1},{x}_{2}^{-1}\right]$  generated by $M=\left\{{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}\right\}.$  The first step towards the solution of this problem is to realize that $f\left(d\right)$  is the cardinality of ${M}^{d}:=\left\{{a}_{1}...{a}_{d}|{a}_{1},...,{a}_{d}\in M\right\}$  while $g\left(d\right)$  is the number of elements in ${M}^{d}$  but not in any ${M}^{i}$  for $i  .
We can produce a presentation for $R$  by mapping a polynomial ring $S=K\left[{y}_{1},...,{y}_{8}\right]$  to $R$  by ${y}_{i}\to {m}_{i}$  where ${m}_{i}$  is the $i$  th element of $M$  . We denote this mapping with $\Psi$  . Notice that the restriction of $\Psi$  to the set of degree- $d$  monomials in $S$  gives a surjection onto the elements of ${M}^{d}$  .
Let $\kappa$  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\left[u,{x}_{1},{x}_{2},{y}_{1},...,{y}_{8}\right]$  generated by
$\left\{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\right\}$
and fix an elimination order where $u,{x}_{1},{x}_{2}$  are the largest variables. Then $\kappa$  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 $\kappa$  is a binomial ideal.
Notice that the ring $R$  is not very interesting: it is in fact identical to $K\left[{x}_{1},{x}_{1}^{-1},{x}_{2},{x}_{2}^{-1}\right]$  (here is a chess proof: ${x}_{1}\in 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}\in R$  .) However, $S/\kappa$  is far more interesting for reasons explained below.
Since the restriction of $\Psi$  to the set of degree- $d$  monomials in $S$  is a surjection onto ${M}^{d}$  , to find $f\left(d\right)$  we need to find the size of a maximal set of degree- $d$  monomials in $S$  which are distinct modulo $\kappa$  . Two such monomials ${\mathbf{y}}^{\alpha }$  and ${\mathbf{y}}^{\beta }$  are distinct modulo $\kappa$  if and only if ${\mathbf{y}}^{\alpha }-{\mathbf{y}}^{\beta }$  is not in the largest homogeneous sub-ideal $H$  of $\kappa$  . It is easy to compute $H$  : the elements of $H$  are the elements of the homogenization of $\kappa$  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\left(d\right)$  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 $\mathcal{ℋ}$  be a Gröbner basis for $H$  consisting of binomials. Now for any two monomials ${\mathbf{y}}^{\alpha }>{\mathbf{y}}^{\beta }$  of the same degree, ${\mathbf{y}}^{\alpha }\equiv {\mathbf{y}}^{\beta }$  modulo $H$  if and only if ${\mathbf{y}}^{\alpha }$  reduces to ${\mathbf{y}}^{\beta }$  with respect to $\mathcal{ℋ}$  . Since each reduction of a monomial with respect to $\mathcal{ℋ}$  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\left(H\right)$  , i.e., $f\left(d\right)={dim}_{K}{\left(S/in\left(H\right)\right)}_{d}={dim}_{K}{\left(S/H\right)}_{d}={HF}_{S/H}\left(d\right)$  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}\left(t\right)=\frac{1+5t+12{t}^{2}-8{t}^{4}+4{t}^{5}}{\left(1-t{\right)}^{3}}$  and that the Hilbert polynomial of $S/H$  is $1+4d+7{d}^{2}$  . Since ${HS}_{S/H}\left(t\right)-{\sum }_{d=0}^{\infty }\left(1+4d+7{d}^{2}\right){t}^{d}=-4{t}^{2}-4t$  we obtain $f\left(d\right)=\left\{\begin{array}{cc}1& d=0\\ 8& d=1\\ 33& d=2\\ 1+4d+7{d}^{2}& d\ge 3\end{array}$  We now proceed to compute $g\left(d\right)$  . 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 $\kappa$  to a monomial appearing earlier in the list. We now show that $g\left(d\right)=#B$  .
If for two distinct degree- $d$  monomials ${\mathbf{y}}^{\alpha }>{\mathbf{y}}^{\beta }$  we have $\Psi \left({\mathbf{y}}^{\alpha }\right)=\Psi \left({\mathbf{y}}^{\beta }\right)$  then ${\mathbf{y}}^{\alpha }-{\mathbf{y}}^{\beta }\in \kappa$  contradicting the choice of $B$  . Hence the restriction of $\Psi$  to $B$  is injective. Similarly, if for some degree- $d$  monomial ${\mathbf{y}}^{\alpha }$  there exist a monomial ${\mathbf{y}}^{\beta }$  of degree $i  so that $\Psi \left({\mathbf{y}}^{\alpha }\right)=\Psi \left({\mathbf{y}}^{\beta }\right)$  then ${\mathbf{y}}^{\alpha }-{\mathbf{y}}^{\beta }\in \kappa$  and since ${\mathbf{y}}^{\alpha }>{\mathbf{y}}^{\beta }$  we get a contradiction to the choice of $B$  . Hence the restriction of $\Psi$  to $B$  is a surjection onto ${M}^{d}\{\cup }_{i  .
Using the fact that $\kappa$  has a Gröbner basis generated by binomials we may deduce that $B$  is the set of all monomials which are not in $in\kappa$  and so $g\left(d\right)={dim}_{K}{\left(S/in\left(\kappa \right)\right)}_{d}={HF}_{\left(S/in\left(\kappa \right)\right)}\left(d\right).$  Another straightforward computation with Macaulay2 shows that ${HS}_{\left(S/in\left(\kappa \right)\right)}\left(t\right)=\frac{1+6t+17{t}^{2}+12{t}^{3}-8{t}^{4}-4{t}^{5}+4{t}^{6}}{\left(1-t{\right)}^{2}}$  and that the Hilbert polynomial of $S/in\left(\kappa \right)$  is $28d-20$  . Since ${HS}_{\left(S/in\left(\kappa \right)\right)}\left(t\right)-{\sum }_{d=0}^{\infty }\left(28d-20\right){t}^{d}=4{t}^{4}+4{t}^{3}-4{t}^{2}+21$  we obtain $g\left(d\right)=\left\{\begin{array}{cc}1& d=0\\ 8& d=1\\ 32& d=2\\ 68& d=3\\ 96& d=4\\ 28d-20& d\ge 5\end{array}$  The methods of this section also generalize in a natural way. Let $W=\left\{\left(\begin{array}{c}{w}_{11}\\ ...\\ {w}_{1m}\end{array}\right),...,\left(\begin{array}{c}{w}_{N1}\\ ...\\ {w}_{Nm}\end{array}\right)\right\}\subset {\mathbb{Z}}^{m}$  be a finite set and consider an infinite directed graph $G$  whose vertex set is ${\mathbb{Z}}^{m}$  and for any $u,v\in {\mathbb{Z}}^{m}$  , $\stackrel{\to }{\left(u,v\right)}$  is a directed edge if and only if $v-u\in W$  .
By replacing $R$  above and its presentation $S\to R$  with the presentation $K\left[{y}_{1},...,{y}_{N}\right]\to K\left[{x}_{1}^{{w}_{11}}\cdot \cdot \cdot \cdot \cdot {x}_{m}^{{w}_{1m}},...,{x}_{1}^{{w}_{N1}}\cdot \cdot \cdot \cdot \cdot {x}_{m}^{{w}_{Nm}}\right]$  which maps ${y}_{i}$  to ${x}_{1}^{{w}_{i1}}\cdot \cdot \cdot \cdot \cdot {x}_{m}^{{w}_{im}}$  for all $1\le i\le N$  , we can, by following exactly the same procedures as before, produce closed formulas for the functions $f\left(d\right)$  which count how many endpoints all length $d$  paths starting at a fix vertex have, and closed formulas for the functions $g\left(d\right)$  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\left(d\right)$  and $Q\left(d\right)$  so that $f\left(d\right)=P\left(d\right)$  and $g\left(d\right)=Q\left(d\right)$  for all $d\gg 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