Skip to content

Commit

Permalink
add separate assess method; add docs on AlefeldPotra methods (#459)
Browse files Browse the repository at this point in the history
* add separate assess method; add docs on AlefeldPotra methods

* version bump
  • Loading branch information
jverzani authored Jan 10, 2025
1 parent 5cce567 commit 65b481f
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name = "Roots"
uuid = "f2b01f46-fcfa-551c-844a-d8ac1e96c665"
version = "2.2.3"
version = "2.2.4"

[deps]
Accessors = "7d9f7c33-5ae7-4f3b-8dc6-eff91059b697"
Expand Down
3 changes: 3 additions & 0 deletions src/Bracketing/alefeld_potra_shi.jl
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ An abstract type for Alefeld-Potra-Shi type bracketing problems, as discussed in
The `update_step` method calls a `calculateΔ` method that can be customized to turn an algorithm based on interpolation into a bracketed algorithm. See [`Roots.BracketedHalley`](@ref) for an example.
This implementation deviates slightly from the printed algorithm, as it may use an initial call to `_middle` rather than a secant step, depending on the signs of ``a`` and ``b``.
!!! note
These algorithms do not check the size of `f` for convergence, so the `atol` or `rtol` are not utilized.
"""
=#
abstract type AbstractAlefeldPotraShi <: AbstractBracketingMethod end
Expand Down
11 changes: 11 additions & 0 deletions src/convergence.jl
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,17 @@ function assess_convergence(M::Any, state::AbstractUnivariateZeroState, options)
return (:not_converged, false)
end

function assess_convergence(M::AbstractBisection, state::AbstractUnivariateZeroState, options::O) where {O <: Union{ExactOptions, XExactOptions}}
# return convergence_flag, boolean
# no check if f == ∞
is_exact_zero_f(M, state, options) && return (:exact_zero, true)
isnan_f(M, state) && return (:nan, true)
is_approx_zero_f(M, state, options) && return (:f_converged, true)
iszero_Δx(M, state, options) && return (:x_converged, true)
return (:not_converged, false)
end


# speeds up exact f values by just a bit (2% or so) over the above, so guess this is worth it.
function assess_convergence(
M::AbstractBracketingMethod,
Expand Down
10 changes: 10 additions & 0 deletions test/test_find_zero.jl
Original file line number Diff line number Diff line change
Expand Up @@ -583,3 +583,13 @@ end
@test ForwardDiff.gradient(H, [1.0, 2])[1] -0.4416107917053284
end
end

@testset "bracketing_atol" begin
## issue $457
f(x) = x^2 - 4
@test find_zero(f, (0,Inf)) 2 # 2.0 correct
@test find_zero(f, (0,Inf), atol=1) 1.9997558593749998
@test find_zero(f, (0,Inf),atol=1e-5) 1.9999998807907102
@test find_zero(f, (0,8), atol=1) 1.99609375
@test find_zero(f, (0,8), atol=1e-3) 2.0000152587890625
end

2 comments on commit 65b481f

@jverzani
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/122767

Tip: Release Notes

Did you know you can add release notes too? Just add markdown formatted text underneath the comment after the text
"Release notes:" and it will be added to the registry PR, and if TagBot is installed it will also be added to the
release that TagBot creates. i.e.

@JuliaRegistrator register

Release notes:

## Breaking changes

- blah

To add them here just re-invoke and the PR will be updated.

Tagging

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v2.2.4 -m "<description of version>" 65b481f358edfab8652bf671da3a96fd12f18e27
git push origin v2.2.4

Please sign in to comment.