In [1]:
import sympy as sym
from sympy.polys.multivariate_resultants import MacaulayResultant

sym.init_printing()

Macaulay Resultant

The Macauly resultant is a multivariate resultant. It is used for calculating the resultant of $n$ polynomials in $n$ variables. The Macaulay resultant is calculated as the determinant of two matrices,

$$R = \frac{\text{det}(A)}{\text{det}(M)}.$$

Matrix $A$

There are a number of steps needed to construct matrix $A$. Let us consider an example from https://dl.acm.org/citation.cfm?id=550525 to show the construction.


In [2]:
x, y, z = sym.symbols('x, y, z')

In [3]:
a_1_1, a_1_2, a_1_3, a_2_2, a_2_3, a_3_3 = sym.symbols('a_1_1, a_1_2, a_1_3, a_2_2, a_2_3, a_3_3')
b_1_1, b_1_2, b_1_3, b_2_2, b_2_3, b_3_3 = sym.symbols('b_1_1, b_1_2, b_1_3, b_2_2, b_2_3, b_3_3')
c_1, c_2, c_3 = sym.symbols('c_1, c_2, c_3')

In [4]:
variables = [x, y, z]

In [5]:
f_1 = a_1_1 * x ** 2 + a_1_2 * x * y + a_1_3 * x * z + a_2_2 * y ** 2 + a_2_3 * y * z + a_3_3 * z ** 2

In [6]:
f_2 = b_1_1 * x ** 2 + b_1_2 * x * y + b_1_3 * x * z + b_2_2 * y ** 2 + b_2_3 * y * z + b_3_3 * z ** 2

In [7]:
f_3 = c_1 * x + c_2 * y + c_3 * z

In [8]:
polynomials = [f_1, f_2, f_3]
mac = MacaulayResultant(polynomials, variables)

Step 1 Calculated $d_i$ for $i \in n$.


In [9]:
mac.degrees


Out[9]:
$$\left [ 2, \quad 2, \quad 1\right ]$$

Step 2. Get $d_M$.


In [10]:
mac.degree_m


Out[10]:
$$3$$

Step 3. All monomials of degree $d_M$ and size of set.


In [11]:
mac.get_monomials_set()

In [12]:
mac.monomial_set


Out[12]:
$$\left [ x^{3}, \quad x^{2} y, \quad x^{2} z, \quad x y^{2}, \quad x y z, \quad x z^{2}, \quad y^{3}, \quad y^{2} z, \quad y z^{2}, \quad z^{3}\right ]$$

In [13]:
mac.monomials_size


Out[13]:
$$10$$

These are the columns of matrix $A$.

Step 4 Get rows and fill matrix.


In [14]:
mac.get_row_coefficients()


Out[14]:
$$\left [ \left [ x, \quad y, \quad z\right ], \quad \left [ x, \quad y, \quad z\right ], \quad \left [ x y, \quad x z, \quad y z, \quad z^{2}\right ]\right ]$$

Each list is being multiplied by polynomials $f_1$, $f_2$ and $f_3$ equivalently. Then we fill the matrix based on the coefficient of the monomials in the columns.


In [15]:
matrix = mac.get_matrix()
matrix


Out[15]:
$$\left[\begin{matrix}a_{1 1} & a_{1 2} & a_{1 3} & a_{2 2} & a_{2 3} & a_{3 3} & 0 & 0 & 0 & 0\\0 & a_{1 1} & 0 & a_{1 2} & a_{1 3} & 0 & a_{2 2} & a_{2 3} & a_{3 3} & 0\\0 & 0 & a_{1 1} & 0 & a_{1 2} & a_{1 3} & 0 & a_{2 2} & a_{2 3} & a_{3 3}\\b_{1 1} & b_{1 2} & b_{1 3} & b_{2 2} & b_{2 3} & b_{3 3} & 0 & 0 & 0 & 0\\0 & b_{1 1} & 0 & b_{1 2} & b_{1 3} & 0 & b_{2 2} & b_{2 3} & b_{3 3} & 0\\0 & 0 & b_{1 1} & 0 & b_{1 2} & b_{1 3} & 0 & b_{2 2} & b_{2 3} & b_{3 3}\\0 & c_{1} & 0 & c_{2} & c_{3} & 0 & 0 & 0 & 0 & 0\\0 & 0 & c_{1} & 0 & c_{2} & c_{3} & 0 & 0 & 0 & 0\\0 & 0 & 0 & 0 & c_{1} & 0 & 0 & c_{2} & c_{3} & 0\\0 & 0 & 0 & 0 & 0 & c_{1} & 0 & 0 & c_{2} & c_{3}\end{matrix}\right]$$

Matrix $M$

Columns that are non reduced are kept. The rows which contain one if the $a_i$s is dropoed. $a_i$s are the coefficients of $x_i ^ {d_i}$.


In [16]:
mac.get_submatrix(matrix)


Out[16]:
$$\left[\begin{matrix}a_{1 1} & a_{2 2}\\b_{1 1} & b_{2 2}\end{matrix}\right]$$

In [17]:
x, y, z = sym.symbols('x, y, z')

In [18]:
a_0, a_1, a_2 = sym.symbols('a_0, a_1, a_2')
b_0, b_1, b_2 = sym.symbols('b_0, b_1, b_2')
c_0, c_1, c_2,c_3, c_4 = sym.symbols('c_0, c_1, c_2, c_3, c_4')

In [19]:
f = a_0 * y -  a_1 * x + a_2 * z
g = b_1 * x ** 2 + b_0 * y ** 2 - b_2 * z ** 2
h = c_0 * y - c_1 * x ** 3 + c_2 * x ** 2 * z - c_3 * x * z ** 2 + c_4 * z ** 3

In [20]:
polynomials = [f, g, h]

In [21]:
mac = MacaulayResultant(polynomials, variables=[x, y, z])

In [22]:
mac.degrees


Out[22]:
$$\left [ 1, \quad 2, \quad 3\right ]$$

In [23]:
mac.degree_m


Out[23]:
$$4$$

In [24]:
mac.get_monomials_set()

In [25]:
mac.get_size()


Out[25]:
$$15$$

In [26]:
mac.monomial_set


Out[26]:
$$\left [ x^{4}, \quad x^{3} y, \quad x^{3} z, \quad x^{2} y^{2}, \quad x^{2} y z, \quad x^{2} z^{2}, \quad x y^{3}, \quad x y^{2} z, \quad x y z^{2}, \quad x z^{3}, \quad y^{4}, \quad y^{3} z, \quad y^{2} z^{2}, \quad y z^{3}, \quad z^{4}\right ]$$

In [27]:
mac.get_row_coefficients()


Out[27]:
$$\left [ \left [ x^{3}, \quad x^{2} y, \quad x^{2} z, \quad x y^{2}, \quad x y z, \quad x z^{2}, \quad y^{3}, \quad y^{2} z, \quad y z^{2}, \quad z^{3}\right ], \quad \left [ y^{2}, \quad y z, \quad z^{2}\right ], \quad \left [ y, \quad z\right ]\right ]$$

In [28]:
matrix = mac.get_matrix()
matrix


Out[28]:
$$\left[\begin{array}{ccccccccccccccc}- a_{1} & a_{0} & a_{2} & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0\\0 & - a_{1} & 0 & a_{0} & a_{2} & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0\\0 & 0 & - a_{1} & 0 & a_{0} & a_{2} & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0\\0 & 0 & 0 & - a_{1} & 0 & 0 & a_{0} & a_{2} & 0 & 0 & 0 & 0 & 0 & 0 & 0\\0 & 0 & 0 & 0 & - a_{1} & 0 & 0 & a_{0} & a_{2} & 0 & 0 & 0 & 0 & 0 & 0\\0 & 0 & 0 & 0 & 0 & - a_{1} & 0 & 0 & a_{0} & a_{2} & 0 & 0 & 0 & 0 & 0\\0 & 0 & 0 & 0 & 0 & 0 & - a_{1} & 0 & 0 & 0 & a_{0} & a_{2} & 0 & 0 & 0\\0 & 0 & 0 & 0 & 0 & 0 & 0 & - a_{1} & 0 & 0 & 0 & a_{0} & a_{2} & 0 & 0\\0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & - a_{1} & 0 & 0 & 0 & a_{0} & a_{2} & 0\\0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & - a_{1} & 0 & 0 & 0 & a_{0} & a_{2}\\0 & 0 & 0 & b_{1} & 0 & 0 & 0 & 0 & 0 & 0 & b_{0} & 0 & - b_{2} & 0 & 0\\0 & 0 & 0 & 0 & b_{1} & 0 & 0 & 0 & 0 & 0 & 0 & b_{0} & 0 & - b_{2} & 0\\0 & 0 & 0 & 0 & 0 & b_{1} & 0 & 0 & 0 & 0 & 0 & 0 & b_{0} & 0 & - b_{2}\\0 & - c_{1} & 0 & 0 & c_{2} & 0 & 0 & 0 & - c_{3} & 0 & 0 & 0 & 0 & c_{4} & 0\\0 & 0 & - c_{1} & 0 & 0 & c_{2} & 0 & 0 & 0 & - c_{3} & 0 & 0 & 0 & 0 & c_{4}\end{array}\right]$$

In [29]:
matrix.shape


Out[29]:
$$\left ( 15, \quad 15\right )$$

In [30]:
mac.get_submatrix(mac.get_matrix())


Out[30]:
$$\left[\begin{matrix}- a_{1} & a_{0} & a_{2} & 0\\0 & - a_{1} & 0 & 0\\0 & 0 & - a_{1} & 0\\0 & 0 & 0 & - a_{1}\end{matrix}\right]$$

In [ ]:


In [ ]: