Average Error: 29.4 → 16.5
Time: 12.4s
Precision: 64
\[\sqrt{x \cdot x + y \cdot y}\]
\[\begin{array}{l} \mathbf{if}\;x \le -8.181359696053478 \cdot 10^{+96}:\\ \;\;\;\;-x\\ \mathbf{elif}\;x \le 7.263939058947569 \cdot 10^{+108}:\\ \;\;\;\;\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 -8.181359696053478 \cdot 10^{+96}:\\
\;\;\;\;-x\\

\mathbf{elif}\;x \le 7.263939058947569 \cdot 10^{+108}:\\
\;\;\;\;\sqrt{y \cdot y + x \cdot x}\\

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

\end{array}
double f(double x, double y) {
        double r40526133 = x;
        double r40526134 = r40526133 * r40526133;
        double r40526135 = y;
        double r40526136 = r40526135 * r40526135;
        double r40526137 = r40526134 + r40526136;
        double r40526138 = sqrt(r40526137);
        return r40526138;
}

double f(double x, double y) {
        double r40526139 = x;
        double r40526140 = -8.181359696053478e+96;
        bool r40526141 = r40526139 <= r40526140;
        double r40526142 = -r40526139;
        double r40526143 = 7.263939058947569e+108;
        bool r40526144 = r40526139 <= r40526143;
        double r40526145 = y;
        double r40526146 = r40526145 * r40526145;
        double r40526147 = r40526139 * r40526139;
        double r40526148 = r40526146 + r40526147;
        double r40526149 = sqrt(r40526148);
        double r40526150 = r40526144 ? r40526149 : r40526139;
        double r40526151 = r40526141 ? r40526142 : r40526150;
        return r40526151;
}

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.4
Target16.4
Herbie16.5
\[\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 < -8.181359696053478e+96

    1. Initial program 47.8

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

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

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

    if -8.181359696053478e+96 < x < 7.263939058947569e+108

    1. Initial program 19.9

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

    if 7.263939058947569e+108 < x

    1. Initial program 49.9

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -8.181359696053478 \cdot 10^{+96}:\\ \;\;\;\;-x\\ \mathbf{elif}\;x \le 7.263939058947569 \cdot 10^{+108}:\\ \;\;\;\;\sqrt{y \cdot y + x \cdot x}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array}\]

Reproduce

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