How to Apply Alpha-Max-Beta-Min to Three Numbers
At a glance
- 1. Take magnitudes
Use absolute values, since a vector length depends on component magnitudes, not their signs.
- 2. Sort the values
Order the three magnitudes as largest, middle, and smallest.
- 3. Choose an extension
For three inputs, include the middle value; max and min alone discard useful information.
- 4. Estimate and compare
Apply the chosen weights, and use the exact square root when accuracy matters.
The alpha-max-beta-min algorithm is commonly used to estimate the length of a two-component vector without evaluating a square root. For three numbers, there is no single standard two-coefficient formula: a direct extension using only the maximum and minimum ignores the middle value.
If you want to approximate the Euclidean length of a three-dimensional vector , first take the absolute values and sort them. A simple three-term approximation is
where are the largest, middle, and smallest of , , and . These weights are a convenient heuristic, not a uniquely defined or universally optimal set of coefficients.
Why two terms are not enough
For two nonnegative values and , the alpha-max-beta-min form is
The constants and depend on the desired error and how the approximation is tuned. This formula uses both inputs. With three values, applying it to only the largest and smallest discards the middle one.
For instance, the triples and have the same largest and smallest values, but their exact lengths are and . Any expression depending only on the largest and smallest must give the same estimate for both, so it cannot represent both lengths exactly. A three-input approximation should normally include the middle value, using a form such as .
A simple three-number algorithm
For a quick approximation, use
One implementation is:
function approximateLength3(x, y, z):
a = abs(x)
b = abs(y)
c = abs(z)
M = max(a, b, c)
m = min(a, b, c)
Q = a + b + c - M - m
return M + 0.5 * Q + 0.25 * m
The subtraction finds the middle magnitude after the maximum and minimum have been identified. Ties cause no problem: if two values are equal, the sorted values and their sum are still correct. The algorithm uses comparisons and arithmetic rather than a square root.
Worked example
Estimate the length of the vector .
First take absolute values: , , and . Thus , , and . The approximation is
The exact length is
So this estimate is about too large, or approximately relative to the exact length. That illustrates why this formula is useful only when a rough, inexpensive estimate is acceptable. Its error depends on the relative sizes of the three components.
Choosing coefficients
A more general three-term approximation is
The appropriate coefficients depend on the error criterion. For example, minimizing the worst-case relative error over all nonzero triples is a different design goal from minimizing average error over a particular workload. If the formula is used in a real-time or embedded system, test candidate coefficients against representative inputs and establish an acceptable error bound for that application. Do not assume coefficients tuned for two inputs remain optimal in three dimensions.
If you need a particular accuracy, calculate the Euclidean length directly with a numerically stable hypot function when your language provides one. For example, a three-argument hypot(x, y, z) avoids some overflow and underflow problems that can arise from directly squaring very large or very small inputs.
Common mistakes
- Using signed inputs in the ordering. Sort , , and , not the original signed values.
- Calling the two-term expression a three-input formula. Using only the largest and smallest loses information about the middle component.
- Treating a heuristic as exact. The weighted sum is an approximation; it does not equal the square-root formula for every triple.
- Using it without checking the error requirement. A fast estimate may be unsuitable for scientific calculations, safety-critical code, or any task requiring a guaranteed tolerance.
- Mixing up the middle and smallest values. The coefficients belong to the ordered magnitudes ; applying them before sorting changes the result depending on input order.
Spotted an error? Send a correction. Read how we write and check articles in our editorial policy.