Average Error: 35.6 → 24.4
Time: 5.2s
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 r32317942 = x;
        double r32317943 = r32317942 * r32317942;
        double r32317944 = y;
        double r32317945 = r32317944 * r32317944;
        double r32317946 = r32317943 + r32317945;
        double r32317947 = z;
        double r32317948 = r32317947 * r32317947;
        double r32317949 = r32317946 + r32317948;
        double r32317950 = sqrt(r32317949);
        return r32317950;
}

double f(double x, double y, double z) {
        double r32317951 = x;
        double r32317952 = -1.3226326560428921e+154;
        bool r32317953 = r32317951 <= r32317952;
        double r32317954 = -r32317951;
        double r32317955 = 1.002146628137244e+84;
        bool r32317956 = r32317951 <= r32317955;
        double r32317957 = z;
        double r32317958 = r32317957 * r32317957;
        double r32317959 = y;
        double r32317960 = r32317959 * r32317959;
        double r32317961 = r32317951 * r32317951;
        double r32317962 = r32317960 + r32317961;
        double r32317963 = r32317958 + r32317962;
        double r32317964 = sqrt(r32317963);
        double r32317965 = r32317956 ? r32317964 : r32317951;
        double r32317966 = r32317953 ? r32317954 : r32317965;
        return r32317966;
}

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