Average Error: 37.8 → 25.6
Time: 2.1s
Precision: 64
\[\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}\]
\[\begin{array}{l} \mathbf{if}\;x \le -6.60009329042165313 \cdot 10^{97}:\\ \;\;\;\;-1 \cdot x\\ \mathbf{elif}\;x \le -7.502177973232327 \cdot 10^{-160}:\\ \;\;\;\;\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}\\ \mathbf{elif}\;x \le -1.62771338830216422 \cdot 10^{-179}:\\ \;\;\;\;z\\ \mathbf{elif}\;x \le 7.27736911506149861 \cdot 10^{124}:\\ \;\;\;\;\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 -6.60009329042165313 \cdot 10^{97}:\\
\;\;\;\;-1 \cdot x\\

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

\mathbf{elif}\;x \le -1.62771338830216422 \cdot 10^{-179}:\\
\;\;\;\;z\\

\mathbf{elif}\;x \le 7.27736911506149861 \cdot 10^{124}:\\
\;\;\;\;\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 r1190385 = x;
        double r1190386 = r1190385 * r1190385;
        double r1190387 = y;
        double r1190388 = r1190387 * r1190387;
        double r1190389 = r1190386 + r1190388;
        double r1190390 = z;
        double r1190391 = r1190390 * r1190390;
        double r1190392 = r1190389 + r1190391;
        double r1190393 = sqrt(r1190392);
        return r1190393;
}

double f(double x, double y, double z) {
        double r1190394 = x;
        double r1190395 = -6.600093290421653e+97;
        bool r1190396 = r1190394 <= r1190395;
        double r1190397 = -1.0;
        double r1190398 = r1190397 * r1190394;
        double r1190399 = -7.502177973232327e-160;
        bool r1190400 = r1190394 <= r1190399;
        double r1190401 = r1190394 * r1190394;
        double r1190402 = y;
        double r1190403 = r1190402 * r1190402;
        double r1190404 = r1190401 + r1190403;
        double r1190405 = z;
        double r1190406 = r1190405 * r1190405;
        double r1190407 = r1190404 + r1190406;
        double r1190408 = sqrt(r1190407);
        double r1190409 = -1.6277133883021642e-179;
        bool r1190410 = r1190394 <= r1190409;
        double r1190411 = 7.277369115061499e+124;
        bool r1190412 = r1190394 <= r1190411;
        double r1190413 = r1190412 ? r1190408 : r1190394;
        double r1190414 = r1190410 ? r1190405 : r1190413;
        double r1190415 = r1190400 ? r1190408 : r1190414;
        double r1190416 = r1190396 ? r1190398 : r1190415;
        return r1190416;
}

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.8
Target25.6
Herbie25.6
\[\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 4 regimes
  2. if x < -6.600093290421653e+97

    1. Initial program 54.3

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

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

    if -6.600093290421653e+97 < x < -7.502177973232327e-160 or -1.6277133883021642e-179 < x < 7.277369115061499e+124

    1. Initial program 29.0

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

    if -7.502177973232327e-160 < x < -1.6277133883021642e-179

    1. Initial program 33.7

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

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

    if 7.277369115061499e+124 < x

    1. Initial program 58.4

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -6.60009329042165313 \cdot 10^{97}:\\ \;\;\;\;-1 \cdot x\\ \mathbf{elif}\;x \le -7.502177973232327 \cdot 10^{-160}:\\ \;\;\;\;\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}\\ \mathbf{elif}\;x \le -1.62771338830216422 \cdot 10^{-179}:\\ \;\;\;\;z\\ \mathbf{elif}\;x \le 7.27736911506149861 \cdot 10^{124}:\\ \;\;\;\;\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array}\]

Reproduce

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