Question: checking for special kind of polynomial

I need to check if expression is "special" kind of polynomial. Where powers are allowed to be non-integers and can be fractions. This is not polynomial in the mathematical sense ofcourse so can not use type(expr,polynom) on it, and did not see a way to tell type(expr,polynom) to accept non-integer exponents.

For an example, given p(x):=x^2+x^(1/3)+3+sqrt(x)+x^Pi+1/x*sin(x): it will return false, due to sin(x) term there. Without this term, it will return true, since all other terms have the form x^anything.

Currently, this is what I do

expr:=x^2+x^(1/3)+3+sqrt(x)+x^Pi+1/x*sin(x):

if type(expr,polynom(anything,x)) then
   print("Yes, normal polynomial");
else
   what_is_left:=remove(Z->type(Z,{`^`('identical'(x),algebraic),'identical'(x)}),expr);
   if has(what_is_left,x) then
      print("Not special polynomial");
   else
      print("Yes, special polynomial");
   fi;
fi;

While with

expr:=x^2+x^(1/3)+3+sqrt(x)+x^Pi+1/x:

It will print "Yes, special polynomial"

Is the above a good way to do this, or do you suggest a better way? It seems to work on the few tests  I did on it so far.

It is always "polynomial" in one symbol, such as x. So if it contains any function of x, other than  x^exponent, where exponent can only be numeric, or other symbol, it will fail the test. So this below will pass the a above test as well

expr:=x^2+x^(1/3)+3+sqrt(x)+x^a+1/x:

 

Please Wait...