Average Error: 31.5 → 17.4
Time: 6.1s
Precision: 64
\[\sqrt{x \cdot x + y \cdot y}\]
\[\begin{array}{l} \mathbf{if}\;x \le -4.1094940511471951 \cdot 10^{119}:\\ \;\;\;\;-x\\ \mathbf{elif}\;x \le 1.1032025771158766 \cdot 10^{142}:\\ \;\;\;\;\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 -4.1094940511471951 \cdot 10^{119}:\\
\;\;\;\;-x\\

\mathbf{elif}\;x \le 1.1032025771158766 \cdot 10^{142}:\\
\;\;\;\;\sqrt{x \cdot x + y \cdot y}\\

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

\end{array}
double f(double x, double y) {
        double r1026130 = x;
        double r1026131 = r1026130 * r1026130;
        double r1026132 = y;
        double r1026133 = r1026132 * r1026132;
        double r1026134 = r1026131 + r1026133;
        double r1026135 = sqrt(r1026134);
        return r1026135;
}

double f(double x, double y) {
        double r1026136 = x;
        double r1026137 = -4.109494051147195e+119;
        bool r1026138 = r1026136 <= r1026137;
        double r1026139 = -r1026136;
        double r1026140 = 1.1032025771158766e+142;
        bool r1026141 = r1026136 <= r1026140;
        double r1026142 = r1026136 * r1026136;
        double r1026143 = y;
        double r1026144 = r1026143 * r1026143;
        double r1026145 = r1026142 + r1026144;
        double r1026146 = sqrt(r1026145);
        double r1026147 = r1026141 ? r1026146 : r1026136;
        double r1026148 = r1026138 ? r1026139 : r1026147;
        return r1026148;
}

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.5
Target17.5
Herbie17.4
\[\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 < -4.109494051147195e+119

    1. Initial program 55.2

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

      \[\leadsto \color{blue}{-1 \cdot x}\]
    3. Simplified9.8

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

    if -4.109494051147195e+119 < x < 1.1032025771158766e+142

    1. Initial program 20.7

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

    if 1.1032025771158766e+142 < x

    1. Initial program 60.2

      \[\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 -4.1094940511471951 \cdot 10^{119}:\\ \;\;\;\;-x\\ \mathbf{elif}\;x \le 1.1032025771158766 \cdot 10^{142}:\\ \;\;\;\;\sqrt{x \cdot x + y \cdot y}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array}\]

Reproduce

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