Average Error: 38.3 → 26.2
Time: 2.1s
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}:\\ \;\;\;\;-1 \cdot 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}:\\
\;\;\;\;-1 \cdot 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 r651802 = x;
        double r651803 = r651802 * r651802;
        double r651804 = y;
        double r651805 = r651804 * r651804;
        double r651806 = r651803 + r651805;
        double r651807 = z;
        double r651808 = r651807 * r651807;
        double r651809 = r651806 + r651808;
        double r651810 = sqrt(r651809);
        return r651810;
}

double f(double x, double y, double z) {
        double r651811 = x;
        double r651812 = -1.356128363832856e+108;
        bool r651813 = r651811 <= r651812;
        double r651814 = -1.0;
        double r651815 = r651814 * r651811;
        double r651816 = 1.0479353069555717e+77;
        bool r651817 = r651811 <= r651816;
        double r651818 = r651811 * r651811;
        double r651819 = y;
        double r651820 = r651819 * r651819;
        double r651821 = r651818 + r651820;
        double r651822 = z;
        double r651823 = r651822 * r651822;
        double r651824 = r651821 + r651823;
        double r651825 = sqrt(r651824);
        double r651826 = r651817 ? r651825 : r651811;
        double r651827 = r651813 ? r651815 : r651826;
        return r651827;
}

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}\]

    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}:\\ \;\;\;\;-1 \cdot 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))))