0
$\begingroup$

From time to time I find myself in the following situation. I have generated a list of polynomials from some ring $R=\mathbb R[x_1,\ldots,x_n]$ and now I wish to view these polynomials as vectors in the linear space $R$. Most commonly, I'm interested in the dimension of the subspace in $R$ spanned by these polynomials, so let us concentrate on this specific task.

Of course, one may explicitly convert each polynomial into a vector with the likes of MonomialList or CoefficientList, turn the list of polynomials into a matrix and find its rank... This is what I've been doing so far but it (the first step that is) does seem a bit tedious given how simple and natural my goal is. Might there exist a neater way? Either with the use of some built-in functionality that I'm not finding or of some (reasonably) dirty trick?

$\endgroup$
  • $\begingroup$ Could you give an example of the vector that should be returned for something like 1+x+x y+x^2+x y^2+x^4 y^3? $\endgroup$ – Carl Woll May 24 at 14:17
  • $\begingroup$ @CarlWoll, I only noticed the comment just now. Well, ideally, these should provide the matrix {{1,2,0,0,0,0,0},{0,1,1,1,0,0,0},{0,0,0,0,1,1,0},{0,0,0,0,0,0,1}}. The rank of this matrix is the dimension of the linear span. The less zero columns are added, the better. $\endgroup$ – imakhlin May 24 at 15:03
  • 1
    $\begingroup$ Your question talks about converting a polynomial into a vector. Your comment suggests it should be converted to a matrix, and I have no idea how your matrix is generated from the polynomial. I think you need to provide some examples of the vector/matrix expected for a polynomial and a brief explanation for how it is derived. $\endgroup$ – Carl Woll May 24 at 16:52
  • $\begingroup$ @CarlWoll My question talks about converting polynomials to vectors as well as converting lists of polynomials to matrices (which is pretty much the same thing), please have another look. I'll see if I can rephrase it to make it clearer though. $\endgroup$ – imakhlin May 24 at 16:59
  • $\begingroup$ In any case, your answer helped tremendously and I will accept it as soon as you extend it in order to cover arbitrary lists of polynomials. $\endgroup$ – imakhlin May 24 at 17:01
3
$\begingroup$

I think you can just use CoefficientArrays. For example, let's start with the following matrix:

SeedRandom[1]
m = RandomInteger[10, {10,10}]

{{1, 4, 0, 7, 0, 0, 8, 6, 0, 4}, {1, 8, 5, 1, 1, 1, 3, 2, 10, 1}, {6, 0, 2, 6, 4, 5, 4, 3, 0, 1}, {3, 5, 3, 0, 3, 2, 3, 9, 5, 1}, {5, 2, 3, 9, 1, 0, 4, 4, 1, 5}, {2, 7, 9, 9, 8, 10, 0, 10, 10, 7}, {4, 9, 2, 6, 3, 2, 1, 1, 6, 1}, {1, 6, 8, 6, 5, 6, 0, 10, 7, 9}, {1, 4, 4, 10, 3, 5, 2, 3, 1, 2}, {5, 10, 8, 3, 6, 3, 10, 3, 10, 3}}

Construct a list of polynomials:

poly = m . Array[Subscript[x, #]&, 10];
poly //TeXForm

$\left\{x_1+4 x_2+7 x_4+8 x_7+6 x_8+4 x_{10},x_1+8 x_2+5 x_3+x_4+x_5+x_6+3 x_7+2 x_8+10 x_9+x_{10},6 x_1+2 x_3+6 x_4+4 x_5+5 x_6+4 x_7+3 x_8+x_{10},3 x_1+5 x_2+3 x_3+3 x_5+2 x_6+3 x_7+9 x_8+5 x_9+x_{10},5 x_1+2 x_2+3 x_3+9 x_4+x_5+4 x_7+4 x_8+x_9+5 x_{10},2 x_1+7 x_2+9 x_3+9 x_4+8 x_5+10 x_6+10 x_8+10 x_9+7 x_{10},4 x_1+9 x_2+2 x_3+6 x_4+3 x_5+2 x_6+x_7+x_8+6 x_9+x_{10},x_1+6 x_2+8 x_3+6 x_4+5 x_5+6 x_6+10 x_8+7 x_9+9 x_{10},x_1+4 x_2+4 x_3+10 x_4+3 x_5+5 x_6+2 x_7+3 x_8+x_9+2 x_{10},5 x_1+10 x_2+8 x_3+3 x_4+6 x_5+3 x_6+10 x_7+3 x_8+10 x_9+3 x_{10}\right\}$

Now, let's use CoefficientArrays to regenerate m:

m2 = CoefficientArrays[poly, Array[Subscript[x, #]&,10]] //Last //Normal

{{1, 4, 0, 7, 0, 0, 8, 6, 0, 4}, {1, 8, 5, 1, 1, 1, 3, 2, 10, 1}, {6, 0, 2, 6, 4, 5, 4, 3, 0, 1}, {3, 5, 3, 0, 3, 2, 3, 9, 5, 1}, {5, 2, 3, 9, 1, 0, 4, 4, 1, 5}, {2, 7, 9, 9, 8, 10, 0, 10, 10, 7}, {4, 9, 2, 6, 3, 2, 1, 1, 6, 1}, {1, 6, 8, 6, 5, 6, 0, 10, 7, 9}, {1, 4, 4, 10, 3, 5, 2, 3, 1, 2}, {5, 10, 8, 3, 6, 3, 10, 3, 10, 3}}

Check:

m == m2

True

$\endgroup$
  • $\begingroup$ Thank you, this is very helpful! I must say, however, that your example is really simplified by the fact that your polynomials are all homogeneous and of the same degree. In the general case I'd have to write something along the lines of MatrixRank[Flatten /@ Transpose[Normal[CoefficientArrays[polys,vars]]]], right? $\endgroup$ – imakhlin May 24 at 14:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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