4
$\begingroup$

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.

$\endgroup$
5
  • 1
    $\begingroup$ FromCoefficientRules[r, {t, u}] recovers the original expression. "Possible Issues" in the documentation of CoefficientRules alludes to similar behavior. $\endgroup$
    – bbgodfrey
    Dec 1, 2021 at 18:49
  • $\begingroup$ @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. $\endgroup$ Dec 1, 2021 at 18:57
  • $\begingroup$ 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. $\endgroup$
    – Domen
    Dec 1, 2021 at 18:59
  • 6
    $\begingroup$ My vote is on "bug". Nobody gave CoefficientRules permission to change the variable order and not say anything about it. $\endgroup$ Dec 2, 2021 at 0:48
  • 3
    $\begingroup$ Reported the bug. $\endgroup$ Dec 2, 2021 at 20:12

1 Answer 1

1
$\begingroup$
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

Blockquote

$\endgroup$
1
  • 1
    $\begingroup$ Nice to see it's been fixed! $\endgroup$ Feb 10, 2023 at 12:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.