Average Error: 31.0 → 17.4
Time: 3.9s
Precision: 64
\[\sqrt{x \cdot x + y \cdot y}\]
\[\begin{array}{l} \mathbf{if}\;x \le -2.222006465724332039862348815623896484961 \cdot 10^{103}:\\ \;\;\;\;-x\\ \mathbf{elif}\;x \le 4.856770854610730383064334389991702440912 \cdot 10^{140}:\\ \;\;\;\;\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.222006465724332039862348815623896484961 \cdot 10^{103}:\\
\;\;\;\;-x\\

\mathbf{elif}\;x \le 4.856770854610730383064334389991702440912 \cdot 10^{140}:\\
\;\;\;\;\sqrt{y \cdot y + x \cdot x}\\

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

\end{array}
double f(double x, double y) {
        double r38665971 = x;
        double r38665972 = r38665971 * r38665971;
        double r38665973 = y;
        double r38665974 = r38665973 * r38665973;
        double r38665975 = r38665972 + r38665974;
        double r38665976 = sqrt(r38665975);
        return r38665976;
}

double f(double x, double y) {
        double r38665977 = x;
        double r38665978 = -2.222006465724332e+103;
        bool r38665979 = r38665977 <= r38665978;
        double r38665980 = -r38665977;
        double r38665981 = 4.85677085461073e+140;
        bool r38665982 = r38665977 <= r38665981;
        double r38665983 = y;
        double r38665984 = r38665983 * r38665983;
        double r38665985 = r38665977 * r38665977;
        double r38665986 = r38665984 + r38665985;
        double r38665987 = sqrt(r38665986);
        double r38665988 = r38665982 ? r38665987 : r38665977;
        double r38665989 = r38665979 ? r38665980 : r38665988;
        return r38665989;
}

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.0
Target17.5
Herbie17.4
\[\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 < -2.222006465724332e+103

    1. Initial program 52.0

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

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

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

    if -2.222006465724332e+103 < x < 4.85677085461073e+140

    1. Initial program 20.7

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

    if 4.85677085461073e+140 < x

    1. Initial program 59.6

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -2.222006465724332039862348815623896484961 \cdot 10^{103}:\\ \;\;\;\;-x\\ \mathbf{elif}\;x \le 4.856770854610730383064334389991702440912 \cdot 10^{140}:\\ \;\;\;\;\sqrt{y \cdot y + x \cdot x}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array}\]

Reproduce

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