JuliaIntervals / IntervalRootFinding.jl

Library for finding the roots of a function using interval arithmetic
https://juliaintervals.github.io/IntervalRootFinding.jl/
Other
126 stars 26 forks source link

Support function returning IntervalBox and only use them internally #107

Open Kolaru opened 5 years ago

Kolaru commented 5 years ago

Currently, the functions passed to roots must return SVector which has several drawbacks:

IB = IntervalBox(emptyinterval(), emptyinterval())
SV = SVector(emptyinterval(), emptyinterval())

Here isempty(IB) evaluates to true while isempty(SV) evaluates to false. This caused some of the bugs I'm trying to fix in #93 (an update is coming soon).

Therefore, I advise that SVector should only be used when ForwardDiff is directly involved, i.e. deep inside the contractors.

It may be possible to support both the current behavior and function returning IntervalBox (converting to the latter internally) using fancy multiple dispatch, otherwise this would be a breaking change.

dpsanders commented 5 years ago

Good point and good idea.

For ForwardDiff I think we just need

import ForwardDiff

ForwardDiff.gradient(f, X::IntervalBox) = ForwardDiff.gradient(f, X.v)
ForwardDiff.jacobian(f, X::IntervalBox) = ForwardDiff.jacobian(f, X.v)
ForwardDiff.hessian(f, X::IntervalBox) = ForwardDiff.hessian(f, X.v)