Average Error: 35.6 → 24.4
Time: 4.4s
Precision: 64
\[\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}\]
\[\begin{array}{l} \mathbf{if}\;x \le -1.3226326560428921 \cdot 10^{+154}:\\ \;\;\;\;-x\\ \mathbf{elif}\;x \le 1.002146628137244 \cdot 10^{+84}:\\ \;\;\;\;\sqrt{z \cdot z + \left(y \cdot y + x \cdot x\right)}\\ \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.3226326560428921 \cdot 10^{+154}:\\
\;\;\;\;-x\\

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

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

\end{array}
double f(double x, double y, double z) {
        double r31939709 = x;
        double r31939710 = r31939709 * r31939709;
        double r31939711 = y;
        double r31939712 = r31939711 * r31939711;
        double r31939713 = r31939710 + r31939712;
        double r31939714 = z;
        double r31939715 = r31939714 * r31939714;
        double r31939716 = r31939713 + r31939715;
        double r31939717 = sqrt(r31939716);
        return r31939717;
}

double f(double x, double y, double z) {
        double r31939718 = x;
        double r31939719 = -1.3226326560428921e+154;
        bool r31939720 = r31939718 <= r31939719;
        double r31939721 = -r31939718;
        double r31939722 = 1.002146628137244e+84;
        bool r31939723 = r31939718 <= r31939722;
        double r31939724 = z;
        double r31939725 = r31939724 * r31939724;
        double r31939726 = y;
        double r31939727 = r31939726 * r31939726;
        double r31939728 = r31939718 * r31939718;
        double r31939729 = r31939727 + r31939728;
        double r31939730 = r31939725 + r31939729;
        double r31939731 = sqrt(r31939730);
        double r31939732 = r31939723 ? r31939731 : r31939718;
        double r31939733 = r31939720 ? r31939721 : r31939732;
        return r31939733;
}

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

Original35.6
Target24.4
Herbie24.4
\[\begin{array}{l} \mathbf{if}\;z \lt -6.396479394109776 \cdot 10^{+136}:\\ \;\;\;\;-z\\ \mathbf{elif}\;z \lt 7.320293694404182 \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.3226326560428921e+154

    1. Initial program 59.2

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

      \[\leadsto \color{blue}{-1 \cdot x}\]
    3. Simplified14.4

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

    if -1.3226326560428921e+154 < x < 1.002146628137244e+84

    1. Initial program 27.7

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

    if 1.002146628137244e+84 < x

    1. Initial program 48.9

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -1.3226326560428921 \cdot 10^{+154}:\\ \;\;\;\;-x\\ \mathbf{elif}\;x \le 1.002146628137244 \cdot 10^{+84}:\\ \;\;\;\;\sqrt{z \cdot z + \left(y \cdot y + x \cdot x\right)}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array}\]

Reproduce

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

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