Average Error: 38.2 → 25.2
Time: 2.1s
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 r755497 = x;
        double r755498 = r755497 * r755497;
        double r755499 = y;
        double r755500 = r755499 * r755499;
        double r755501 = r755498 + r755500;
        double r755502 = z;
        double r755503 = r755502 * r755502;
        double r755504 = r755501 + r755503;
        double r755505 = sqrt(r755504);
        return r755505;
}

double f(double x, double y, double z) {
        double r755506 = x;
        double r755507 = -3.0743391220001314e+144;
        bool r755508 = r755506 <= r755507;
        double r755509 = -r755506;
        double r755510 = 4.244899767656578e+97;
        bool r755511 = r755506 <= r755510;
        double r755512 = r755506 * r755506;
        double r755513 = y;
        double r755514 = r755513 * r755513;
        double r755515 = r755512 + r755514;
        double r755516 = z;
        double r755517 = r755516 * r755516;
        double r755518 = r755515 + r755517;
        double r755519 = sqrt(r755518);
        double r755520 = r755511 ? r755519 : r755506;
        double r755521 = r755508 ? r755509 : r755520;
        return r755521;
}

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))))