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

Simple example runs forever? #134

Closed caseykneale closed 4 years ago

caseykneale commented 4 years ago

Sorry this is a repost from a different repository. Was trying this package out and found a weird simple case that appears to run forever?

using IntervalRootFinding, IntervalArithmetic, StaticArrays
line1( x ) = 2.0 * (x^2.0)
line2( x ) = 4.0*x - 2.0
fun(x) = line1(x) - line2(x)
@time rts = roots(fun, Interval( -10..10 ) )

Am I missing something? Why does this happen?

dpsanders commented 4 years ago

There is something strange happening here. Adding a small tolerance gives a result:

julia> @time rts = roots(fun, Interval( -10..10 ), 1e-8)
  0.001795 seconds (24.34 k allocations: 997.430 KiB)
7-element Array{Root{Interval{Float64}},1}:
 Root([1, 1.00001], :unknown)
 Root([1, 1.00001], :unknown)
 Root([1, 1.00001], :unknown)
 Root([0.999999, 1.00001], :unknown)
 Root([0.999999, 1], :unknown)
 Root([0.999999, 1], :unknown)
 Root([0.999999, 1], :unknown)

but without the tolerance it does seem to hang.

dpsanders commented 4 years ago

BTW, note that -10..10 already makes an interval -- you don't need Interval as well.

dpsanders commented 4 years ago

The default tolerance is far too low.

dpsanders commented 4 years ago

The fact that it is reporting several boxes with apparently the same interval (although this is just due to the default output precision, which can be changed with @format) is exactly due to the face that the function has a double root, which interval methods are not able to prove.

Kolaru commented 4 years ago

I think this works as expected, the number of intervals around 1 with undecidable status that you can build with 1e-15 tolerance is simply too high, thus decreasing the tolerance seems to be the correct fix.

We should maybe use relative tolerance by default to get a more consistent behavior.

caseykneale commented 4 years ago

Thanks!