Average Error: 38.0 → 26.0
Time: 12.6s
Precision: 64
\[\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}\]
\[\begin{array}{l} \mathbf{if}\;x \le -2.061657435745164054885343908681554798474 \cdot 10^{101}:\\ \;\;\;\;-x\\ \mathbf{elif}\;x \le 2.030268028165567603283501741474824619367 \cdot 10^{-131}:\\ \;\;\;\;\sqrt{z \cdot z + \left(y \cdot y + x \cdot x\right)}\\ \mathbf{elif}\;x \le 9.401516089224205428725032958536335802456 \cdot 10^{-110}:\\ \;\;\;\;z\\ \mathbf{elif}\;x \le 1.507674832315874830585518015460277676166 \cdot 10^{110}:\\ \;\;\;\;\sqrt{z \cdot z + \left(y \cdot y + x \cdot x\right)}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array}\]
\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}
\begin{array}{l}
\mathbf{if}\;x \le -2.061657435745164054885343908681554798474 \cdot 10^{101}:\\
\;\;\;\;-x\\

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

\mathbf{elif}\;x \le 9.401516089224205428725032958536335802456 \cdot 10^{-110}:\\
\;\;\;\;z\\

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

\mathbf{else}:\\
\;\;\;\;x\\

\end{array}
double f(double x, double y, double z) {
        double r34315347 = x;
        double r34315348 = r34315347 * r34315347;
        double r34315349 = y;
        double r34315350 = r34315349 * r34315349;
        double r34315351 = r34315348 + r34315350;
        double r34315352 = z;
        double r34315353 = r34315352 * r34315352;
        double r34315354 = r34315351 + r34315353;
        double r34315355 = sqrt(r34315354);
        return r34315355;
}

double f(double x, double y, double z) {
        double r34315356 = x;
        double r34315357 = -2.061657435745164e+101;
        bool r34315358 = r34315356 <= r34315357;
        double r34315359 = -r34315356;
        double r34315360 = 2.0302680281655676e-131;
        bool r34315361 = r34315356 <= r34315360;
        double r34315362 = z;
        double r34315363 = r34315362 * r34315362;
        double r34315364 = y;
        double r34315365 = r34315364 * r34315364;
        double r34315366 = r34315356 * r34315356;
        double r34315367 = r34315365 + r34315366;
        double r34315368 = r34315363 + r34315367;
        double r34315369 = sqrt(r34315368);
        double r34315370 = 9.401516089224205e-110;
        bool r34315371 = r34315356 <= r34315370;
        double r34315372 = 1.5076748323158748e+110;
        bool r34315373 = r34315356 <= r34315372;
        double r34315374 = r34315373 ? r34315369 : r34315356;
        double r34315375 = r34315371 ? r34315362 : r34315374;
        double r34315376 = r34315361 ? r34315369 : r34315375;
        double r34315377 = r34315358 ? r34315359 : r34315376;
        return r34315377;
}

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

Original38.0
Target25.7
Herbie26.0
\[\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 < -2.061657435745164e+101

    1. Initial program 54.3

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

      \[\leadsto \color{blue}{-1 \cdot x}\]
    3. Simplified17.7

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

    if -2.061657435745164e+101 < x < 2.0302680281655676e-131 or 9.401516089224205e-110 < x < 1.5076748323158748e+110

    1. Initial program 29.7

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

    if 2.0302680281655676e-131 < x < 9.401516089224205e-110

    1. Initial program 29.1

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

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

    if 1.5076748323158748e+110 < x

    1. Initial program 55.7

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -2.061657435745164054885343908681554798474 \cdot 10^{101}:\\ \;\;\;\;-x\\ \mathbf{elif}\;x \le 2.030268028165567603283501741474824619367 \cdot 10^{-131}:\\ \;\;\;\;\sqrt{z \cdot z + \left(y \cdot y + x \cdot x\right)}\\ \mathbf{elif}\;x \le 9.401516089224205428725032958536335802456 \cdot 10^{-110}:\\ \;\;\;\;z\\ \mathbf{elif}\;x \le 1.507674832315874830585518015460277676166 \cdot 10^{110}:\\ \;\;\;\;\sqrt{z \cdot z + \left(y \cdot y + x \cdot x\right)}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array}\]

Reproduce

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