Average Error: 37.8 → 25.7
Time: 6.7s
Precision: 64
\[\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}\]
\[\begin{array}{l} \mathbf{if}\;x \le -3.7872604668456225 \cdot 10^{151}:\\ \;\;\;\;-x\\ \mathbf{elif}\;x \le 2.36744042376759273 \cdot 10^{134}:\\ \;\;\;\;\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 -3.7872604668456225 \cdot 10^{151}:\\
\;\;\;\;-x\\

\mathbf{elif}\;x \le 2.36744042376759273 \cdot 10^{134}:\\
\;\;\;\;\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 r519020 = x;
        double r519021 = r519020 * r519020;
        double r519022 = y;
        double r519023 = r519022 * r519022;
        double r519024 = r519021 + r519023;
        double r519025 = z;
        double r519026 = r519025 * r519025;
        double r519027 = r519024 + r519026;
        double r519028 = sqrt(r519027);
        return r519028;
}

double f(double x, double y, double z) {
        double r519029 = x;
        double r519030 = -3.7872604668456225e+151;
        bool r519031 = r519029 <= r519030;
        double r519032 = -r519029;
        double r519033 = 2.3674404237675927e+134;
        bool r519034 = r519029 <= r519033;
        double r519035 = r519029 * r519029;
        double r519036 = y;
        double r519037 = r519036 * r519036;
        double r519038 = r519035 + r519037;
        double r519039 = z;
        double r519040 = r519039 * r519039;
        double r519041 = r519038 + r519040;
        double r519042 = sqrt(r519041);
        double r519043 = r519034 ? r519042 : r519029;
        double r519044 = r519031 ? r519032 : r519043;
        return r519044;
}

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.8
Target25.0
Herbie25.7
\[\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 3 regimes
  2. if x < -3.7872604668456225e+151

    1. Initial program 63.2

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

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

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

    if -3.7872604668456225e+151 < x < 2.3674404237675927e+134

    1. Initial program 29.4

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

    if 2.3674404237675927e+134 < x

    1. Initial program 59.7

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -3.7872604668456225 \cdot 10^{151}:\\ \;\;\;\;-x\\ \mathbf{elif}\;x \le 2.36744042376759273 \cdot 10^{134}:\\ \;\;\;\;\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array}\]

Reproduce

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

  :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))))