M2
M2 copied to clipboard
coefficients in iterated rings
This is not really a bug (and I understand why it happens -- kind of...), but I still find it disturbing and unpleasant:
i1 : R=QQ[x]; S=R[y];
i3 : coefficients(x+y,Monomials=>{x,y})
o3 = (| x y |, {0, 1} | x |)
{1, 0} | 1 |
o3 : Sequence
i4 : first oo * last oo -- not the expected result x+y !
o4 = | y+x2 |
1 1
o4 : Matrix S <--- S
This is definitely a bug! I'm not sure yet how to handle it. Perhaps if Variables or Monomials is given, their support should be variables in the outer polynomial ring, and an error could be given in that case? Flattening the ring implicitly is probably not a good idea.
Flattening is indeed not good; in fact the example in the help makes it clear how it's supposed to work with iterated rings. Even if we stick to the current logic, then
- either it should throw an error, complaining that x is not a monomial of S
- or if it insists on viewing x as a monomial of S, namely the constant monomial, then it should normalize the monomial (get rid of its constant in front, which here happens to be x) so that the output would be
{ | 1 y | , | x | }
| 1 |
which at least satisfies first oo * last oo == x+y.
But maybe there are smarter ways to deal with this problem...