# Is it intended that CoefficientRules permutes exponent vectors when given a monomial order?

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 of CoefficientRules alludes to similar behavior. Dec 1, 2021 at 18:49
• @bbgodfrey I was using that as a workaround, but is this exponent vector permutation expected? The documentation says FromCoefficientRules is the inverse to CoefficientRules, 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 use Variables. Dec 1, 2021 at 18:57
• At the first sight, I would consider this either a bug or a weird undocumented behaviour. The same happens for "NegativeDegreeReverseLexicographic". Taking a look at Neat Examples for CoefficientRules, 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. Dec 1, 2021 at 18:59
• My vote is on "bug". Nobody gave CoefficientRules permission to change the variable order and not say anything about it. Dec 2, 2021 at 0:48
• Reported the bug. Dec 2, 2021 at 20:12

r = CoefficientRules[t^2 + 3 u, {u, t}, "NegativeDegreeLexicographic"]


gives

{{1, 0} -> 3, {0, 2} -> 1}

and

FromCoefficientRules[r, {u, t}]


returns

t^2 + 3 u

Likewise for the other example from the OP.

A screenshot for clarity and completeness

• Nice to see it's been fixed! Feb 10 at 12:53