Average Error: 37.5 → 25.8
Time: 1.6s
Precision: 64
\[\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}\]
\[\begin{array}{l} \mathbf{if}\;x \le -2.225117955444305 \cdot 10^{79}:\\ \;\;\;\;-1 \cdot x\\ \mathbf{elif}\;x \le 3.509581298916955 \cdot 10^{90}:\\ \;\;\;\;\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.225117955444305 \cdot 10^{79}:\\
\;\;\;\;-1 \cdot x\\

\mathbf{elif}\;x \le 3.509581298916955 \cdot 10^{90}:\\
\;\;\;\;\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 r677334 = x;
        double r677335 = r677334 * r677334;
        double r677336 = y;
        double r677337 = r677336 * r677336;
        double r677338 = r677335 + r677337;
        double r677339 = z;
        double r677340 = r677339 * r677339;
        double r677341 = r677338 + r677340;
        double r677342 = sqrt(r677341);
        return r677342;
}

double f(double x, double y, double z) {
        double r677343 = x;
        double r677344 = -2.225117955444305e+79;
        bool r677345 = r677343 <= r677344;
        double r677346 = -1.0;
        double r677347 = r677346 * r677343;
        double r677348 = 3.509581298916955e+90;
        bool r677349 = r677343 <= r677348;
        double r677350 = r677343 * r677343;
        double r677351 = y;
        double r677352 = r677351 * r677351;
        double r677353 = r677350 + r677352;
        double r677354 = z;
        double r677355 = r677354 * r677354;
        double r677356 = r677353 + r677355;
        double r677357 = sqrt(r677356);
        double r677358 = r677349 ? r677357 : r677343;
        double r677359 = r677345 ? r677347 : r677358;
        return r677359;
}

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.5
Target25.1
Herbie25.8
\[\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 < -2.225117955444305e+79

    1. Initial program 50.7

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

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

    if -2.225117955444305e+79 < x < 3.509581298916955e+90

    1. Initial program 29.6

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

    if 3.509581298916955e+90 < x

    1. Initial program 53.5

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

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

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

Reproduce

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