Below is a function intended to test if an expression is a polynomial in which all the coefficients and exponents are integers:
intPolyQ[Optional[_Integer] +
Plus[Optional[_Integer] x_Symbol^Optional[_Integer] ...], x_] := True;
intPolyQ[___] := False;
It gives unexpected results in some cases. For example,
intPolyQ[#, x] & /@ {x, 2 x, 2 x + 1, 2 x^2 + 3 x, 2 x^2 + 3 x + 1}
gives
{True, True, True, False, True}
which is wrong in the 4th case.
Why does this happen? How do I fix it?