ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Sun, 29 Aug 2021 05:02:37 +0200support() and coefficients() in combinatorial free moduleshttps://ask.sagemath.org/question/58724/support-and-coefficients-in-combinatorial-free-modules/I was surprised that in the code below I could not count on the lists returned by support() and coefficients() to correspond. Is there a proper way to use these methods in conjunction with each other, or should I adopt a different approach? If I sort the list returned by support() will I be able to count on the coefficients corresponding with generators?
k3.<w3> = CyclotomicField(3)
F3 = CombinatorialFreeModule(k3,NN,prefix='v3')
v3 = F3.basis()
v3
> Lazy family (Term map from Non negative integer semiring to Free module generated by Non negative integer semiring over Cyclotomic Field of order 3 and degree 2(i))_{i in Non negative integer semiring}
expr = -2*v3[34] - (-2*w3)*v3[42] - 2*v3[58] - (2*w3+2)*v3[66]
[expr.support(),expr.coefficients()]
> [[34, 42, 66, 58], [-2, 2*w3, -2, -2*w3 - 2]]
Perhaps I should ask my real question, while I'm here. I have a list of module elements (actually vectors) and would like to find the kernel of the matrix with these vectors as rows. The matrix is likely to be sparse. I encountered the issue described above while trying to set up the matrix by hand from the list of vectors.
**Added:** The suggestion of John Palmieri in a comment and of tmonteil in an answer to use expr.monomial_coefficients() solves my problem, but I think it still worth trying to pin down the answer to the original question.
The documentation for support() says
> Return a list of the objects indexing the basis of "self.parent()"
whose corresponding coefficients of "self" are non-zero.
>
> This method returns these objects in an arbitrary order.
The documentation for coefficients() says
> Return a list of the (non-zero) coefficients appearing on the basis elements in "self" (in an arbitrary order).
>
> INPUT:
>
> * "sort" -- (default: "True") to sort the coefficients based upon the default ordering of the indexing set
Both mention that elements are returned "in an arbitrary order". Since it is not specified that the arbitrary order returned by the two functions is the same, one must assume the orders could be different. I wonder, however, whether they are intended to be the same since it is difficult to imagine many uses for a function that returns coefficients without making it possible to determine what they are coefficients of.
The other striking thing is that coefficients() actually doesn't default to the behavior described in the first line of the documentation: it defaults to "sort=True" which causes the coefficients to be returned in an order corresponding to the sorted order of the elements of the support, and not an arbitrary order. Since support() has no "sort" option, the only option is the "arbitrary" order. I strongly suspect that if one turns off the default option in coefficients() by setting "sort=False", one will get an arbitrary order that corresponds to that of support(), but, if true, it would be nice to have that documented somewhere.Will OrrickSun, 29 Aug 2021 05:02:37 +0200https://ask.sagemath.org/question/58724/