Average Error: 38.2 → 26.8
Time: 2.2s
Precision: 64
\[\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}\]
\[\begin{array}{l} \mathbf{if}\;x \le -4.349939923085003293068967551425183555235 \cdot 10^{145}:\\ \;\;\;\;-1 \cdot x\\ \mathbf{elif}\;x \le -8.945854204682411796604703943989415353032 \cdot 10^{-30}:\\ \;\;\;\;\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}\\ \mathbf{elif}\;x \le -6.392181742208723609802711114151542199928 \cdot 10^{-88}:\\ \;\;\;\;z\\ \mathbf{elif}\;x \le 770005.742688843398354947566986083984375:\\ \;\;\;\;\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}\\ \mathbf{elif}\;x \le 256569146045255076915233238198859595776:\\ \;\;\;\;z\\ \mathbf{elif}\;x \le 1.111117861372056477673919193000107087999 \cdot 10^{145}:\\ \;\;\;\;\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 -4.349939923085003293068967551425183555235 \cdot 10^{145}:\\
\;\;\;\;-1 \cdot x\\

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

\mathbf{elif}\;x \le -6.392181742208723609802711114151542199928 \cdot 10^{-88}:\\
\;\;\;\;z\\

\mathbf{elif}\;x \le 770005.742688843398354947566986083984375:\\
\;\;\;\;\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}\\

\mathbf{elif}\;x \le 256569146045255076915233238198859595776:\\
\;\;\;\;z\\

\mathbf{elif}\;x \le 1.111117861372056477673919193000107087999 \cdot 10^{145}:\\
\;\;\;\;\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 r638275 = x;
        double r638276 = r638275 * r638275;
        double r638277 = y;
        double r638278 = r638277 * r638277;
        double r638279 = r638276 + r638278;
        double r638280 = z;
        double r638281 = r638280 * r638280;
        double r638282 = r638279 + r638281;
        double r638283 = sqrt(r638282);
        return r638283;
}

double f(double x, double y, double z) {
        double r638284 = x;
        double r638285 = -4.3499399230850033e+145;
        bool r638286 = r638284 <= r638285;
        double r638287 = -1.0;
        double r638288 = r638287 * r638284;
        double r638289 = -8.945854204682412e-30;
        bool r638290 = r638284 <= r638289;
        double r638291 = r638284 * r638284;
        double r638292 = y;
        double r638293 = r638292 * r638292;
        double r638294 = r638291 + r638293;
        double r638295 = z;
        double r638296 = r638295 * r638295;
        double r638297 = r638294 + r638296;
        double r638298 = sqrt(r638297);
        double r638299 = -6.392181742208724e-88;
        bool r638300 = r638284 <= r638299;
        double r638301 = 770005.7426888434;
        bool r638302 = r638284 <= r638301;
        double r638303 = 2.5656914604525508e+38;
        bool r638304 = r638284 <= r638303;
        double r638305 = 1.1111178613720565e+145;
        bool r638306 = r638284 <= r638305;
        double r638307 = r638306 ? r638298 : r638284;
        double r638308 = r638304 ? r638295 : r638307;
        double r638309 = r638302 ? r638298 : r638308;
        double r638310 = r638300 ? r638295 : r638309;
        double r638311 = r638290 ? r638298 : r638310;
        double r638312 = r638286 ? r638288 : r638311;
        return r638312;
}

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.9
Herbie26.8
\[\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 4 regimes
  2. if x < -4.3499399230850033e+145

    1. Initial program 62.4

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

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

    if -4.3499399230850033e+145 < x < -8.945854204682412e-30 or -6.392181742208724e-88 < x < 770005.7426888434 or 2.5656914604525508e+38 < x < 1.1111178613720565e+145

    1. Initial program 29.2

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

    if -8.945854204682412e-30 < x < -6.392181742208724e-88 or 770005.7426888434 < x < 2.5656914604525508e+38

    1. Initial program 31.1

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

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

    if 1.1111178613720565e+145 < x

    1. Initial program 61.7

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -4.349939923085003293068967551425183555235 \cdot 10^{145}:\\ \;\;\;\;-1 \cdot x\\ \mathbf{elif}\;x \le -8.945854204682411796604703943989415353032 \cdot 10^{-30}:\\ \;\;\;\;\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}\\ \mathbf{elif}\;x \le -6.392181742208723609802711114151542199928 \cdot 10^{-88}:\\ \;\;\;\;z\\ \mathbf{elif}\;x \le 770005.742688843398354947566986083984375:\\ \;\;\;\;\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}\\ \mathbf{elif}\;x \le 256569146045255076915233238198859595776:\\ \;\;\;\;z\\ \mathbf{elif}\;x \le 1.111117861372056477673919193000107087999 \cdot 10^{145}:\\ \;\;\;\;\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array}\]

Reproduce

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

  :herbie-target
  (if (< z -6.3964793941097758e136) (- z) (if (< z 7.3202936944041821e117) (sqrt (+ (+ (* z z) (* x x)) (* y y))) z))

  (sqrt (+ (+ (* x x) (* y y)) (* z z))))