Average Error: 29.4 → 16.8
Time: 7.3s
Precision: 64
\[\sqrt{x \cdot x + y \cdot y}\]
\[\begin{array}{l} \mathbf{if}\;x \le -2.6806112513558803 \cdot 10^{+152}:\\ \;\;\;\;-x\\ \mathbf{elif}\;x \le 3.221654116729901 \cdot 10^{+106}:\\ \;\;\;\;\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 -2.6806112513558803 \cdot 10^{+152}:\\
\;\;\;\;-x\\

\mathbf{elif}\;x \le 3.221654116729901 \cdot 10^{+106}:\\
\;\;\;\;\sqrt{y \cdot y + x \cdot x}\\

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

\end{array}
double f(double x, double y) {
        double r33951976 = x;
        double r33951977 = r33951976 * r33951976;
        double r33951978 = y;
        double r33951979 = r33951978 * r33951978;
        double r33951980 = r33951977 + r33951979;
        double r33951981 = sqrt(r33951980);
        return r33951981;
}

double f(double x, double y) {
        double r33951982 = x;
        double r33951983 = -2.6806112513558803e+152;
        bool r33951984 = r33951982 <= r33951983;
        double r33951985 = -r33951982;
        double r33951986 = 3.221654116729901e+106;
        bool r33951987 = r33951982 <= r33951986;
        double r33951988 = y;
        double r33951989 = r33951988 * r33951988;
        double r33951990 = r33951982 * r33951982;
        double r33951991 = r33951989 + r33951990;
        double r33951992 = sqrt(r33951991);
        double r33951993 = r33951987 ? r33951992 : r33951982;
        double r33951994 = r33951984 ? r33951985 : r33951993;
        return r33951994;
}

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.9
Herbie16.8
\[\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 < -2.6806112513558803e+152

    1. Initial program 58.8

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

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

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

    if -2.6806112513558803e+152 < x < 3.221654116729901e+106

    1. Initial program 19.7

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

    if 3.221654116729901e+106 < x

    1. Initial program 48.9

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -2.6806112513558803 \cdot 10^{+152}:\\ \;\;\;\;-x\\ \mathbf{elif}\;x \le 3.221654116729901 \cdot 10^{+106}:\\ \;\;\;\;\sqrt{y \cdot y + x \cdot x}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array}\]

Reproduce

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