Average Error: 31.9 → 17.7
Time: 4.1s
Precision: 64
\[\sqrt{x \cdot x + y \cdot y}\]
\[\begin{array}{l} \mathbf{if}\;x \le -1.287656836218587817843721098850935729447 \cdot 10^{137}:\\ \;\;\;\;-1 \cdot x\\ \mathbf{elif}\;x \le 2.715346883449109812449415853977495365892 \cdot 10^{73}:\\ \;\;\;\;\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 -1.287656836218587817843721098850935729447 \cdot 10^{137}:\\
\;\;\;\;-1 \cdot x\\

\mathbf{elif}\;x \le 2.715346883449109812449415853977495365892 \cdot 10^{73}:\\
\;\;\;\;\sqrt{x \cdot x + y \cdot y}\\

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

\end{array}
double f(double x, double y) {
        double r442862 = x;
        double r442863 = r442862 * r442862;
        double r442864 = y;
        double r442865 = r442864 * r442864;
        double r442866 = r442863 + r442865;
        double r442867 = sqrt(r442866);
        return r442867;
}

double f(double x, double y) {
        double r442868 = x;
        double r442869 = -1.2876568362185878e+137;
        bool r442870 = r442868 <= r442869;
        double r442871 = -1.0;
        double r442872 = r442871 * r442868;
        double r442873 = 2.7153468834491098e+73;
        bool r442874 = r442868 <= r442873;
        double r442875 = r442868 * r442868;
        double r442876 = y;
        double r442877 = r442876 * r442876;
        double r442878 = r442875 + r442877;
        double r442879 = sqrt(r442878);
        double r442880 = r442874 ? r442879 : r442868;
        double r442881 = r442870 ? r442872 : r442880;
        return r442881;
}

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.9
Target17.6
Herbie17.7
\[\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 < -1.2876568362185878e+137

    1. Initial program 59.8

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

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

    if -1.2876568362185878e+137 < x < 2.7153468834491098e+73

    1. Initial program 21.5

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

    if 2.7153468834491098e+73 < x

    1. Initial program 47.0

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -1.287656836218587817843721098850935729447 \cdot 10^{137}:\\ \;\;\;\;-1 \cdot x\\ \mathbf{elif}\;x \le 2.715346883449109812449415853977495365892 \cdot 10^{73}:\\ \;\;\;\;\sqrt{x \cdot x + y \cdot y}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array}\]

Reproduce

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

  :herbie-target
  (if (< x -1.123695082659983e145) (- x) (if (< x 1.11655762118336204e93) (sqrt (+ (* x x) (* y y))) x))

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