A Groebner basis is a specific generating set of an ideal or submodule over a polynomial ring. It is not minimal in general, but has extremely nice properties; it is reasonably easy to extract information about the ideal or submodule from a Groebner basis. We first describe Groebner bases in the important special case of an ideal in a polynomial ring. We will then describe Groebner bases of submodules, and over more general rings.
Let $R = k[x_1, ..., x_n]$ be a polynomial ring over a field $k$, and let $I \subset R$ be an ideal. A
monomial order on $R$ is a total order, $>$, on the monomials of $R$, which satisfies two conditions: (1) $m > 1$, for every monomial $m \neq 1$, and (2) the order is multiplicative: $m > n$ implies that $mp > np$, for all monomials $m$, $n$, $p$.
In Macaulay2, each ring has a monomial order (also called a term order) associated with it. The default monomial order is
GRevLex. See
monomial orderings for more information.
Given a term order, the leading term is the one whose monomial is greatest in this order.
i1 : R = ZZ/1277[a..d]
o1 = R
o1 : PolynomialRing

i2 : F = 5*a^3 + d^2 + a*d + b*c + 1
3 2
o2 = 5a + b*c + a*d + d + 1
o2 : R

i3 : leadTerm F
3
o3 = 5a
o3 : R

For an ideal $I \subset R$, the initial ideal $in(I)$ is the ideal generated by the leading terms of the elements in I. A Groebner basis for I is a set of generators for I whose leading terms generate $in(I)$.
i4 : R = ZZ/1277[x,y];

i5 : I = ideal(x^3  2*x*y, x^2*y  2*y^2 + x);
o5 : Ideal of R

i6 : leadTerm I
o6 =  y2 xy x2 
1 3
o6 : Matrix R < R

i7 : gens gb I
o7 =  y2+638x xy x2 
1 3
o7 : Matrix R < R

The above example also shows that the leading terms of any set of generators of I do not necessarily generate in(I).
A Groebner basis for an ideal depends on the monomial ordering used in the ring .
i8 : R = ZZ/1277[x,y, MonomialOrder => Lex];

i9 : I = ideal(x^3  2*x*y, x^2*y  2*y^2 + x);
o9 : Ideal of R

i10 : gens gb I
o10 =  y3 x2y2 
1 2
o10 : Matrix R < R
