# Checking whether one polynomial is a factor of another

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?

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

One possibility might be to use PolynomialRemainder
PolynomialRemainder[x^4-1,x^2-1,x]==0

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.