Average Error: 31.7 → 17.8
Time: 3.8s
Precision: 64
\[\sqrt{x \cdot x + y \cdot y}\]
\[\begin{array}{l} \mathbf{if}\;x \le -1.178594449777199163791033377764152427439 \cdot 10^{109}:\\ \;\;\;\;-x\\ \mathbf{elif}\;x \le 1.876761322676858408683984671658326382422 \cdot 10^{119}:\\ \;\;\;\;\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.178594449777199163791033377764152427439 \cdot 10^{109}:\\
\;\;\;\;-x\\

\mathbf{elif}\;x \le 1.876761322676858408683984671658326382422 \cdot 10^{119}:\\
\;\;\;\;\sqrt{x \cdot x + y \cdot y}\\

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

\end{array}
double f(double x, double y) {
        double r507375 = x;
        double r507376 = r507375 * r507375;
        double r507377 = y;
        double r507378 = r507377 * r507377;
        double r507379 = r507376 + r507378;
        double r507380 = sqrt(r507379);
        return r507380;
}

double f(double x, double y) {
        double r507381 = x;
        double r507382 = -1.1785944497771992e+109;
        bool r507383 = r507381 <= r507382;
        double r507384 = -r507381;
        double r507385 = 1.8767613226768584e+119;
        bool r507386 = r507381 <= r507385;
        double r507387 = r507381 * r507381;
        double r507388 = y;
        double r507389 = r507388 * r507388;
        double r507390 = r507387 + r507389;
        double r507391 = sqrt(r507390);
        double r507392 = r507386 ? r507391 : r507381;
        double r507393 = r507383 ? r507384 : r507392;
        return r507393;
}

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.9
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.1785944497771992e+109

    1. Initial program 54.3

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

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

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

    if -1.1785944497771992e+109 < x < 1.8767613226768584e+119

    1. Initial program 21.4

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

    if 1.8767613226768584e+119 < x

    1. Initial program 55.9

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -1.178594449777199163791033377764152427439 \cdot 10^{109}:\\ \;\;\;\;-x\\ \mathbf{elif}\;x \le 1.876761322676858408683984671658326382422 \cdot 10^{119}:\\ \;\;\;\;\sqrt{x \cdot x + y \cdot y}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array}\]

Reproduce

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