Golden-section search
View on Wikipedia
This article includes a list of references, related reading, or external links, but its sources remain unclear because it lacks inline citations. (June 2024) |
The golden-section search is a technique for finding an extremum (minimum or maximum) of a function inside a specified interval. For a strictly unimodal function with an extremum inside the interval, it will find that extremum, while for an interval containing multiple extrema (possibly including the interval boundaries), it will converge to one of them. If the only extremum on the interval is on a boundary of the interval, it will converge to that boundary point. The method operates by successively narrowing the range of values on the specified interval, which makes it relatively slow, but very robust. The technique derives its name from the fact that the algorithm maintains the function values for four points whose three interval widths are in the ratio φ:1:φ, where φ is the golden ratio. These ratios are maintained for each iteration and are maximally efficient. Excepting boundary points, when searching for a minimum, the central point is always less than or equal to the outer points, assuring that a minimum is contained between the outer points. The converse is true when searching for a maximum. The algorithm is the limit of Fibonacci search (also described below) for many function evaluations. Fibonacci search and golden-section search were discovered by Kiefer (1953) (see also Avriel and Wilde (1966)).
Basic idea
[edit]The discussion here is posed in terms of searching for a minimum (searching for a maximum is similar) of a unimodal function. Unlike finding a zero, where two function evaluations with opposite sign are sufficient to bracket a root, when searching for a minimum, three values are necessary. The golden-section search is an efficient way to progressively reduce the interval locating the minimum. The key is to observe that regardless of how many points have been evaluated, the minimum lies within the interval defined by the two points adjacent to the point with the least value so far evaluated.
The diagram above illustrates a single step in the technique for finding a minimum. The functional values of are on the vertical axis, and the horizontal axis is the x parameter. The value of has already been evaluated at the three points: , , and . Since is smaller than either or , it is clear that a minimum lies inside the interval from to .
The next step in the minimization process is to "probe" the function by evaluating it at a new value of x, namely . It is most efficient to choose somewhere inside the largest interval, i.e. between and . From the diagram, it is clear that if the function yields , then a minimum lies between and , and the new triplet of points will be , , and . However, if the function yields the value , then a minimum lies between and , and the new triplet of points will be , , and . Thus, in either case, we can construct a new narrower search interval that is guaranteed to contain the function's minimum.
Probe point selection
[edit]From the diagram above, it is seen that the new search interval will be either between and with a length of a + c, or between and with a length of b. The golden-section search requires that these intervals be equal. If they are not, a run of "bad luck" could lead to the wider interval being used many times, thus slowing down the rate of convergence. To ensure that b = a + c, the algorithm should choose .
However, there still remains the question of where should be placed in relation to and . The golden-section search chooses the spacing between these points in such a way that these points have the same proportion of spacing as the subsequent triple or . By maintaining the same proportion of spacing throughout the algorithm, we avoid a situation in which is very close to or and guarantee that the interval width shrinks by the same constant proportion in each step.
Mathematically, to ensure that the spacing after evaluating is proportional to the spacing prior to that evaluation, if is and our new triplet of points is , , and , then we want
However, if is and our new triplet of points is , , and , then we want
Eliminating c from these two simultaneous equations yields
or
where φ is the golden ratio:
The appearance of the golden ratio in the proportional spacing of the evaluation points is how this search algorithm gets its name.
Termination condition
[edit]Any number of termination conditions may be applied, depending upon the application. The interval ΔX = X4 − X1 is a measure of the absolute error in the estimation of the minimum X and may be used to terminate the algorithm. The value of ΔX is reduced by a factor of r = φ − 1 for each iteration, so the number of iterations to reach an absolute error of ΔX is about ln(ΔX/ΔX0) / ln(r), where ΔX0 is the initial value of ΔX.
Because smooth functions are flat (their first derivative is close to zero) near a minimum, attention must be paid not to expect too great an accuracy in locating the minimum. The termination condition provided in the book Numerical Recipes in C is based on testing the gaps among , , and , terminating when within the relative accuracy bounds
where is a tolerance parameter of the algorithm, and is the absolute value of . The check is based on the bracket size relative to its central value, because that relative error in is approximately proportional to the squared absolute error in in typical cases. For that same reason, the Numerical Recipes text recommends that , where is the required absolute precision of .
Algorithm
[edit]Note! The examples here describe an algorithm that is for finding the minimum of a function. For maximum, the comparison operators need to be reversed.
Iterative algorithm
[edit]
- Specify the function to be minimized, , the interval to be searched as {X1,X4}, and their functional values F1 and F4.
- Calculate an interior point and its functional value F2. The two interval lengths are in the ratio c : r or r : c where r = φ − 1; and c = 1 − r, with φ being the golden ratio.
- Using the triplet, determine if convergence criteria are fulfilled. If they are, estimate the X at the minimum from that triplet and return.
- From the triplet, calculate the other interior point and its functional value. The three intervals will be in the ratio .
- The three points for the next iteration will be the one where F is a minimum, and the two points closest to it in X.
- Go to step 3.
"""
Python program for golden section search. This implementation
does not reuse function evaluations and assumes the minimum is c
or d (not on the edges at a or b)
"""
import math
invphi = (math.sqrt(5) - 1) / 2 # 1 / phi
def gss(f, a, b, tolerance=1e-5):
"""
Golden-section search
to find the minimum of f on [a,b]
* f: a strictly unimodal function on [a,b]
Example:
>>> def f(x): return (x - 2) ** 2
>>> x = gss(f, 1, 5)
>>> print(f"{x:.5f}")
2.00000
"""
while b - a > tolerance:
c = b - (b - a) * invphi
d = a + (b - a) * invphi
if f(c) < f(d):
b = d
else: # f(c) > f(d) to find the maximum
a = c
return (b + a) / 2
// a and c define range to search
// func(x) returns value of function at x to be minimized
function goldenSection(a, c, func) {
function split(x1, x2) { return x1 + 0.6180339887498949*(x2-x1); }
var b = split(a, c);
var bv = func(b);
while (a != c) {
var x = split(a, b);
var xv = func(x);
if (xv < bv) {
bv = xv;
c = b;
b = x;
}
else {
a = c;
c = x;
}
}
return b;
}
function test(x) { return -Math.sin(x); }
console.log(goldenSection(0, 3, test)); // prints PI/2
"""
Python program for golden section search. This implementation
does not reuse function evaluations and assumes the minimum is c
or d (not on the edges at a or b)
"""
import math
invphi = (math.sqrt(5) - 1) / 2 # 1 / phi
invphi2 = (3 - math.sqrt(5)) / 2 # 1 / phi^2
def gss(f, a, b, tolerance=1e-5):
"""
Golden-section search.
Given a function f with a single local minimum in
the interval [a,b], gss returns a subset interval
[c,d] that contains the minimum with d-c <= tolerance.
Example:
>>> def f(x): return (x - 2) ** 2
>>> print(*gss(f, a=1, b=5, tolerance=1e-5))
1.9999959837979107 2.0000050911830893
"""
a, b = min(a, b), max(a, b)
h = b - a
if h <= tolerance:
return (a, b)
# Required steps to achieve tolerance
n = int(math.ceil(math.log(tolerance / h) / math.log(invphi)))
c, d = a + invphi2 * h, a + invphi * h
yc, yd = f(c), f(d)
for _ in range(n - 1):
h *= invphi
if yc < yd:
b, d = d, c
yd = yc
c = a + invphi2 * h
yc = f(c)
else: # yc > yd to find the maximum
a, c = c, d
yc = yd
d = a + invphi * h
yd = f(d)
return (a, d) if yc < yd else (c, b)
Recursive algorithm
[edit]public class GoldenSectionSearch {
public static final double invphi = (Math.sqrt(5.0) - 1) / 2.0;
public static final double invphi2 = (3 - Math.sqrt(5.0)) / 2.0;
public interface Function {
double of(double x);
}
// Returns subinterval of [a,b] containing minimum of f
public static double[] gss(Function f, double a, double b, double tol) {
return gss(f, a, b, tol, b - a, true, 0, 0, true, 0, 0);
}
private static double[] gss(Function f, double a, double b, double tol,
double h, boolean noC, double c, double fc,
boolean noD, double d, double fd) {
if (Math.abs(h) <= tol) {
return new double[] { a, b };
}
if (noC) {
c = a + invphi2 * h;
fc = f.of(c);
}
if (noD) {
d = a + invphi * h;
fd = f.of(d);
}
if (fc < fd) { // fc > fd to find the maximum
return gss(f, a, d, tol, h * invphi, true, 0, 0, false, c, fc);
} else {
return gss(f, c, b, tol, h * invphi, false, d, fd, true, 0, 0);
}
}
public static void main(String[] args) {
Function f = (x)->Math.pow(x-2, 2);
double a = 1;
double b = 5;
double tol = 1e-5;
double [] ans = gss(f, a, b, tol);
System.out.println("[" + ans[0] + "," + ans[1] + "]");
// [1.9999959837979107,2.0000050911830893]
}
}
import math
invphi = (math.sqrt(5) - 1) / 2 # 1 / phi
invphi2 = (3 - math.sqrt(5)) / 2 # 1 / phi^2
def gssrec(f, a, b, tol=1e-5, h=None, c=None, d=None, fc=None, fd=None):
"""Golden-section search, recursive.
Given a function f with a single local minimum in
the interval [a, b], gss returns a subset interval
[c, d] that contains the minimum with d-c <= tol.
Example:
>>> f = lambda x: (x - 2) ** 2
>>> a = 1
>>> b = 5
>>> tol = 1e-5
>>> (c, d) = gssrec(f, a, b, tol)
>>> print (c, d)
1.9999959837979107 2.0000050911830893
"""
(a, b) = (min(a, b), max(a, b))
if h is None:
h = b - a
if h <= tol:
return (a, b)
if c is None:
c = a + invphi2 * h
if d is None:
d = a + invphi * h
if fc is None:
fc = f(c)
if fd is None:
fd = f(d)
if fc < fd: # fc > fd to find the maximum
return gssrec(f, a, d, tol, h * invphi, c=None, fc=None, d=c, fd=fc)
else:
return gssrec(f, c, b, tol, h * invphi, c=d, fc=fd, d=None, fd=None)
Related algorithms
[edit]Fibonacci search
[edit]A very similar algorithm can also be used to find the extremum (minimum or maximum) of a sequence of values that has a single local minimum or local maximum. In order to approximate the probe positions of golden section search while probing only integer sequence indices, the variant of the algorithm for this case typically maintains a bracketing of the solution in which the length of the bracketed interval is a Fibonacci number. For this reason, the sequence variant of golden section search is often called Fibonacci search.
Fibonacci search was first devised by Kiefer (1953) as a minimax search for the maximum (minimum) of a unimodal function in an interval.
Bisection method
[edit]The Bisection method is a similar algorithm for finding a zero of a function. Note that, for bracketing a zero, only two points are needed, rather than three. The interval ratio decreases by 2 in each step, rather than by the golden ratio.
See also
[edit]References
[edit]- Kiefer, J. (1953), "Sequential minimax search for a maximum", Proceedings of the American Mathematical Society, 4 (3): 502–506, doi:10.2307/2032161, JSTOR 2032161, MR 0055639
- Avriel, Mordecai; Wilde, Douglass J. (1966), "Optimality proof for the symmetric Fibonacci search technique", Fibonacci Quarterly, 4 (3): 265–269, doi:10.1080/00150517.1966.12431364, MR 0208812
- Press, WH; Teukolsky, SA; Vetterling, WT; Flannery, BP (2007), "Section 10.2. Golden Section Search in One Dimension", Numerical Recipes: The Art of Scientific Computing (3rd ed.), New York: Cambridge University Press, ISBN 978-0-521-88068-8, archived from the original on 2011-08-11, retrieved 2011-08-12
Golden-section search
View on GrokipediaIntroduction
Definition and Purpose
The golden-section search is a technique for finding the minimum or maximum of a unimodal function over an initial interval without requiring derivatives, relying instead on successive function evaluations to progressively narrow the search interval containing the extremum.[2] This method assumes the function is continuous and unimodal, meaning it possesses a single interior extremum within the interval, with the function values decreasing toward the extremum and increasing afterward.[1] The primary purpose of the golden-section search is to efficiently bracket and converge to the extremum by leveraging the reciprocal of the golden ratio (approximately 0.618)—to divide the interval in a way that minimizes the total number of function evaluations needed for a given precision.[2] It achieves this by reducing the interval length by a constant factor related to the golden ratio at each iteration, ensuring predictable and optimal convergence for one-dimensional optimization problems.[1] At a high level, the process initiates by selecting and evaluating two interior probe points within the initial interval, which is assumed to bracket the extremum, after which each subsequent step eliminates a portion of the interval based on function value comparisons, shrinking the search space to approximately 61.8% of its previous length per iteration.[2] A key advantage is its derivative-free nature, making it particularly robust for optimizing noisy functions or those that are computationally expensive to evaluate, such as in engineering simulations or black-box models where gradient information is unavailable or unreliable.[4]Historical Background
The golden-section search was independently developed by Jack Kiefer in 1953 as part of a broader class of sequential search methods designed for locating extrema of unimodal functions.[5] This technique emerged during a period of growing interest in efficient, derivative-free optimization strategies, particularly for problems where function evaluations were costly.[6] Kiefer's foundational work formalized the approach in his paper "Sequential minimax search for a maximum," published in the Proceedings of the American Mathematical Society, where he demonstrated the optimality of using the golden ratio to place probe points within an interval, minimizing the worst-case interval of uncertainty after each evaluation.[5] The method was later refined by Mordecai Avriel and Douglass J. Wilde in their 1966 paper "Optimal Search for a Maximum with Sequences of Simultaneous Function Evaluations," which extended the framework to handle parallel or sequential evaluations while preserving minimax properties under recurrent costs.[7] The evolution of the golden-section search drew from earlier ideas involving Fibonacci sequences in optimization, such as those implicit in Kiefer's own minimax framework, which approximated golden-ratio divisions through discrete Fibonacci numbers.[5] However, it is distinguished by its reliance on fixed-ratio interval divisions based directly on the golden ratio, allowing consistent efficiency regardless of the total number of iterations, unlike variable-ratio Fibonacci methods that depend on precomputed sequence lengths.[7] Since the 1970s, the golden-section search has been widely adopted in numerical analysis and optimization literature, appearing as a core example in influential textbooks such as R. P. Brent's Algorithms for Minimization without Derivatives (1973), which highlights its reliability for one-dimensional problems.[8] The core algorithm has remained fundamentally unchanged since its inception, though variants and improvements have been developed since 2000, including applications in engineering and computational problems as of 2025.[8][9][4]Assumptions and Prerequisites
The golden-section search method relies on the function being unimodal within the search interval, meaning that for a function on , it strictly decreases from to a single interior minimum point (where ) and then strictly increases from to .[2][4] This property ensures a unique extremum without additional local minima or maxima that could mislead the search.[1] Key prerequisites include the function being continuous and evaluable at any point within the initial finite interval , which must fully contain the extremum .[2][4] Unlike derivative-based methods, no gradient information is required, making the algorithm suitable for non-differentiable but continuous functions, provided that function evaluations are computationally feasible or inexpensive.[1] These assumptions limit applicability: the method fails for multimodal functions with multiple extrema, as it may converge to a suboptimal point, and it does not handle discontinuities, which violate the continuity requirement and prevent guaranteed convergence.[2][4] Convergence efficiency specifically depends on strict unimodality, as violations can lead to incorrect bracketing or stalled progress.[1] A representative example of a unimodal function is the quadratic on the interval , which decreases from to the minimum at and then increases to .[4]Mathematical Foundation
The Golden Ratio
The golden ratio, denoted by , is the positive real solution to the equation , which rearranges to the quadratic equation . Solving for gives .[10] This number is irrational, meaning it cannot be expressed as a ratio of integers, and its continued fraction expansion is the infinite periodic form , representing the simplest such expansion among quadratic irrationals. The golden ratio also emerges as the limit of the ratios of consecutive terms in the Fibonacci sequence, defined by , , and for , such that . Geometrically, appears in the proportions of a regular pentagon, where the ratio of the length of a diagonal to the length of a side equals .[10] In the golden-section search method, the golden ratio's defining property enables an optimal asymmetric division of a search interval into two parts via probe points, such that the ratio of the whole interval to the larger subinterval equals the ratio of the larger subinterval to the smaller one, both equaling . This self-similar division allows one probe point from the previous iteration to be reused in the next, reducing the required number of function evaluations while maintaining efficiency.[11] The method's efficiency stems from a contraction factor of per iteration, meaning the uncertainty interval's length is reduced to approximately 61.8% of its previous size, resulting in exponential convergence toward the optimum. This reduction rate, which minimizes the worst-case number of evaluations for unimodal functions under minimax criteria, was formalized in the foundational development of sequential search procedures.[11]Properties of Interval Division
In the golden-section search, the interval of length is divided by placing two interior probe points and according to the golden ratio . Specifically, and , where . This positioning maintains the ratio , ensuring the larger subinterval to the smaller subinterval is always .[1][2] A key efficiency property arises after evaluating the function at one of the new probe points: the search discards the subinterval that does not contain the extremum, retaining the larger subinterval as the new search domain, which has length reduced by the factor relative to . Due to the symmetric placement enabled by the golden ratio, the previously evaluated interior point can be reused in the subsequent iteration without recomputation, requiring only one new function evaluation per step.[1][2][12] Geometrically, the division scheme produces self-similar subdivisions, where each reduced interval replicates the proportional structure of the original, a direct consequence of the golden ratio's defining property that . This self-similarity optimizes the process by minimizing the worst-case number of evaluations needed to shrink the interval, outperforming equal-interval divisions (like bisection) in the minimax sense for unimodal functions, as the retained interval consistently avoids smaller segments in adversarial scenarios.[12] The method exhibits linear convergence, with the interval length after iterations given by . Equivalently, to reduce the interval by a factor of , approximately evaluations are required, establishing the scale of its reliable but sub-quadratic performance.[2][12]Procedure
Initial Bracketing
In the golden-section search algorithm, the initial bracketing phase establishes a starting interval that contains the extremum of a unimodal function , ensuring the search begins with a reliable enclosure of the minimum or maximum. This interval is selected to be sufficiently wide based on domain knowledge of the function's behavior or preliminary evaluations at scattered points, often starting from two distinct initial guesses and where , and expanding outward if necessary to capture the suspected optimum.[13][12] The bracketing process involves evaluating the function at the endpoints and , along with an interior probe point (typically chosen near the midpoint or via an initial step), to form a triplet of points. Adjustments are made by shifting or expanding the interval until the condition (for minimization) is satisfied, confirming that the function decreases from to and increases from to , thereby enclosing the extremum within . This setup requires three points to verify the bracketing, as the middle point's lower value relative to the endpoints demonstrates the unimodal nature by indicating a local decrease followed by an increase.[13][14] If the initial evaluations fail to bracket the extremum—for instance, if the function continues to decrease beyond or the unimodality is not evident—the interval should be expanded by taking larger steps outward from the current points until a suitable triplet is found, or the unimodality assumption should be re-evaluated through additional function assessments. This phase is crucial for the algorithm's reliability, as it provides a secure enclosure before proceeding to narrower searches.[12][14]Probe Point Selection
In the golden-section search algorithm, after establishing an initial bracket containing the minimum of a unimodal function with an existing probe point where , the next probe point is selected to maintain the golden ratio proportions while enabling reuse of the prior function evaluation at .[2] Specifically, is computed as , ensuring that the distance from to equals the distance from to or from to , depending on the configuration.[15] The function is then evaluated.[2] The positions of the probe points within the current interval (where and ) are given byTermination Criteria
The golden-section search algorithm terminates when the length of the current uncertainty interval, |x₃ - x₁|, is less than a user-defined tolerance ε, which may be specified as either an absolute or relative value. This condition ensures that the interval containing the extremum has been sufficiently narrowed for practical purposes.[16] To promote numerical stability, especially in implementations sensitive to floating-point precision, a relative tolerance is frequently used: |x₃ - x₁| < τ (|x₁| + |x₃|), where τ ≈ √ε_mach and ε_mach denotes the machine epsilon (typically around 2.22 × 10^{-16} for double-precision arithmetic). This approach avoids premature termination due to rounding errors while adapting to the scale of the search interval.[12] At termination, the approximate location of the extremum is estimated as the midpoint of the final interval, (x₁ + x₃)/2, providing a balanced point within the reduced uncertainty region; alternatively, the probe point with the lowest function value among the evaluated points may serve as the estimate to leverage available function information.[17][1] The method guarantees that the error in the estimated extremum position is at most ε/2, half the final interval length. The required number of iterations n to achieve this precision is approximately n ≈ \log_\phi (L_0 / \epsilon), where \phi = (1 + \sqrt{5})/2 is the golden ratio and L_0 is the initial interval length, reflecting the interval's geometric reduction by a factor of 1/\phi per iteration.[17]Implementations
Iterative Algorithm
The iterative algorithm for golden-section search implements the procedure using a loop to repeatedly narrow the search interval until a termination criterion is met, typically based on the interval width or function value difference. This approach initializes the bounding interval [a, b] and two interior probe points x₁ and x₂ using the reciprocal of the golden ratio, then updates the interval based on function evaluations at these points, reusing one point in each iteration to minimize computations.[2][1] The key steps begin by setting resφ = (√5 - 1)/2 ≈ 0.618, the reciprocal of the golden ratio. The initial probe points are then computed as x₁ = a + (b - a) × (1 - resφ) ≈ a + 0.382(b - a) (closer to a) and x₂ = a + (b - a) × resφ ≈ a + 0.618(b - a) (closer to b), with function values f(x₁) and f(x₂) evaluated. In the loop, while the interval length |b - a| exceeds a specified tolerance ε (e.g., 10^{-6}), a new probe point x₄ is calculated symmetrically to the discarded side, and f(x₄) is evaluated. If f(x₁) < f(x₂), the minimum lies in [a, x₂], so b is set to x₂, x₂ to x₁, and x₁ updated as a + (b - a) × (1 - resφ); otherwise, the symmetric update occurs: a to x₁, x₁ to x₂, and x₂ as a + (b - a) × resφ. This reduces the interval by a factor of resφ each step.[2][1] The following pseudocode outlines the iterative implementation for minimizing a unimodal function f over [a, b]:function golden_section_iterative(f, a, b, tol=1e-6, max_iter=100):
resphi = (sqrt(5) - 1) / 2
x1 = a + (b - a) * (1 - resphi)
x2 = a + (b - a) * resphi
f1 = f(x1)
f2 = f(x2)
iter = 0
while (b - a) > tol and iter < max_iter:
if f1 < f2:
b = x2
x2 = x1
f2 = f1
x1 = a + (b - a) * (1 - resphi)
f1 = f(x1)
else:
a = x1
x1 = x2
f1 = f2
x2 = a + (b - a) * resphi
f2 = f(x2)
iter += 1
return (a + b) / 2 # Approximate minimum location
This structure ensures only one new function evaluation per iteration after the initial two.[2][1]
The iterative formulation is memory-efficient, as it avoids the call stack overhead of recursive calls, preventing stack overflow for problems requiring many iterations (e.g., high precision), and is straightforward to implement in most programming languages without reliance on recursion support.[2]
To illustrate, consider minimizing f(x) = x² over [0, 2], a unimodal quadratic with minimum at x = 0. Initial length is 2. In the first iteration, x₁ ≈ 0.764, x₂ ≈ 1.236, f(x₁) ≈ 0.583 < f(x₂) ≈ 1.528, so the interval shrinks to [0, 1.236] (length ≈ 1.236). In the second iteration, new x₁ ≈ 0.472, new x₂ ≈ 0.764, f(new x₁) ≈ 0.223 < f(new x₂) ≈ 0.583, shrinking to [0, 0.764] (length ≈ 0.764). The interval reduces by ≈0.618 each step, converging toward 0.[2][1]
| Iteration | a | b | x₁ | x₂ | f(x₁) | f(x₂) | Length |
|---|---|---|---|---|---|---|---|
| 0 | 0 | 2 | 0.764 | 1.236 | 0.583 | 1.528 | 2.000 |
| 1 | 0 | 1.236 | 0.472 | 0.764 | 0.223 | 0.583 | 1.236 |
| 2 | 0 | 0.764 | 0.292 | 0.472 | 0.085 | 0.223 | 0.764 |
Recursive Algorithm
The recursive formulation of the golden-section search algorithm expresses the interval reduction process as a self-calling function that narrows the search space based on function evaluations at interior probe points, embodying a divide-and-conquer approach suitable for unimodal functions.[2] This structure leverages the properties of the golden ratio to ensure efficient contraction of the interval while minimizing redundant evaluations through careful parameter passing. The core recursive function, typically denoted assearch(a, b, f, tol), takes the current interval endpoints a and b, the objective function f, and a tolerance tol as inputs. In the base case, if the interval width |b - a| falls below tol, the algorithm terminates and returns the midpoint (a + b)/2 as an approximation of the extremum. Otherwise, it computes the probe points x1 and x2 within [a, b] using the golden ratio proportions—specifically, x1 = a + (3 - \sqrt{5})/2 \cdot (b - a) and x2 = a + (\sqrt{5} - 1)/2 \cdot (b - a) (or vice versa, depending on convention)—evaluates f(x1) and f(x2), and recursively invokes itself on the reduced subinterval: if f(x1) < f(x2), it searches [a, x2]; else, it searches [x1, b].[2]
To optimize efficiency and reuse prior evaluations, the recursive calls can pass the surviving probe point and its function value as additional parameters, avoiding recomputation of the retained interior point from the previous step; for instance, the function signature might extend to search(a, b, x_old, f_old, f, tol), where x_old and f_old carry over the reusable data, and only one new evaluation occurs per recursion level.[2] This adaptation maintains the algorithm's hallmark of requiring just one additional function evaluation per iteration after the initial two.
The recursive structure offers a modular and intuitive representation of the optimization process, facilitating comprehension of how successive interval halvings (contracted by the factor \approx 0.618) converge to the optimum, though it carries the inherent risk of stack overflow in implementations requiring deep recursion depths—typically around 45-70 levels for tolerances on the order of machine epsilon in double-precision arithmetic, which exceeds limits on some systems with shallow stack sizes.[2]

