Average Error: 38.1 → 26.2
Time: 1.2s
Precision: 64
\[\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}\]
\[\begin{array}{l} \mathbf{if}\;x \le -4.36083027610352862 \cdot 10^{110}:\\ \;\;\;\;-1 \cdot x\\ \mathbf{elif}\;x \le 6.32055311910495607 \cdot 10^{79}:\\ \;\;\;\;\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 -4.36083027610352862 \cdot 10^{110}:\\
\;\;\;\;-1 \cdot x\\

\mathbf{elif}\;x \le 6.32055311910495607 \cdot 10^{79}:\\
\;\;\;\;\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 r679538 = x;
        double r679539 = r679538 * r679538;
        double r679540 = y;
        double r679541 = r679540 * r679540;
        double r679542 = r679539 + r679541;
        double r679543 = z;
        double r679544 = r679543 * r679543;
        double r679545 = r679542 + r679544;
        double r679546 = sqrt(r679545);
        return r679546;
}

double f(double x, double y, double z) {
        double r679547 = x;
        double r679548 = -4.3608302761035286e+110;
        bool r679549 = r679547 <= r679548;
        double r679550 = -1.0;
        double r679551 = r679550 * r679547;
        double r679552 = 6.320553119104956e+79;
        bool r679553 = r679547 <= r679552;
        double r679554 = r679547 * r679547;
        double r679555 = y;
        double r679556 = r679555 * r679555;
        double r679557 = r679554 + r679556;
        double r679558 = z;
        double r679559 = r679558 * r679558;
        double r679560 = r679557 + r679559;
        double r679561 = sqrt(r679560);
        double r679562 = r679553 ? r679561 : r679547;
        double r679563 = r679549 ? r679551 : r679562;
        return r679563;
}

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.8
Herbie26.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 < -4.3608302761035286e+110

    1. Initial program 56.1

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

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

    if -4.3608302761035286e+110 < x < 6.320553119104956e+79

    1. Initial program 29.8

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

    if 6.320553119104956e+79 < x

    1. Initial program 52.0

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -4.36083027610352862 \cdot 10^{110}:\\ \;\;\;\;-1 \cdot x\\ \mathbf{elif}\;x \le 6.32055311910495607 \cdot 10^{79}:\\ \;\;\;\;\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array}\]

Reproduce

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