diff --git a/src/algorithms.jl b/src/algorithms.jl index 405b0a6f..807299dd 100644 --- a/src/algorithms.jl +++ b/src/algorithms.jl @@ -182,6 +182,7 @@ the interval/interval box. The algorithm also looks at the sign of the derivative / gradient to see if the range can be computed directly. By default, the derivative / gradient is computed using `ForwardDiff.jl`, but a custom value can be passed via the `df` keyword argument to [`enclose`](@ref). +Pass `df = nothing` to avoid computing any derivatives. ### Examples diff --git a/src/branchandbound.jl b/src/branchandbound.jl index 5baf54fd..363bedb9 100644 --- a/src/branchandbound.jl +++ b/src/branchandbound.jl @@ -13,9 +13,11 @@ end function _branch_bound(bab::BranchAndBoundEnclosure, f::Function, X::Interval_or_IntervalBox, df; initial=emptyinterval(first(X)), cnt=1) - dfX = df(X) - range_extrema, flag = _monotonicity_check(f, X, dfX) - flag && return hull(range_extrema, initial) + if !isnothing(df) + dfX = df(X) + range_extrema, flag = _monotonicity_check(f, X, dfX) + flag && return hull(range_extrema, initial) + end fX = f(X) # TODO: allow user to choose how to evaluate this (mean value, natural enclosure) # if tolerance or maximum number of iteration is met, return current enclosure diff --git a/test/univariate.jl b/test/univariate.jl index 9ab07ef2..db49c6c0 100644 --- a/test/univariate.jl +++ b/test/univariate.jl @@ -72,4 +72,8 @@ end x = enclose(f, dom, BranchAndBoundEnclosure()) rleft, rright = relative_precision(x, xref) @test rleft ≈ 0 && 2.04e-14 ≤ rright ≤ 2.05e-14 + + x = enclose(f, dom, BranchAndBoundEnclosure(), df=nothing) + rleft, rright = relative_precision(x, xref) + @test rleft ≈ 0 && 2.04e-14 ≤ rright ≤ 2.05e-14 end