Average Error: 38.6 → 26.9
Time: 3.6s
Precision: 64
\[\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}\]
\[\begin{array}{l} \mathbf{if}\;x \le -9.893983514208573471491540982534572022572 \cdot 10^{152}:\\ \;\;\;\;-1 \cdot x\\ \mathbf{elif}\;x \le -2.623547536657377133536502149572890753313 \cdot 10^{-278}:\\ \;\;\;\;\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}\\ \mathbf{elif}\;x \le -8.416887720474182221763875588195087644835 \cdot 10^{-307}:\\ \;\;\;\;z\\ \mathbf{elif}\;x \le 3.871233825359605951288495732077425103951 \cdot 10^{64}:\\ \;\;\;\;\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 -9.893983514208573471491540982534572022572 \cdot 10^{152}:\\
\;\;\;\;-1 \cdot x\\

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

\mathbf{elif}\;x \le -8.416887720474182221763875588195087644835 \cdot 10^{-307}:\\
\;\;\;\;z\\

\mathbf{elif}\;x \le 3.871233825359605951288495732077425103951 \cdot 10^{64}:\\
\;\;\;\;\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 r514227 = x;
        double r514228 = r514227 * r514227;
        double r514229 = y;
        double r514230 = r514229 * r514229;
        double r514231 = r514228 + r514230;
        double r514232 = z;
        double r514233 = r514232 * r514232;
        double r514234 = r514231 + r514233;
        double r514235 = sqrt(r514234);
        return r514235;
}

double f(double x, double y, double z) {
        double r514236 = x;
        double r514237 = -9.893983514208573e+152;
        bool r514238 = r514236 <= r514237;
        double r514239 = -1.0;
        double r514240 = r514239 * r514236;
        double r514241 = -2.623547536657377e-278;
        bool r514242 = r514236 <= r514241;
        double r514243 = r514236 * r514236;
        double r514244 = y;
        double r514245 = r514244 * r514244;
        double r514246 = r514243 + r514245;
        double r514247 = z;
        double r514248 = r514247 * r514247;
        double r514249 = r514246 + r514248;
        double r514250 = sqrt(r514249);
        double r514251 = -8.416887720474182e-307;
        bool r514252 = r514236 <= r514251;
        double r514253 = 3.871233825359606e+64;
        bool r514254 = r514236 <= r514253;
        double r514255 = r514254 ? r514250 : r514236;
        double r514256 = r514252 ? r514247 : r514255;
        double r514257 = r514242 ? r514250 : r514256;
        double r514258 = r514238 ? r514240 : r514257;
        return r514258;
}

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.6
Target25.6
Herbie26.9
\[\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 4 regimes
  2. if x < -9.893983514208573e+152

    1. Initial program 63.9

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

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

    if -9.893983514208573e+152 < x < -2.623547536657377e-278 or -8.416887720474182e-307 < x < 3.871233825359606e+64

    1. Initial program 30.0

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

    if -2.623547536657377e-278 < x < -8.416887720474182e-307

    1. Initial program 32.4

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

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

    if 3.871233825359606e+64 < x

    1. Initial program 51.1

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -9.893983514208573471491540982534572022572 \cdot 10^{152}:\\ \;\;\;\;-1 \cdot x\\ \mathbf{elif}\;x \le -2.623547536657377133536502149572890753313 \cdot 10^{-278}:\\ \;\;\;\;\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}\\ \mathbf{elif}\;x \le -8.416887720474182221763875588195087644835 \cdot 10^{-307}:\\ \;\;\;\;z\\ \mathbf{elif}\;x \le 3.871233825359605951288495732077425103951 \cdot 10^{64}:\\ \;\;\;\;\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array}\]

Reproduce

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