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

\mathbf{elif}\;x \le 5.555039258021857291544043064059614500874 \cdot 10^{144}:\\
\;\;\;\;\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 r693864 = x;
        double r693865 = r693864 * r693864;
        double r693866 = y;
        double r693867 = r693866 * r693866;
        double r693868 = r693865 + r693867;
        double r693869 = z;
        double r693870 = r693869 * r693869;
        double r693871 = r693868 + r693870;
        double r693872 = sqrt(r693871);
        return r693872;
}

double f(double x, double y, double z) {
        double r693873 = x;
        double r693874 = -2.090433146826483e+130;
        bool r693875 = r693873 <= r693874;
        double r693876 = -1.0;
        double r693877 = r693876 * r693873;
        double r693878 = 5.555039258021857e+144;
        bool r693879 = r693873 <= r693878;
        double r693880 = r693873 * r693873;
        double r693881 = y;
        double r693882 = r693881 * r693881;
        double r693883 = r693880 + r693882;
        double r693884 = z;
        double r693885 = r693884 * r693884;
        double r693886 = r693883 + r693885;
        double r693887 = sqrt(r693886);
        double r693888 = r693879 ? r693887 : r693873;
        double r693889 = r693875 ? r693877 : r693888;
        return r693889;
}

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.7
Herbie25.3
\[\begin{array}{l} \mathbf{if}\;z \lt -6.396479394109775845820908799933348003545 \cdot 10^{136}:\\ \;\;\;\;-z\\ \mathbf{elif}\;z \lt 7.320293694404182125923160810847974073098 \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 < -2.090433146826483e+130

    1. Initial program 59.2

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

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

    if -2.090433146826483e+130 < x < 5.555039258021857e+144

    1. Initial program 29.6

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

    if 5.555039258021857e+144 < x

    1. Initial program 61.8

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

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

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

Reproduce

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