sagemath / sage

Main repository of SageMath
https://www.sagemath.org
Other
1.34k stars 454 forks source link

`PolynomialSequence.coefficient_matrix()` returns a matrix instead of a vector as second element #37027

Closed mantepse closed 7 months ago

mantepse commented 8 months ago

Steps To Reproduce

sage: from sage.rings.polynomial.multi_polynomial_sequence import PolynomialSequence
sage: R.<x,y> = QQ[]
sage: PolynomialSequence([x+2*y+3, 4*x, 5]).coefficient_matrix()
(
[1 2 3]  [x]
[4 0 0]  [y]
[0 0 5], [1]
)
sage: _[1].parent()
Full MatrixSpace of 3 by 1 dense matrices over Multivariate Polynomial Ring in x, y over Rational Field

Expected Behavior

The second element should be a vector - it is the vector of monomials appearing in the sequence.

Actual Behavior

It returns a 1-column matrix.

Additional Information

The problem is that iterating over a vector gives the elements, whereas iterating over a 1-column matrix gives vectors.

Environment

irrelevant.

Checklist

mantepse commented 8 months ago

I am not sure how to deprecate this properly. The current behaviour is likely worked around in a lot of user code, so deprecation is certainly necessary.

RuchitJagodara commented 8 months ago

I think we should not change this because then operations like below will not work

sage: sage: from sage.rings.polynomial.multi_polynomial_sequence import PolynomialSequence
....: sage: R.<x,y> = QQ[]
....: sage: B = PolynomialSequence([x+2*y+3, 4*x, 5]).coefficient_matrix()
sage: B[0]*B[1]
[x + 2*y + 3]
[        4*x]
[          5]

If we return a vector it will not give us the same answer as above.

mantepse commented 8 months ago

Of course not - it will return a vector, which makes more sense I think, and also follows the documentation:

sage: from sage.rings.polynomial.multi_polynomial_sequence import PolynomialSequence
sage: R.<x,y> = QQ[]
sage: m, v = PolynomialSequence([x+2*y+3, 4*x, 5]).coefficient_matrix()
sage: m
[1 2 3]
[4 0 0]
[0 0 5]
sage: v
[x]
[y]
[1]
sage: vector(v)
(x, y, 1)
sage: m*vector(v)
(x + 2*y + 3, 4*x, 5)
RuchitJagodara commented 8 months ago

Ya, you are right. This makes more sense !