From b446799aae494be88af16cde3a12a82c2b185408 Mon Sep 17 00:00:00 2001 From: Luis Benet Date: Tue, 23 Jun 2026 15:56:46 -0600 Subject: [PATCH 1/4] Use ` .. ` (with spaces) --- docs/src/roots.md | 28 ++++++++++++++-------------- examples/roots.jl | 12 ++++++------ test/linear_eq.jl | 6 +++--- 3 files changed, 23 insertions(+), 23 deletions(-) diff --git a/docs/src/roots.md b/docs/src/roots.md index 12b1b94..c7e445c 100644 --- a/docs/src/roots.md +++ b/docs/src/roots.md @@ -17,15 +17,15 @@ Both the Newton and Krawczyk methods can determine if a root is unique in an int The method used is given using the `contractor` keyword argument: ```jldoctest -julia> roots(log, -2..2 ; contractor = Newton) +julia> roots(log, -2 .. 2 ; contractor = Newton) 1-element Vector{Root{Interval{Float64}}}: Root([0.999999, 1.00001]_com, :unique) -julia> roots(log, -2..2 ; contractor = Krawczyk) +julia> roots(log, -2 .. 2 ; contractor = Krawczyk) 1-element Vector{Root{Interval{Float64}}}: Root([0.999999, 1.00001]_com, :unique) -julia> roots(log, -2..2 ; contractor = Bisection) +julia> roots(log, -2 .. 2 ; contractor = Bisection) 1-element Vector{Root{Interval{Float64}}}: Root([0.999999, 1.00001]_com, :unknown) ``` @@ -37,11 +37,11 @@ Note that as shown in the example, the `log` function does not complain about be Newton and Krawczyk methods require the function to be differentiable, but the derivative is usually computed automatically using forward-mode automatic differentiation, provided by the `ForwardDiff.jl` package. It is however possible to provide the derivative explicitly using the `derivative` keyword argument: ```jldoctest -julia> roots(log, -2..2 ; contractor = Newton, derivative = x -> 1/x) +julia> roots(log, -2 .. 2 ; contractor = Newton, derivative = x -> 1/x) 1-element Vector{Root{Interval{Float64}}}: Root([0.999999, 1.00001]_com_NG, :unique) -julia> roots(log, -2..2 ; contractor = Krawczyk, derivative = x -> 1/x) +julia> roots(log, -2 .. 2 ; contractor = Krawczyk, derivative = x -> 1/x) 1-element Vector{Root{Interval{Float64}}}: Root([0.999999, 1.00001]_com_NG, :unique) ``` @@ -51,12 +51,12 @@ When providing the derivative explicitly, the computation is expected to be slig ```julia-repl julia> using BenchmarkTools -julia> @btime roots(log, -2..2 ; derivative = x -> 1/x) +julia> @btime roots(log, -2 .. 2 ; derivative = x -> 1/x) 7.050 μs (129 allocations: 9.33 KiB) 1-element Vector{Root{Interval{Float64}}}: Root([1.0, 1.0]_com_NG, :unique) -julia> @btime roots(log, -2..2) +julia> @btime roots(log, -2 .. 2) 7.743 μs (129 allocations: 9.33 KiB) 1-element Vector{Root{Interval{Float64}}}: Root([1.0, 1.0]_com, :unique) @@ -73,7 +73,7 @@ f (generic function with 1 method) julia> df( (x, y) ) = [cos(x) 0 ; 0 -sin(y)] df (generic function with 1 method) -julia> roots(f, [-3..3, -3..3] ; derivative = df) +julia> roots(f, [-3 .. 3, -3 .. 3] ; derivative = df) 2-element Vector{Root{Vector{Interval{Float64}}}}: Root(Interval{Float64}[[-3.93242e-20, 3.93242e-20]_com_NG, [-1.5708, -1.57079]_com_NG], :unique) Root(Interval{Float64}[[-3.93242e-20, 3.93242e-20]_com_NG, [1.57079, 1.5708]_com_NG], :unique) @@ -87,12 +87,12 @@ An absolute tolerance for the search may be specified as the `abstol` keyword ar julia> g(x) = sin(exp(x)) g (generic function with 1 method) -julia> roots(g, 0..2) +julia> roots(g, 0 .. 2) 2-element Vector{Root{Interval{Float64}}}: Root([1.14472, 1.14473]_com, :unique) Root([1.83787, 1.83788]_com, :unique) -julia> roots(g, 0..2 ; abstol = 1e-1) +julia> roots(g, 0 .. 2 ; abstol = 1e-1) 2-element Vector{Root{Interval{Float64}}}: Root([1.12049, 1.16994]_com, :unique) Root([1.82369, 1.85206]_com, :unique) @@ -104,7 +104,7 @@ A lower tolerance may greatly reduce the computation time, at the cost of an inc julia> h(x) = cos(x) * sin(1 / x) h (generic function with 1 method) -julia> @btime roots(h, 0.05..1) +julia> @btime roots(h, 0.05 .. 1) 484.488 μs (12218 allocations: 590.76 KiB) 6-element Vector{Root{Interval{Float64}}}: Root([0.0530516, 0.0530517]_com_NG, :unique) @@ -114,7 +114,7 @@ julia> @btime roots(h, 0.05..1) Root([0.159155, 0.159155]_com_NG, :unique) Root([0.31831, 0.31831]_com_NG, :unique) -julia> @btime roots(h, 0.05..1 ; abstol = 1e-2) +julia> @btime roots(h, 0.05 .. 1 ; abstol = 1e-2) 249.720 μs (6141 allocations: 297.80 KiB) 6-element Vector{Root{Interval{Float64}}}: Root([0.0514446, 0.0531086]_com_NG, :unique) @@ -128,7 +128,7 @@ julia> @btime roots(h, 0.05..1 ; abstol = 1e-2) Not converged: region size smaller than the tolerance Root([0.317161, 0.319318]_com_NG, :unique) -julia> @btime roots(h, 0.05..1 ; abstol = 1e-1) +julia> @btime roots(h, 0.05 .. 1 ; abstol = 1e-1) 66.330 μs (1402 allocations: 69.10 KiB) 3-element Vector{Root{Interval{Float64}}}: Root([0.05, 0.107541]_com, :unknown) @@ -178,7 +178,7 @@ so that the process is interrupted as soon as an error is encountered. This is useful while debugging your code. ```julia-repl -julia> roots(f, -10..10, ; ignored_errors = []) +julia> roots(f, -10 .. 10, ; ignored_errors = []) ERROR: InconclusiveBooleanOperation: The operation `[2.0, 2.0]_com_NG < [-10.0, 10.0]_com` cannot be determined unambiguously. See the documentation for more information. See also `strictprecedes`. Stacktrace: [..] ``` \ No newline at end of file diff --git a/examples/roots.jl b/examples/roots.jl index efad1ab..5027d33 100644 --- a/examples/roots.jl +++ b/examples/roots.jl @@ -3,8 +3,8 @@ using IntervalArithmetic.Symbols using IntervalRootFinding # Find roots of a function in a search region with defaul parameters -rts = roots(sin, -5..5) -rts = roots(sin, -5..6 ; contractor = Bisection, abstol = 1e-1) +rts = roots(sin, -5 .. 5) +rts = roots(sin, -5 .. 6 ; contractor = Bisection, abstol = 1e-1) # Refine roots with different options rts = vcat(roots.(sin, rts ; contractor = Krawczyk)...) @@ -13,12 +13,12 @@ rts = vcat(roots.(sin, rts ; contractor = Krawczyk)...) f(x, y) = [x^2 + y^2 - 1, y - x] f(X) = f(X...) # Function must take a single vector as input -rts = roots(f, [-5..5, -5..5]) +rts = roots(f, [-5 .. 5, -5 .. 5]) # When defining function mixing numbers and intervals use @exact to avoid the NG interval flag @exact fe(x, y) = [x^2 + y^2 - 1, y - x] fe(X) = fe(X...) # Function must take a single vector as input -rts = roots(fe, [-5..5, -5..5]) +rts = roots(fe, [-5 .. 5, -5 .. 5]) # From R docs: @@ -34,7 +34,7 @@ function g(x) ) end -X = (-5..5) +X = (-5 .. 5) rts = roots(g, SVector(X, X, X)) h(xv) = ((x,y) = xv; SVector(2*x - y - exp(-x), -x + 2*y - exp(-y))) @@ -53,7 +53,7 @@ rts = roots(h, SVector(X, X)) ## MINPACK benchmarks: https://github.com/JuliaNLSolvers/NLsolve.jl/blob/master/test/minpack.jl rosenbrock(xx) = ( (x, y) = xx; SVector( 1 - x, 1000 * (y - x^2) ) ) -X = SVector(-1e5..1e5, -1e5..1e5) +X = SVector(-1e5 .. 1e5, -1e5 .. 1e5) rts = roots(rosenbrock, X) diff --git a/test/linear_eq.jl b/test/linear_eq.jl index c1f96c8..02714ab 100644 --- a/test/linear_eq.jl +++ b/test/linear_eq.jl @@ -19,9 +19,9 @@ end @testset "Linear Equations" begin - As = [[2..3 0..1; 1..2 2..3], ] - bs = [[0..120, 60..240], ] - xs = [[-120..90, -60..240], ] + As = [[2 .. 3 0 .. 1; 1 .. 2 2 .. 3], ] + bs = [[0 .. 120, 60 .. 240], ] + xs = [[-120 .. 90, -60 .. 240], ] for i in 1:10 rand_A = rand_mat(i)[1] From ec1cff6c0900db45f4cdd4b4fa1ab0da5e8374a8 Mon Sep 17 00:00:00 2001 From: Luis Benet Date: Tue, 23 Jun 2026 18:09:52 -0600 Subject: [PATCH 2/4] Fix one forgotten instance --- src/linear_eq.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/linear_eq.jl b/src/linear_eq.jl index 5a69ce7..346af4c 100644 --- a/src/linear_eq.jl +++ b/src/linear_eq.jl @@ -178,7 +178,7 @@ end function gauss_elimination_interval1(A::AbstractMatrix, b::AbstractArray; precondition=true) n = size(A, 1) - x = fill(-1e16..1e16, n) + x = fill(-1e16 .. 1e16, n) x = gauss_elimination_interval1!(x, A, b, precondition=precondition) From 354e90c0ea177656c4e9653837118c70a54fa3e6 Mon Sep 17 00:00:00 2001 From: Luis Benet Date: Tue, 23 Jun 2026 18:12:14 -0600 Subject: [PATCH 3/4] More minor fixes --- README.md | 2 +- docs/src/index.md | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 15eb491..1491f27 100644 --- a/README.md +++ b/README.md @@ -36,7 +36,7 @@ julia> using IntervalArithmetic.Symbols # to use `..` julia> f(x) = sin(x) - 0.1*x^2 + 1 f (generic function with 1 method) -julia> roots(f, -10..10) +julia> roots(f, -10 .. 10) 4-element Vector{Root{Interval{Float64}}}: Root([-4.42654, -4.42653]_com_NG, :unique) Root([-3.10682, -3.10681]_com_NG, :unique) diff --git a/docs/src/index.md b/docs/src/index.md index 61669de..feb317c 100644 --- a/docs/src/index.md +++ b/docs/src/index.md @@ -17,7 +17,7 @@ To do so, it uses methods from interval analysis, using interval arithmetic from To begin, we need a standard Julia function and an interval in which to search roots of that function. Intervals use the `Interval` type provided by the `IntervalArithmetic.jl` package Intervals are generally constructed using the `..` syntax (from the `IntervalArithmetic.Symbols` submodule), -`a..b` representing the closed interval $[a, b]$. +`a .. b` representing the closed interval $[a, b]$. When provided with this information, the `roots` function will return a vector of all roots of the function in the given interval. @@ -26,7 +26,7 @@ Example: ```jldoctest julia> using IntervalArithmetic, IntervalArithmetic.Symbols, IntervalRootFinding -julia> rts = roots(x -> x^2 - 2x, 0..10) +julia> rts = roots(x -> x^2 - 2x, 0 .. 10) 2-element Vector{Root{Interval{Float64}}}: Root([0.0, 3.73951e-8]_com_NG, :unknown) Root([1.99999, 2.00001]_com_NG, :unique) @@ -67,7 +67,7 @@ For example: julia> g(x) = (x^2 - 2)^2 * (x^2 - 3) g (generic function with 1 method) -julia> roots(g, -10..10) +julia> roots(g, -10 .. 10) 4-element Vector{Root{Interval{Float64}}}: Root([-1.73206, -1.73205]_com_NG, :unique) Root([-1.41422, -1.41421]_com_NG, :unknown) @@ -96,7 +96,7 @@ julia> function g( (x1, x2, x3) ) end g (generic function with 1 method) -julia> X = -5..5 +julia> X = -5 .. 5 [-5.0, 5.0]_com julia> rts = roots(g, [X, X, X]) @@ -117,7 +117,7 @@ julia> using StaticArrays julia> h((x, y)) = SVector(x^2 - 4, y^2 - 16) h (generic function with 1 method) -julia> X = -5..5 +julia> X = -5 .. 5 [-5.0, 5.0]_com julia> roots(h, SVector(X, X)) From a0b1d05e39312b7371ae155df6e5d6871df681c0 Mon Sep 17 00:00:00 2001 From: Luis Benet Date: Tue, 23 Jun 2026 18:16:48 -0600 Subject: [PATCH 4/4] Bump patch version --- Project.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Project.toml b/Project.toml index f7d474e..898282c 100644 --- a/Project.toml +++ b/Project.toml @@ -1,6 +1,6 @@ name = "IntervalRootFinding" uuid = "d2bf35a9-74e0-55ec-b149-d360ff49b807" -version = "0.7.1" +version = "0.7.2" [deps] BranchAndPrune = "d3bc4f2e-91e6-11e9-365e-cd067da536ce"