import sympy as sym
from sympy.polys import subresultants_qq_zz
sym.init_printing()
If $p$ and $q$ are two polynomials over a commutative ring with identity which can be factored into linear factors,
then the resultant $R(p,q)$ of $p$ and $q$ is defined as:
$$R(p,q)=a^n_{0}b^m_{0}\prod_{i=1}^{m}\prod_{j=1}^{n}(r_i - s_j)$$Since the resultant is a symmetric function of the roots of the polynomials $p$ and $q$, it can be expressed as a polynomial in the coefficients of $p$ and $q$.
From the definition, it is clear that the resultant will equal zero if and only if $p$ and $q$ have at least one common root. Thus, the resultant becomes very useful in identifying whether common roots exist.
It was proven that the determinant of the Sylvester's matrix is equal to the resultant. Assume the two polynomials:
Then the Sylverster matrix in the $(m+n)\times(m+n)$ matrix:
$$ \left| \begin{array}{cccccc} a_{0} & a_{1} & a_{2} & \ldots & a_{m} & 0 & \ldots &0 \\ 0 & a_{0} & a_{1} & \ldots &a_{m-1} & a_{m} & \ldots &0 \\ \vdots & \ddots & \ddots& \ddots& \ddots& \ddots& \ddots&\vdots \\ 0 & 0 & \ddots & \ddots& \ddots& \ddots& \ddots&a_{m}\\ b_{0} & b_{1} & b_{2} & \ldots & b_{n} & 0 & \ldots & 0 \\ 0 & b_{0} & b_{1} & \ldots & b_{n-1} & b_{n} & \ldots & 0\\ \ddots &\ddots & \ddots& \ddots& \ddots& \ddots& \ddots&\ddots \\ 0 & 0 & \ldots& \ldots& \ldots& \ldots& \ldots& b_{n}\\ \end{array} \right| = \Delta $$Thus $\Delta$ is equal to the $R(p, q)$.
Two examples are consider here. Note that if the system has a common root we are expecting the resultant/determinant to equal to zero.
x = sym.symbols('x')
A common root exists.
f = x ** 2 - 5 * x + 6
g = x ** 2 - 3 * x + 2
f, g
subresultants_qq_zz.sylvester(f, g, x)
subresultants_qq_zz.sylvester(f, g, x).det()
A common root does not exist.
z = x ** 2 - 7 * x + 12
h = x ** 2 - x
z, h
matrix = subresultants_qq_zz.sylvester(z, h, x)
matrix
matrix.det()
When we have system of two variables we solve for one and the second is kept as a coefficient.Thus we can find the roots of the equations, that is why the resultant is often refeered to as the eliminator.
y = sym.symbols('y')
f = x ** 2 + x * y + 2 * x + y -1
g = x ** 2 + 3 * x - y ** 2 + 2 * y - 1
f, g
matrix = subresultants_qq_zz.sylvester(f, g, y)
matrix
matrix.det().factor()
Three roots for x $\in \{-3, 0, 1\}$.
For $x=-3$ then $y=1$.
f.subs({x:-3}).factor(), g.subs({x:-3}).factor()
f.subs({x:-3, y:1}), g.subs({x:-3, y:1})
For $x=0$ the $y=1$.
f.subs({x:0}).factor(), g.subs({x:0}).factor()
f.subs({x:0, y:1}), g.subs({x:0, y:1})
For $x=1$ then $y=-1$ is the common root,
f.subs({x:1}).factor(), g.subs({x:1}).factor()
f.subs({x:1, y:-1}), g.subs({x:1, y:-1})
f.subs({x:1, y:3}), g.subs({x:1, y:3})
a = sym.IndexedBase("a")
b = sym.IndexedBase("b")
f = a[1] * x + a[0]
g = b[2] * x ** 2 + b[1] * x + b[0]
matrix = subresultants_qq_zz.sylvester(f, g, x)
matrix.det()