9
$\begingroup$

Suppose p is a homogeneous polynomial in four variables, say

p = x^10 y^10 z^5 w^5 + 3 a x^10 w^20;

p is a homogeneous polynomial of degree 30, where a is a free parameter. I want to extract the coefficients of monomials, which is just

{1, 3 a}

There is a function in Mathematica, CoefficentList; however, it is very very inefficient, if I do the following evaluation

Flatten[CoefficientList[p, {x, y, z, w}]]

It contains 15246 coefficients and 15244 coefficients out of 15246 are 0. So is there any more efficient and more quick way to extract the coefficients of a homogeneous polynomial of high degree in four variables?

$\endgroup$
2
  • 1
    $\begingroup$ Maybe In[9]:= Apply[List, p] /. Thread[{x, y, z, w} -> 1] Out[9]= {3 a, 1} $\endgroup$ Commented Jul 10, 2016 at 14:41
  • $\begingroup$ Does this look familiar to you? $\endgroup$ Commented Jul 11, 2016 at 4:29

1 Answer 1

14
$\begingroup$

Using an undocumented function:

GroebnerBasis`DistributedTermsList[x^10 y^10 z^5 w^5 + 3 a x^10 w^20,
                                   {x, y, z, w}][[1, All, -1]]
   {1, 3 a}

Here's a documented solution:

CoefficientRules[x^10 y^10 z^5 w^5 + 3 a x^10 w^20, {x, y, z, w}]
   {{10, 10, 5, 5} -> 1, {10, 0, 0, 20} -> 3 a}
$\endgroup$
4
  • $\begingroup$ Thank you very much, do you know where I could find more details about this DistributedTermsList? $\endgroup$
    – Wenzhe
    Commented Jul 10, 2016 at 12:41
  • $\begingroup$ As I had emphasized in my answer, it's undocumented. This has been used before on this site and in MathGroup (you can search for those examples yourself), but there is no documentation for it. $\endgroup$ Commented Jul 10, 2016 at 12:49
  • $\begingroup$ @Wenzhe - You can at least see the available options using Options[GroebnerBasis`DistributedTermsList]. $\endgroup$
    – Bob Hanlon
    Commented Jul 10, 2016 at 13:49
  • $\begingroup$ @BobHanlon Thank you! $\endgroup$
    – Wenzhe
    Commented Jul 10, 2016 at 14:10

Not the answer you're looking for? Browse other questions tagged or ask your own question.