Average Error: 31.5 → 17.4
Time: 991.0ms
Precision: 64
\[\sqrt{x \cdot x + y \cdot y}\]
\[\begin{array}{l} \mathbf{if}\;x \le -2.5872918038759956 \cdot 10^{153}:\\ \;\;\;\;-1 \cdot x\\ \mathbf{elif}\;x \le 4.5752696805163673 \cdot 10^{135}:\\ \;\;\;\;\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 -2.5872918038759956 \cdot 10^{153}:\\
\;\;\;\;-1 \cdot x\\

\mathbf{elif}\;x \le 4.5752696805163673 \cdot 10^{135}:\\
\;\;\;\;\sqrt{x \cdot x + y \cdot y}\\

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

\end{array}
double f(double x, double y) {
        double r704925 = x;
        double r704926 = r704925 * r704925;
        double r704927 = y;
        double r704928 = r704927 * r704927;
        double r704929 = r704926 + r704928;
        double r704930 = sqrt(r704929);
        return r704930;
}

double f(double x, double y) {
        double r704931 = x;
        double r704932 = -2.5872918038759956e+153;
        bool r704933 = r704931 <= r704932;
        double r704934 = -1.0;
        double r704935 = r704934 * r704931;
        double r704936 = 4.575269680516367e+135;
        bool r704937 = r704931 <= r704936;
        double r704938 = r704931 * r704931;
        double r704939 = y;
        double r704940 = r704939 * r704939;
        double r704941 = r704938 + r704940;
        double r704942 = sqrt(r704941);
        double r704943 = r704937 ? r704942 : r704931;
        double r704944 = r704933 ? r704935 : r704943;
        return r704944;
}

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.5
Target17.4
Herbie17.4
\[\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 < -2.5872918038759956e+153

    1. Initial program 63.9

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

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

    if -2.5872918038759956e+153 < x < 4.575269680516367e+135

    1. Initial program 20.7

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

    if 4.575269680516367e+135 < x

    1. Initial program 59.0

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -2.5872918038759956 \cdot 10^{153}:\\ \;\;\;\;-1 \cdot x\\ \mathbf{elif}\;x \le 4.5752696805163673 \cdot 10^{135}:\\ \;\;\;\;\sqrt{x \cdot x + y \cdot y}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array}\]

Reproduce

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