JuliaAlgebra / DynamicPolynomials.jl

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

Undefined behavior for incomplete evaluations #30

Closed b-reinke closed 5 years ago

b-reinke commented 6 years ago

It is possible to evaluate a polynomial with incomplete variable assignments, if the substitution uses simple enough types. See for example

julia> using DynamicPolynomials

julia> @polyvar x y
y

julia> f = x + y
x + y

julia> f(x=>1)
140545602820497 (or other garbage)

contrast to

julia> f(x=>BigInt(1))
ERROR: AssertionError: Variable y was not assigned a value

It seems to be a bug in

https://github.com/JuliaAlgebra/DynamicPolynomials.jl/blob/09bd7915f6dd1e6f4e98ba93d8d8b28ef5e4190e/src/subs.jl#L29-L37

as Vector{Int}(undef, n) and isassigned do not work together in the same way as for more complected types.

blegat commented 6 years ago

@b-reinke Yes, this is annoying, we found no way to add for a check for values such as Int without sacrificing performance in the evaluation. We would be interested if anyone has an idea :)