3

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]};
Smilia
  • 592
  • 4
  • 14

1 Answers1

3

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}

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

Mr.Wizard
  • 271,378
  • 34
  • 587
  • 1,371
  • No, it doesn't answer the question:

    take $p = x^2 y + y$, $deg(p) = 3$ but it's not what you compute....

    – Smilia 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? – Mr.Wizard Jan 24 '17 at 12:11
  • Ok, here you go a definition in the preambule of the degree of multivariate polynomial:

    https://en.wikipedia.org/wiki/Degree_of_a_polynomial

    – Smilia Jan 24 '17 at 12:20
  • @Smilia I don't know why but I overlooked your final line of code and made a bad guess as to how to use g. I think I see what you want now? I shall update my answer. Please let me know. If I still fail I'll delete this answer. – Mr.Wizard Jan 24 '17 at 12:32
  • 2
    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). – Daniel Lichtblau Jan 24 '17 at 19:26
  • 1
    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. – Daniel Lichtblau Jan 24 '17 at 19:30
  • @Daniel Thanks for coming to the rescue. – Mr.Wizard Jan 25 '17 at 00:11