Skip to content

Commit d0453d8

Browse files
authored
More beautiful display of :unknown (#247)
* Change display in :compact IOContext * Use fancy connectors to group the information * Fix doctests
1 parent 133fb66 commit d0453d8

4 files changed

Lines changed: 20 additions & 9 deletions

File tree

docs/src/index.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ julia> using IntervalArithmetic, IntervalArithmetic.Symbols, IntervalRootFinding
2929
julia> rts = roots(x -> x^2 - 2x, 0..10)
3030
2-element Vector{Root{Interval{Float64}}}:
3131
Root([0.0, 3.73951e-8]_com_NG, :unknown)
32+
└ Not converged: region size smaller than the tolerance
3233
Root([1.99999, 2.00001]_com_NG, :unique)
3334
```
3435

@@ -71,7 +72,9 @@ julia> roots(g, -10..10)
7172
4-element Vector{Root{Interval{Float64}}}:
7273
Root([-1.73206, -1.73205]_com_NG, :unique)
7374
Root([-1.41422, -1.41421]_com_NG, :unknown)
75+
└ Not converged: region size smaller than the tolerance
7476
Root([1.41421, 1.41422]_com_NG, :unknown)
77+
└ Not converged: region size smaller than the tolerance
7578
Root([1.73205, 1.73206]_com_NG, :unique)
7679
```
7780

docs/src/internals.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,10 +100,15 @@ SearchState{BreadthFirst{Root{Interval{Float64}}}, Root{Interval{Float64}}}
100100
iteration: 15
101101
5 regions being processed
102102
Root([-0.078125, 1.15235]_com, :unknown)
103+
└ Not converged: the root is still being processed
103104
Root([-3.84735, -2.5975]_com, :unknown)
105+
└ Not converged: the root is still being processed
104106
Root([-5.07782, -3.84734]_com, :unknown)
107+
└ Not converged: the root is still being processed
105108
Root([-8.78861, -7.55813]_com, :unknown)
109+
└ Not converged: the root is still being processed
106110
Root([-10.0, -8.7886]_com, :unknown)
111+
└ Not converged: the root is still being processed
107112
1 finalized regions
108113
Root([-6.28132, -6.28131]_com, :unique)
109114

docs/src/roots.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ julia> roots(log, -2..2 ; contractor = Krawczyk)
2828
julia> roots(log, -2..2 ; contractor = Bisection)
2929
1-element Vector{Root{Interval{Float64}}}:
3030
Root([0.999999, 1.00001]_com, :unknown)
31+
└ Not converged: region size smaller than the tolerance
3132
```
3233

3334
Note that as shown in the example, the `log` function does not complain about being given an interval going outside its domain. While this may be surprising, this is the expected behavior and no root will ever be found outside the domain of a function.
@@ -168,6 +169,9 @@ julia> roots(f, -10 .. 10)
168169
3-element Vector{Root{Interval{Float64}}}:
169170
Root([0.0, 0.0]_com, :unique)
170171
Root([1.99999, 2.00001]_com, :unknown)
172+
├ Not converged: region size smaller than the tolerance
173+
├ Warning: error encountered during computation (use showerror(root.error) to see the whole stacktrace)
174+
└ InconclusiveBooleanOperation: The operation `[2.0, 2.0]_com_NG < [1.99999, 2.00001]_com` cannot be determined unambiguously. See the documentation for more information. See also `strictprecedes`.
171175
Root([7.0, 7.0]_com_NG, :unique)
172176
```
173177

src/root_object.jl

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -57,23 +57,22 @@ isunique(rt::Root{T}) where {T} = (rt.status == :unique)
5757

5858
function show(io::IO, rt::Root)
5959
print(io, "Root($(rt.region), :$(rt.status))")
60-
end
6160

62-
function show(io::IO, ::MIME"text/plain", rt::Root)
63-
show(io, rt)
64-
if rt.status == :unknown
61+
if !get(io, :compact, false) && rt.status == :unknown
62+
connector = isnothing(rt.error) ? "" : ""
63+
6564
if rt.convergence == :tolerance
66-
print(io, "\n Not converged: region size smaller than the tolerance")
65+
print(io, "\n $connector Not converged: region size smaller than the tolerance")
6766
elseif rt.convergence == :max_iterartion
68-
print(io, "\n Not converged: reached maximal number of iterations")
67+
print(io, "\n $connector Not converged: reached maximal number of iterations")
6968
elseif rt.convergence == :none
70-
print(io, "\n Not converged: the root is still being processed")
69+
print(io, "\n $connector Not converged: the root is still being processed")
7170
else
72-
print(io, "\n Not converged: unknown reason $(rt.convergence)")
71+
print(io, "\n $connector Not converged: unknown reason $(rt.convergence)")
7372
end
7473

7574
if !isnothing(rt.error)
76-
print(io, "\n Warning: error encountered during computation (use showerror(root.error) to see the whole stacktrace)\n ")
75+
print(io, "\n Warning: error encountered during computation (use showerror(root.error) to see the whole stacktrace)\n ")
7776
showerror(io, rt.error[1])
7877
end
7978
end

0 commit comments

Comments
 (0)