How to check if an arbitrary equation is a polynomial?

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*)


Questions:

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;

• 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 = ReduceFreeVariables[eq]}, PolynomialQ[First[GroebnerBasis[eq, vars]], vars]]] should give the expected answer. Commented Mar 24, 2020 at 14:10
• Would Numerator[Together[expr]] give what you want? Commented Mar 24, 2020 at 19:16
• @J.M.'stechnicaldifficulties Important information has been added to the question, please see Commented Mar 24, 2020 at 21:26
• I would then amend Daniel's suggestion to Numerator[Together[Apply[Subtract, expr]]]. Commented Mar 25, 2020 at 0:28

InternalRationalFunctionQ[a + 1/a - k, a]
(*True*)

• 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 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]

• 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 Commented Mar 24, 2020 at 22:13
• what if you use Numerator@Together[a/(x + 1/x)^2 + b/(x - 1/x)^2 - 1]? Commented Mar 24, 2020 at 22:29

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