Average Error: 37.4 → 24.9
Time: 3.4s
Precision: 64
\[\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}\]
\[\begin{array}{l} \mathbf{if}\;x \le -1.6174687293654252 \cdot 10^{118}:\\ \;\;\;\;-1 \cdot x\\ \mathbf{elif}\;x \le 1.3566371815103393 \cdot 10^{105}:\\ \;\;\;\;\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 -1.6174687293654252 \cdot 10^{118}:\\
\;\;\;\;-1 \cdot x\\

\mathbf{elif}\;x \le 1.3566371815103393 \cdot 10^{105}:\\
\;\;\;\;\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 r583181 = x;
        double r583182 = r583181 * r583181;
        double r583183 = y;
        double r583184 = r583183 * r583183;
        double r583185 = r583182 + r583184;
        double r583186 = z;
        double r583187 = r583186 * r583186;
        double r583188 = r583185 + r583187;
        double r583189 = sqrt(r583188);
        return r583189;
}

double f(double x, double y, double z) {
        double r583190 = x;
        double r583191 = -1.6174687293654252e+118;
        bool r583192 = r583190 <= r583191;
        double r583193 = -1.0;
        double r583194 = r583193 * r583190;
        double r583195 = 1.3566371815103393e+105;
        bool r583196 = r583190 <= r583195;
        double r583197 = r583190 * r583190;
        double r583198 = y;
        double r583199 = r583198 * r583198;
        double r583200 = r583197 + r583199;
        double r583201 = z;
        double r583202 = r583201 * r583201;
        double r583203 = r583200 + r583202;
        double r583204 = sqrt(r583203);
        double r583205 = r583196 ? r583204 : r583190;
        double r583206 = r583192 ? r583194 : r583205;
        return r583206;
}

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.4
Target25.0
Herbie24.9
\[\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 3 regimes
  2. if x < -1.6174687293654252e+118

    1. Initial program 57.2

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

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

    if -1.6174687293654252e+118 < x < 1.3566371815103393e+105

    1. Initial program 28.5

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

    if 1.3566371815103393e+105 < x

    1. Initial program 55.5

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -1.6174687293654252 \cdot 10^{118}:\\ \;\;\;\;-1 \cdot x\\ \mathbf{elif}\;x \le 1.3566371815103393 \cdot 10^{105}:\\ \;\;\;\;\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array}\]

Reproduce

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