Average Error: 28.9 → 16.6
Time: 10.6s
Precision: 64
\[\sqrt{x \cdot x + y \cdot y}\]
\[\begin{array}{l} \mathbf{if}\;x \le -1.2743190345131582 \cdot 10^{+154}:\\ \;\;\;\;-x\\ \mathbf{elif}\;x \le 5.887500437435469 \cdot 10^{+139}:\\ \;\;\;\;\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 -1.2743190345131582 \cdot 10^{+154}:\\
\;\;\;\;-x\\

\mathbf{elif}\;x \le 5.887500437435469 \cdot 10^{+139}:\\
\;\;\;\;\sqrt{y \cdot y + x \cdot x}\\

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

\end{array}
double f(double x, double y) {
        double r29188749 = x;
        double r29188750 = r29188749 * r29188749;
        double r29188751 = y;
        double r29188752 = r29188751 * r29188751;
        double r29188753 = r29188750 + r29188752;
        double r29188754 = sqrt(r29188753);
        return r29188754;
}

double f(double x, double y) {
        double r29188755 = x;
        double r29188756 = -1.2743190345131582e+154;
        bool r29188757 = r29188755 <= r29188756;
        double r29188758 = -r29188755;
        double r29188759 = 5.887500437435469e+139;
        bool r29188760 = r29188755 <= r29188759;
        double r29188761 = y;
        double r29188762 = r29188761 * r29188761;
        double r29188763 = r29188755 * r29188755;
        double r29188764 = r29188762 + r29188763;
        double r29188765 = sqrt(r29188764);
        double r29188766 = r29188760 ? r29188765 : r29188755;
        double r29188767 = r29188757 ? r29188758 : r29188766;
        return r29188767;
}

Error

Bits error versus x

Bits error versus y

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original28.9
Target16.7
Herbie16.6
\[\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 < -1.2743190345131582e+154

    1. Initial program 59.3

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

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

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

    if -1.2743190345131582e+154 < x < 5.887500437435469e+139

    1. Initial program 19.4

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

    if 5.887500437435469e+139 < x

    1. Initial program 56.3

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -1.2743190345131582 \cdot 10^{+154}:\\ \;\;\;\;-x\\ \mathbf{elif}\;x \le 5.887500437435469 \cdot 10^{+139}:\\ \;\;\;\;\sqrt{y \cdot y + x \cdot x}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array}\]

Reproduce

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