Average Error: 37.2 → 25.0
Time: 5.2s
Precision: 64
\[\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}\]
\[\begin{array}{l} \mathbf{if}\;x \le -9.459978473614104028021320068483777672215 \cdot 10^{97}:\\ \;\;\;\;-1 \cdot x\\ \mathbf{elif}\;x \le 5.252172480184967942795128237719074438802 \cdot 10^{109}:\\ \;\;\;\;\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 -9.459978473614104028021320068483777672215 \cdot 10^{97}:\\
\;\;\;\;-1 \cdot x\\

\mathbf{elif}\;x \le 5.252172480184967942795128237719074438802 \cdot 10^{109}:\\
\;\;\;\;\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 r716205 = x;
        double r716206 = r716205 * r716205;
        double r716207 = y;
        double r716208 = r716207 * r716207;
        double r716209 = r716206 + r716208;
        double r716210 = z;
        double r716211 = r716210 * r716210;
        double r716212 = r716209 + r716211;
        double r716213 = sqrt(r716212);
        return r716213;
}

double f(double x, double y, double z) {
        double r716214 = x;
        double r716215 = -9.459978473614104e+97;
        bool r716216 = r716214 <= r716215;
        double r716217 = -1.0;
        double r716218 = r716217 * r716214;
        double r716219 = 5.252172480184968e+109;
        bool r716220 = r716214 <= r716219;
        double r716221 = r716214 * r716214;
        double r716222 = y;
        double r716223 = r716222 * r716222;
        double r716224 = r716221 + r716223;
        double r716225 = z;
        double r716226 = r716225 * r716225;
        double r716227 = r716224 + r716226;
        double r716228 = sqrt(r716227);
        double r716229 = r716220 ? r716228 : r716214;
        double r716230 = r716216 ? r716218 : r716229;
        return r716230;
}

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.2
Target25.1
Herbie25.0
\[\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.459978473614104e+97

    1. Initial program 53.3

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

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

    if -9.459978473614104e+97 < x < 5.252172480184968e+109

    1. Initial program 28.9

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

    if 5.252172480184968e+109 < x

    1. Initial program 54.9

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -9.459978473614104028021320068483777672215 \cdot 10^{97}:\\ \;\;\;\;-1 \cdot x\\ \mathbf{elif}\;x \le 5.252172480184967942795128237719074438802 \cdot 10^{109}:\\ \;\;\;\;\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array}\]

Reproduce

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