Average Error: 37.7 → 25.8
Time: 7.9s
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 r484472 = x;
        double r484473 = r484472 * r484472;
        double r484474 = y;
        double r484475 = r484474 * r484474;
        double r484476 = r484473 + r484475;
        double r484477 = z;
        double r484478 = r484477 * r484477;
        double r484479 = r484476 + r484478;
        double r484480 = sqrt(r484479);
        return r484480;
}

double f(double x, double y, double z) {
        double r484481 = z;
        double r484482 = -2.0158187983075897e+101;
        bool r484483 = r484481 <= r484482;
        double r484484 = -r484481;
        double r484485 = -1.0571252577216274e-128;
        bool r484486 = r484481 <= r484485;
        double r484487 = r484481 * r484481;
        double r484488 = y;
        double r484489 = r484488 * r484488;
        double r484490 = x;
        double r484491 = r484490 * r484490;
        double r484492 = r484489 + r484491;
        double r484493 = r484487 + r484492;
        double r484494 = sqrt(r484493);
        double r484495 = -1.667229468183297e-140;
        bool r484496 = r484481 <= r484495;
        double r484497 = 5.835216049861505e+140;
        bool r484498 = r484481 <= r484497;
        double r484499 = r484498 ? r484494 : r484481;
        double r484500 = r484496 ? r484488 : r484499;
        double r484501 = r484486 ? r484494 : r484500;
        double r484502 = r484483 ? r484484 : r484501;
        return r484502;
}

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