Average Error: 37.7 → 25.5
Time: 4.0s
Precision: 64
\[\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}\]
\[\begin{array}{l} \mathbf{if}\;x \le -7.934591556850648877179646504172286937752 \cdot 10^{139}:\\ \;\;\;\;-x\\ \mathbf{elif}\;x \le 1.758065253567775503978920400402254303936 \cdot 10^{99}:\\ \;\;\;\;\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 -7.934591556850648877179646504172286937752 \cdot 10^{139}:\\
\;\;\;\;-x\\

\mathbf{elif}\;x \le 1.758065253567775503978920400402254303936 \cdot 10^{99}:\\
\;\;\;\;\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 r409247 = x;
        double r409248 = r409247 * r409247;
        double r409249 = y;
        double r409250 = r409249 * r409249;
        double r409251 = r409248 + r409250;
        double r409252 = z;
        double r409253 = r409252 * r409252;
        double r409254 = r409251 + r409253;
        double r409255 = sqrt(r409254);
        return r409255;
}

double f(double x, double y, double z) {
        double r409256 = x;
        double r409257 = -7.934591556850649e+139;
        bool r409258 = r409256 <= r409257;
        double r409259 = -r409256;
        double r409260 = 1.7580652535677755e+99;
        bool r409261 = r409256 <= r409260;
        double r409262 = r409256 * r409256;
        double r409263 = y;
        double r409264 = r409263 * r409263;
        double r409265 = r409262 + r409264;
        double r409266 = z;
        double r409267 = r409266 * r409266;
        double r409268 = r409265 + r409267;
        double r409269 = sqrt(r409268);
        double r409270 = r409261 ? r409269 : r409256;
        double r409271 = r409258 ? r409259 : r409270;
        return r409271;
}

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.7
Target25.4
Herbie25.5
\[\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 < -7.934591556850649e+139

    1. Initial program 60.7

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

      \[\leadsto \color{blue}{-1 \cdot x}\]
    3. Simplified14.2

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

    if -7.934591556850649e+139 < x < 1.7580652535677755e+99

    1. Initial program 29.3

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

    if 1.7580652535677755e+99 < x

    1. Initial program 54.2

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -7.934591556850648877179646504172286937752 \cdot 10^{139}:\\ \;\;\;\;-x\\ \mathbf{elif}\;x \le 1.758065253567775503978920400402254303936 \cdot 10^{99}:\\ \;\;\;\;\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array}\]

Reproduce

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