Average Error: 38.2 → 25.7
Time: 7.8s
Precision: 64
\[\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}\]
\[\begin{array}{l} \mathbf{if}\;x \le -2.199349386776017456661293481624717960114 \cdot 10^{110}:\\ \;\;\;\;-x\\ \mathbf{elif}\;x \le 3.408719160070714088752655754041470680881 \cdot 10^{143}:\\ \;\;\;\;\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 -2.199349386776017456661293481624717960114 \cdot 10^{110}:\\
\;\;\;\;-x\\

\mathbf{elif}\;x \le 3.408719160070714088752655754041470680881 \cdot 10^{143}:\\
\;\;\;\;\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 r32626294 = x;
        double r32626295 = r32626294 * r32626294;
        double r32626296 = y;
        double r32626297 = r32626296 * r32626296;
        double r32626298 = r32626295 + r32626297;
        double r32626299 = z;
        double r32626300 = r32626299 * r32626299;
        double r32626301 = r32626298 + r32626300;
        double r32626302 = sqrt(r32626301);
        return r32626302;
}

double f(double x, double y, double z) {
        double r32626303 = x;
        double r32626304 = -2.1993493867760175e+110;
        bool r32626305 = r32626303 <= r32626304;
        double r32626306 = -r32626303;
        double r32626307 = 3.408719160070714e+143;
        bool r32626308 = r32626303 <= r32626307;
        double r32626309 = z;
        double r32626310 = r32626309 * r32626309;
        double r32626311 = y;
        double r32626312 = r32626311 * r32626311;
        double r32626313 = r32626303 * r32626303;
        double r32626314 = r32626312 + r32626313;
        double r32626315 = r32626310 + r32626314;
        double r32626316 = sqrt(r32626315);
        double r32626317 = r32626308 ? r32626316 : r32626303;
        double r32626318 = r32626305 ? r32626306 : r32626317;
        return r32626318;
}

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.2
Target25.7
Herbie25.7
\[\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.1993493867760175e+110

    1. Initial program 56.6

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

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

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

    if -2.1993493867760175e+110 < x < 3.408719160070714e+143

    1. Initial program 29.5

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

    if 3.408719160070714e+143 < x

    1. Initial program 61.8

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -2.199349386776017456661293481624717960114 \cdot 10^{110}:\\ \;\;\;\;-x\\ \mathbf{elif}\;x \le 3.408719160070714088752655754041470680881 \cdot 10^{143}:\\ \;\;\;\;\sqrt{z \cdot z + \left(y \cdot y + x \cdot x\right)}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array}\]

Reproduce

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