Average Error: 37.7 → 25.8
Time: 8.0s
Precision: 64
\[\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}\]
\[\begin{array}{l} \mathbf{if}\;z \le -2.015818798307589698471256123888820846637 \cdot 10^{101}:\\ \;\;\;\;-z\\ \mathbf{elif}\;z \le -1.057125257721627397236301082579382629389 \cdot 10^{-128}:\\ \;\;\;\;\sqrt{z \cdot z + \left(y \cdot y + x \cdot x\right)}\\ \mathbf{elif}\;z \le -1.667229468183296932651493990427109777518 \cdot 10^{-140}:\\ \;\;\;\;y\\ \mathbf{elif}\;z \le 5.835216049861505255575859015333496730733 \cdot 10^{140}:\\ \;\;\;\;\sqrt{z \cdot z + \left(y \cdot y + x \cdot x\right)}\\ \mathbf{else}:\\ \;\;\;\;z\\ \end{array}\]
\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}
\begin{array}{l}
\mathbf{if}\;z \le -2.015818798307589698471256123888820846637 \cdot 10^{101}:\\
\;\;\;\;-z\\

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

\mathbf{elif}\;z \le -1.667229468183296932651493990427109777518 \cdot 10^{-140}:\\
\;\;\;\;y\\

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

\mathbf{else}:\\
\;\;\;\;z\\

\end{array}
double f(double x, double y, double z) {
        double r605406 = x;
        double r605407 = r605406 * r605406;
        double r605408 = y;
        double r605409 = r605408 * r605408;
        double r605410 = r605407 + r605409;
        double r605411 = z;
        double r605412 = r605411 * r605411;
        double r605413 = r605410 + r605412;
        double r605414 = sqrt(r605413);
        return r605414;
}

double f(double x, double y, double z) {
        double r605415 = z;
        double r605416 = -2.0158187983075897e+101;
        bool r605417 = r605415 <= r605416;
        double r605418 = -r605415;
        double r605419 = -1.0571252577216274e-128;
        bool r605420 = r605415 <= r605419;
        double r605421 = r605415 * r605415;
        double r605422 = y;
        double r605423 = r605422 * r605422;
        double r605424 = x;
        double r605425 = r605424 * r605424;
        double r605426 = r605423 + r605425;
        double r605427 = r605421 + r605426;
        double r605428 = sqrt(r605427);
        double r605429 = -1.667229468183297e-140;
        bool r605430 = r605415 <= r605429;
        double r605431 = 5.835216049861505e+140;
        bool r605432 = r605415 <= r605431;
        double r605433 = r605432 ? r605428 : r605415;
        double r605434 = r605430 ? r605422 : r605433;
        double r605435 = r605420 ? r605428 : r605434;
        double r605436 = r605417 ? r605418 : r605435;
        return r605436;
}

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.6
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 z < -2.0158187983075897e+101

    1. Initial program 54.5

      \[\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}\]
    2. Simplified54.5

      \[\leadsto \color{blue}{\sqrt{z \cdot z + \left(x \cdot x + y \cdot y\right)}}\]
    3. Taylor expanded around -inf 18.6

      \[\leadsto \color{blue}{-1 \cdot z}\]
    4. Simplified18.6

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

    if -2.0158187983075897e+101 < z < -1.0571252577216274e-128 or -1.667229468183297e-140 < z < 5.835216049861505e+140

    1. Initial program 29.3

      \[\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}\]
    2. Simplified29.3

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

    if -1.0571252577216274e-128 < z < -1.667229468183297e-140

    1. Initial program 32.0

      \[\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}\]
    2. Simplified32.0

      \[\leadsto \color{blue}{\sqrt{z \cdot z + \left(x \cdot x + y \cdot y\right)}}\]
    3. Taylor expanded around 0 48.3

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

    if 5.835216049861505e+140 < z

    1. Initial program 61.9

      \[\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}\]
    2. Simplified61.9

      \[\leadsto \color{blue}{\sqrt{z \cdot z + \left(x \cdot x + y \cdot y\right)}}\]
    3. Taylor expanded around inf 14.7

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;z \le -2.015818798307589698471256123888820846637 \cdot 10^{101}:\\ \;\;\;\;-z\\ \mathbf{elif}\;z \le -1.057125257721627397236301082579382629389 \cdot 10^{-128}:\\ \;\;\;\;\sqrt{z \cdot z + \left(y \cdot y + x \cdot x\right)}\\ \mathbf{elif}\;z \le -1.667229468183296932651493990427109777518 \cdot 10^{-140}:\\ \;\;\;\;y\\ \mathbf{elif}\;z \le 5.835216049861505255575859015333496730733 \cdot 10^{140}:\\ \;\;\;\;\sqrt{z \cdot z + \left(y \cdot y + x \cdot x\right)}\\ \mathbf{else}:\\ \;\;\;\;z\\ \end{array}\]

Reproduce

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

  :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))))