TITLE: Alpha max plus beta min algorithm for three numbers
QUESTION [6 upvotes]: There exists fast algorithm to approximate length of 2D vector - Alpha max plus beta min algorithm.
It says that $\alpha\cdot\max(x,y)+\beta\cdot\min(x,y)\approx\sqrt{x^2+y^2}$ for some constants $\alpha$ and $\beta$.
Also there exists constants $\alpha_0$ and $\beta_0$ that give closest approximation (smallest error).
$$\alpha_0 = \frac{2 \cos \frac{\pi}{8}}{1 + \cos \frac{\pi}{8}},\ \beta_0 = \frac{2 \sin \frac{\pi}{8}}{1 + \cos \frac{\pi}{8}}$$
I feel like similar algorithm exist for approximating length of 3D vector with formula:
$$\sqrt{x^2+y^2+z^2}\approx\alpha\cdot\max(x,y,z)+\beta\cdot \text{medium}(x,y,z)+\gamma\cdot\min(x,y,z)$$
I'm wondering what values $\alpha_0$, $\beta_0$ and $\gamma_0$ have and how to find them.

REPLY [2 votes]: The approximation given by @uranix is nice, but can be improved slightly, because we know the hypotenuse is never shorter than the largest of the three inputs.
So, borrowing the nice constants given by @uranix and assuming $0<=z<=y<=x$:
const double alphaMax = 0.9398086351723256, betaMed = 0.38928148272372454, gammaMin = 0.2987061876143797;
double hypotenuse = Max(x, alphaMax * x + betaMed * y + gammaMin * z);

This clamps the errors when x is relatively much larger than y and z; a common special case where the errors otherwise would be relatively large and noticeable.
Side-note: Because the multiplications are with constants, they could be approximated with bit-shifts and additions. This is most useful when using fixed-point arithmetic on embedded systems, where floating-point and multiplications may be expensive.