JuliaAlgebra / DynamicPolynomials.jl

Multivariate polynomials implementation of commutative and non-commutative variables
Other
60 stars 20 forks source link

Cannot always create monomials with specified degrees #132

Closed baggepinnen closed 1 year ago

baggepinnen commented 1 year ago

Below, monomials(x, [3,2]) works, but monomials(x, [2,2]) errors. Why?

julia> @polyvar x[1:2]
(PolyVar{true}[x₁, x₂],)

julia> monomials(x, [3,2])
7-element MonomialVector{true}:
 x₁³
 x₁²x₂
 x₁x₂²
 x₂³
 x₁²
 x₁x₂
 x₂²

julia> monomials(x, [2,2])
ERROR: AssertionError: issorted(Z, rev = true, lt = grlex)
Stacktrace:
 [1] getZfordegs(n::Int64, degs::Vector{Int64}, #unused#::Type{Val{true}}, filter::Function)
   @ DynamicPolynomials ~/.julia/packages/DynamicPolynomials/JQRi1/src/monovec.jl:134
 [2] MonomialVector (repeats 2 times)
   @ ~/.julia/packages/DynamicPolynomials/JQRi1/src/monovec.jl:139 [inlined]
 [3] monomials(vars::Vector{PolyVar{true}}, args::Vector{Int64})
   @ DynamicPolynomials ~/.julia/packages/DynamicPolynomials/JQRi1/src/monovec.jl:154
 [4] top-level scope
   @ REPL[114]:1
blegat commented 1 year ago

What are you trying to achieve with monomials(x, [2,2]) ? Why don't you do monomials(x, [2]) ?

baggepinnen commented 1 year ago

I would like to be able to create all monomials where x[i] appear up to order deg[i] similar to what monomials(x, [3,2]) does. The problem is that for some choices of deg, I get the error above

blegat commented 1 year ago

monomials(x, [3,2]) gives you all monomials of degree 3 followed by all monomials of degree 2. Note that you have x[2]^3 in the output.

baggepinnen commented 1 year ago

I think I misunderstood how the degree argument worked, I managed to get what I wanted by using the filter function, thanks for your help :)