# Detect (multivariate) polynomial

Posted 9 years ago
2778 Views
|
2 Replies
|
1 Total Likes
|
 I would like to detect multivariate polynomials. Ideally write a function that returns True if the argument is a polynomial.I have expressions like "x/(y+1) + x^2 / (y+2)", "x y^-30 + x / (y^2-2),.. I would like to filter these to only have the ones that are polynomials, e.g. "x^10 y^x + x^5 y^8". Any ideas?
2 Replies
Sort By:
Posted 9 years ago
 Thanks!y^x was a typo.
Posted 9 years ago
 Hi, There is a build-in function PolynomialQ[], you can use it together with Select[] to filter a given list, say: polys = { x/(y + 1) + x^2/(y + 2), x y^-30 + x/(y^2 - 2), x^10 y^x + x^5 y^8, x^10 y^2 + x^5 y^8 }; PolynomialQ[#, {x, y}] & /@ polys Select[polys, PolynomialQ[#, {x, y}] &] Also, note that "x^10 y^x + x^5 y^8" is not a polynomial in (x,y) variables, since it involves y^x. If you just need to remove expressions with denominators, then from: x/(y^2 - 2) // FullForm it can be seen that they match the pattern of the form a__ + b__ Power[c__, -1]: x^10 y^x + x^5 y^8 /. a__ + b__ Power[c__, -1] -> 1 x/(y + 1) + x^2/(y + 2) /. a__ + b__ Power[c__, -1] -> 1 x y^-30 + x/(y^2 - 2) /. a__ + b__ Power[c__, -1] -> 1 DeleteCases[polys /. a__ + b__ Power[c__, -1] -> 1 , _Integer] I.M.