Average Error: 31.5 → 18.0
Time: 7.1s
Precision: 64
\[\sqrt{x \cdot x + y \cdot y}\]
\[\begin{array}{l} \mathbf{if}\;x \le -1.940119593462783780503740532731557409155 \cdot 10^{70}:\\ \;\;\;\;-x\\ \mathbf{elif}\;x \le 1.149380376403675710903737768625835202966 \cdot 10^{95}:\\ \;\;\;\;\sqrt{y \cdot y + x \cdot x}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array}\]
\sqrt{x \cdot x + y \cdot y}
\begin{array}{l}
\mathbf{if}\;x \le -1.940119593462783780503740532731557409155 \cdot 10^{70}:\\
\;\;\;\;-x\\

\mathbf{elif}\;x \le 1.149380376403675710903737768625835202966 \cdot 10^{95}:\\
\;\;\;\;\sqrt{y \cdot y + x \cdot x}\\

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

\end{array}
double f(double x, double y) {
        double r744446 = x;
        double r744447 = r744446 * r744446;
        double r744448 = y;
        double r744449 = r744448 * r744448;
        double r744450 = r744447 + r744449;
        double r744451 = sqrt(r744450);
        return r744451;
}

double f(double x, double y) {
        double r744452 = x;
        double r744453 = -1.9401195934627838e+70;
        bool r744454 = r744452 <= r744453;
        double r744455 = -r744452;
        double r744456 = 1.1493803764036757e+95;
        bool r744457 = r744452 <= r744456;
        double r744458 = y;
        double r744459 = r744458 * r744458;
        double r744460 = r744452 * r744452;
        double r744461 = r744459 + r744460;
        double r744462 = sqrt(r744461);
        double r744463 = r744457 ? r744462 : r744452;
        double r744464 = r744454 ? r744455 : r744463;
        return r744464;
}

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.7
Herbie18.0
\[\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 < -1.9401195934627838e+70

    1. Initial program 46.3

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

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

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

    if -1.9401195934627838e+70 < x < 1.1493803764036757e+95

    1. Initial program 21.8

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

    if 1.1493803764036757e+95 < x

    1. Initial program 49.0

      \[\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 simplification18.0

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -1.940119593462783780503740532731557409155 \cdot 10^{70}:\\ \;\;\;\;-x\\ \mathbf{elif}\;x \le 1.149380376403675710903737768625835202966 \cdot 10^{95}:\\ \;\;\;\;\sqrt{y \cdot y + x \cdot x}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array}\]

Reproduce

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