Average Error: 38.6 → 25.6
Time: 2.6s
Precision: 64
\[\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}\]
\[\begin{array}{l} \mathbf{if}\;x \le -1.4467202670789784 \cdot 10^{138}:\\ \;\;\;\;-1 \cdot x\\ \mathbf{elif}\;x \le 1.0960437794666031 \cdot 10^{127}:\\ \;\;\;\;\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.4467202670789784 \cdot 10^{138}:\\
\;\;\;\;-1 \cdot x\\

\mathbf{elif}\;x \le 1.0960437794666031 \cdot 10^{127}:\\
\;\;\;\;\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 r3573 = x;
        double r3574 = r3573 * r3573;
        double r3575 = y;
        double r3576 = r3575 * r3575;
        double r3577 = r3574 + r3576;
        double r3578 = z;
        double r3579 = r3578 * r3578;
        double r3580 = r3577 + r3579;
        double r3581 = sqrt(r3580);
        return r3581;
}

double f(double x, double y, double z) {
        double r3582 = x;
        double r3583 = -1.4467202670789784e+138;
        bool r3584 = r3582 <= r3583;
        double r3585 = -1.0;
        double r3586 = r3585 * r3582;
        double r3587 = 1.096043779466603e+127;
        bool r3588 = r3582 <= r3587;
        double r3589 = r3582 * r3582;
        double r3590 = y;
        double r3591 = r3590 * r3590;
        double r3592 = r3589 + r3591;
        double r3593 = z;
        double r3594 = r3593 * r3593;
        double r3595 = r3592 + r3594;
        double r3596 = sqrt(r3595);
        double r3597 = r3588 ? r3596 : r3582;
        double r3598 = r3584 ? r3586 : r3597;
        return r3598;
}

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.6
Target26.1
Herbie25.6
\[\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.4467202670789784e+138

    1. Initial program 61.0

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

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

    if -1.4467202670789784e+138 < x < 1.096043779466603e+127

    1. Initial program 29.7

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

    if 1.096043779466603e+127 < x

    1. Initial program 58.4

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -1.4467202670789784 \cdot 10^{138}:\\ \;\;\;\;-1 \cdot x\\ \mathbf{elif}\;x \le 1.0960437794666031 \cdot 10^{127}:\\ \;\;\;\;\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array}\]

Reproduce

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