Average Error: 38.4 → 25.6
Time: 3.7s
Precision: 64
\[\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}\]
\[\begin{array}{l} \mathbf{if}\;x \le -2.344189575344254982519991103329315240932 \cdot 10^{116}:\\ \;\;\;\;-1 \cdot x\\ \mathbf{elif}\;x \le 1.038735686858710929062176730744016244556 \cdot 10^{130}:\\ \;\;\;\;\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.344189575344254982519991103329315240932 \cdot 10^{116}:\\
\;\;\;\;-1 \cdot x\\

\mathbf{elif}\;x \le 1.038735686858710929062176730744016244556 \cdot 10^{130}:\\
\;\;\;\;\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 r494998 = x;
        double r494999 = r494998 * r494998;
        double r495000 = y;
        double r495001 = r495000 * r495000;
        double r495002 = r494999 + r495001;
        double r495003 = z;
        double r495004 = r495003 * r495003;
        double r495005 = r495002 + r495004;
        double r495006 = sqrt(r495005);
        return r495006;
}

double f(double x, double y, double z) {
        double r495007 = x;
        double r495008 = -2.344189575344255e+116;
        bool r495009 = r495007 <= r495008;
        double r495010 = -1.0;
        double r495011 = r495010 * r495007;
        double r495012 = 1.0387356868587109e+130;
        bool r495013 = r495007 <= r495012;
        double r495014 = r495007 * r495007;
        double r495015 = y;
        double r495016 = r495015 * r495015;
        double r495017 = r495014 + r495016;
        double r495018 = z;
        double r495019 = r495018 * r495018;
        double r495020 = r495017 + r495019;
        double r495021 = sqrt(r495020);
        double r495022 = r495013 ? r495021 : r495007;
        double r495023 = r495009 ? r495011 : r495022;
        return r495023;
}

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.4
Target25.9
Herbie25.6
\[\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.344189575344255e+116

    1. Initial program 56.6

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

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

    if -2.344189575344255e+116 < x < 1.0387356868587109e+130

    1. Initial program 29.8

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

    if 1.0387356868587109e+130 < x

    1. Initial program 59.1

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -2.344189575344254982519991103329315240932 \cdot 10^{116}:\\ \;\;\;\;-1 \cdot x\\ \mathbf{elif}\;x \le 1.038735686858710929062176730744016244556 \cdot 10^{130}:\\ \;\;\;\;\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array}\]

Reproduce

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