Average Error: 37.1 → 25.8
Time: 9.8s
Precision: 64
\[\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}\]
\[\begin{array}{l} \mathbf{if}\;x \le -7.060606248743601504632612473600212365221 \cdot 10^{50}:\\ \;\;\;\;-x\\ \mathbf{elif}\;x \le 7.898403675517637649655314019741343921642 \cdot 10^{123}:\\ \;\;\;\;\sqrt{z \cdot z + \left(y \cdot y + x \cdot x\right)}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array}\]
\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}
\begin{array}{l}
\mathbf{if}\;x \le -7.060606248743601504632612473600212365221 \cdot 10^{50}:\\
\;\;\;\;-x\\

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

\mathbf{else}:\\
\;\;\;\;x\\

\end{array}
double f(double x, double y, double z) {
        double r32798296 = x;
        double r32798297 = r32798296 * r32798296;
        double r32798298 = y;
        double r32798299 = r32798298 * r32798298;
        double r32798300 = r32798297 + r32798299;
        double r32798301 = z;
        double r32798302 = r32798301 * r32798301;
        double r32798303 = r32798300 + r32798302;
        double r32798304 = sqrt(r32798303);
        return r32798304;
}

double f(double x, double y, double z) {
        double r32798305 = x;
        double r32798306 = -7.0606062487436015e+50;
        bool r32798307 = r32798305 <= r32798306;
        double r32798308 = -r32798305;
        double r32798309 = 7.898403675517638e+123;
        bool r32798310 = r32798305 <= r32798309;
        double r32798311 = z;
        double r32798312 = r32798311 * r32798311;
        double r32798313 = y;
        double r32798314 = r32798313 * r32798313;
        double r32798315 = r32798305 * r32798305;
        double r32798316 = r32798314 + r32798315;
        double r32798317 = r32798312 + r32798316;
        double r32798318 = sqrt(r32798317);
        double r32798319 = r32798310 ? r32798318 : r32798305;
        double r32798320 = r32798307 ? r32798308 : r32798319;
        return r32798320;
}

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.1
Target24.8
Herbie25.8
\[\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 < -7.0606062487436015e+50

    1. Initial program 47.6

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

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

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

    if -7.0606062487436015e+50 < x < 7.898403675517638e+123

    1. Initial program 29.1

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

    if 7.898403675517638e+123 < x

    1. Initial program 58.2

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -7.060606248743601504632612473600212365221 \cdot 10^{50}:\\ \;\;\;\;-x\\ \mathbf{elif}\;x \le 7.898403675517637649655314019741343921642 \cdot 10^{123}:\\ \;\;\;\;\sqrt{z \cdot z + \left(y \cdot y + x \cdot x\right)}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array}\]

Reproduce

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

  :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))))