Average Error: 38.4 → 25.6
Time: 5.2s
Precision: 64
\[\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}\]
\[\begin{array}{l} \mathbf{if}\;x \le -1.514147348156684897594805824258822056861 \cdot 10^{135}:\\ \;\;\;\;-1 \cdot x\\ \mathbf{elif}\;x \le 2.273383634008566533481719288833752498864 \cdot 10^{132}:\\ \;\;\;\;\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 -1.514147348156684897594805824258822056861 \cdot 10^{135}:\\
\;\;\;\;-1 \cdot x\\

\mathbf{elif}\;x \le 2.273383634008566533481719288833752498864 \cdot 10^{132}:\\
\;\;\;\;\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 r588250 = x;
        double r588251 = r588250 * r588250;
        double r588252 = y;
        double r588253 = r588252 * r588252;
        double r588254 = r588251 + r588253;
        double r588255 = z;
        double r588256 = r588255 * r588255;
        double r588257 = r588254 + r588256;
        double r588258 = sqrt(r588257);
        return r588258;
}

double f(double x, double y, double z) {
        double r588259 = x;
        double r588260 = -1.514147348156685e+135;
        bool r588261 = r588259 <= r588260;
        double r588262 = -1.0;
        double r588263 = r588262 * r588259;
        double r588264 = 2.2733836340085665e+132;
        bool r588265 = r588259 <= r588264;
        double r588266 = r588259 * r588259;
        double r588267 = y;
        double r588268 = r588267 * r588267;
        double r588269 = r588266 + r588268;
        double r588270 = z;
        double r588271 = r588270 * r588270;
        double r588272 = r588269 + r588271;
        double r588273 = sqrt(r588272);
        double r588274 = r588265 ? r588273 : r588259;
        double r588275 = r588261 ? r588263 : r588274;
        return r588275;
}

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.8
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 < -1.514147348156685e+135

    1. Initial program 60.9

      \[\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 -1.514147348156685e+135 < x < 2.2733836340085665e+132

    1. Initial program 29.6

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

    if 2.2733836340085665e+132 < x

    1. Initial program 59.6

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -1.514147348156684897594805824258822056861 \cdot 10^{135}:\\ \;\;\;\;-1 \cdot x\\ \mathbf{elif}\;x \le 2.273383634008566533481719288833752498864 \cdot 10^{132}:\\ \;\;\;\;\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array}\]

Reproduce

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