Average Error: 31.1 → 17.3
Time: 2.6s
Precision: 64
\[\sqrt{x \cdot x + y \cdot y}\]
\[\begin{array}{l} \mathbf{if}\;x \le -3.6980740601030615 \cdot 10^{63}:\\ \;\;\;\;-1 \cdot x\\ \mathbf{elif}\;x \le 9.1753737888878369 \cdot 10^{116}:\\ \;\;\;\;\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 -3.6980740601030615 \cdot 10^{63}:\\
\;\;\;\;-1 \cdot x\\

\mathbf{elif}\;x \le 9.1753737888878369 \cdot 10^{116}:\\
\;\;\;\;\sqrt{x \cdot x + y \cdot y}\\

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

\end{array}
double f(double x, double y) {
        double r781981 = x;
        double r781982 = r781981 * r781981;
        double r781983 = y;
        double r781984 = r781983 * r781983;
        double r781985 = r781982 + r781984;
        double r781986 = sqrt(r781985);
        return r781986;
}

double f(double x, double y) {
        double r781987 = x;
        double r781988 = -3.6980740601030615e+63;
        bool r781989 = r781987 <= r781988;
        double r781990 = -1.0;
        double r781991 = r781990 * r781987;
        double r781992 = 9.175373788887837e+116;
        bool r781993 = r781987 <= r781992;
        double r781994 = r781987 * r781987;
        double r781995 = y;
        double r781996 = r781995 * r781995;
        double r781997 = r781994 + r781996;
        double r781998 = sqrt(r781997);
        double r781999 = r781993 ? r781998 : r781987;
        double r782000 = r781989 ? r781991 : r781999;
        return r782000;
}

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.1
Target17.3
Herbie17.3
\[\begin{array}{l} \mathbf{if}\;x \lt -1.123695082659983 \cdot 10^{145}:\\ \;\;\;\;-x\\ \mathbf{elif}\;x \lt 1.11655762118336204 \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.6980740601030615e+63

    1. Initial program 46.0

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

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

    if -3.6980740601030615e+63 < x < 9.175373788887837e+116

    1. Initial program 20.9

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

    if 9.175373788887837e+116 < x

    1. Initial program 55.4

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -3.6980740601030615 \cdot 10^{63}:\\ \;\;\;\;-1 \cdot x\\ \mathbf{elif}\;x \le 9.1753737888878369 \cdot 10^{116}:\\ \;\;\;\;\sqrt{x \cdot x + y \cdot y}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array}\]

Reproduce

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