Let $f(x)=\sum_{i=0}^{n}a_{i}x^{i}$ be a polynomial with rational coefficients. I am interested in an efficient way which allows checking whether the finite sequence $A=(a_{i})_{i\in\{0,\ldots,n\}}$ is unimodal. Let us recall that the sequence is unimodal if there is $k\in\{0,\ldots,n\}$ such that $a_{0}\leq \ldots\leq a_{k-1}\leq a_{k}\geq a_{k+1}\geq \ldots \geq a_{n}$.
1 Answer
Very late response, but here's a method to do just that:
Diff[f_] := Select[Differences[Sign[Select[
Differences[CoefficientList[f, x]], Unequal[#, 0] &]]], Unequal[#, 0] &]
Unimodal[f_] :=
MemberQ[{{}, {-2}}, Diff[f]]
The idea is similar to JM's response in the above comment, but it removes differences that are equal to zero at two points in the computation.
In particular, Sign[Select[Differences[CoefficientList[f, x]], Unequal[#, 0] &]]
returns either the empty list (if all numbers are equal) or a list of -1s and 1s in some order depending on whether the corresponding difference was negative or positive. The next application of Select[Differences[...]]
then extracts the points in which this sequence changes from 1 to -1 or vice versa. This list is then unimodal if the resulting list is either the empty list (in which case the sequence was monotonic) or {-2} (coming from only 1s followed by only -1s).
Differences[Sign[Differences[CoefficientList[poly, x]]]]
be useful to you? $\endgroup$