Average Error: 38.2 → 25.9
Time: 5.9s
Precision: 64
\[\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}\]
\[\begin{array}{l} \mathbf{if}\;x \le -9.708346480390896462673015323847225793618 \cdot 10^{60}:\\ \;\;\;\;-x\\ \mathbf{elif}\;x \le 3.944222842624814118300636568846403967432 \cdot 10^{93}:\\ \;\;\;\;\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 -9.708346480390896462673015323847225793618 \cdot 10^{60}:\\
\;\;\;\;-x\\

\mathbf{elif}\;x \le 3.944222842624814118300636568846403967432 \cdot 10^{93}:\\
\;\;\;\;\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 r32702079 = x;
        double r32702080 = r32702079 * r32702079;
        double r32702081 = y;
        double r32702082 = r32702081 * r32702081;
        double r32702083 = r32702080 + r32702082;
        double r32702084 = z;
        double r32702085 = r32702084 * r32702084;
        double r32702086 = r32702083 + r32702085;
        double r32702087 = sqrt(r32702086);
        return r32702087;
}

double f(double x, double y, double z) {
        double r32702088 = x;
        double r32702089 = -9.708346480390896e+60;
        bool r32702090 = r32702088 <= r32702089;
        double r32702091 = -r32702088;
        double r32702092 = 3.944222842624814e+93;
        bool r32702093 = r32702088 <= r32702092;
        double r32702094 = z;
        double r32702095 = r32702094 * r32702094;
        double r32702096 = y;
        double r32702097 = r32702096 * r32702096;
        double r32702098 = r32702088 * r32702088;
        double r32702099 = r32702097 + r32702098;
        double r32702100 = r32702095 + r32702099;
        double r32702101 = sqrt(r32702100);
        double r32702102 = r32702093 ? r32702101 : r32702088;
        double r32702103 = r32702090 ? r32702091 : r32702102;
        return r32702103;
}

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.9
Herbie25.9
\[\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 < -9.708346480390896e+60

    1. Initial program 50.4

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

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

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

    if -9.708346480390896e+60 < x < 3.944222842624814e+93

    1. Initial program 29.6

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

    if 3.944222842624814e+93 < x

    1. Initial program 54.7

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -9.708346480390896462673015323847225793618 \cdot 10^{60}:\\ \;\;\;\;-x\\ \mathbf{elif}\;x \le 3.944222842624814118300636568846403967432 \cdot 10^{93}:\\ \;\;\;\;\sqrt{z \cdot z + \left(y \cdot y + x \cdot x\right)}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array}\]

Reproduce

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