I want to define a function FF described as follows:

The input of FF is a polynomial such as

m*u*x^4*y + n*v*x^2*y^3

where mm and nn are constants, and uu, vv, xx and yy are variables.

Assume that FF receives a monomial.

Then FF counts the number of exponents of xx and yy in the following way.

F(x^k*y^l) = (k, k+l).

More generally,

F(m*u*x^k*y^l) = m*(k, k+l).

Here the constant mm is multiplied in front of the 2-tuple,

while we ignore the variable uu because we just want to count the exponents of xx and yy only. Hence it holds that for instance

F(x^4) = (4,4)

F(x^2y^3) = (2,5)

and

F(2xy^2) = 2(1,3).

Finally, suppose that FF receives a polynomial. In this case,

F(mux^4*y + nvx^2*y^3) = m*(4,5) + n*(2,5).

As a matter of fact, I prefer not to compute the result m∗(4,5)+n∗(2,5)m*(4,5) + n*(2,5) so that it becomes (4m+2n,5m+5n)(4m+2n, 5m+5n).

Could you help me in defining this function?

Thank you in advance!

=================

Would you please explain the logic of why m is used but u is discarded?

– Mr.Wizard♦

Oct 10 ’14 at 1:00

Also why F(x^4) should yield (4,4) rather than (4,0).

– Mr.Wizard♦

Oct 10 ’14 at 1:01

The only characters mm and nn serve as constants. (mm and nn denote quantities like the dimension of the problem.) Except them, every character is regarded as a variable. In particular uu, vv, xx and yy are considered to be variables. I want to count the exponents of xx and yy only, discarding the other variables uu and vv.

– Seunghyeok

Oct 10 ’14 at 1:16

Also, I want to regard x4x^4 as x4y0x^4y^0. Since F(x^ky^l) = (k, k+l), we should have F(x4)=F(x4y0)=(4,4+0)=(4,4)F(x^4) = F(x^4y^0) = (4, 4+0) = (4,4). Thank you for your comment!

– Seunghyeok

Oct 10 ’14 at 1:19

=================

2 Answers

2

=================

I propose

pol = m*u*x^4*y + n*v*x^2*y^3

Defer@*Times @@@ CoefficientRules[pol /. {u|v -> 1, x -> x y}, {x, y}] // Total

(* {4, 5} m + {2, 5} n *)

Use Composition[Defer, Times] instead of Defer@*Times if you have version 9 or earlier.

A more general definition:

vars = {x, y};

ignore = {u, v};

Defer@Times@## &[#2, Accumulate@#[[;; Length[vars]]]] & @@@

CoefficientRules[pol, Join[vars, ignore]] // Total

(* n {2, 5} + m {4, 5} *)

Thank you so much! I will try to understand your suggestion.

– Seunghyeok

Oct 10 ’14 at 1:28

The answer is what I really wanted. I sincerely appreciate for it!

– Seunghyeok

Oct 10 ’14 at 4:33

This doesn’t appear to yield the desired output for x^k*y^l or m*u*x^k*y^l, the first two examples.

– Mr.Wizard♦

Oct 10 ’14 at 13:29

@Mr.Wizard, unfortunately, CoefficientRules works with integer powers only.

– ybeltukov

Oct 10 ’14 at 15:18

I guess that’s not a problem for the OP since he Accepted it. Vote restored.

– Mr.Wizard♦

Oct 10 ’14 at 16:37

There is an internal function that might be of use here.

pol = m*u*x^4*y + n*v*x^2*y^3;

GroebnerBasis`DistributedTermsList[pol, {u, v, x, y}][[1]]

(* Out[176]= {{{1, 0, 4, 1}, m}, {{0, 1, 2, 3}, n}} *)

Thanks 🙂 It seems good for me. I will check it out.

– Seunghyeok

Oct 12 ’14 at 23:30