Average Error: 38.3 → 26.2
Time: 3.7s
Precision: 64
\[\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}\]
\[\begin{array}{l} \mathbf{if}\;x \le -1.35612836383285588 \cdot 10^{108}:\\ \;\;\;\;-x\\ \mathbf{elif}\;x \le 1.04793530695557172 \cdot 10^{77}:\\ \;\;\;\;\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.35612836383285588 \cdot 10^{108}:\\
\;\;\;\;-x\\

\mathbf{elif}\;x \le 1.04793530695557172 \cdot 10^{77}:\\
\;\;\;\;\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 r517800 = x;
        double r517801 = r517800 * r517800;
        double r517802 = y;
        double r517803 = r517802 * r517802;
        double r517804 = r517801 + r517803;
        double r517805 = z;
        double r517806 = r517805 * r517805;
        double r517807 = r517804 + r517806;
        double r517808 = sqrt(r517807);
        return r517808;
}

double f(double x, double y, double z) {
        double r517809 = x;
        double r517810 = -1.356128363832856e+108;
        bool r517811 = r517809 <= r517810;
        double r517812 = -r517809;
        double r517813 = 1.0479353069555717e+77;
        bool r517814 = r517809 <= r517813;
        double r517815 = r517809 * r517809;
        double r517816 = y;
        double r517817 = r517816 * r517816;
        double r517818 = r517815 + r517817;
        double r517819 = z;
        double r517820 = r517819 * r517819;
        double r517821 = r517818 + r517820;
        double r517822 = sqrt(r517821);
        double r517823 = r517814 ? r517822 : r517809;
        double r517824 = r517811 ? r517812 : r517823;
        return r517824;
}

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.3
Target25.7
Herbie26.2
\[\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 < -1.356128363832856e+108

    1. Initial program 55.3

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

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

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

    if -1.356128363832856e+108 < x < 1.0479353069555717e+77

    1. Initial program 29.8

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

    if 1.0479353069555717e+77 < x

    1. Initial program 53.1

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -1.35612836383285588 \cdot 10^{108}:\\ \;\;\;\;-x\\ \mathbf{elif}\;x \le 1.04793530695557172 \cdot 10^{77}:\\ \;\;\;\;\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array}\]

Reproduce

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