Average Error: 31.2 → 17.7
Time: 3.2s
Precision: 64
\[\sqrt{x \cdot x + y \cdot y}\]
\[\begin{array}{l} \mathbf{if}\;x \le -2.47409571178928762 \cdot 10^{117}:\\ \;\;\;\;-x\\ \mathbf{elif}\;x \le 5.43513758536357538 \cdot 10^{84}:\\ \;\;\;\;\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.47409571178928762 \cdot 10^{117}:\\
\;\;\;\;-x\\

\mathbf{elif}\;x \le 5.43513758536357538 \cdot 10^{84}:\\
\;\;\;\;\sqrt{x \cdot x + y \cdot y}\\

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

\end{array}
double f(double x, double y) {
        double r566733 = x;
        double r566734 = r566733 * r566733;
        double r566735 = y;
        double r566736 = r566735 * r566735;
        double r566737 = r566734 + r566736;
        double r566738 = sqrt(r566737);
        return r566738;
}

double f(double x, double y) {
        double r566739 = x;
        double r566740 = -2.4740957117892876e+117;
        bool r566741 = r566739 <= r566740;
        double r566742 = -r566739;
        double r566743 = 5.435137585363575e+84;
        bool r566744 = r566739 <= r566743;
        double r566745 = r566739 * r566739;
        double r566746 = y;
        double r566747 = r566746 * r566746;
        double r566748 = r566745 + r566747;
        double r566749 = sqrt(r566748);
        double r566750 = r566744 ? r566749 : r566739;
        double r566751 = r566741 ? r566742 : r566750;
        return r566751;
}

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.2
Target17.6
Herbie17.7
\[\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.4740957117892876e+117

    1. Initial program 55.4

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

      \[\leadsto \color{blue}{-1 \cdot x}\]
    3. Simplified9.4

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

    if -2.4740957117892876e+117 < x < 5.435137585363575e+84

    1. Initial program 21.3

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

    if 5.435137585363575e+84 < x

    1. Initial program 47.8

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -2.47409571178928762 \cdot 10^{117}:\\ \;\;\;\;-x\\ \mathbf{elif}\;x \le 5.43513758536357538 \cdot 10^{84}:\\ \;\;\;\;\sqrt{x \cdot x + y \cdot y}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array}\]

Reproduce

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

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

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