Average Error: 38.0 → 25.7
Time: 1.5s
Precision: 64
\[\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}\]
\[\begin{array}{l} \mathbf{if}\;x \le -1.5602497723888015 \cdot 10^{48}:\\ \;\;\;\;-1 \cdot x\\ \mathbf{elif}\;x \le 2.816119708780296 \cdot 10^{121}:\\ \;\;\;\;\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.5602497723888015 \cdot 10^{48}:\\
\;\;\;\;-1 \cdot x\\

\mathbf{elif}\;x \le 2.816119708780296 \cdot 10^{121}:\\
\;\;\;\;\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 r570530 = x;
        double r570531 = r570530 * r570530;
        double r570532 = y;
        double r570533 = r570532 * r570532;
        double r570534 = r570531 + r570533;
        double r570535 = z;
        double r570536 = r570535 * r570535;
        double r570537 = r570534 + r570536;
        double r570538 = sqrt(r570537);
        return r570538;
}

double f(double x, double y, double z) {
        double r570539 = x;
        double r570540 = -1.5602497723888015e+48;
        bool r570541 = r570539 <= r570540;
        double r570542 = -1.0;
        double r570543 = r570542 * r570539;
        double r570544 = 2.816119708780296e+121;
        bool r570545 = r570539 <= r570544;
        double r570546 = r570539 * r570539;
        double r570547 = y;
        double r570548 = r570547 * r570547;
        double r570549 = r570546 + r570548;
        double r570550 = z;
        double r570551 = r570550 * r570550;
        double r570552 = r570549 + r570551;
        double r570553 = sqrt(r570552);
        double r570554 = r570545 ? r570553 : r570539;
        double r570555 = r570541 ? r570543 : r570554;
        return r570555;
}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original38.0
Target25.7
Herbie25.7
\[\begin{array}{l} \mathbf{if}\;z \lt -6.3964793941097758 \cdot 10^{136}:\\ \;\;\;\;-z\\ \mathbf{elif}\;z \lt 7.3202936944041821 \cdot 10^{117}:\\ \;\;\;\;\sqrt{\left(z \cdot z + x \cdot x\right) + y \cdot y}\\ \mathbf{else}:\\ \;\;\;\;z\\ \end{array}\]

Derivation

  1. Split input into 3 regimes
  2. if x < -1.5602497723888015e+48

    1. Initial program 50.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}\]

    if -1.5602497723888015e+48 < x < 2.816119708780296e+121

    1. Initial program 29.5

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

    if 2.816119708780296e+121 < x

    1. Initial program 57.0

      \[\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}\]
    2. Taylor expanded around inf 15.6

      \[\leadsto \color{blue}{x}\]
  3. Recombined 3 regimes into one program.
  4. Final simplification25.7

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -1.5602497723888015 \cdot 10^{48}:\\ \;\;\;\;-1 \cdot x\\ \mathbf{elif}\;x \le 2.816119708780296 \cdot 10^{121}:\\ \;\;\;\;\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array}\]

Reproduce

herbie shell --seed 2020024 
(FPCore (x y z)
  :name "FRP.Yampa.Vector3:vector3Rho from Yampa-0.10.2"
  :precision binary64

  :herbie-target
  (if (< z -6.396479394109776e+136) (- z) (if (< z 7.320293694404182e+117) (sqrt (+ (+ (* z z) (* x x)) (* y y))) z))

  (sqrt (+ (+ (* x x) (* y y)) (* z z))))