I have a slightly different question than this post:

How do I find the degree of a multivariable polynomial automatically?

I would like to compute the degree of a multivariate polynomial but with respect to a gradation that is I put weights on variables to compute the order.

For instance, $p=x^2y + z^3 + y^4$ with the gradation $(1,1,2)$ for $(x,y,z)$ is of degree $6$.

I have that to compute the order of a monomial $x^i y^j z^k$ I apply


1 Answer 1



Daniel provided a proper solution in the comments. I am including it here (and leading with it) as he did not choose to post an answer of his own.

p = x^2 y + z^3 + y^4;

wts = {1, 1, 2};
vars = {x, y, z};

Exponent[p /. Thread[vars -> (t*vars)^wts], t]

This might be made into a function:

deg[vars_, wts_][poly_] /; Length[vars] == Length[wts] := 
  Module[{t}, Exponent[poly /. Thread[vars -> (t*vars)^wts], t]]

deg[{x, y, z}, {1, 1, 2}] /@
   x^2 y + z^3 + y^4,
   x^2 y + y,
   x^2 y + z^3 - y^6
{6, 3, 6}

Old, unreliable answer

Second try, hopefully closer to what you need this time.

p = x^2 y + z^3 + y^4;
v = {x, y, z};
g = {1, 1, 2};

Exponent[p /. Thread[v -> E^g], E]
Exponent[x^2 y + y /. Thread[v -> E^g], E]

Incidentally the entire Thread[v -> E^g] may be unwanted but I tried to provide code that was more easily generalized, in case you have more variables or need to iterate over different weights, etc.

  • $\begingroup$ No, it doesn't answer the question: take $p = x^2 y + y$, $deg(p) = 3$ but it's not what you compute.... $\endgroup$
    – Smilia
    Jan 24, 2017 at 12:02
  • $\begingroup$ @Smilia I am probably being obtuse or ignorant but would you please explain for me how the degree is 3 there? $\endgroup$
    – Mr.Wizard
    Jan 24, 2017 at 12:11
  • $\begingroup$ Ok, here you go a definition in the preambule of the degree of multivariate polynomial: en.wikipedia.org/wiki/Degree_of_a_polynomial $\endgroup$
    – Smilia
    Jan 24, 2017 at 12:20
  • 2
    $\begingroup$ I would recommend using a new variable and just reweighting. That new variable should not be a built-in symbol such as E. wts = {1, 1, 2}; vars = {x, y, z}; Exponent[p /. Thread[vars -> (t*vars)^wts], t] Also, the method above will fail on p = x^2 y + z^3 - y^6 (because it is not safe against cancellation of lead terms). $\endgroup$ Jan 24, 2017 at 19:26
  • 1
    $\begingroup$ Also there is GroebnerBasis`DistributedTermsList[p, {x, y, z}, MonomialOrder -> Join[{wts}, NullSpace[{wts}]]][[1, 1, 1]].wts where wts is the weight vector. Requires that it be all nonnegative rationals, I think. $\endgroup$ Jan 24, 2017 at 19:30

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.