Gröbner Bases: SageMath Examples

Companion worksheet to the course Gröbner bases and convex polytopes: between algebra, geometry, and combinatorics by Sara Veneziale. Edit the code and click Run to experiment. Note that variables are not shared between cells.

1. Division algorithm

In one variable, the division algorithm is unique: given $f, g \in k[x]$, there exist unique $q, r$ with $f = qg + r$ and $\deg(r) < \deg(g)$.

Every ideal in $k[x]$ is principal:

2. Monomial orders

In multiple variables, we need to choose a monomial order. Different orders give different leading terms. Let's see the three standard orders on the same polynomial. Try to find a polynomial that has a different leading order for each and one that has the same leading order for all.

Exercise: Find $f$ such that $\mathrm{LT}(f)$ under lex is $x^3$ but $\mathrm{LT}(f)$ under degrevlex is $y^2 z^2$.

3. Multivariate division algorithm

The multivariate division algorithm produces $f = h_1 f_1 + \cdots + h_s f_s + r$, but the remainder $r$ depends on the order in which we divide.

Exercise: Try changing the order above and see if you can get zero remainder.

Sage's built-in reduce divides by all polynomials simultaneously, so the list order doesn't matter. To see the order-dependence, we need the textbook algorithm where the break restarts from the top of the divisor list:

4. Initial ideals

Let's start by computing the leading terms with respect to some order.

Exercise: Is this true with respect to all monomial orderings?

5. Gröbner bases

Let's compute the Gröbner basis of a simple ideal and verify that the remainder is now unique regardless of division order.

One of the main uses of Gröbner bases: testing whether a polynomial belongs to an ideal.

6. Different orderings give different Gröbner bases

This is a key point: the same ideal has different Gröbner bases under different monomial orders. Let's see this with an example.

7. S-polynomials and Buchberger's algorithm

Let's implement Buchberger's algorithm naively, with full logging so we can follow each step.