Average Error: 31.3 → 17.5
Time: 1.1s
Precision: 64
\[\sqrt{x \cdot x + y \cdot y}\]
\[\begin{array}{l} \mathbf{if}\;x \le -2.066866671709845106834464667975644144779 \cdot 10^{108}:\\ \;\;\;\;-1 \cdot x\\ \mathbf{elif}\;x \le 4.80613782352259500769138488086471841751 \cdot 10^{109}:\\ \;\;\;\;\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.066866671709845106834464667975644144779 \cdot 10^{108}:\\
\;\;\;\;-1 \cdot x\\

\mathbf{elif}\;x \le 4.80613782352259500769138488086471841751 \cdot 10^{109}:\\
\;\;\;\;\sqrt{x \cdot x + y \cdot y}\\

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

\end{array}
double f(double x, double y) {
        double r827990 = x;
        double r827991 = r827990 * r827990;
        double r827992 = y;
        double r827993 = r827992 * r827992;
        double r827994 = r827991 + r827993;
        double r827995 = sqrt(r827994);
        return r827995;
}

double f(double x, double y) {
        double r827996 = x;
        double r827997 = -2.066866671709845e+108;
        bool r827998 = r827996 <= r827997;
        double r827999 = -1.0;
        double r828000 = r827999 * r827996;
        double r828001 = 4.806137823522595e+109;
        bool r828002 = r827996 <= r828001;
        double r828003 = r827996 * r827996;
        double r828004 = y;
        double r828005 = r828004 * r828004;
        double r828006 = r828003 + r828005;
        double r828007 = sqrt(r828006);
        double r828008 = r828002 ? r828007 : r827996;
        double r828009 = r827998 ? r828000 : r828008;
        return r828009;
}

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.3
Target17.5
Herbie17.5
\[\begin{array}{l} \mathbf{if}\;x \lt -1.123695082659982632437974301616192301785 \cdot 10^{145}:\\ \;\;\;\;-x\\ \mathbf{elif}\;x \lt 1.116557621183362039388201959321597704512 \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.066866671709845e+108

    1. Initial program 52.1

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

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

    if -2.066866671709845e+108 < x < 4.806137823522595e+109

    1. Initial program 21.0

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

    if 4.806137823522595e+109 < x

    1. Initial program 53.6

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -2.066866671709845106834464667975644144779 \cdot 10^{108}:\\ \;\;\;\;-1 \cdot x\\ \mathbf{elif}\;x \le 4.80613782352259500769138488086471841751 \cdot 10^{109}:\\ \;\;\;\;\sqrt{x \cdot x + y \cdot y}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array}\]

Reproduce

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