Average Error: 38.2 → 25.7
Time: 7.6s
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{\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.199349386776017456661293481624717960114 \cdot 10^{110}:\\
\;\;\;\;-x\\

\mathbf{elif}\;x \le 3.408719160070714088752655754041470680881 \cdot 10^{143}:\\
\;\;\;\;\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 r42605385 = x;
        double r42605386 = r42605385 * r42605385;
        double r42605387 = y;
        double r42605388 = r42605387 * r42605387;
        double r42605389 = r42605386 + r42605388;
        double r42605390 = z;
        double r42605391 = r42605390 * r42605390;
        double r42605392 = r42605389 + r42605391;
        double r42605393 = sqrt(r42605392);
        return r42605393;
}

double f(double x, double y, double z) {
        double r42605394 = x;
        double r42605395 = -2.1993493867760175e+110;
        bool r42605396 = r42605394 <= r42605395;
        double r42605397 = -r42605394;
        double r42605398 = 3.408719160070714e+143;
        bool r42605399 = r42605394 <= r42605398;
        double r42605400 = r42605394 * r42605394;
        double r42605401 = y;
        double r42605402 = r42605401 * r42605401;
        double r42605403 = r42605400 + r42605402;
        double r42605404 = z;
        double r42605405 = r42605404 * r42605404;
        double r42605406 = r42605403 + r42605405;
        double r42605407 = sqrt(r42605406);
        double r42605408 = r42605399 ? r42605407 : r42605394;
        double r42605409 = r42605396 ? r42605397 : r42605408;
        return r42605409;
}

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{\left(x \cdot x + y \cdot y\right) + z \cdot z}\\ \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))))