MultivariatePolynomials.jl icon indicating copy to clipboard operation
MultivariatePolynomials.jl copied to clipboard

Safe evaluation

Open blegat opened this issue 5 years ago • 4 comments

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

blegat avatar Aug 08 '18 09:08 blegat

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.

saschatimme avatar Aug 08 '18 10:08 saschatimme

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, ...

blegat avatar Aug 08 '18 11:08 blegat

I agree with defaulting to the safe side (I had some headaches caused by silent garbage).

How would the user set check?

chriscoey avatar Aug 09 '18 00:08 chriscoey

How would the user set check?

MP.subs(MP.Eval(false), p, x => 1)

blegat avatar Aug 09 '18 06:08 blegat