# Degree of multivariate polynomials with weights

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

ordMonome[mon]:=Log[mon]/.{x->Exp[1],y->Exp[1],z->Exp[2]};


### Solution

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]

6


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}


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]

6

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

3


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.

• No, it doesn't answer the question: take $p = x^2 y + y$, $deg(p) = 3$ but it's not what you compute.... Jan 24 '17 at 12:02
• @Smilia I am probably being obtuse or ignorant but would you please explain for me how the degree is 3 there? Jan 24 '17 at 12:11
• Ok, here you go a definition in the preambule of the degree of multivariate polynomial: en.wikipedia.org/wiki/Degree_of_a_polynomial Jan 24 '17 at 12:20
• 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). Jan 24 '17 at 19:26
• Also there is GroebnerBasisDistributedTermsList[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. Jan 24 '17 at 19:30