Average Error: 34.7 → 23.9
Time: 5.6s
Precision: 64
\[\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}\]
\[\begin{array}{l} \mathbf{if}\;x \le -1.5524096722827354 \cdot 10^{+146}:\\ \;\;\;\;-x\\ \mathbf{elif}\;x \le 2.8767154662268737 \cdot 10^{+124}:\\ \;\;\;\;\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.5524096722827354 \cdot 10^{+146}:\\
\;\;\;\;-x\\

\mathbf{elif}\;x \le 2.8767154662268737 \cdot 10^{+124}:\\
\;\;\;\;\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 r33682876 = x;
        double r33682877 = r33682876 * r33682876;
        double r33682878 = y;
        double r33682879 = r33682878 * r33682878;
        double r33682880 = r33682877 + r33682879;
        double r33682881 = z;
        double r33682882 = r33682881 * r33682881;
        double r33682883 = r33682880 + r33682882;
        double r33682884 = sqrt(r33682883);
        return r33682884;
}

double f(double x, double y, double z) {
        double r33682885 = x;
        double r33682886 = -1.5524096722827354e+146;
        bool r33682887 = r33682885 <= r33682886;
        double r33682888 = -r33682885;
        double r33682889 = 2.8767154662268737e+124;
        bool r33682890 = r33682885 <= r33682889;
        double r33682891 = z;
        double r33682892 = r33682891 * r33682891;
        double r33682893 = y;
        double r33682894 = r33682893 * r33682893;
        double r33682895 = r33682885 * r33682885;
        double r33682896 = r33682894 + r33682895;
        double r33682897 = r33682892 + r33682896;
        double r33682898 = sqrt(r33682897);
        double r33682899 = r33682890 ? r33682898 : r33682885;
        double r33682900 = r33682887 ? r33682888 : r33682899;
        return r33682900;
}

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

Original34.7
Target23.5
Herbie23.9
\[\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.5524096722827354e+146

    1. Initial program 57.6

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

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

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

    if -1.5524096722827354e+146 < x < 2.8767154662268737e+124

    1. Initial program 26.8

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

    if 2.8767154662268737e+124 < x

    1. Initial program 54.0

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -1.5524096722827354 \cdot 10^{+146}:\\ \;\;\;\;-x\\ \mathbf{elif}\;x \le 2.8767154662268737 \cdot 10^{+124}:\\ \;\;\;\;\sqrt{z \cdot z + \left(y \cdot y + x \cdot x\right)}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array}\]

Reproduce

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