Average Error: 31.9 → 17.7
Time: 12.7s
Precision: 64
\[\sqrt{x \cdot x + y \cdot y}\]
\[\begin{array}{l} \mathbf{if}\;x \le -1.287656836218587817843721098850935729447 \cdot 10^{137}:\\ \;\;\;\;-x\\ \mathbf{elif}\;x \le 2.715346883449109812449415853977495365892 \cdot 10^{73}:\\ \;\;\;\;\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.287656836218587817843721098850935729447 \cdot 10^{137}:\\
\;\;\;\;-x\\

\mathbf{elif}\;x \le 2.715346883449109812449415853977495365892 \cdot 10^{73}:\\
\;\;\;\;\sqrt{x \cdot x + y \cdot y}\\

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

\end{array}
double f(double x, double y) {
        double r511291 = x;
        double r511292 = r511291 * r511291;
        double r511293 = y;
        double r511294 = r511293 * r511293;
        double r511295 = r511292 + r511294;
        double r511296 = sqrt(r511295);
        return r511296;
}

double f(double x, double y) {
        double r511297 = x;
        double r511298 = -1.2876568362185878e+137;
        bool r511299 = r511297 <= r511298;
        double r511300 = -r511297;
        double r511301 = 2.7153468834491098e+73;
        bool r511302 = r511297 <= r511301;
        double r511303 = r511297 * r511297;
        double r511304 = y;
        double r511305 = r511304 * r511304;
        double r511306 = r511303 + r511305;
        double r511307 = sqrt(r511306);
        double r511308 = r511302 ? r511307 : r511297;
        double r511309 = r511299 ? r511300 : r511308;
        return r511309;
}

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.9
Target17.6
Herbie17.7
\[\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.2876568362185878e+137

    1. Initial program 59.8

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

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

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

    if -1.2876568362185878e+137 < x < 2.7153468834491098e+73

    1. Initial program 21.5

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

    if 2.7153468834491098e+73 < x

    1. Initial program 47.0

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -1.287656836218587817843721098850935729447 \cdot 10^{137}:\\ \;\;\;\;-x\\ \mathbf{elif}\;x \le 2.715346883449109812449415853977495365892 \cdot 10^{73}:\\ \;\;\;\;\sqrt{x \cdot x + y \cdot y}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array}\]

Reproduce

herbie shell --seed 2019304 
(FPCore (x y)
  :name "Data.Octree.Internal:octantDistance  from Octree-0.5.4.2"
  :precision binary64

  :herbie-target
  (if (< x -1.123695082659983e145) (- x) (if (< x 1.11655762118336204e93) (sqrt (+ (* x x) (* y y))) x))

  (sqrt (+ (* x x) (* y y))))