JuliaAlgebra / DynamicPolynomials.jl

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

monovec boolean indexing #111

Closed projekter closed 2 years ago

projekter commented 2 years ago

Currently, indexing a monovec with a boolean array gives wrong results, as the implementation sorts the index array: https://github.com/JuliaAlgebra/DynamicPolynomials.jl/blob/2ca5cd58f993e8166f46420a1da17f11fba26537/src/monovec.jl#L42-L44

Therefore, regardless of how the t true values are distributed in the index array, we will always get the t last monomials. Example:

@polyvar x[1:2]
basis = monomials(x, 0:1)

gives

3-element DynamicPolynomials.MonomialVector{true}:
 x₁
 x₂
 1

so that basis[[true, true, false]] should give the first two monomials, but instead we get the last two.

This also directly affects filter, since it internally uses boolean indexing: filter(mon -> degree(mon) == 1, basis) should give the first two elements, but it returns the last two.

blegat commented 2 years ago

Thanks for reporting this, bugs that silently return wrong answers are the worse