Average Error: 31.4 → 17.8
Time: 5.4s
Precision: 64
\[\sqrt{x \cdot x + y \cdot y}\]
\[\begin{array}{l} \mathbf{if}\;x \le -2.273448994496035253530762983989520870583 \cdot 10^{87}:\\ \;\;\;\;-x\\ \mathbf{elif}\;x \le 1.763702591686904819827254628881572839528 \cdot 10^{111}:\\ \;\;\;\;\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 -2.273448994496035253530762983989520870583 \cdot 10^{87}:\\
\;\;\;\;-x\\

\mathbf{elif}\;x \le 1.763702591686904819827254628881572839528 \cdot 10^{111}:\\
\;\;\;\;\sqrt{y \cdot y + x \cdot x}\\

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

\end{array}
double f(double x, double y) {
        double r36790458 = x;
        double r36790459 = r36790458 * r36790458;
        double r36790460 = y;
        double r36790461 = r36790460 * r36790460;
        double r36790462 = r36790459 + r36790461;
        double r36790463 = sqrt(r36790462);
        return r36790463;
}

double f(double x, double y) {
        double r36790464 = x;
        double r36790465 = -2.2734489944960353e+87;
        bool r36790466 = r36790464 <= r36790465;
        double r36790467 = -r36790464;
        double r36790468 = 1.7637025916869048e+111;
        bool r36790469 = r36790464 <= r36790468;
        double r36790470 = y;
        double r36790471 = r36790470 * r36790470;
        double r36790472 = r36790464 * r36790464;
        double r36790473 = r36790471 + r36790472;
        double r36790474 = sqrt(r36790473);
        double r36790475 = r36790469 ? r36790474 : r36790464;
        double r36790476 = r36790466 ? r36790467 : r36790475;
        return r36790476;
}

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.4
Target17.7
Herbie17.8
\[\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.2734489944960353e+87

    1. Initial program 49.1

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

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

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

    if -2.2734489944960353e+87 < x < 1.7637025916869048e+111

    1. Initial program 21.4

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

    if 1.7637025916869048e+111 < x

    1. Initial program 53.8

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -2.273448994496035253530762983989520870583 \cdot 10^{87}:\\ \;\;\;\;-x\\ \mathbf{elif}\;x \le 1.763702591686904819827254628881572839528 \cdot 10^{111}:\\ \;\;\;\;\sqrt{y \cdot y + x \cdot x}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array}\]

Reproduce

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