With DynamicPolynomials and non-commutative variables, (x+y)*z does not work

How to right-multiply x+y by z in DynamicPolynomials when x, y, z are non-commutative? I have tried (x+y)*z, but Julia returns an ERROR: MethodError: no method matching map_exponents(::typeof(+), ::MonomialVector{…}, ::Variable{…})

Strangely, z*(x+y) yields the result zy + zx properly. The documentation for DynamicPolynomials is terse and it does not indicate anything special about right-multiplication by a single variable.

You can cheat a bit with a polynomial equal to the variable e.g. @ncpolyvar x y z; (x+y)*(z+0). The MethodError seems to warrant filing an issue; even if intentional, the API should be clarified and ideally documented.

It works! Many thanks.

This got patched with a new method and released in v0.6.7: Pull Request #205 · JuliaAlgebra/DynamicPolynomials.jl. It’s still a little odd because the commutative right-multiplication still uses the MultivariatePolynomials method that caused this problem, but maybe that just happens to be what it could support for DynamicPolynomials types.

Update. I have reported another related issue: z*(x+y) is correctly evaluated but 2z*(x+y), -z*(x+y), -2z*(x+y) etc. are not. Your workaround still works: (2z+0)*(x+y) yields a correct answer.