Average Error: 29.6 → 16.7
Time: 4.2s
Precision: 64
\[\sqrt{x \cdot x + y \cdot y}\]
\[\begin{array}{l} \mathbf{if}\;x \le -3.628100188584437 \cdot 10^{+152}:\\ \;\;\;\;-x\\ \mathbf{elif}\;x \le 2.6796985192192203 \cdot 10^{+137}:\\ \;\;\;\;\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 -3.628100188584437 \cdot 10^{+152}:\\
\;\;\;\;-x\\

\mathbf{elif}\;x \le 2.6796985192192203 \cdot 10^{+137}:\\
\;\;\;\;\sqrt{y \cdot y + x \cdot x}\\

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

\end{array}
double f(double x, double y) {
        double r35809825 = x;
        double r35809826 = r35809825 * r35809825;
        double r35809827 = y;
        double r35809828 = r35809827 * r35809827;
        double r35809829 = r35809826 + r35809828;
        double r35809830 = sqrt(r35809829);
        return r35809830;
}

double f(double x, double y) {
        double r35809831 = x;
        double r35809832 = -3.628100188584437e+152;
        bool r35809833 = r35809831 <= r35809832;
        double r35809834 = -r35809831;
        double r35809835 = 2.6796985192192203e+137;
        bool r35809836 = r35809831 <= r35809835;
        double r35809837 = y;
        double r35809838 = r35809837 * r35809837;
        double r35809839 = r35809831 * r35809831;
        double r35809840 = r35809838 + r35809839;
        double r35809841 = sqrt(r35809840);
        double r35809842 = r35809836 ? r35809841 : r35809831;
        double r35809843 = r35809833 ? r35809834 : r35809842;
        return r35809843;
}

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

    1. Initial program 58.8

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

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

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

    if -3.628100188584437e+152 < x < 2.6796985192192203e+137

    1. Initial program 19.9

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

    if 2.6796985192192203e+137 < x

    1. Initial program 53.9

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

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

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

Reproduce

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