From abad863f966e9e67cb7afb0026f044472a2f4c71 Mon Sep 17 00:00:00 2001 From: ParadaCarleton <71727937+ParadaCarleton@users.noreply.github.com> Date: Tue, 27 Oct 2026 08:18:29 -0700 Subject: [PATCH] BackTracking: negate the quadratic minimizer when the cubic coefficient vanishes --- src/backtracking.jl | 2 +- test/root_finding_tests.jl | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/backtracking.jl b/src/backtracking.jl index fff1440..b347c4c 100644 --- a/src/backtracking.jl +++ b/src/backtracking.jl @@ -146,7 +146,7 @@ end a = (a₁ - a₂) * div b = (-α₁ * a₁ + α₂ * a₂) * div - return ifelse(iszero(a), dϕ₀ / 2b, (-b + sqrt(max(b^2 - 3a * dϕ₀, T(0)))) / 3a) + return ifelse(iszero(a), -dϕ₀ / 2b, (-b + sqrt(max(b^2 - 3a * dϕ₀, T(0)))) / 3a) end function SciMLBase.reinit!( diff --git a/test/root_finding_tests.jl b/test/root_finding_tests.jl index eb20230..5ecc1ac 100644 --- a/test/root_finding_tests.jl +++ b/test/root_finding_tests.jl @@ -210,6 +210,11 @@ end end end +@testset "BackTracking cubic step on a quadratic merit" begin + # ϕ(α) = (1 - α)², sampled at α = 1 and 1/2: the cubic coefficient vanishes and the minimizer is α = 1. + @test LineSearch.compute_alpha_backtracking(Val(3), Float64, -2.0, 1.0, 0.0, 0.25, 1.0, 0.5) == 1.0 +end + @testset "Static Strong Wolfe residual mode" begin using CommonSolve: init, solve! using SciMLBase: NonlinearProblem, ReturnCode