Skip to content

HagerZhang: do not evaluate a secant point that is not strictly inside the bracket - #213

Merged
pkofod merged 2 commits into
JuliaNLSolvers:masterfrom
andreasnoack:hz-secant-endpoint
Sep 14, 2026
Merged

pkofod merged 2 commits into
JuliaNLSolvers:masterfrom
andreasnoack:hz-secant-endpoint

Conversation

@andreasnoack

Copy link
Copy Markdown
Contributor

HagerZhang: do not evaluate a secant point that is not strictly inside the bracket

Follow-up to #211 / #212.

The problem

secant2! computes the secant root c and calls ϕdϕ(c) before checking where c landed. Only afterwards does update! classify it, and since #212 it rejects a c that is not strictly interior. So a secant root that rounds onto an endpoint costs a full objective evaluation whose result is thrown away.

The root lands on an endpoint in two ordinary situations: the bracket is a few ulps wide, or one slope is negligible against the other, so (a * dphi_b - b * dphi_a) / (dphi_b - dphi_a) rounds to a or b. The value and slope at both endpoints are already stored, so there is nothing to learn from evaluating there.

This is also the evaluation that exposed #211. With a == 0, the wasted call re-evaluates the objective at x + 0 * s == x, and if the slope it returns differs from the stored dphi_0 by rounding, it can differ in sign once the true slope is at the noise floor. #212 made update! robust to that; this PR removes the evaluation that produced the disagreement in the first place. With it, nothing in HagerZhang ever re-evaluates the objective at alpha = 0, so the route by which the caller computed dphi_0 cannot matter to the line search.

The change

The trajectory of a line search that never produces an endpoint root is unchanged. When one is produced, the bisection midpoint replaces the discarded endpoint evaluation, so the evaluation count does not increase.

Test

A new testset in test/errors.jl builds a bracket [1.0, nextfloat(1.0, 2)] with slopes chosen so the secant root rounds exactly onto a in one case and onto b in the other, checks that it does, then calls secant2! with a recording ϕdϕ and asserts every evaluation is strictly interior. On master both cases fail (the endpoint is evaluated); on this branch they pass.

Related

The same measurement that motivated JuliaNLSolvers/Optim.jl#1284 shows the two slope routes differ at the level of the objective's own derivative noise (it tracks the ODE solver tolerance of that objective one for one), so re-evaluating at an endpoint could never have given a more trustworthy slope than the stored one. JuliaNLSolvers/Optim.jl#1286 reverts #1285 on that basis.

…e the bracket

`secant2!` evaluated `ϕdϕ(c)` at the secant root before checking where it landed. The
root is not finite when the two slopes coincide, which was already handled by bisecting,
and it rounds onto an endpoint when the bracket is a few ulps wide or one slope is
negligible against the other. The value and slope at an endpoint are already stored, so
that evaluation is a wasted objective call, and `update!` (since JuliaNLSolvers#212) discards its
result anyway. It is also the evaluation that exposed JuliaNLSolvers#211: a fresh slope at alpha = 0
that disagreed in sign with the stored `dphi_0`.

Treat a non-interior secant root like a non-finite one and bisect instead, and require
the second secant point to be strictly interior as well.
Comment thread src/hagerzhang.jl Resolved
@pkofod
pkofod merged commit 5e26277 into JuliaNLSolvers:master Sep 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants