Average Error: 31.4 → 17.4
Time: 1.8s
Precision: 64
\[\sqrt{x \cdot x + y \cdot y}\]
\[\begin{array}{l} \mathbf{if}\;y \le -2.8884266593894412 \cdot 10^{145}:\\ \;\;\;\;-1 \cdot y\\ \mathbf{elif}\;y \le -8.59044981858877489 \cdot 10^{-223}:\\ \;\;\;\;\sqrt{x \cdot x + y \cdot y}\\ \mathbf{elif}\;y \le 3.3111519867076028 \cdot 10^{-267}:\\ \;\;\;\;-1 \cdot x\\ \mathbf{elif}\;y \le 4.35781193024123746 \cdot 10^{99}:\\ \;\;\;\;\sqrt{x \cdot x + y \cdot y}\\ \mathbf{else}:\\ \;\;\;\;y\\ \end{array}\]
\sqrt{x \cdot x + y \cdot y}
\begin{array}{l}
\mathbf{if}\;y \le -2.8884266593894412 \cdot 10^{145}:\\
\;\;\;\;-1 \cdot y\\

\mathbf{elif}\;y \le -8.59044981858877489 \cdot 10^{-223}:\\
\;\;\;\;\sqrt{x \cdot x + y \cdot y}\\

\mathbf{elif}\;y \le 3.3111519867076028 \cdot 10^{-267}:\\
\;\;\;\;-1 \cdot x\\

\mathbf{elif}\;y \le 4.35781193024123746 \cdot 10^{99}:\\
\;\;\;\;\sqrt{x \cdot x + y \cdot y}\\

\mathbf{else}:\\
\;\;\;\;y\\

\end{array}
double f(double x, double y) {
        double r771457 = x;
        double r771458 = r771457 * r771457;
        double r771459 = y;
        double r771460 = r771459 * r771459;
        double r771461 = r771458 + r771460;
        double r771462 = sqrt(r771461);
        return r771462;
}

double f(double x, double y) {
        double r771463 = y;
        double r771464 = -2.888426659389441e+145;
        bool r771465 = r771463 <= r771464;
        double r771466 = -1.0;
        double r771467 = r771466 * r771463;
        double r771468 = -8.590449818588775e-223;
        bool r771469 = r771463 <= r771468;
        double r771470 = x;
        double r771471 = r771470 * r771470;
        double r771472 = r771463 * r771463;
        double r771473 = r771471 + r771472;
        double r771474 = sqrt(r771473);
        double r771475 = 3.311151986707603e-267;
        bool r771476 = r771463 <= r771475;
        double r771477 = r771466 * r771470;
        double r771478 = 4.3578119302412375e+99;
        bool r771479 = r771463 <= r771478;
        double r771480 = r771479 ? r771474 : r771463;
        double r771481 = r771476 ? r771477 : r771480;
        double r771482 = r771469 ? r771474 : r771481;
        double r771483 = r771465 ? r771467 : r771482;
        return r771483;
}

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.4
Target17.6
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 4 regimes
  2. if y < -2.888426659389441e+145

    1. Initial program 61.0

      \[\sqrt{x \cdot x + y \cdot y}\]
    2. Using strategy rm
    3. Applied flip-+64.0

      \[\leadsto \sqrt{\color{blue}{\frac{\left(x \cdot x\right) \cdot \left(x \cdot x\right) - \left(y \cdot y\right) \cdot \left(y \cdot y\right)}{x \cdot x - y \cdot y}}}\]
    4. Simplified64.0

      \[\leadsto \sqrt{\frac{\color{blue}{\left(-{y}^{3}\right) \cdot y + {x}^{4}}}{x \cdot x - y \cdot y}}\]
    5. Taylor expanded around -inf 7.4

      \[\leadsto \color{blue}{-1 \cdot y}\]

    if -2.888426659389441e+145 < y < -8.590449818588775e-223 or 3.311151986707603e-267 < y < 4.3578119302412375e+99

    1. Initial program 19.3

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

    if -8.590449818588775e-223 < y < 3.311151986707603e-267

    1. Initial program 30.2

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

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

    if 4.3578119302412375e+99 < y

    1. Initial program 50.7

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \le -2.8884266593894412 \cdot 10^{145}:\\ \;\;\;\;-1 \cdot y\\ \mathbf{elif}\;y \le -8.59044981858877489 \cdot 10^{-223}:\\ \;\;\;\;\sqrt{x \cdot x + y \cdot y}\\ \mathbf{elif}\;y \le 3.3111519867076028 \cdot 10^{-267}:\\ \;\;\;\;-1 \cdot x\\ \mathbf{elif}\;y \le 4.35781193024123746 \cdot 10^{99}:\\ \;\;\;\;\sqrt{x \cdot x + y \cdot y}\\ \mathbf{else}:\\ \;\;\;\;y\\ \end{array}\]

Reproduce

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