Average Error: 31.0 → 17.4
Time: 4.1s
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 r37651688 = x;
        double r37651689 = r37651688 * r37651688;
        double r37651690 = y;
        double r37651691 = r37651690 * r37651690;
        double r37651692 = r37651689 + r37651691;
        double r37651693 = sqrt(r37651692);
        return r37651693;
}

double f(double x, double y) {
        double r37651694 = x;
        double r37651695 = -2.222006465724332e+103;
        bool r37651696 = r37651694 <= r37651695;
        double r37651697 = -r37651694;
        double r37651698 = 4.85677085461073e+140;
        bool r37651699 = r37651694 <= r37651698;
        double r37651700 = y;
        double r37651701 = r37651700 * r37651700;
        double r37651702 = r37651694 * r37651694;
        double r37651703 = r37651701 + r37651702;
        double r37651704 = sqrt(r37651703);
        double r37651705 = r37651699 ? r37651704 : r37651694;
        double r37651706 = r37651696 ? r37651697 : r37651705;
        return r37651706;
}

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))))