I am has some equation, how to check if it is a polynomial(or can be converted to polynomial)?

Example equation: $a+\frac{1}{a}=k$

I know about PolynomialQ, but it does not working for this equation:

PolynomialQ[a + 1/a - k, a](*False*)

The $a+\frac{1}{a}=k$ is eqvivalent to $a^{2}-ak+1=0$

Now, PolynomialQ is correct work:

PolynomialQ[a^2 - a*k + 1, a](*True*)


  1. How to use Mathematica for attempt to convert some equation to polynomial form and print result?
  2. Similar question for WolframAlpha

Edit: I am interested about the general method of checking a certain equation for the possibility of converting to a polynomial, but, it is difficult (or impossible), therefore, assume that the input equation is rational.

Another example, of a polynomial equation(proof): $$\frac{a}{\left(x+\frac{1}{x}\right)^{2}}+\frac{b}{\left(x-\frac{1}{x}\right)^{2}}=1$$

eq = a/(x + 1/x)^2 + b /(x - 1/x)^2 == 1;
  • $\begingroup$ It is unclear to me if you'll always encounter rational functions, or you'll encounter something transcendental that can be made polynomial through a substitution. Nevertheless, for your current example: With[{eq = a + 1/a == k}, With[{vars = Reduce`FreeVariables[eq]}, PolynomialQ[First[GroebnerBasis[eq, vars]], vars]]] should give the expected answer. $\endgroup$ Commented Mar 24, 2020 at 14:10
  • $\begingroup$ Would Numerator[Together[expr]] give what you want? $\endgroup$ Commented Mar 24, 2020 at 19:16
  • $\begingroup$ @J.M.'stechnicaldifficulties Important information has been added to the question, please see $\endgroup$
    – PavelDev
    Commented Mar 24, 2020 at 21:26
  • 1
    $\begingroup$ I would then amend Daniel's suggestion to Numerator[Together[Apply[Subtract, expr]]]. $\endgroup$ Commented Mar 25, 2020 at 0:28

3 Answers 3


How about

Internal`RationalFunctionQ[a + 1/a - k, a]
  • $\begingroup$ This is perfectly fine. Note that now it is exposed publicly as a resource function: In[9]:= ResourceFunction["RationalFunctionQ"][a + 1/a - k, a] Out[9]= True $\endgroup$ Commented Mar 25, 2020 at 15:35

You essentially want to test whether a given expression is rational in some given variable. The general case is probably going to be subtle, but the naive approach works for your particular example:

And @@ {
        PolynomialQ[Numerator[#], a], 
        PolynomialQ[Denominator[#], a]
       } &@ Together[a + 1/a - k]

If you want the expanded form, use

Expand[# a^Exponent[Denominator[Together[#]], a]] &[a + 1/a - k]
  • $\begingroup$ This works for a second example. Obtaining a polynomial form for an equation also interests me, but this code(for getting expanded form) does not work for the second example $\endgroup$
    – PavelDev
    Commented Mar 24, 2020 at 22:13
  • $\begingroup$ what if you use Numerator@Together[a/(x + 1/x)^2 + b/(x - 1/x)^2 - 1]? $\endgroup$ Commented Mar 24, 2020 at 22:29

I suspect that the problem is undecidable, except for particulars classes of expressions, e. g., rational expressions.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.