Average Error: 31.6 → 17.8
Time: 13.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 r579157 = x;
        double r579158 = r579157 * r579157;
        double r579159 = y;
        double r579160 = r579159 * r579159;
        double r579161 = r579158 + r579160;
        double r579162 = sqrt(r579161);
        return r579162;
}

double f(double x, double y) {
        double r579163 = x;
        double r579164 = -1.1564076018637175e+112;
        bool r579165 = r579163 <= r579164;
        double r579166 = -r579163;
        double r579167 = 1.3595155319523303e+138;
        bool r579168 = r579163 <= r579167;
        double r579169 = r579163 * r579163;
        double r579170 = y;
        double r579171 = r579170 * r579170;
        double r579172 = r579169 + r579171;
        double r579173 = sqrt(r579172);
        double r579174 = r579168 ? r579173 : r579163;
        double r579175 = r579165 ? r579166 : r579174;
        return r579175;
}

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