The alpha max plus beta min algorithm is a high-speed approximation of the square root of the sum of two squares. The square root of the sum of two squares, also known as Pythagorean addition, is a useful function, because it finds the hypotenuse of a right triangle given the two side lengths, the norm of a 2-D vector, or the magnitude |z| = sqrt (a^2 + b^2) of a complex number z = a + bi given the real and imaginary parts.
The algorithm avoids performing the square and square-root operations, instead using simple operations such as comparison, multiplication, and addition. Some choices of the α and β parameters of the algorithm allow the multiplication operation to be reduced to a simple shift of binary digits that is particularly well suited to implementation in high-speed digital circuitry.
The approximation is expressed as: |z| = alpha*Max +beta*Min
where Max is the maximum absolute value of a and b and Min is the minimum absolute value of a and b. For the closest approximation, the optimum values for alpha and beta are
, giving a maximum error of 3.96%.
|alpha||beta||Largest error (%)||Mean error (%)|
When alpha < 1, |z| becomes smaller than Max (which is geometrically impossible) near the axes where Min is near 0. This can be remedied by replacing the result with Max whenever that is greater, essentially splitting the line into two different segments.
Depending on the hardware, this improvement can be almost free.
Using this improvement changes which parameter values are optimal, because they no longer need a close match for the entire interval. A lower alpha and higher beta can therefore increase precision further.
Increasing precision: When splitting the line in two like this one could improve precision even more by replacing the first segment by a better estimate than Max, and adjust alpha and beta accordingly.
|alpha0||beta0||alpha1||beta1||Largest error (%)|
Beware however, that a non-zero beta0 would require at least one extra addition and some bit-shifts (or a multiplication), probably nearly doubling the cost and, depending on the hardware, possibly defeat the purpose of using an approximation in the first place.
- Lyons, Richard G. Understanding Digital Signal Processing, section 13.2. Prentice Hall, 2004 ISBN 0-13-108989-7.
- Griffin, Grant. DSP Trick: Magnitude Estimator.