Average Error: 38.6 → 25.6
Time: 1.3s
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 r890864 = x;
        double r890865 = r890864 * r890864;
        double r890866 = y;
        double r890867 = r890866 * r890866;
        double r890868 = r890865 + r890867;
        double r890869 = z;
        double r890870 = r890869 * r890869;
        double r890871 = r890868 + r890870;
        double r890872 = sqrt(r890871);
        return r890872;
}

double f(double x, double y, double z) {
        double r890873 = x;
        double r890874 = -1.4467202670789784e+138;
        bool r890875 = r890873 <= r890874;
        double r890876 = -1.0;
        double r890877 = r890876 * r890873;
        double r890878 = 1.096043779466603e+127;
        bool r890879 = r890873 <= r890878;
        double r890880 = r890873 * r890873;
        double r890881 = y;
        double r890882 = r890881 * r890881;
        double r890883 = r890880 + r890882;
        double r890884 = z;
        double r890885 = r890884 * r890884;
        double r890886 = r890883 + r890885;
        double r890887 = sqrt(r890886);
        double r890888 = r890879 ? r890887 : r890873;
        double r890889 = r890875 ? r890877 : r890888;
        return r890889;
}

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