Average Error: 38.1 → 25.8
Time: 1.5s
Precision: 64
\[\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}\]
\[\begin{array}{l} \mathbf{if}\;x \le -8.2785642049712221 \cdot 10^{77}:\\ \;\;\;\;-1 \cdot x\\ \mathbf{elif}\;x \le 5.69671373933162088 \cdot 10^{116}:\\ \;\;\;\;\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 -8.2785642049712221 \cdot 10^{77}:\\
\;\;\;\;-1 \cdot x\\

\mathbf{elif}\;x \le 5.69671373933162088 \cdot 10^{116}:\\
\;\;\;\;\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 r664849 = x;
        double r664850 = r664849 * r664849;
        double r664851 = y;
        double r664852 = r664851 * r664851;
        double r664853 = r664850 + r664852;
        double r664854 = z;
        double r664855 = r664854 * r664854;
        double r664856 = r664853 + r664855;
        double r664857 = sqrt(r664856);
        return r664857;
}

double f(double x, double y, double z) {
        double r664858 = x;
        double r664859 = -8.278564204971222e+77;
        bool r664860 = r664858 <= r664859;
        double r664861 = -1.0;
        double r664862 = r664861 * r664858;
        double r664863 = 5.696713739331621e+116;
        bool r664864 = r664858 <= r664863;
        double r664865 = r664858 * r664858;
        double r664866 = y;
        double r664867 = r664866 * r664866;
        double r664868 = r664865 + r664867;
        double r664869 = z;
        double r664870 = r664869 * r664869;
        double r664871 = r664868 + r664870;
        double r664872 = sqrt(r664871);
        double r664873 = r664864 ? r664872 : r664858;
        double r664874 = r664860 ? r664862 : r664873;
        return r664874;
}

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.1
Target25.7
Herbie25.8
\[\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 < -8.278564204971222e+77

    1. Initial program 53.1

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

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

    if -8.278564204971222e+77 < x < 5.696713739331621e+116

    1. Initial program 29.1

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

    if 5.696713739331621e+116 < x

    1. Initial program 57.1

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -8.2785642049712221 \cdot 10^{77}:\\ \;\;\;\;-1 \cdot x\\ \mathbf{elif}\;x \le 5.69671373933162088 \cdot 10^{116}:\\ \;\;\;\;\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array}\]

Reproduce

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