MultivariatePolynomials.jl
MultivariatePolynomials.jl copied to clipboard
Safe evaluation
The number 1 issue with DP is with the following:
@polyvar x y
p = x + y
p(x => 1) # Garbage
What prevents us from showing a nice error message is that checking whether all variables are assigned would make the evaluation slower. We could maybe replace https://github.com/JuliaAlgebra/MultivariatePolynomials.jl/blob/cd76ab85ef40d2b4d3bce2f1330e56ef5142d1b6/src/substitution.jl#L21 by
struct Eval <: AbstractSubstitutionType
check::Bool
end
and if check
is true
(which would be the default), the call will need to take an extra time if needed to make a nice error messages in case not all variables are assigned a value.
What do you think ?
cc @chriscoey
Doesn't this check only has to be done once at the beginning? I would be completely fine with this, since I only use DynamicPolynomials for construction of systems and lightweight analysis, so no evaluation heavy stuff. Also I think it would be better to be by default on the safe side, since the current behaviour is very subtle and even can happen unnoticed.
What do you mean at the beginning ? I imagine doing the check here:
https://github.com/JuliaAlgebra/DynamicPolynomials.jl/blob/a546440ea886873e6b3ccf073984465c62f30e3d/src/subs.jl#L30
with a BitSet
instead of
https://github.com/JuliaAlgebra/DynamicPolynomials.jl/blob/a546440ea886873e6b3ccf073984465c62f30e3d/src/subs.jl#L33-L35
which doesn't work for Int
, ...
I agree with defaulting to the safe side (I had some headaches caused by silent garbage).
How would the user set check
?
How would the user set
check
?
MP.subs(MP.Eval(false), p, x => 1)