Bug introduced in 13.0 or earlier. Fixed in 13.2.0 or earlier.
I noticed an odd behavior in CoefficientRules
when you give it a monomial order:
In[1]:= r = CoefficientRules[t^2 + 3 u, {u, t}, "NegativeDegreeLexicographic"]
Out[1]= {{0, 1} -> 3, {2, 0} -> 1}
In[2]:= FromCoefficientRules[r, {u, t}]
Out[2]= 3 t + u^2
Without "NegativeDegreeLexicographic"
, then the exponent vectors respect the {u, t}
order and FromCoefficientRules
results in the expected t^2 + 3 u
. Since FromCoefficientRules
doesn't take a monomial ordering as an argument, this has the appearance of a bug, but I wanted to check that I wasn't missing something about CoefficientRules
before reaching that conclusion.
Maybe a clearer example is this:
In[1]:= r = CoefficientRules[a + 2 b + 3 c + 4 d, {a, b, c, d},
"NegativeDegreeLexicographic"]
Out[1]= {{0, 0, 0, 1} -> 1, {0, 0, 1, 0} -> 2, {0, 1, 0, 0} ->
3, {1, 0, 0, 0} -> 4}
In[2]:= FromCoefficientRules[r, {a, b, c, d}]
Out[2]= 4 a + 3 b + 2 c + d
It seems to be reversing the variables completely, maybe a consequence to how "NegativeDegreeLexicographic"
might be implemented.
FromCoefficientRules[r, {t, u}]
recovers the original expression. "Possible Issues" in the documentation ofCoefficientRules
alludes to similar behavior. $\endgroup$FromCoefficientRules
is the inverse toCoefficientRules
, and needing to change the variable order doesn't seem right. I had thought the "Possible Issues" section was referring to how when you don't give variables it will useVariables
. $\endgroup$"NegativeDegreeReverseLexicographic"
. Taking a look at Neat Examples forCoefficientRules
, one can see that they unfortunately chose same bounds up to 5. But if one changes them to{i, 0, 5}, {j, 0, 3}
, we can see that the result is weird – the last two being transposed. $\endgroup$CoefficientRules
permission to change the variable order and not say anything about it. $\endgroup$