Average Error: 31.9 → 18.9
Time: 1.2s
Precision: 64
\[\sqrt{x \cdot x + y \cdot y}\]
\[\begin{array}{l} \mathbf{if}\;x \le -6.8846914672875272 \cdot 10^{72}:\\ \;\;\;\;-1 \cdot x\\ \mathbf{elif}\;x \le -6.10111052612686754 \cdot 10^{-93}:\\ \;\;\;\;\sqrt{x \cdot x + y \cdot y}\\ \mathbf{elif}\;x \le -3.3124292600034948 \cdot 10^{-125}:\\ \;\;\;\;y\\ \mathbf{elif}\;x \le 9.88783731726367163 \cdot 10^{72}:\\ \;\;\;\;\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 -6.8846914672875272 \cdot 10^{72}:\\
\;\;\;\;-1 \cdot x\\

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

\mathbf{elif}\;x \le -3.3124292600034948 \cdot 10^{-125}:\\
\;\;\;\;y\\

\mathbf{elif}\;x \le 9.88783731726367163 \cdot 10^{72}:\\
\;\;\;\;\sqrt{x \cdot x + y \cdot y}\\

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

\end{array}
double f(double x, double y) {
        double r756324 = x;
        double r756325 = r756324 * r756324;
        double r756326 = y;
        double r756327 = r756326 * r756326;
        double r756328 = r756325 + r756327;
        double r756329 = sqrt(r756328);
        return r756329;
}

double f(double x, double y) {
        double r756330 = x;
        double r756331 = -6.884691467287527e+72;
        bool r756332 = r756330 <= r756331;
        double r756333 = -1.0;
        double r756334 = r756333 * r756330;
        double r756335 = -6.1011105261268675e-93;
        bool r756336 = r756330 <= r756335;
        double r756337 = r756330 * r756330;
        double r756338 = y;
        double r756339 = r756338 * r756338;
        double r756340 = r756337 + r756339;
        double r756341 = sqrt(r756340);
        double r756342 = -3.312429260003495e-125;
        bool r756343 = r756330 <= r756342;
        double r756344 = 9.887837317263672e+72;
        bool r756345 = r756330 <= r756344;
        double r756346 = r756345 ? r756341 : r756330;
        double r756347 = r756343 ? r756338 : r756346;
        double r756348 = r756336 ? r756341 : r756347;
        double r756349 = r756332 ? r756334 : r756348;
        return r756349;
}

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.9
Target18.0
Herbie18.9
\[\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 x < -6.884691467287527e+72

    1. Initial program 47.3

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

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

    if -6.884691467287527e+72 < x < -6.1011105261268675e-93 or -3.312429260003495e-125 < x < 9.887837317263672e+72

    1. Initial program 22.1

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

    if -6.1011105261268675e-93 < x < -3.312429260003495e-125

    1. Initial program 17.7

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

      \[\leadsto \color{blue}{y}\]

    if 9.887837317263672e+72 < x

    1. Initial program 48.3

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -6.8846914672875272 \cdot 10^{72}:\\ \;\;\;\;-1 \cdot x\\ \mathbf{elif}\;x \le -6.10111052612686754 \cdot 10^{-93}:\\ \;\;\;\;\sqrt{x \cdot x + y \cdot y}\\ \mathbf{elif}\;x \le -3.3124292600034948 \cdot 10^{-125}:\\ \;\;\;\;y\\ \mathbf{elif}\;x \le 9.88783731726367163 \cdot 10^{72}:\\ \;\;\;\;\sqrt{x \cdot x + y \cdot y}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array}\]

Reproduce

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