Ask Your Question

Revision history [back]

Polynomial systems

Chapter 9 of the open-source book Calcul mathématique avec Sage (in French) is about polynomial systems. In particular, check section 9.2. The book is available for free download from: (click "Telecharger le PDF").

The answer below closely follows that reference, with minor adaptations in order to address the ask-sage question by MvG.

Credit goes to Marc Mezzaroba who authored that chapter, and more generally to the team who authored the book and kindly provides it under a Creative Commons license allowing all to copy and redistribute the material in any medium or format, and to remix, transform, and build upon the material, for any purpose.

The system

In section 9.2.1, the following polynomial system is considered:

$$ \left \{ \quad \begin{array}{@{}ccc@{}} x^2 \; y \; z & = & 18 \\ x \; y^3 \; z & = & 24\\ x \; y \; z^4 & = & 6 \\ \end{array}\right. $$

Numerical solve vs algebraic approach

While section 2.2 of the book explained how to solve numerically with solve,

sage: x, y, z = var('x, y, z')
sage: solve([x^2 * y * z == 18, x * y^3 * z == 24,\
....: x * y * z^4 == 3], x, y, z)
[[x == (-2.76736473308 - 1.71347969911*I), y == (-0.570103503963 +
2.00370597877*I), z == (-0.801684337646 - 0.14986077496*I)], ...]

section 9.2.1 explains how to solve algebraically.

Ideal in a polynomial ring

First translate the problem in more algebraic terms: we are looking for the common zeros of three polynomials, so we consider the polynomial ring over QQ in three variables, and in this ring we consider the ideal generated by the three polynomials whose common zeros we are looking for.

sage: R.<x,y,z> = QQ[]
sage: J = R.ideal(x^2 * y * z - 18,
....:             x * y^3 * z - 24,
....:             x * y * z^4 - 6)

We check that the dimension of this ideal is zero, which means the system has finitely many solutions.

sage: J.dimension()

Solution, algebraic variety, choice of base ring

The command variety will compute all the solutions of the system. However, its default behaviour is to give the solutions in the base ring of the polynomial ring. Here, this means it gives only the rational solutions.

sage: J.variety()
[{y: 2, z: 1, x: 3}]

We want to enumerate the complex solutions, as exact algebraic numbers. To do that, we use the field of algebraic numbers, QQbar. We find the 17 solutions (which were revealed by the numerical approach with solve).

sage: V = J.variety(QQbar)
sage: len(V)

Here is what the last three solutions look like as complex numbers.

sage: V[-3:]
[{z: 0.9324722294043558? - 0.3612416661871530?*I,
y: -1.700434271459229? + 1.052864325754712?*I,
x: 1.337215067329615? - 2.685489874065187?*I},
{z: 0.9324722294043558? + 0.3612416661871530?*I,
y: -1.700434271459229? - 1.052864325754712?*I,
x: 1.337215067329615? + 2.685489874065187?*I},
{z: 1, y: 2, x: 3}]

Each solution is given as a dictionary, whose keys are the generators of QQbar['x,y,z'] (and not QQ['x,y,z'], which means accessing them requires a little trick illustrated below), and values are the coordinates of the solution.

This checks that the first coordinate in each non-rational solution has degree 16.

sage: (xx, yy, zz) = QQbar['x,y,z'].gens()
sage: [ pt[xx].degree() for pt in V ]
[16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 1]

Going further

The chapter goes on to explain how to

  • compute with the solutions,
  • identify the structure of the set of solutions,
  • obtain closed formulas,
  • simplify the system.

If it is useful, I can expand my answer and translate those points too.