Average Error: 38.2 → 27.3
Time: 2.5s
Precision: 64
\[\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}\]
\[\begin{array}{l} \mathbf{if}\;x \le -3.4794970398246474 \cdot 10^{55}:\\ \;\;\;\;-1 \cdot x\\ \mathbf{elif}\;x \le 4.54583198998115572 \cdot 10^{65}:\\ \;\;\;\;\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}\\ \mathbf{elif}\;x \le 1.59746099954173198 \cdot 10^{121}:\\ \;\;\;\;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.4794970398246474 \cdot 10^{55}:\\
\;\;\;\;-1 \cdot x\\

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

\mathbf{elif}\;x \le 1.59746099954173198 \cdot 10^{121}:\\
\;\;\;\;z\\

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

\end{array}
double f(double x, double y, double z) {
        double r657548 = x;
        double r657549 = r657548 * r657548;
        double r657550 = y;
        double r657551 = r657550 * r657550;
        double r657552 = r657549 + r657551;
        double r657553 = z;
        double r657554 = r657553 * r657553;
        double r657555 = r657552 + r657554;
        double r657556 = sqrt(r657555);
        return r657556;
}

double f(double x, double y, double z) {
        double r657557 = x;
        double r657558 = -3.4794970398246474e+55;
        bool r657559 = r657557 <= r657558;
        double r657560 = -1.0;
        double r657561 = r657560 * r657557;
        double r657562 = 4.545831989981156e+65;
        bool r657563 = r657557 <= r657562;
        double r657564 = r657557 * r657557;
        double r657565 = y;
        double r657566 = r657565 * r657565;
        double r657567 = r657564 + r657566;
        double r657568 = z;
        double r657569 = r657568 * r657568;
        double r657570 = r657567 + r657569;
        double r657571 = sqrt(r657570);
        double r657572 = 1.597460999541732e+121;
        bool r657573 = r657557 <= r657572;
        double r657574 = r657573 ? r657568 : r657557;
        double r657575 = r657563 ? r657571 : r657574;
        double r657576 = r657559 ? r657561 : r657575;
        return r657576;
}

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.5
Herbie27.3
\[\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 4 regimes
  2. if x < -3.4794970398246474e+55

    1. Initial program 49.3

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

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

    if -3.4794970398246474e+55 < x < 4.545831989981156e+65

    1. Initial program 29.9

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

    if 4.545831989981156e+65 < x < 1.597460999541732e+121

    1. Initial program 29.3

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

      \[\leadsto \color{blue}{z}\]

    if 1.597460999541732e+121 < x

    1. Initial program 58.5

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

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

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

Reproduce

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