Average Error: 38.1 → 25.5
Time: 2.4s
Precision: 64
\[\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}\]
\[\begin{array}{l} \mathbf{if}\;x \le -1.9353333948222178 \cdot 10^{136}:\\ \;\;\;\;-1 \cdot x\\ \mathbf{elif}\;x \le 5.0542352973125761 \cdot 10^{73}:\\ \;\;\;\;\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.9353333948222178 \cdot 10^{136}:\\
\;\;\;\;-1 \cdot x\\

\mathbf{elif}\;x \le 5.0542352973125761 \cdot 10^{73}:\\
\;\;\;\;\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 r664654 = x;
        double r664655 = r664654 * r664654;
        double r664656 = y;
        double r664657 = r664656 * r664656;
        double r664658 = r664655 + r664657;
        double r664659 = z;
        double r664660 = r664659 * r664659;
        double r664661 = r664658 + r664660;
        double r664662 = sqrt(r664661);
        return r664662;
}

double f(double x, double y, double z) {
        double r664663 = x;
        double r664664 = -1.9353333948222178e+136;
        bool r664665 = r664663 <= r664664;
        double r664666 = -1.0;
        double r664667 = r664666 * r664663;
        double r664668 = 5.054235297312576e+73;
        bool r664669 = r664663 <= r664668;
        double r664670 = r664663 * r664663;
        double r664671 = y;
        double r664672 = r664671 * r664671;
        double r664673 = r664670 + r664672;
        double r664674 = z;
        double r664675 = r664674 * r664674;
        double r664676 = r664673 + r664675;
        double r664677 = sqrt(r664676);
        double r664678 = r664669 ? r664677 : r664663;
        double r664679 = r664665 ? r664667 : r664678;
        return r664679;
}

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.1
Target25.8
Herbie25.5
\[\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.9353333948222178e+136

    1. Initial program 59.9

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

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

    if -1.9353333948222178e+136 < x < 5.054235297312576e+73

    1. Initial program 29.3

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

    if 5.054235297312576e+73 < x

    1. Initial program 52.2

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -1.9353333948222178 \cdot 10^{136}:\\ \;\;\;\;-1 \cdot x\\ \mathbf{elif}\;x \le 5.0542352973125761 \cdot 10^{73}:\\ \;\;\;\;\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array}\]

Reproduce

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