Average Error: 35.3 → 24.0
Time: 4.6s
Precision: 64
\[\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}\]
\[\begin{array}{l} \mathbf{if}\;x \le -1.0194035731107022 \cdot 10^{+155}:\\ \;\;\;\;-x\\ \mathbf{elif}\;x \le 6.799350921495747 \cdot 10^{+134}:\\ \;\;\;\;\sqrt{z \cdot z + \left(y \cdot y + x \cdot x\right)}\\ \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.0194035731107022 \cdot 10^{+155}:\\
\;\;\;\;-x\\

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

\mathbf{else}:\\
\;\;\;\;x\\

\end{array}
double f(double x, double y, double z) {
        double r31678762 = x;
        double r31678763 = r31678762 * r31678762;
        double r31678764 = y;
        double r31678765 = r31678764 * r31678764;
        double r31678766 = r31678763 + r31678765;
        double r31678767 = z;
        double r31678768 = r31678767 * r31678767;
        double r31678769 = r31678766 + r31678768;
        double r31678770 = sqrt(r31678769);
        return r31678770;
}

double f(double x, double y, double z) {
        double r31678771 = x;
        double r31678772 = -1.0194035731107022e+155;
        bool r31678773 = r31678771 <= r31678772;
        double r31678774 = -r31678771;
        double r31678775 = 6.799350921495747e+134;
        bool r31678776 = r31678771 <= r31678775;
        double r31678777 = z;
        double r31678778 = r31678777 * r31678777;
        double r31678779 = y;
        double r31678780 = r31678779 * r31678779;
        double r31678781 = r31678771 * r31678771;
        double r31678782 = r31678780 + r31678781;
        double r31678783 = r31678778 + r31678782;
        double r31678784 = sqrt(r31678783);
        double r31678785 = r31678776 ? r31678784 : r31678771;
        double r31678786 = r31678773 ? r31678774 : r31678785;
        return r31678786;
}

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

Original35.3
Target24.3
Herbie24.0
\[\begin{array}{l} \mathbf{if}\;z \lt -6.396479394109776 \cdot 10^{+136}:\\ \;\;\;\;-z\\ \mathbf{elif}\;z \lt 7.320293694404182 \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.0194035731107022e+155

    1. Initial program 59.2

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

      \[\leadsto \color{blue}{-1 \cdot x}\]
    3. Simplified13.6

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

    if -1.0194035731107022e+155 < x < 6.799350921495747e+134

    1. Initial program 27.4

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

    if 6.799350921495747e+134 < x

    1. Initial program 55.8

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

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

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

Reproduce

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