Average Error: 38.0 → 25.8
Time: 2.6s
Precision: 64
\[\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}\]
\[\begin{array}{l} \mathbf{if}\;x \le -2.88352274157357012 \cdot 10^{144}:\\ \;\;\;\;-x\\ \mathbf{elif}\;x \le 5.5672647142085938 \cdot 10^{147}:\\ \;\;\;\;\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 -2.88352274157357012 \cdot 10^{144}:\\
\;\;\;\;-x\\

\mathbf{elif}\;x \le 5.5672647142085938 \cdot 10^{147}:\\
\;\;\;\;\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 r727894 = x;
        double r727895 = r727894 * r727894;
        double r727896 = y;
        double r727897 = r727896 * r727896;
        double r727898 = r727895 + r727897;
        double r727899 = z;
        double r727900 = r727899 * r727899;
        double r727901 = r727898 + r727900;
        double r727902 = sqrt(r727901);
        return r727902;
}

double f(double x, double y, double z) {
        double r727903 = x;
        double r727904 = -2.88352274157357e+144;
        bool r727905 = r727903 <= r727904;
        double r727906 = -r727903;
        double r727907 = 5.567264714208594e+147;
        bool r727908 = r727903 <= r727907;
        double r727909 = r727903 * r727903;
        double r727910 = y;
        double r727911 = r727910 * r727910;
        double r727912 = r727909 + r727911;
        double r727913 = z;
        double r727914 = r727913 * r727913;
        double r727915 = r727912 + r727914;
        double r727916 = sqrt(r727915);
        double r727917 = r727908 ? r727916 : r727903;
        double r727918 = r727905 ? r727906 : r727917;
        return r727918;
}

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.0
Target25.4
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 < -2.88352274157357e+144

    1. Initial program 61.1

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

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

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

    if -2.88352274157357e+144 < x < 5.567264714208594e+147

    1. Initial program 29.7

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

    if 5.567264714208594e+147 < x

    1. Initial program 62.0

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -2.88352274157357012 \cdot 10^{144}:\\ \;\;\;\;-x\\ \mathbf{elif}\;x \le 5.5672647142085938 \cdot 10^{147}:\\ \;\;\;\;\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array}\]

Reproduce

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