Average Error: 31.2 → 17.7
Time: 9.1s
Precision: 64
\[\sqrt{x \cdot x + y \cdot y}\]
\[\begin{array}{l} \mathbf{if}\;x \le -3.678618962503878310745576389575152495213 \cdot 10^{116}:\\ \;\;\;\;-x\\ \mathbf{elif}\;x \le 5.040226837234034558242684540958197337932 \cdot 10^{87}:\\ \;\;\;\;\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 -3.678618962503878310745576389575152495213 \cdot 10^{116}:\\
\;\;\;\;-x\\

\mathbf{elif}\;x \le 5.040226837234034558242684540958197337932 \cdot 10^{87}:\\
\;\;\;\;\sqrt{y \cdot y + x \cdot x}\\

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

\end{array}
double f(double x, double y) {
        double r641517 = x;
        double r641518 = r641517 * r641517;
        double r641519 = y;
        double r641520 = r641519 * r641519;
        double r641521 = r641518 + r641520;
        double r641522 = sqrt(r641521);
        return r641522;
}

double f(double x, double y) {
        double r641523 = x;
        double r641524 = -3.678618962503878e+116;
        bool r641525 = r641523 <= r641524;
        double r641526 = -r641523;
        double r641527 = 5.0402268372340346e+87;
        bool r641528 = r641523 <= r641527;
        double r641529 = y;
        double r641530 = r641529 * r641529;
        double r641531 = r641523 * r641523;
        double r641532 = r641530 + r641531;
        double r641533 = sqrt(r641532);
        double r641534 = r641528 ? r641533 : r641523;
        double r641535 = r641525 ? r641526 : r641534;
        return r641535;
}

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.2
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 < -3.678618962503878e+116

    1. Initial program 54.0

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

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

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

    if -3.678618962503878e+116 < x < 5.0402268372340346e+87

    1. Initial program 21.0

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

    if 5.0402268372340346e+87 < x

    1. Initial program 50.4

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -3.678618962503878310745576389575152495213 \cdot 10^{116}:\\ \;\;\;\;-x\\ \mathbf{elif}\;x \le 5.040226837234034558242684540958197337932 \cdot 10^{87}:\\ \;\;\;\;\sqrt{y \cdot y + x \cdot x}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array}\]

Reproduce

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