Average Error: 31.6 → 17.8
Time: 14.2s
Precision: 64
\[\sqrt{x \cdot x + y \cdot y}\]
\[\begin{array}{l} \mathbf{if}\;x \le -1.156407601863717509012505141513837828653 \cdot 10^{112}:\\ \;\;\;\;-x\\ \mathbf{elif}\;x \le 1.359515531952330295686549505956711156315 \cdot 10^{138}:\\ \;\;\;\;\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 -1.156407601863717509012505141513837828653 \cdot 10^{112}:\\
\;\;\;\;-x\\

\mathbf{elif}\;x \le 1.359515531952330295686549505956711156315 \cdot 10^{138}:\\
\;\;\;\;\sqrt{x \cdot x + y \cdot y}\\

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

\end{array}
double f(double x, double y) {
        double r485458 = x;
        double r485459 = r485458 * r485458;
        double r485460 = y;
        double r485461 = r485460 * r485460;
        double r485462 = r485459 + r485461;
        double r485463 = sqrt(r485462);
        return r485463;
}

double f(double x, double y) {
        double r485464 = x;
        double r485465 = -1.1564076018637175e+112;
        bool r485466 = r485464 <= r485465;
        double r485467 = -r485464;
        double r485468 = 1.3595155319523303e+138;
        bool r485469 = r485464 <= r485468;
        double r485470 = r485464 * r485464;
        double r485471 = y;
        double r485472 = r485471 * r485471;
        double r485473 = r485470 + r485472;
        double r485474 = sqrt(r485473);
        double r485475 = r485469 ? r485474 : r485464;
        double r485476 = r485466 ? r485467 : r485475;
        return r485476;
}

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.6
Target17.8
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 < -1.1564076018637175e+112

    1. Initial program 52.8

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

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

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

    if -1.1564076018637175e+112 < x < 1.3595155319523303e+138

    1. Initial program 21.4

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

    if 1.3595155319523303e+138 < x

    1. Initial program 58.8

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -1.156407601863717509012505141513837828653 \cdot 10^{112}:\\ \;\;\;\;-x\\ \mathbf{elif}\;x \le 1.359515531952330295686549505956711156315 \cdot 10^{138}:\\ \;\;\;\;\sqrt{x \cdot x + y \cdot y}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array}\]

Reproduce

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