4
$\begingroup$

Given two polynomials, $f(x)$ and $g(x)$, I need to determine whether $f(x)$ is a factor of $g(x)$. Seems simple enough, and the way I initially did it was just checking if $f(x)$ is in a FactorList of $g(x)$:

MemberQ[Flatten[FactorList[ g[x] ]][[;; ;; 2]], f[x] ]

This almost works, however, when you consider something like $g(x)=x^4-1$ and $f(x)=x^2-1$, it should return true since $g(x) = f(x) (x^2+1)$. However, FactorList gives a list of irreducible polynomials, which doesn't include $x^2-1$.

So, how do I check if one polynomial is a factor of another in Mathematica?

$\endgroup$
  • 4
    $\begingroup$ Check if remainder is zero, as in In[187]:= PolynomialRemainder[x^4 - 1, x^2 - 1, x] Out[187]= 0 $\endgroup$ – Daniel Lichtblau Jan 8 '18 at 22:59
  • 4
    $\begingroup$ Could also use PolynomialMod[x^4-1, x^2-1] $\endgroup$ – Carl Woll Jan 8 '18 at 23:00
8
$\begingroup$

how do I check if one polynomial is a factor of another in Mathematica?

One possibility might be to use PolynomialRemainder

PolynomialRemainder[x^4-1,x^2-1,x]==0
(*True*)

Based on using $\frac{p(x)}{d(x)} = Q(x) + \frac{R(x)}{d(x)}$. Where $R(x)$ is the Remainder and $Q(x)$ is the quotient. So if $d(x)$ is factor of $p(x)$ then the Remainder should be zero.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.