Average Error: 38.2 → 25.2
Time: 1.3s
Precision: 64
\[\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}\]
\[\begin{array}{l} \mathbf{if}\;x \le -3.07433912200013139 \cdot 10^{144}:\\ \;\;\;\;-1 \cdot x\\ \mathbf{elif}\;x \le 4.24489976765657814 \cdot 10^{97}:\\ \;\;\;\;\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 -3.07433912200013139 \cdot 10^{144}:\\
\;\;\;\;-1 \cdot x\\

\mathbf{elif}\;x \le 4.24489976765657814 \cdot 10^{97}:\\
\;\;\;\;\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 r667689 = x;
        double r667690 = r667689 * r667689;
        double r667691 = y;
        double r667692 = r667691 * r667691;
        double r667693 = r667690 + r667692;
        double r667694 = z;
        double r667695 = r667694 * r667694;
        double r667696 = r667693 + r667695;
        double r667697 = sqrt(r667696);
        return r667697;
}

double f(double x, double y, double z) {
        double r667698 = x;
        double r667699 = -3.0743391220001314e+144;
        bool r667700 = r667698 <= r667699;
        double r667701 = -1.0;
        double r667702 = r667701 * r667698;
        double r667703 = 4.244899767656578e+97;
        bool r667704 = r667698 <= r667703;
        double r667705 = r667698 * r667698;
        double r667706 = y;
        double r667707 = r667706 * r667706;
        double r667708 = r667705 + r667707;
        double r667709 = z;
        double r667710 = r667709 * r667709;
        double r667711 = r667708 + r667710;
        double r667712 = sqrt(r667711);
        double r667713 = r667704 ? r667712 : r667698;
        double r667714 = r667700 ? r667702 : r667713;
        return r667714;
}

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.2
Target25.9
Herbie25.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 < -3.0743391220001314e+144

    1. Initial program 61.9

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

    if -3.0743391220001314e+144 < x < 4.244899767656578e+97

    1. Initial program 29.1

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

    if 4.244899767656578e+97 < x

    1. Initial program 54.8

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -3.07433912200013139 \cdot 10^{144}:\\ \;\;\;\;-1 \cdot x\\ \mathbf{elif}\;x \le 4.24489976765657814 \cdot 10^{97}:\\ \;\;\;\;\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array}\]

Reproduce

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