Average Error: 38.2 → 25.2
Time: 2.4s
Precision: 64
\[\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}\]
\[\begin{array}{l} \mathbf{if}\;x \le -3.07433912200013139 \cdot 10^{144}:\\ \;\;\;\;-x\\ \mathbf{elif}\;x \le 4.24489976765657814 \cdot 10^{97}:\\ \;\;\;\;\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 -3.07433912200013139 \cdot 10^{144}:\\
\;\;\;\;-x\\

\mathbf{elif}\;x \le 4.24489976765657814 \cdot 10^{97}:\\
\;\;\;\;\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 r1395537 = x;
        double r1395538 = r1395537 * r1395537;
        double r1395539 = y;
        double r1395540 = r1395539 * r1395539;
        double r1395541 = r1395538 + r1395540;
        double r1395542 = z;
        double r1395543 = r1395542 * r1395542;
        double r1395544 = r1395541 + r1395543;
        double r1395545 = sqrt(r1395544);
        return r1395545;
}

double f(double x, double y, double z) {
        double r1395546 = x;
        double r1395547 = -3.0743391220001314e+144;
        bool r1395548 = r1395546 <= r1395547;
        double r1395549 = -r1395546;
        double r1395550 = 4.244899767656578e+97;
        bool r1395551 = r1395546 <= r1395550;
        double r1395552 = r1395546 * r1395546;
        double r1395553 = y;
        double r1395554 = r1395553 * r1395553;
        double r1395555 = r1395552 + r1395554;
        double r1395556 = z;
        double r1395557 = r1395556 * r1395556;
        double r1395558 = r1395555 + r1395557;
        double r1395559 = sqrt(r1395558);
        double r1395560 = r1395551 ? r1395559 : r1395546;
        double r1395561 = r1395548 ? r1395549 : r1395560;
        return r1395561;
}

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.2
Target25.9
Herbie25.2
\[\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 < -3.0743391220001314e+144

    1. Initial program 61.9

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

      \[\leadsto \color{blue}{-1 \cdot x}\]
    3. Simplified13.6

      \[\leadsto \color{blue}{-x}\]

    if -3.0743391220001314e+144 < x < 4.244899767656578e+97

    1. Initial program 29.1

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

    if 4.244899767656578e+97 < x

    1. Initial program 54.8

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -3.07433912200013139 \cdot 10^{144}:\\ \;\;\;\;-x\\ \mathbf{elif}\;x \le 4.24489976765657814 \cdot 10^{97}:\\ \;\;\;\;\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array}\]

Reproduce

herbie shell --seed 2020047 
(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))))