How to tell if a polynomial has only two distinct roots So by only two distinct roots I meant that the polynomial, say $f(x)$, is of the form $f(x) = (x-a)^{p}(x-b)^{q}$. Now, I also wish to know this if $a, b \in \mathbb{C}$. That is it is possible that $a$ has a non-zero imaginary part while $b$ is an integer and vice versa. It would really help if there was some easy method to find it out. Also I would like to know the suitability of the term only two distinct roots. Thank you for the help!
 A: If you compute (by Euclidean Algorithm) $\gcd(f(x),f^{(n)}(x))$ for successive derivatives of $f(x)$ then you'll find out right away whether $f$ is of the desired form.  For example, let
$$f(x) = x^5-15x^3+10x^2+60x-72.$$
Then
$$f'(x) = 5x^4-45x^2+20x+60$$
and $\gcd(f(x), f'(x)) = x^3-x^2-8x+12.$  Then
$$f''(x) = 20x^3-90x+20$$
and $\gcd(f(x), f'(x)) = x-2$.  That tells me that $(x-2)^3$ exactly divides $f(x)$.  So I compute $g(x)=f(x)/(x-2)^3 = x^2+6x+9$.  Then repeat the above for $g(x)$:
$$g'(x) = 2x+6$$
and $\gcd(g(x), g'(x)) = (x+3).$ So I know that $(x+3)^2$ exactly divides $g(x)$ and hence $f(x)$.  And in fact
$f(x) = (x-2)^3(x+3)^2.$
So you need to know two things here:  If a linear factor appears to the $n$th power in a polynomial, then it appears to the $n-1$ power in the derivative.  And you need to know how to do the Euclidean Algorithm on polynomials.   This will work just fine over the complex numbers.
EDIT:  Sil's comment above gives a much faster way, using these same ideas.
A: Polynomial $f \in \mathbb{C}[x]$ has exactly $\deg f-\deg (\gcd(f,f'))$ distinct (complex) roots.
Proof (sketch). Write $f(x)=(x-\alpha_1)^{k_1}\cdots(x-\alpha_n)^{k_n}$ where $\alpha_i$ are distinct roots and $k_i\geq 1$ their multiplicities, then you can show $\gcd(f(x),f'(x))=(x-\alpha_1)^{k_1-1}\cdots(x-\alpha_n)^{k_n-1}$ and so $f(x)/\gcd(f(x),f'(x))$ is just $(x-\alpha_1)\cdots(x-\alpha_n)$, also called squarefree part of $f$. Its degree $n$ is number of distinct roots of $f$. $\square$

In your case you need to check $\deg f-\deg (\gcd(f,f'))=2$. For this note that $\gcd(f,f')$ can be computed efficiently using Euclid's algorithm for polynomials. If you need the exact roots $a,b$, you can extract them from $f/\gcd(f,f')$ using the quadratic formula.

Example. Consider $f(x)=x^6-9x^5 + 33x^4 - 63x^3 + 66x^2 - 36x + 8$. Then $$f'(x)=6x^5 - 45x^4 + 132x^3 - 189x^2 + 132x - 36$$
and $\gcd(f(x),f'(x))=x^4 - 6x^3 + 13x^2 - 12x + 4$. Hence $\deg f-\deg \gcd(f,f')=2$ and so $f$ has exactly two distinct roots. Furthemore $f(x)/\gcd(f(x),f'(x))=x^2-3x+2$ and so the two roots are $a=1$ and $b=2$. With a bit more work we can find the exponents. Let $f(x)=(x-a)^p(x-b)^q$, then it can be shown that $$\frac{f'(x)}{\gcd(f(x),f'(x))}=(p+q)x-(qa+pb).$$
In the example $f'(x)/\gcd(f(x),f'(x))=6x-9$ and so by comparing the coefficients we get $p=q=3$, i.e. $f(x)=(x-1)^3(x-2)^3$.
Using for example PARI/GP the number of distinct roots by the above method can be computed as:
f = x^6-9*x^5+33*x^4-63*x^3+66*x^2-36*x+8
n = poldegree(f) - poldegree(gcd(f,deriv(f,x)))

A: There are already some great answers, but let me add some more info in the case where the exponents are fixed beforehand. One can homogenize and turn the single-variable nonhomogeneous polynomial $f(x)$ into a homogeneous polynomial, a.k.a. a binary form, $F(x_1,x_2)=x_2^{p+q}f(x_1/x_2)$. Then for fixed given $p,q$ consider $X_{p,q}$ defined as the set of such polynomials which can be written as $F=K^pL^q$ for some linear forms $K$ and $L$. The previous answers give an algorithmic way, for a given specific $F$, to tell if F is in $X_{p,q}$ or in a union of such sets for $p+q$ fixed. Another approach is to try to find polynomial equations in the coefficients of a generic $F$ which vanish exactly when $F$ is in $X_{p,q}$, namely, finding set-theoretic equations for $X_{p,q}$. A much more difficult problem (which includes the previous one) is to find generators for the ideal of all polynomials in the coefficients of $F$ which vanish on $X_{p,q}$ (ideal-theoretic equations). This latter problem was solved by my colleague Chipalkatti and myself in the two articles:

*

*A. Abdesselam, and J. Chipalkatti, "Brill–Gordan loci, transvectants and an analogue of the Foulkes conjecture." Advances in Mathematics 208, no. 2 (2007): 491-520.

*A. Abdesselam, and J. Chipalkatti. "The bipartite Brill-Gordan locus and angular momentum." Transformation groups 11, no. 3 (2006): 341-370.

These respectively concern the $p=q$ and $p\neq q$ cases which are quite different.
