JuliaIntervals / IntervalRootFinding.jl

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

`tan` tangent function missing roots #196

Open PeterARBork opened 4 months ago

PeterARBork commented 4 months ago

I expected roots to find all the roots of the tangent function in the simple case below, but it doesn't. The roots should be $n \pi$ with $n$ an integer.

roots(tan, 0..10)

1-element Vector{Root{Interval{Float64}}}:
 Root([6.28318, 6.28319], :unique)

find_zeros finds too many

find_zeros(tan, [0, 10])

7-element Vector{Float64}:
 0.0
 1.5707963267948966
 3.141592653589793
 4.71238898038469
 6.283185307179586
 7.853981633974483
 9.42477796076938

Am I missing something?

Kolaru commented 4 months ago

Yep that's a bug. It is probably due to an assumption that fails because tan is not continuous (and diverges).

The branch IA_v0.22 (work in progress to update to the latest IntervalArithmetic which is more careful with those cases), has the correct behavior:

julia> roots(tan, interval(-1, 10))
7-element Vector{Root{Interval{Float64}}}:
 Root(Interval{Float64}(-5.9220971777070724e-8, 4.47088230066256e-9, com, NG), :unique)
 Root(Interval{Float64}(1.570796246929277, 1.5707963269211673, com), :unknown)
 Root(Interval{Float64}(3.141592653589474, 3.141592653589817, com, NG), :unique)
 Root(Interval{Float64}(4.712388946492333, 4.712389022821055, com), :unknown)
 Root(Interval{Float64}(6.283185307098206, 6.28318530826717, com, NG), :unique)
 Root(Interval{Float64}(7.85398162069253, 7.853981705843563, com), :unknown)
 Root(Interval{Float64}(9.42477796076779, 9.424777960769498, com, NG), :unique)

There are extra roots because there is no way currently to prove that there is no zero at the singularities.