Average Error: 31.7 → 17.4
Time: 3.1s
Precision: 64
\[\sqrt{x \cdot x + y \cdot y}\]
\[\begin{array}{l} \mathbf{if}\;x \le -1.688721359903120564949235071844216306814 \cdot 10^{100}:\\ \;\;\;\;-x\\ \mathbf{elif}\;x \le 4.314940489788706082274641758508570148355 \cdot 10^{92}:\\ \;\;\;\;\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 -1.688721359903120564949235071844216306814 \cdot 10^{100}:\\
\;\;\;\;-x\\

\mathbf{elif}\;x \le 4.314940489788706082274641758508570148355 \cdot 10^{92}:\\
\;\;\;\;\sqrt{y \cdot y + x \cdot x}\\

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

\end{array}
double f(double x, double y) {
        double r50166488 = x;
        double r50166489 = r50166488 * r50166488;
        double r50166490 = y;
        double r50166491 = r50166490 * r50166490;
        double r50166492 = r50166489 + r50166491;
        double r50166493 = sqrt(r50166492);
        return r50166493;
}

double f(double x, double y) {
        double r50166494 = x;
        double r50166495 = -1.6887213599031206e+100;
        bool r50166496 = r50166494 <= r50166495;
        double r50166497 = -r50166494;
        double r50166498 = 4.314940489788706e+92;
        bool r50166499 = r50166494 <= r50166498;
        double r50166500 = y;
        double r50166501 = r50166500 * r50166500;
        double r50166502 = r50166494 * r50166494;
        double r50166503 = r50166501 + r50166502;
        double r50166504 = sqrt(r50166503);
        double r50166505 = r50166499 ? r50166504 : r50166494;
        double r50166506 = r50166496 ? r50166497 : r50166505;
        return r50166506;
}

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.7
Target17.4
Herbie17.4
\[\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.6887213599031206e+100

    1. Initial program 51.8

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

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

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

    if -1.6887213599031206e+100 < x < 4.314940489788706e+92

    1. Initial program 21.3

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

    if 4.314940489788706e+92 < x

    1. Initial program 50.0

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -1.688721359903120564949235071844216306814 \cdot 10^{100}:\\ \;\;\;\;-x\\ \mathbf{elif}\;x \le 4.314940489788706082274641758508570148355 \cdot 10^{92}:\\ \;\;\;\;\sqrt{y \cdot y + x \cdot x}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array}\]

Reproduce

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