Average Error: 32.0 → 18.4
Time: 2.0s
Precision: 64
\[\sqrt{x \cdot x + y \cdot y}\]
\[\begin{array}{l} \mathbf{if}\;x \le -5.9648958467837301 \cdot 10^{102}:\\ \;\;\;\;-1 \cdot x\\ \mathbf{elif}\;x \le 3.49168277985170575 \cdot 10^{70}:\\ \;\;\;\;\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 -5.9648958467837301 \cdot 10^{102}:\\
\;\;\;\;-1 \cdot x\\

\mathbf{elif}\;x \le 3.49168277985170575 \cdot 10^{70}:\\
\;\;\;\;\sqrt{x \cdot x + y \cdot y}\\

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

\end{array}
double f(double x, double y) {
        double r911929 = x;
        double r911930 = r911929 * r911929;
        double r911931 = y;
        double r911932 = r911931 * r911931;
        double r911933 = r911930 + r911932;
        double r911934 = sqrt(r911933);
        return r911934;
}

double f(double x, double y) {
        double r911935 = x;
        double r911936 = -5.96489584678373e+102;
        bool r911937 = r911935 <= r911936;
        double r911938 = -1.0;
        double r911939 = r911938 * r911935;
        double r911940 = 3.491682779851706e+70;
        bool r911941 = r911935 <= r911940;
        double r911942 = r911935 * r911935;
        double r911943 = y;
        double r911944 = r911943 * r911943;
        double r911945 = r911942 + r911944;
        double r911946 = sqrt(r911945);
        double r911947 = r911941 ? r911946 : r911935;
        double r911948 = r911937 ? r911939 : r911947;
        return r911948;
}

Error

Bits error versus x

Bits error versus y

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original32.0
Target18.3
Herbie18.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 < -5.96489584678373e+102

    1. Initial program 53.0

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

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

    if -5.96489584678373e+102 < x < 3.491682779851706e+70

    1. Initial program 22.2

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

    if 3.491682779851706e+70 < x

    1. Initial program 47.4

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -5.9648958467837301 \cdot 10^{102}:\\ \;\;\;\;-1 \cdot x\\ \mathbf{elif}\;x \le 3.49168277985170575 \cdot 10^{70}:\\ \;\;\;\;\sqrt{x \cdot x + y \cdot y}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array}\]

Reproduce

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