# Does Mathematica have a function which yields the degree of a polynomial with respect to one variable? [closed]

Since Mathematica seems not to have a function yielding the degree of a polynomial with respect to one variable, I wrote one:

Deg[pol_,x_]:=
(CoefficientList[Numerator[Together[pol]],x]//Length)-1;
Deg[Sum[x^(5 - i) y^i, {i, 0, 5}], x]


Is there a Mathematica function already available?

• Without your 5.7MB polynomial it is difficult to guess why it didn't work. Can you look at the structure that MMA displays for Numerator[Together[pol]] and let us know whether that is a "flat" polynomial that should have then worked with CoefficientList or if it possibly has some remaining denominators or other visible reasons why this might not have worked as expected?
– Bill
Commented Jun 4 at 4:05
• Can you show the command that did not work? And it is not good idea to start your function with UpperCases. These are reserved for Mathematica. Commented Jun 4 at 4:51
• What do you mean that it "doesn't work"? It runs forever? It kills the kernel? It returns unevaluated? Etc. Commented Jun 4 at 15:29
• "Since Mathematica seems not to have a function yielding the degree of a polynomial..." -- Have you seen Exponent? Commented Jun 4 at 16:22
• Using Version 14.0, in Windows 11 I obtain the desired result 5 more or less instantly. Commented Jun 4 at 19:40

I understand the difficulty of providing the 5.7MB polynomial, but without it, it'll be hard for us to debug. But I'd suggest that you dig further through the documentation and find an alternate implementation. For example there is Exponent which seems to do exactly what you want.

poly = Sum[x^(5 - i)  y^i, {i, 0, 5}];
Deg[poly, x]
(* 5 *)

Exponent[poly, x]
(* 5 *)


Or maybe you want to look into MonomialList, which seems a more direct way to get what you're after than CoefficientList.

MonomialList[poly, x]
(* {x^5, x^4*y, x^3*y^2, x^2*y^3, x*y^4, y^5} *)


From that you could extract the first term and find the exponent. MonomialList takes a third argument for the ordering you want, which might be relevant.

Also, it seems like you're not really looking for the degree of the polynomial per se, but just the degree with respect to a specified variable. But if you were looking for overall degree, these approaches could be modified for that.

Obviously I can't know how either of those approaches will work on your big polynomial, but since they avoid the extra computations of Together, Numerator, and Length, I suspect they will be more performant.