Average Error: 38.2 → 27.3
Time: 2.1s
Precision: 64
\[\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}\]
\[\begin{array}{l} \mathbf{if}\;x \le -3.4794970398246474 \cdot 10^{55}:\\ \;\;\;\;-1 \cdot x\\ \mathbf{elif}\;x \le 4.54583198998115572 \cdot 10^{65}:\\ \;\;\;\;\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}\\ \mathbf{elif}\;x \le 1.59746099954173198 \cdot 10^{121}:\\ \;\;\;\;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 -3.4794970398246474 \cdot 10^{55}:\\
\;\;\;\;-1 \cdot x\\

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

\mathbf{elif}\;x \le 1.59746099954173198 \cdot 10^{121}:\\
\;\;\;\;z\\

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

\end{array}
double f(double x, double y, double z) {
        double r686183 = x;
        double r686184 = r686183 * r686183;
        double r686185 = y;
        double r686186 = r686185 * r686185;
        double r686187 = r686184 + r686186;
        double r686188 = z;
        double r686189 = r686188 * r686188;
        double r686190 = r686187 + r686189;
        double r686191 = sqrt(r686190);
        return r686191;
}

double f(double x, double y, double z) {
        double r686192 = x;
        double r686193 = -3.4794970398246474e+55;
        bool r686194 = r686192 <= r686193;
        double r686195 = -1.0;
        double r686196 = r686195 * r686192;
        double r686197 = 4.545831989981156e+65;
        bool r686198 = r686192 <= r686197;
        double r686199 = r686192 * r686192;
        double r686200 = y;
        double r686201 = r686200 * r686200;
        double r686202 = r686199 + r686201;
        double r686203 = z;
        double r686204 = r686203 * r686203;
        double r686205 = r686202 + r686204;
        double r686206 = sqrt(r686205);
        double r686207 = 1.597460999541732e+121;
        bool r686208 = r686192 <= r686207;
        double r686209 = r686208 ? r686203 : r686192;
        double r686210 = r686198 ? r686206 : r686209;
        double r686211 = r686194 ? r686196 : r686210;
        return r686211;
}

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.5
Herbie27.3
\[\begin{array}{l} \mathbf{if}\;z \lt -6.3964793941097758 \cdot 10^{136}:\\ \;\;\;\;-z\\ \mathbf{elif}\;z \lt 7.3202936944041821 \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 4 regimes
  2. if x < -3.4794970398246474e+55

    1. Initial program 49.3

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

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

    if -3.4794970398246474e+55 < x < 4.545831989981156e+65

    1. Initial program 29.9

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

    if 4.545831989981156e+65 < x < 1.597460999541732e+121

    1. Initial program 29.3

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

      \[\leadsto \color{blue}{z}\]

    if 1.597460999541732e+121 < x

    1. Initial program 58.5

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -3.4794970398246474 \cdot 10^{55}:\\ \;\;\;\;-1 \cdot x\\ \mathbf{elif}\;x \le 4.54583198998115572 \cdot 10^{65}:\\ \;\;\;\;\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}\\ \mathbf{elif}\;x \le 1.59746099954173198 \cdot 10^{121}:\\ \;\;\;\;z\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array}\]

Reproduce

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

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