Average Error: 37.3 → 25.5
Time: 2.8s
Precision: 64
\[\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}\]
\[\begin{array}{l} \mathbf{if}\;x \le -1.472200864118953065071901202153872070472 \cdot 10^{97}:\\ \;\;\;\;-1 \cdot x\\ \mathbf{elif}\;x \le 9.739776979507705930755011088832346945497 \cdot 10^{134}:\\ \;\;\;\;\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.472200864118953065071901202153872070472 \cdot 10^{97}:\\
\;\;\;\;-1 \cdot x\\

\mathbf{elif}\;x \le 9.739776979507705930755011088832346945497 \cdot 10^{134}:\\
\;\;\;\;\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 r544882 = x;
        double r544883 = r544882 * r544882;
        double r544884 = y;
        double r544885 = r544884 * r544884;
        double r544886 = r544883 + r544885;
        double r544887 = z;
        double r544888 = r544887 * r544887;
        double r544889 = r544886 + r544888;
        double r544890 = sqrt(r544889);
        return r544890;
}

double f(double x, double y, double z) {
        double r544891 = x;
        double r544892 = -1.472200864118953e+97;
        bool r544893 = r544891 <= r544892;
        double r544894 = -1.0;
        double r544895 = r544894 * r544891;
        double r544896 = 9.739776979507706e+134;
        bool r544897 = r544891 <= r544896;
        double r544898 = r544891 * r544891;
        double r544899 = y;
        double r544900 = r544899 * r544899;
        double r544901 = r544898 + r544900;
        double r544902 = z;
        double r544903 = r544902 * r544902;
        double r544904 = r544901 + r544903;
        double r544905 = sqrt(r544904);
        double r544906 = r544897 ? r544905 : r544891;
        double r544907 = r544893 ? r544895 : r544906;
        return r544907;
}

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.3
Target24.7
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.472200864118953e+97

    1. Initial program 55.7

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

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

    if -1.472200864118953e+97 < x < 9.739776979507706e+134

    1. Initial program 28.8

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

    if 9.739776979507706e+134 < x

    1. Initial program 59.9

      \[\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.5

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -1.472200864118953065071901202153872070472 \cdot 10^{97}:\\ \;\;\;\;-1 \cdot x\\ \mathbf{elif}\;x \le 9.739776979507705930755011088832346945497 \cdot 10^{134}:\\ \;\;\;\;\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array}\]

Reproduce

herbie shell --seed 2019303 
(FPCore (x y z)
  :name "FRP.Yampa.Vector3:vector3Rho from Yampa-0.10.2"
  :precision binary64

  :herbie-target
  (if (< z -6.3964793941097758e136) (- z) (if (< z 7.3202936944041821e117) (sqrt (+ (+ (* z z) (* x x)) (* y y))) z))

  (sqrt (+ (+ (* x x) (* y y)) (* z z))))