Average Error: 31.6 → 17.8
Time: 13.3s
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 r483446 = x;
        double r483447 = r483446 * r483446;
        double r483448 = y;
        double r483449 = r483448 * r483448;
        double r483450 = r483447 + r483449;
        double r483451 = sqrt(r483450);
        return r483451;
}

double f(double x, double y) {
        double r483452 = x;
        double r483453 = -1.1564076018637175e+112;
        bool r483454 = r483452 <= r483453;
        double r483455 = -r483452;
        double r483456 = 1.3595155319523303e+138;
        bool r483457 = r483452 <= r483456;
        double r483458 = r483452 * r483452;
        double r483459 = y;
        double r483460 = r483459 * r483459;
        double r483461 = r483458 + r483460;
        double r483462 = sqrt(r483461);
        double r483463 = r483457 ? r483462 : r483452;
        double r483464 = r483454 ? r483455 : r483463;
        return r483464;
}

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))))