Average Error: 37.7 → 25.5
Time: 5.8s
Precision: 64
\[\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}\]
\[\begin{array}{l} \mathbf{if}\;x \le -2.467174117849677708571701352829713367668 \cdot 10^{104}:\\ \;\;\;\;-x\\ \mathbf{elif}\;x \le 2.822964666556508986496297792793531329942 \cdot 10^{137}:\\ \;\;\;\;\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.467174117849677708571701352829713367668 \cdot 10^{104}:\\
\;\;\;\;-x\\

\mathbf{elif}\;x \le 2.822964666556508986496297792793531329942 \cdot 10^{137}:\\
\;\;\;\;\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 r434351 = x;
        double r434352 = r434351 * r434351;
        double r434353 = y;
        double r434354 = r434353 * r434353;
        double r434355 = r434352 + r434354;
        double r434356 = z;
        double r434357 = r434356 * r434356;
        double r434358 = r434355 + r434357;
        double r434359 = sqrt(r434358);
        return r434359;
}

double f(double x, double y, double z) {
        double r434360 = x;
        double r434361 = -2.4671741178496777e+104;
        bool r434362 = r434360 <= r434361;
        double r434363 = -r434360;
        double r434364 = 2.822964666556509e+137;
        bool r434365 = r434360 <= r434364;
        double r434366 = r434360 * r434360;
        double r434367 = y;
        double r434368 = r434367 * r434367;
        double r434369 = r434366 + r434368;
        double r434370 = z;
        double r434371 = r434370 * r434370;
        double r434372 = r434369 + r434371;
        double r434373 = sqrt(r434372);
        double r434374 = r434365 ? r434373 : r434360;
        double r434375 = r434362 ? r434363 : r434374;
        return r434375;
}

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.7
Target25.0
Herbie25.5
\[\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 3 regimes
  2. if x < -2.4671741178496777e+104

    1. Initial program 55.3

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

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

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

    if -2.4671741178496777e+104 < x < 2.822964666556509e+137

    1. Initial program 28.9

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

    if 2.822964666556509e+137 < x

    1. Initial program 61.2

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -2.467174117849677708571701352829713367668 \cdot 10^{104}:\\ \;\;\;\;-x\\ \mathbf{elif}\;x \le 2.822964666556508986496297792793531329942 \cdot 10^{137}:\\ \;\;\;\;\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array}\]

Reproduce

herbie shell --seed 2019209 
(FPCore (x y z)
  :name "FRP.Yampa.Vector3:vector3Rho from Yampa-0.10.2"
  :precision binary64

  :herbie-target
  (if (< z -6.3964793941097758e136) (- z) (if (< z 7.3202936944041821e117) (sqrt (+ (+ (* z z) (* x x)) (* y y))) z))

  (sqrt (+ (+ (* x x) (* y y)) (* z z))))