Average Error: 31.7 → 18.2
Time: 3.3s
Precision: 64
\[\sqrt{x \cdot x + y \cdot y}\]
\[\begin{array}{l} \mathbf{if}\;x \le -2.27109209614237641 \cdot 10^{59}:\\ \;\;\;\;-1 \cdot x\\ \mathbf{elif}\;x \le 9.6349667233636427 \cdot 10^{131}:\\ \;\;\;\;\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 -2.27109209614237641 \cdot 10^{59}:\\
\;\;\;\;-1 \cdot x\\

\mathbf{elif}\;x \le 9.6349667233636427 \cdot 10^{131}:\\
\;\;\;\;\sqrt{x \cdot x + y \cdot y}\\

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

\end{array}
double f(double x, double y) {
        double r818555 = x;
        double r818556 = r818555 * r818555;
        double r818557 = y;
        double r818558 = r818557 * r818557;
        double r818559 = r818556 + r818558;
        double r818560 = sqrt(r818559);
        return r818560;
}

double f(double x, double y) {
        double r818561 = x;
        double r818562 = -2.2710920961423764e+59;
        bool r818563 = r818561 <= r818562;
        double r818564 = -1.0;
        double r818565 = r818564 * r818561;
        double r818566 = 9.634966723363643e+131;
        bool r818567 = r818561 <= r818566;
        double r818568 = r818561 * r818561;
        double r818569 = y;
        double r818570 = r818569 * r818569;
        double r818571 = r818568 + r818570;
        double r818572 = sqrt(r818571);
        double r818573 = r818567 ? r818572 : r818561;
        double r818574 = r818563 ? r818565 : r818573;
        return r818574;
}

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
Herbie18.2
\[\begin{array}{l} \mathbf{if}\;x \lt -1.123695082659983 \cdot 10^{145}:\\ \;\;\;\;-x\\ \mathbf{elif}\;x \lt 1.11655762118336204 \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 < -2.2710920961423764e+59

    1. Initial program 45.1

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

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

    if -2.2710920961423764e+59 < x < 9.634966723363643e+131

    1. Initial program 22.0

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

    if 9.634966723363643e+131 < x

    1. Initial program 57.8

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -2.27109209614237641 \cdot 10^{59}:\\ \;\;\;\;-1 \cdot x\\ \mathbf{elif}\;x \le 9.6349667233636427 \cdot 10^{131}:\\ \;\;\;\;\sqrt{x \cdot x + y \cdot y}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array}\]

Reproduce

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