Average Error: 31.7 → 17.5
Time: 1.7s
Precision: 64
\[\sqrt{x \cdot x + y \cdot y}\]
\[\begin{array}{l} \mathbf{if}\;x \le -8.2785642049712221 \cdot 10^{77}:\\ \;\;\;\;-1 \cdot x\\ \mathbf{elif}\;x \le 1.9891121466079622 \cdot 10^{116}:\\ \;\;\;\;\sqrt{x \cdot x + y \cdot y}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array}\]
\sqrt{x \cdot x + y \cdot y}
\begin{array}{l}
\mathbf{if}\;x \le -8.2785642049712221 \cdot 10^{77}:\\
\;\;\;\;-1 \cdot x\\

\mathbf{elif}\;x \le 1.9891121466079622 \cdot 10^{116}:\\
\;\;\;\;\sqrt{x \cdot x + y \cdot y}\\

\mathbf{else}:\\
\;\;\;\;x\\

\end{array}
double f(double x, double y) {
        double r755927 = x;
        double r755928 = r755927 * r755927;
        double r755929 = y;
        double r755930 = r755929 * r755929;
        double r755931 = r755928 + r755930;
        double r755932 = sqrt(r755931);
        return r755932;
}

double f(double x, double y) {
        double r755933 = x;
        double r755934 = -8.278564204971222e+77;
        bool r755935 = r755933 <= r755934;
        double r755936 = -1.0;
        double r755937 = r755936 * r755933;
        double r755938 = 1.9891121466079622e+116;
        bool r755939 = r755933 <= r755938;
        double r755940 = r755933 * r755933;
        double r755941 = y;
        double r755942 = r755941 * r755941;
        double r755943 = r755940 + r755942;
        double r755944 = sqrt(r755943);
        double r755945 = r755939 ? r755944 : r755933;
        double r755946 = r755935 ? r755937 : r755945;
        return r755946;
}

Error

Bits error versus x

Bits error versus y

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original31.7
Target17.4
Herbie17.5
\[\begin{array}{l} \mathbf{if}\;x \lt -1.123695082659983 \cdot 10^{145}:\\ \;\;\;\;-x\\ \mathbf{elif}\;x \lt 1.11655762118336204 \cdot 10^{93}:\\ \;\;\;\;\sqrt{x \cdot x + y \cdot y}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array}\]

Derivation

  1. Split input into 3 regimes
  2. if x < -8.278564204971222e+77

    1. Initial program 48.5

      \[\sqrt{x \cdot x + y \cdot y}\]
    2. Taylor expanded around -inf 11.8

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

    if -8.278564204971222e+77 < x < 1.9891121466079622e+116

    1. Initial program 21.2

      \[\sqrt{x \cdot x + y \cdot y}\]

    if 1.9891121466079622e+116 < x

    1. Initial program 54.7

      \[\sqrt{x \cdot x + y \cdot y}\]
    2. Taylor expanded around inf 8.7

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -8.2785642049712221 \cdot 10^{77}:\\ \;\;\;\;-1 \cdot x\\ \mathbf{elif}\;x \le 1.9891121466079622 \cdot 10^{116}:\\ \;\;\;\;\sqrt{x \cdot x + y \cdot y}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array}\]

Reproduce

herbie shell --seed 2020081 
(FPCore (x y)
  :name "Data.Octree.Internal:octantDistance  from Octree-0.5.4.2"
  :precision binary64

  :herbie-target
  (if (< x -1.123695082659983e+145) (- x) (if (< x 1.116557621183362e+93) (sqrt (+ (* x x) (* y y))) x))

  (sqrt (+ (* x x) (* y y))))