Average Error: 29.6 → 17.1
Time: 4.4s
Precision: 64
\[\sqrt{x \cdot x + y \cdot y}\]
\[\begin{array}{l} \mathbf{if}\;x \le -6.15241991167455 \cdot 10^{+150}:\\ \;\;\;\;-x\\ \mathbf{elif}\;x \le 1.8791426213625292 \cdot 10^{+66}:\\ \;\;\;\;\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 -6.15241991167455 \cdot 10^{+150}:\\
\;\;\;\;-x\\

\mathbf{elif}\;x \le 1.8791426213625292 \cdot 10^{+66}:\\
\;\;\;\;\sqrt{y \cdot y + x \cdot x}\\

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

\end{array}
double f(double x, double y) {
        double r43615466 = x;
        double r43615467 = r43615466 * r43615466;
        double r43615468 = y;
        double r43615469 = r43615468 * r43615468;
        double r43615470 = r43615467 + r43615469;
        double r43615471 = sqrt(r43615470);
        return r43615471;
}

double f(double x, double y) {
        double r43615472 = x;
        double r43615473 = -6.15241991167455e+150;
        bool r43615474 = r43615472 <= r43615473;
        double r43615475 = -r43615472;
        double r43615476 = 1.8791426213625292e+66;
        bool r43615477 = r43615472 <= r43615476;
        double r43615478 = y;
        double r43615479 = r43615478 * r43615478;
        double r43615480 = r43615472 * r43615472;
        double r43615481 = r43615479 + r43615480;
        double r43615482 = sqrt(r43615481);
        double r43615483 = r43615477 ? r43615482 : r43615472;
        double r43615484 = r43615474 ? r43615475 : r43615483;
        return r43615484;
}

Error

Bits error versus x

Bits error versus y

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original29.6
Target17.0
Herbie17.1
\[\begin{array}{l} \mathbf{if}\;x \lt -1.1236950826599826 \cdot 10^{+145}:\\ \;\;\;\;-x\\ \mathbf{elif}\;x \lt 1.116557621183362 \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 < -6.15241991167455e+150

    1. Initial program 58.2

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

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

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

    if -6.15241991167455e+150 < x < 1.8791426213625292e+66

    1. Initial program 20.3

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

    if 1.8791426213625292e+66 < x

    1. Initial program 44.2

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -6.15241991167455 \cdot 10^{+150}:\\ \;\;\;\;-x\\ \mathbf{elif}\;x \le 1.8791426213625292 \cdot 10^{+66}:\\ \;\;\;\;\sqrt{y \cdot y + x \cdot x}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array}\]

Reproduce

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