Average Error: 37.7 → 25.5
Time: 9.4s
Precision: 64
$\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}$
$\begin{array}{l} \mathbf{if}\;x \le -1.324658437546774214300692136580246152968 \cdot 10^{50}:\\ \;\;\;\;-x\\ \mathbf{elif}\;x \le 5.318175054981041455737691344586413861204 \cdot 10^{96}:\\ \;\;\;\;\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array}$
\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}
\begin{array}{l}
\mathbf{if}\;x \le -1.324658437546774214300692136580246152968 \cdot 10^{50}:\\
\;\;\;\;-x\\

\mathbf{elif}\;x \le 5.318175054981041455737691344586413861204 \cdot 10^{96}:\\
\;\;\;\;\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}\\

\mathbf{else}:\\
\;\;\;\;x\\

\end{array}
double f(double x, double y, double z) {
double r748843 = x;
double r748844 = r748843 * r748843;
double r748845 = y;
double r748846 = r748845 * r748845;
double r748847 = r748844 + r748846;
double r748848 = z;
double r748849 = r748848 * r748848;
double r748850 = r748847 + r748849;
double r748851 = sqrt(r748850);
return r748851;
}


double f(double x, double y, double z) {
double r748852 = x;
double r748853 = -1.3246584375467742e+50;
bool r748854 = r748852 <= r748853;
double r748855 = -r748852;
double r748856 = 5.318175054981041e+96;
bool r748857 = r748852 <= r748856;
double r748858 = r748852 * r748852;
double r748859 = y;
double r748860 = r748859 * r748859;
double r748861 = r748858 + r748860;
double r748862 = z;
double r748863 = r748862 * r748862;
double r748864 = r748861 + r748863;
double r748865 = sqrt(r748864);
double r748866 = r748857 ? r748865 : r748852;
double r748867 = r748854 ? r748855 : r748866;
return r748867;
}



# Try it out

Results

 In Out
Enter valid numbers for all inputs

# Derivation

1. Split input into 3 regimes
2. ## if x < -1.3246584375467742e+50

1. Initial program 49.4

$\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}$
2. Taylor expanded around -inf 21.2

$\leadsto \color{blue}{-1 \cdot x}$
3. Simplified21.2

$\leadsto \color{blue}{-x}$

## if -1.3246584375467742e+50 < x < 5.318175054981041e+96

1. Initial program 29.1

$\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}$

## if 5.318175054981041e+96 < x

1. Initial program 53.7

$\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}$
2. Taylor expanded around inf 18.4

$\leadsto \color{blue}{x}$
3. Recombined 3 regimes into one program.
4. Final simplification25.5

$\leadsto \begin{array}{l} \mathbf{if}\;x \le -1.324658437546774214300692136580246152968 \cdot 10^{50}:\\ \;\;\;\;-x\\ \mathbf{elif}\;x \le 5.318175054981041455737691344586413861204 \cdot 10^{96}:\\ \;\;\;\;\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array}$

# Reproduce

herbie shell --seed 1
(FPCore (x y z)
:name "sqrt(x*x+y*y+z*z)"
:precision binary64
(sqrt (+ (+ (* x x) (* y y)) (* z z))))