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 r37897655 = x;
        double r37897656 = r37897655 * r37897655;
        double r37897657 = y;
        double r37897658 = r37897657 * r37897657;
        double r37897659 = r37897656 + r37897658;
        double r37897660 = sqrt(r37897659);
        return r37897660;
}

double f(double x, double y) {
        double r37897661 = x;
        double r37897662 = -6.15241991167455e+150;
        bool r37897663 = r37897661 <= r37897662;
        double r37897664 = -r37897661;
        double r37897665 = 1.8791426213625292e+66;
        bool r37897666 = r37897661 <= r37897665;
        double r37897667 = y;
        double r37897668 = r37897667 * r37897667;
        double r37897669 = r37897661 * r37897661;
        double r37897670 = r37897668 + r37897669;
        double r37897671 = sqrt(r37897670);
        double r37897672 = r37897666 ? r37897671 : r37897661;
        double r37897673 = r37897663 ? r37897664 : r37897672;
        return r37897673;
}

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))))