Average Error: 37.7 → 25.8
Time: 1.3s
Precision: 64
\[\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}\]
\[\begin{array}{l} \mathbf{if}\;x \le -3.579487785954697432023486781062392489463 \cdot 10^{94}:\\ \;\;\;\;-1 \cdot x\\ \mathbf{elif}\;x \le 6.058132317483692417052640734859374750552 \cdot 10^{-184}:\\ \;\;\;\;\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}\\ \mathbf{elif}\;x \le 4.463507529461488747590627312338750545799 \cdot 10^{-156}:\\ \;\;\;\;z\\ \mathbf{elif}\;x \le 1.388151731591545501959511120790879854274 \cdot 10^{99}:\\ \;\;\;\;\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.579487785954697432023486781062392489463 \cdot 10^{94}:\\
\;\;\;\;-1 \cdot x\\

\mathbf{elif}\;x \le 6.058132317483692417052640734859374750552 \cdot 10^{-184}:\\
\;\;\;\;\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}\\

\mathbf{elif}\;x \le 4.463507529461488747590627312338750545799 \cdot 10^{-156}:\\
\;\;\;\;z\\

\mathbf{elif}\;x \le 1.388151731591545501959511120790879854274 \cdot 10^{99}:\\
\;\;\;\;\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 r880890 = x;
        double r880891 = r880890 * r880890;
        double r880892 = y;
        double r880893 = r880892 * r880892;
        double r880894 = r880891 + r880893;
        double r880895 = z;
        double r880896 = r880895 * r880895;
        double r880897 = r880894 + r880896;
        double r880898 = sqrt(r880897);
        return r880898;
}

double f(double x, double y, double z) {
        double r880899 = x;
        double r880900 = -3.5794877859546974e+94;
        bool r880901 = r880899 <= r880900;
        double r880902 = -1.0;
        double r880903 = r880902 * r880899;
        double r880904 = 6.058132317483692e-184;
        bool r880905 = r880899 <= r880904;
        double r880906 = r880899 * r880899;
        double r880907 = y;
        double r880908 = r880907 * r880907;
        double r880909 = r880906 + r880908;
        double r880910 = z;
        double r880911 = r880910 * r880910;
        double r880912 = r880909 + r880911;
        double r880913 = sqrt(r880912);
        double r880914 = 4.463507529461489e-156;
        bool r880915 = r880899 <= r880914;
        double r880916 = 1.3881517315915455e+99;
        bool r880917 = r880899 <= r880916;
        double r880918 = r880917 ? r880913 : r880899;
        double r880919 = r880915 ? r880910 : r880918;
        double r880920 = r880905 ? r880913 : r880919;
        double r880921 = r880901 ? r880903 : r880920;
        return r880921;
}

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.7
Target25.5
Herbie25.8
\[\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 4 regimes
  2. if x < -3.5794877859546974e+94

    1. Initial program 52.6

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

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

    if -3.5794877859546974e+94 < x < 6.058132317483692e-184 or 4.463507529461489e-156 < x < 1.3881517315915455e+99

    1. Initial program 29.0

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

    if 6.058132317483692e-184 < x < 4.463507529461489e-156

    1. Initial program 31.8

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

      \[\leadsto \color{blue}{z}\]

    if 1.3881517315915455e+99 < x

    1. Initial program 54.4

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -3.579487785954697432023486781062392489463 \cdot 10^{94}:\\ \;\;\;\;-1 \cdot x\\ \mathbf{elif}\;x \le 6.058132317483692417052640734859374750552 \cdot 10^{-184}:\\ \;\;\;\;\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}\\ \mathbf{elif}\;x \le 4.463507529461488747590627312338750545799 \cdot 10^{-156}:\\ \;\;\;\;z\\ \mathbf{elif}\;x \le 1.388151731591545501959511120790879854274 \cdot 10^{99}:\\ \;\;\;\;\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array}\]

Reproduce

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