Average Error: 38.1 → 25.5
Time: 12.9s
Precision: 64
\[\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}\]
\[\begin{array}{l} \mathbf{if}\;x \le -1.884385188290897584934334479478417400382 \cdot 10^{109}:\\ \;\;\;\;-x\\ \mathbf{elif}\;x \le 1.945330258922093722171531403348915767504 \cdot 10^{138}:\\ \;\;\;\;\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.884385188290897584934334479478417400382 \cdot 10^{109}:\\
\;\;\;\;-x\\

\mathbf{elif}\;x \le 1.945330258922093722171531403348915767504 \cdot 10^{138}:\\
\;\;\;\;\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 r487617 = x;
        double r487618 = r487617 * r487617;
        double r487619 = y;
        double r487620 = r487619 * r487619;
        double r487621 = r487618 + r487620;
        double r487622 = z;
        double r487623 = r487622 * r487622;
        double r487624 = r487621 + r487623;
        double r487625 = sqrt(r487624);
        return r487625;
}

double f(double x, double y, double z) {
        double r487626 = x;
        double r487627 = -1.8843851882908976e+109;
        bool r487628 = r487626 <= r487627;
        double r487629 = -r487626;
        double r487630 = 1.9453302589220937e+138;
        bool r487631 = r487626 <= r487630;
        double r487632 = r487626 * r487626;
        double r487633 = y;
        double r487634 = r487633 * r487633;
        double r487635 = r487632 + r487634;
        double r487636 = z;
        double r487637 = r487636 * r487636;
        double r487638 = r487635 + r487637;
        double r487639 = sqrt(r487638);
        double r487640 = r487631 ? r487639 : r487626;
        double r487641 = r487628 ? r487629 : r487640;
        return r487641;
}

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.3
Herbie25.5
\[\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 < -1.8843851882908976e+109

    1. Initial program 55.1

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

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

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

    if -1.8843851882908976e+109 < x < 1.9453302589220937e+138

    1. Initial program 29.6

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

    if 1.9453302589220937e+138 < x

    1. Initial program 60.4

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -1.884385188290897584934334479478417400382 \cdot 10^{109}:\\ \;\;\;\;-x\\ \mathbf{elif}\;x \le 1.945330258922093722171531403348915767504 \cdot 10^{138}:\\ \;\;\;\;\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array}\]

Reproduce

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