Average Error: 38.2 → 25.2
Time: 2.1s
Precision: 64
\[\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}\]
\[\begin{array}{l} \mathbf{if}\;x \le -3.07433912200013139 \cdot 10^{144}:\\ \;\;\;\;-x\\ \mathbf{elif}\;x \le 4.24489976765657814 \cdot 10^{97}:\\ \;\;\;\;\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 -3.07433912200013139 \cdot 10^{144}:\\
\;\;\;\;-x\\

\mathbf{elif}\;x \le 4.24489976765657814 \cdot 10^{97}:\\
\;\;\;\;\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 r704423 = x;
        double r704424 = r704423 * r704423;
        double r704425 = y;
        double r704426 = r704425 * r704425;
        double r704427 = r704424 + r704426;
        double r704428 = z;
        double r704429 = r704428 * r704428;
        double r704430 = r704427 + r704429;
        double r704431 = sqrt(r704430);
        return r704431;
}

double f(double x, double y, double z) {
        double r704432 = x;
        double r704433 = -3.0743391220001314e+144;
        bool r704434 = r704432 <= r704433;
        double r704435 = -r704432;
        double r704436 = 4.244899767656578e+97;
        bool r704437 = r704432 <= r704436;
        double r704438 = r704432 * r704432;
        double r704439 = y;
        double r704440 = r704439 * r704439;
        double r704441 = r704438 + r704440;
        double r704442 = z;
        double r704443 = r704442 * r704442;
        double r704444 = r704441 + r704443;
        double r704445 = sqrt(r704444);
        double r704446 = r704437 ? r704445 : r704432;
        double r704447 = r704434 ? r704435 : r704446;
        return r704447;
}

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.2
Target25.9
Herbie25.2
\[\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 3 regimes
  2. if x < -3.0743391220001314e+144

    1. Initial program 61.9

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

      \[\leadsto \color{blue}{-1 \cdot x}\]
    3. Simplified13.6

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

    if -3.0743391220001314e+144 < x < 4.244899767656578e+97

    1. Initial program 29.1

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

    if 4.244899767656578e+97 < x

    1. Initial program 54.8

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -3.07433912200013139 \cdot 10^{144}:\\ \;\;\;\;-x\\ \mathbf{elif}\;x \le 4.24489976765657814 \cdot 10^{97}:\\ \;\;\;\;\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array}\]

Reproduce

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