Message Boards Message Boards

0
|
3376 Views
|
2 Replies
|
1 Total Likes
View groups...
Share
Share this post:

Detect (multivariate) polynomial

Posted 10 years ago

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?

POSTED BY: Jaka Spaka
2 Replies
Posted 10 years ago

Thanks!

y^x was a typo.

POSTED BY: Jaka Spaka

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.

POSTED BY: Ivan Morozov
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract