Average Error: 31.3 → 18.0
Time: 12.3s
Precision: 64
\[\sqrt{x \cdot x + y \cdot y}\]
\[\begin{array}{l} \mathbf{if}\;x \le -6.380870002726310342811700587071868218435 \cdot 10^{59}:\\ \;\;\;\;-x\\ \mathbf{elif}\;x \le 2.566938280750767851167015199229297462562 \cdot 10^{114}:\\ \;\;\;\;\sqrt{x \cdot x + y \cdot y}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array}\]
\sqrt{x \cdot x + y \cdot y}
\begin{array}{l}
\mathbf{if}\;x \le -6.380870002726310342811700587071868218435 \cdot 10^{59}:\\
\;\;\;\;-x\\

\mathbf{elif}\;x \le 2.566938280750767851167015199229297462562 \cdot 10^{114}:\\
\;\;\;\;\sqrt{x \cdot x + y \cdot y}\\

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

\end{array}
double f(double x, double y) {
        double r513882 = x;
        double r513883 = r513882 * r513882;
        double r513884 = y;
        double r513885 = r513884 * r513884;
        double r513886 = r513883 + r513885;
        double r513887 = sqrt(r513886);
        return r513887;
}

double f(double x, double y) {
        double r513888 = x;
        double r513889 = -6.38087000272631e+59;
        bool r513890 = r513888 <= r513889;
        double r513891 = -r513888;
        double r513892 = 2.566938280750768e+114;
        bool r513893 = r513888 <= r513892;
        double r513894 = r513888 * r513888;
        double r513895 = y;
        double r513896 = r513895 * r513895;
        double r513897 = r513894 + r513896;
        double r513898 = sqrt(r513897);
        double r513899 = r513893 ? r513898 : r513888;
        double r513900 = r513890 ? r513891 : r513899;
        return r513900;
}

Error

Bits error versus x

Bits error versus y

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original31.3
Target17.7
Herbie18.0
\[\begin{array}{l} \mathbf{if}\;x \lt -1.123695082659982632437974301616192301785 \cdot 10^{145}:\\ \;\;\;\;-x\\ \mathbf{elif}\;x \lt 1.116557621183362039388201959321597704512 \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.38087000272631e+59

    1. Initial program 44.7

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

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

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

    if -6.38087000272631e+59 < x < 2.566938280750768e+114

    1. Initial program 21.7

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

    if 2.566938280750768e+114 < x

    1. Initial program 53.4

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -6.380870002726310342811700587071868218435 \cdot 10^{59}:\\ \;\;\;\;-x\\ \mathbf{elif}\;x \le 2.566938280750767851167015199229297462562 \cdot 10^{114}:\\ \;\;\;\;\sqrt{x \cdot x + y \cdot y}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array}\]

Reproduce

herbie shell --seed 2019326 
(FPCore (x y)
  :name "Data.Octree.Internal:octantDistance  from Octree-0.5.4.2"
  :precision binary64

  :herbie-target
  (if (< x -1.123695082659983e+145) (- x) (if (< x 1.116557621183362e+93) (sqrt (+ (* x x) (* y y))) x))

  (sqrt (+ (* x x) (* y y))))