Below is a function intended to test if thean expression is a polynomial with integerin which all the coefficients and exponents onlyare integers:
intPolyQ[Optional[_Integer] + Plus[Optional[_Integer] x_Symbol^Optional[_Integer] ...], x_] := True; intPolyQ[___] := False; but it turns outIt 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 and how to correctly use Optional as an omissible parameterdoes this happen? How do I fix it?