Average Error: 38.6 → 27.8
Time: 2.5s
Precision: 64
\[\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}\]
\[\begin{array}{l} \mathbf{if}\;x \le -2.83348214917540354 \cdot 10^{169}:\\ \;\;\;\;-1 \cdot x\\ \mathbf{elif}\;x \le -1.8758942929933885 \cdot 10^{86}:\\ \;\;\;\;z\\ \mathbf{elif}\;x \le 4.189357432179195 \cdot 10^{83}:\\ \;\;\;\;\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 -2.83348214917540354 \cdot 10^{169}:\\
\;\;\;\;-1 \cdot x\\

\mathbf{elif}\;x \le -1.8758942929933885 \cdot 10^{86}:\\
\;\;\;\;z\\

\mathbf{elif}\;x \le 4.189357432179195 \cdot 10^{83}:\\
\;\;\;\;\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 r782300 = x;
        double r782301 = r782300 * r782300;
        double r782302 = y;
        double r782303 = r782302 * r782302;
        double r782304 = r782301 + r782303;
        double r782305 = z;
        double r782306 = r782305 * r782305;
        double r782307 = r782304 + r782306;
        double r782308 = sqrt(r782307);
        return r782308;
}

double f(double x, double y, double z) {
        double r782309 = x;
        double r782310 = -2.8334821491754035e+169;
        bool r782311 = r782309 <= r782310;
        double r782312 = -1.0;
        double r782313 = r782312 * r782309;
        double r782314 = -1.8758942929933885e+86;
        bool r782315 = r782309 <= r782314;
        double r782316 = z;
        double r782317 = 4.189357432179195e+83;
        bool r782318 = r782309 <= r782317;
        double r782319 = r782309 * r782309;
        double r782320 = y;
        double r782321 = r782320 * r782320;
        double r782322 = r782319 + r782321;
        double r782323 = r782316 * r782316;
        double r782324 = r782322 + r782323;
        double r782325 = sqrt(r782324);
        double r782326 = r782318 ? r782325 : r782309;
        double r782327 = r782315 ? r782316 : r782326;
        double r782328 = r782311 ? r782313 : r782327;
        return r782328;
}

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.6
Target26.1
Herbie27.8
\[\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 4 regimes
  2. if x < -2.8334821491754035e+169

    1. Initial program 64.0

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

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

    if -2.8334821491754035e+169 < x < -1.8758942929933885e+86

    1. Initial program 35.3

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

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

    if -1.8758942929933885e+86 < x < 4.189357432179195e+83

    1. Initial program 30.3

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

    if 4.189357432179195e+83 < x

    1. Initial program 53.0

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -2.83348214917540354 \cdot 10^{169}:\\ \;\;\;\;-1 \cdot x\\ \mathbf{elif}\;x \le -1.8758942929933885 \cdot 10^{86}:\\ \;\;\;\;z\\ \mathbf{elif}\;x \le 4.189357432179195 \cdot 10^{83}:\\ \;\;\;\;\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array}\]

Reproduce

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