Average Error: 31.6 → 17.7
Time: 11.1s
Precision: 64
\[\sqrt{x \cdot x + y \cdot y}\]
\[\begin{array}{l} \mathbf{if}\;x \le -2.60085321524529635506480666887989434939 \cdot 10^{111}:\\ \;\;\;\;-x\\ \mathbf{elif}\;x \le 2.967077572269142663773808601587033057531 \cdot 10^{83}:\\ \;\;\;\;\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.60085321524529635506480666887989434939 \cdot 10^{111}:\\
\;\;\;\;-x\\

\mathbf{elif}\;x \le 2.967077572269142663773808601587033057531 \cdot 10^{83}:\\
\;\;\;\;\sqrt{y \cdot y + x \cdot x}\\

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

\end{array}
double f(double x, double y) {
        double r34696299 = x;
        double r34696300 = r34696299 * r34696299;
        double r34696301 = y;
        double r34696302 = r34696301 * r34696301;
        double r34696303 = r34696300 + r34696302;
        double r34696304 = sqrt(r34696303);
        return r34696304;
}

double f(double x, double y) {
        double r34696305 = x;
        double r34696306 = -2.6008532152452964e+111;
        bool r34696307 = r34696305 <= r34696306;
        double r34696308 = -r34696305;
        double r34696309 = 2.9670775722691427e+83;
        bool r34696310 = r34696305 <= r34696309;
        double r34696311 = y;
        double r34696312 = r34696311 * r34696311;
        double r34696313 = r34696305 * r34696305;
        double r34696314 = r34696312 + r34696313;
        double r34696315 = sqrt(r34696314);
        double r34696316 = r34696310 ? r34696315 : r34696305;
        double r34696317 = r34696307 ? r34696308 : r34696316;
        return r34696317;
}

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.6
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 < -2.6008532152452964e+111

    1. Initial program 53.2

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

      \[\leadsto \color{blue}{-1 \cdot x}\]
    3. Simplified8.9

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

    if -2.6008532152452964e+111 < x < 2.9670775722691427e+83

    1. Initial program 21.6

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

    if 2.9670775722691427e+83 < x

    1. Initial program 47.9

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -2.60085321524529635506480666887989434939 \cdot 10^{111}:\\ \;\;\;\;-x\\ \mathbf{elif}\;x \le 2.967077572269142663773808601587033057531 \cdot 10^{83}:\\ \;\;\;\;\sqrt{y \cdot y + x \cdot x}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array}\]

Reproduce

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