Average Error: 31.7 → 17.4
Time: 4.3s
Precision: 64
\[\sqrt{x \cdot x + y \cdot y}\]
\[\begin{array}{l} \mathbf{if}\;x \le -1.688721359903120564949235071844216306814 \cdot 10^{100}:\\ \;\;\;\;-x\\ \mathbf{elif}\;x \le 4.314940489788706082274641758508570148355 \cdot 10^{92}:\\ \;\;\;\;\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 -1.688721359903120564949235071844216306814 \cdot 10^{100}:\\
\;\;\;\;-x\\

\mathbf{elif}\;x \le 4.314940489788706082274641758508570148355 \cdot 10^{92}:\\
\;\;\;\;\sqrt{y \cdot y + x \cdot x}\\

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

\end{array}
double f(double x, double y) {
        double r41767911 = x;
        double r41767912 = r41767911 * r41767911;
        double r41767913 = y;
        double r41767914 = r41767913 * r41767913;
        double r41767915 = r41767912 + r41767914;
        double r41767916 = sqrt(r41767915);
        return r41767916;
}

double f(double x, double y) {
        double r41767917 = x;
        double r41767918 = -1.6887213599031206e+100;
        bool r41767919 = r41767917 <= r41767918;
        double r41767920 = -r41767917;
        double r41767921 = 4.314940489788706e+92;
        bool r41767922 = r41767917 <= r41767921;
        double r41767923 = y;
        double r41767924 = r41767923 * r41767923;
        double r41767925 = r41767917 * r41767917;
        double r41767926 = r41767924 + r41767925;
        double r41767927 = sqrt(r41767926);
        double r41767928 = r41767922 ? r41767927 : r41767917;
        double r41767929 = r41767919 ? r41767920 : r41767928;
        return r41767929;
}

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.7
Target17.4
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 < -1.6887213599031206e+100

    1. Initial program 51.8

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

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

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

    if -1.6887213599031206e+100 < x < 4.314940489788706e+92

    1. Initial program 21.3

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

    if 4.314940489788706e+92 < x

    1. Initial program 50.0

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -1.688721359903120564949235071844216306814 \cdot 10^{100}:\\ \;\;\;\;-x\\ \mathbf{elif}\;x \le 4.314940489788706082274641758508570148355 \cdot 10^{92}:\\ \;\;\;\;\sqrt{y \cdot y + x \cdot x}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array}\]

Reproduce

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