Skip to content

Commit beb47c1

Browse files
authored
Refactor and cleanup. Removes NewtonContractor (#55)
* Add interval and status functions for roots * Bisect by default not exactly in centre * Use broadcast for contains_zero * Move contractors to contractors.jl * Rename N -> 𝒩 * WIP refactor to remove NewtonContractor * Refactoring to pass through tolerance. All except complex working * Fix complex root finding * bisect_place -> where_bisect * Fix tests * Changes from review * More fixes * Force bisection of infinite intervals in Newton * Add tests with infinite intervals * Remove old tests for the moment * Split out Root object into new file, cleanup * Fix failing Newton1D test * Add missing source file
1 parent 14d97bf commit beb47c1

13 files changed

+359
-376
lines changed

src/IntervalRootFinding.jl

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ using IntervalArithmetic
88
using ForwardDiff
99
using StaticArrays
1010

11+
12+
import Base: , show, big
13+
1114
import Polynomials: roots
1215

1316
## Root finding
@@ -17,26 +20,15 @@ export
1720
roots, find_roots,
1821
bisect, newton1d
1922

20-
import Base: , show
21-
22-
const Interval = IntervalArithmetic.Interval
23+
export isunique, root_status
2324

24-
const derivative = ForwardDiff.derivative
25-
const D = derivative
2625

27-
# Root object:
28-
immutable Root{T}
29-
interval::T
30-
status::Symbol
31-
end
26+
import IntervalArithmetic.interval
3227

33-
show(io::IO, root::Root) = print(io, "Root($(root.interval), :$(root.status))")
3428

35-
is_unique{T}(root::Root{T}) = root.status == :unique
36-
37-
(a::Interval, b::Root) = a b.interval # the Root object has the interval in the first entry
38-
(a::Root, b::Root) = a.interval b.interval
3929

30+
const derivative = ForwardDiff.derivative
31+
const D = derivative
4032

4133
# Common functionality:
4234

@@ -56,12 +48,15 @@ function guarded_mid{T}(f::Function, x::Interval{T})
5648
end
5749

5850

51+
include("root_object.jl")
5952
include("bisect.jl")
60-
include("bisection.jl")
53+
6154
include("newton.jl")
6255
include("krawczyk.jl")
56+
6357
include("complex.jl")
64-
include("branch_and_prune.jl")
58+
include("contractors.jl")
59+
include("roots.jl")
6560
include("newton1d.jl")
6661

6762

src/bisect.jl

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11

2+
const where_bisect = 0.49609375
3+
24
doc"""
35
bisect(X::Interval, α=0.5)
46
57
Split the interval `X` at position α; α=0.5 corresponds to the midpoint.
68
Returns a tuple of the new intervals.
79
"""
8-
function bisect(X::Interval, α=0.5)
10+
function bisect(X::Interval, α=where_bisect)
911
@assert 0 α 1
1012

1113
m = mid(X, α)
@@ -18,7 +20,7 @@ doc"""
1820
1921
Bisect the `IntervalBox` `X` at position α ∈ [0,1] along its longest side.
2022
"""
21-
function bisect(X::IntervalBox, α=0.5)
23+
function bisect(X::IntervalBox, α=where_bisect)
2224
i = indmax(diam.(X)) # find longest side
2325

2426
return bisect(X, i, α)
@@ -29,7 +31,7 @@ doc"""
2931
3032
Bisect the `IntervalBox` in side number `i`.
3133
"""
32-
function bisect(X::IntervalBox, i::Integer, α=0.5)
34+
function bisect(X::IntervalBox, i::Integer, α=where_bisect)
3335

3436
x1, x2 = bisect(X[i], α)
3537

src/bisection.jl

Lines changed: 0 additions & 40 deletions
This file was deleted.

src/branch_and_prune.jl

Lines changed: 0 additions & 223 deletions
This file was deleted.

0 commit comments

Comments
 (0)