Average Error: 38.1 → 28.1
Time: 7.4s
Precision: 64
\[\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}\]
\[\begin{array}{l} \mathbf{if}\;x \le -3.392976980857097373698799426280579016197 \cdot 10^{74}:\\ \;\;\;\;-x\\ \mathbf{elif}\;x \le -2.707821872810366607173790892700689991865 \cdot 10^{-297}:\\ \;\;\;\;\sqrt{z \cdot z + \left(y \cdot y + x \cdot x\right)}\\ \mathbf{elif}\;x \le 5.893708537160267831832204882094624293929 \cdot 10^{-164}:\\ \;\;\;\;z\\ \mathbf{elif}\;x \le 6.610853035061558680305609626269336989806 \cdot 10^{124}:\\ \;\;\;\;\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 -3.392976980857097373698799426280579016197 \cdot 10^{74}:\\
\;\;\;\;-x\\

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

\mathbf{elif}\;x \le 5.893708537160267831832204882094624293929 \cdot 10^{-164}:\\
\;\;\;\;z\\

\mathbf{elif}\;x \le 6.610853035061558680305609626269336989806 \cdot 10^{124}:\\
\;\;\;\;\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 r377482 = x;
        double r377483 = r377482 * r377482;
        double r377484 = y;
        double r377485 = r377484 * r377484;
        double r377486 = r377483 + r377485;
        double r377487 = z;
        double r377488 = r377487 * r377487;
        double r377489 = r377486 + r377488;
        double r377490 = sqrt(r377489);
        return r377490;
}

double f(double x, double y, double z) {
        double r377491 = x;
        double r377492 = -3.3929769808570974e+74;
        bool r377493 = r377491 <= r377492;
        double r377494 = -r377491;
        double r377495 = -2.7078218728103666e-297;
        bool r377496 = r377491 <= r377495;
        double r377497 = z;
        double r377498 = r377497 * r377497;
        double r377499 = y;
        double r377500 = r377499 * r377499;
        double r377501 = r377491 * r377491;
        double r377502 = r377500 + r377501;
        double r377503 = r377498 + r377502;
        double r377504 = sqrt(r377503);
        double r377505 = 5.893708537160268e-164;
        bool r377506 = r377491 <= r377505;
        double r377507 = 6.610853035061559e+124;
        bool r377508 = r377491 <= r377507;
        double r377509 = r377508 ? r377504 : r377491;
        double r377510 = r377506 ? r377497 : r377509;
        double r377511 = r377496 ? r377504 : r377510;
        double r377512 = r377493 ? r377494 : r377511;
        return r377512;
}

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.1
Target25.2
Herbie28.1
\[\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.3929769808570974e+74

    1. Initial program 51.7

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

      \[\leadsto \color{blue}{-1 \cdot x}\]
    3. Simplified20.8

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

    if -3.3929769808570974e+74 < x < -2.7078218728103666e-297 or 5.893708537160268e-164 < x < 6.610853035061559e+124

    1. Initial program 29.2

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

    if -2.7078218728103666e-297 < x < 5.893708537160268e-164

    1. Initial program 32.0

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

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

    if 6.610853035061559e+124 < x

    1. Initial program 58.4

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -3.392976980857097373698799426280579016197 \cdot 10^{74}:\\ \;\;\;\;-x\\ \mathbf{elif}\;x \le -2.707821872810366607173790892700689991865 \cdot 10^{-297}:\\ \;\;\;\;\sqrt{z \cdot z + \left(y \cdot y + x \cdot x\right)}\\ \mathbf{elif}\;x \le 5.893708537160267831832204882094624293929 \cdot 10^{-164}:\\ \;\;\;\;z\\ \mathbf{elif}\;x \le 6.610853035061558680305609626269336989806 \cdot 10^{124}:\\ \;\;\;\;\sqrt{z \cdot z + \left(y \cdot y + x \cdot x\right)}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array}\]

Reproduce

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