Average Error: 37.4 → 25.0
Time: 5.2s
Precision: 64
\[\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}\]
\[\begin{array}{l} \mathbf{if}\;x \le -3.655717002048407242527182258465352811621 \cdot 10^{123}:\\ \;\;\;\;-x\\ \mathbf{elif}\;x \le 1.32214930301390480212609639206850133243 \cdot 10^{51}:\\ \;\;\;\;\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 -3.655717002048407242527182258465352811621 \cdot 10^{123}:\\
\;\;\;\;-x\\

\mathbf{elif}\;x \le 1.32214930301390480212609639206850133243 \cdot 10^{51}:\\
\;\;\;\;\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 r692845 = x;
        double r692846 = r692845 * r692845;
        double r692847 = y;
        double r692848 = r692847 * r692847;
        double r692849 = r692846 + r692848;
        double r692850 = z;
        double r692851 = r692850 * r692850;
        double r692852 = r692849 + r692851;
        double r692853 = sqrt(r692852);
        return r692853;
}

double f(double x, double y, double z) {
        double r692854 = x;
        double r692855 = -3.655717002048407e+123;
        bool r692856 = r692854 <= r692855;
        double r692857 = -r692854;
        double r692858 = 1.3221493030139048e+51;
        bool r692859 = r692854 <= r692858;
        double r692860 = r692854 * r692854;
        double r692861 = y;
        double r692862 = r692861 * r692861;
        double r692863 = r692860 + r692862;
        double r692864 = z;
        double r692865 = r692864 * r692864;
        double r692866 = r692863 + r692865;
        double r692867 = sqrt(r692866);
        double r692868 = r692859 ? r692867 : r692854;
        double r692869 = r692856 ? r692857 : r692868;
        return r692869;
}

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

Original37.4
Target25.4
Herbie25.0
\[\begin{array}{l} \mathbf{if}\;z \lt -6.396479394109775845820908799933348003545 \cdot 10^{136}:\\ \;\;\;\;-z\\ \mathbf{elif}\;z \lt 7.320293694404182125923160810847974073098 \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 < -3.655717002048407e+123

    1. Initial program 58.2

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

      \[\leadsto \color{blue}{-1 \cdot x}\]
    3. Simplified15.6

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

    if -3.655717002048407e+123 < x < 1.3221493030139048e+51

    1. Initial program 28.4

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

    if 1.3221493030139048e+51 < x

    1. Initial program 50.3

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -3.655717002048407242527182258465352811621 \cdot 10^{123}:\\ \;\;\;\;-x\\ \mathbf{elif}\;x \le 1.32214930301390480212609639206850133243 \cdot 10^{51}:\\ \;\;\;\;\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array}\]

Reproduce

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