Average Error: 37.8 → 27.0
Time: 4.1s
Precision: 64
\[\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}\]
\[\begin{array}{l} \mathbf{if}\;x \le -2.016424411749676 \cdot 10^{133}:\\ \;\;\;\;-1 \cdot x\\ \mathbf{elif}\;x \le 1.4232710093281964 \cdot 10^{-37}:\\ \;\;\;\;\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}\\ \mathbf{elif}\;x \le 5.4695075101521495 \cdot 10^{42}:\\ \;\;\;\;z\\ \mathbf{elif}\;x \le 1.199826361110612 \cdot 10^{75}:\\ \;\;\;\;\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 -2.016424411749676 \cdot 10^{133}:\\
\;\;\;\;-1 \cdot x\\

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

\mathbf{elif}\;x \le 5.4695075101521495 \cdot 10^{42}:\\
\;\;\;\;z\\

\mathbf{elif}\;x \le 1.199826361110612 \cdot 10^{75}:\\
\;\;\;\;\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 r733495 = x;
        double r733496 = r733495 * r733495;
        double r733497 = y;
        double r733498 = r733497 * r733497;
        double r733499 = r733496 + r733498;
        double r733500 = z;
        double r733501 = r733500 * r733500;
        double r733502 = r733499 + r733501;
        double r733503 = sqrt(r733502);
        return r733503;
}

double f(double x, double y, double z) {
        double r733504 = x;
        double r733505 = -2.016424411749676e+133;
        bool r733506 = r733504 <= r733505;
        double r733507 = -1.0;
        double r733508 = r733507 * r733504;
        double r733509 = 1.4232710093281964e-37;
        bool r733510 = r733504 <= r733509;
        double r733511 = r733504 * r733504;
        double r733512 = y;
        double r733513 = r733512 * r733512;
        double r733514 = r733511 + r733513;
        double r733515 = z;
        double r733516 = r733515 * r733515;
        double r733517 = r733514 + r733516;
        double r733518 = sqrt(r733517);
        double r733519 = 5.4695075101521495e+42;
        bool r733520 = r733504 <= r733519;
        double r733521 = 1.199826361110612e+75;
        bool r733522 = r733504 <= r733521;
        double r733523 = r733522 ? r733518 : r733504;
        double r733524 = r733520 ? r733515 : r733523;
        double r733525 = r733510 ? r733518 : r733524;
        double r733526 = r733506 ? r733508 : r733525;
        return r733526;
}

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.5
Herbie27.0
\[\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 < -2.016424411749676e+133

    1. Initial program 59.7

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

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

    if -2.016424411749676e+133 < x < 1.4232710093281964e-37 or 5.4695075101521495e+42 < x < 1.199826361110612e+75

    1. Initial program 29.3

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

    if 1.4232710093281964e-37 < x < 5.4695075101521495e+42

    1. Initial program 27.8

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

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

    if 1.199826361110612e+75 < x

    1. Initial program 52.4

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -2.016424411749676 \cdot 10^{133}:\\ \;\;\;\;-1 \cdot x\\ \mathbf{elif}\;x \le 1.4232710093281964 \cdot 10^{-37}:\\ \;\;\;\;\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}\\ \mathbf{elif}\;x \le 5.4695075101521495 \cdot 10^{42}:\\ \;\;\;\;z\\ \mathbf{elif}\;x \le 1.199826361110612 \cdot 10^{75}:\\ \;\;\;\;\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array}\]

Reproduce

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