L=lexIdeal(R,hilb) or L=lexIdeal(Q,hilb) or L=lexIdeal(I)
When R is a polynomial ring, if hilb is an Osequence (that is, it satisfies Macaulay's Theorem), such an L always exists. When Q is a quotient of a polynomial ring, there may be no lexicographic ideal with a particular Hilbert function even if it is an Osequence. lexIdeal returns null if no lexicographic ideal L corresponding to the Hilbert function hilb exists in R or Q.
When lexIdeal has an ideal as its input, it returns the lexicographic ideal with the same Hilbert function as its output. If no such ideal exists, which may happen since Macaulay's Theorem fails in some quotient rings, then lexIdeal returns null.
The function now works for quotients by arbitrary homogeneous ideals, not just monomial ideals. We thank David Eisenbud and Jeff Mermin for contributing their ideas.







Note that we use the Gotzmann Persistence Theorem as a stopping criterion, so one should make sure this holds in the ring in which one is computing.
The object lexIdeal is a method function.