Average Error: 38.1 → 25.5
Time: 11.2s
Precision: 64
\[\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}\]
\[\begin{array}{l} \mathbf{if}\;x \le -1.884385188290897584934334479478417400382 \cdot 10^{109}:\\ \;\;\;\;-x\\ \mathbf{elif}\;x \le 1.945330258922093722171531403348915767504 \cdot 10^{138}:\\ \;\;\;\;\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.884385188290897584934334479478417400382 \cdot 10^{109}:\\
\;\;\;\;-x\\

\mathbf{elif}\;x \le 1.945330258922093722171531403348915767504 \cdot 10^{138}:\\
\;\;\;\;\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 r456298 = x;
        double r456299 = r456298 * r456298;
        double r456300 = y;
        double r456301 = r456300 * r456300;
        double r456302 = r456299 + r456301;
        double r456303 = z;
        double r456304 = r456303 * r456303;
        double r456305 = r456302 + r456304;
        double r456306 = sqrt(r456305);
        return r456306;
}

double f(double x, double y, double z) {
        double r456307 = x;
        double r456308 = -1.8843851882908976e+109;
        bool r456309 = r456307 <= r456308;
        double r456310 = -r456307;
        double r456311 = 1.9453302589220937e+138;
        bool r456312 = r456307 <= r456311;
        double r456313 = r456307 * r456307;
        double r456314 = y;
        double r456315 = r456314 * r456314;
        double r456316 = r456313 + r456315;
        double r456317 = z;
        double r456318 = r456317 * r456317;
        double r456319 = r456316 + r456318;
        double r456320 = sqrt(r456319);
        double r456321 = r456312 ? r456320 : r456307;
        double r456322 = r456309 ? r456310 : r456321;
        return r456322;
}

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.1
Target25.3
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 < -1.8843851882908976e+109

    1. Initial program 55.1

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

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

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

    if -1.8843851882908976e+109 < x < 1.9453302589220937e+138

    1. Initial program 29.6

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

    if 1.9453302589220937e+138 < x

    1. Initial program 60.4

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

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

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

Reproduce

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