Average Error: 38.4 → 26.3
Time: 1.5s
Precision: 64
\[\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}\]
\[\begin{array}{l} \mathbf{if}\;x \le -7.03926747243829217 \cdot 10^{95}:\\ \;\;\;\;-1 \cdot x\\ \mathbf{elif}\;x \le 1.8300456071335354 \cdot 10^{67}:\\ \;\;\;\;\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 -7.03926747243829217 \cdot 10^{95}:\\
\;\;\;\;-1 \cdot x\\

\mathbf{elif}\;x \le 1.8300456071335354 \cdot 10^{67}:\\
\;\;\;\;\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 r766079 = x;
        double r766080 = r766079 * r766079;
        double r766081 = y;
        double r766082 = r766081 * r766081;
        double r766083 = r766080 + r766082;
        double r766084 = z;
        double r766085 = r766084 * r766084;
        double r766086 = r766083 + r766085;
        double r766087 = sqrt(r766086);
        return r766087;
}

double f(double x, double y, double z) {
        double r766088 = x;
        double r766089 = -7.039267472438292e+95;
        bool r766090 = r766088 <= r766089;
        double r766091 = -1.0;
        double r766092 = r766091 * r766088;
        double r766093 = 1.8300456071335354e+67;
        bool r766094 = r766088 <= r766093;
        double r766095 = r766088 * r766088;
        double r766096 = y;
        double r766097 = r766096 * r766096;
        double r766098 = r766095 + r766097;
        double r766099 = z;
        double r766100 = r766099 * r766099;
        double r766101 = r766098 + r766100;
        double r766102 = sqrt(r766101);
        double r766103 = r766094 ? r766102 : r766088;
        double r766104 = r766090 ? r766092 : r766103;
        return r766104;
}

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.4
Target25.8
Herbie26.3
\[\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 < -7.039267472438292e+95

    1. Initial program 54.1

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

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

    if -7.039267472438292e+95 < x < 1.8300456071335354e+67

    1. Initial program 29.7

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

    if 1.8300456071335354e+67 < x

    1. Initial program 51.9

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -7.03926747243829217 \cdot 10^{95}:\\ \;\;\;\;-1 \cdot x\\ \mathbf{elif}\;x \le 1.8300456071335354 \cdot 10^{67}:\\ \;\;\;\;\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array}\]

Reproduce

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