Average Error: 31.9 → 17.8
Time: 3.0s
Precision: 64
\[\sqrt{x \cdot x + y \cdot y}\]
\[\begin{array}{l} \mathbf{if}\;x \le -6.4851444497691187 \cdot 10^{83}:\\ \;\;\;\;-1 \cdot x\\ \mathbf{elif}\;x \le 9.19480309029371711 \cdot 10^{-296}:\\ \;\;\;\;\sqrt{x \cdot x + y \cdot y}\\ \mathbf{elif}\;x \le 1.1600661433813666 \cdot 10^{-208}:\\ \;\;\;\;y\\ \mathbf{elif}\;x \le 1.21429121453061369 \cdot 10^{146}:\\ \;\;\;\;\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.4851444497691187 \cdot 10^{83}:\\
\;\;\;\;-1 \cdot x\\

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

\mathbf{elif}\;x \le 1.1600661433813666 \cdot 10^{-208}:\\
\;\;\;\;y\\

\mathbf{elif}\;x \le 1.21429121453061369 \cdot 10^{146}:\\
\;\;\;\;\sqrt{x \cdot x + y \cdot y}\\

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

\end{array}
double f(double x, double y) {
        double r733323 = x;
        double r733324 = r733323 * r733323;
        double r733325 = y;
        double r733326 = r733325 * r733325;
        double r733327 = r733324 + r733326;
        double r733328 = sqrt(r733327);
        return r733328;
}

double f(double x, double y) {
        double r733329 = x;
        double r733330 = -6.485144449769119e+83;
        bool r733331 = r733329 <= r733330;
        double r733332 = -1.0;
        double r733333 = r733332 * r733329;
        double r733334 = 9.194803090293717e-296;
        bool r733335 = r733329 <= r733334;
        double r733336 = r733329 * r733329;
        double r733337 = y;
        double r733338 = r733337 * r733337;
        double r733339 = r733336 + r733338;
        double r733340 = sqrt(r733339);
        double r733341 = 1.1600661433813666e-208;
        bool r733342 = r733329 <= r733341;
        double r733343 = 1.2142912145306137e+146;
        bool r733344 = r733329 <= r733343;
        double r733345 = r733344 ? r733340 : r733329;
        double r733346 = r733342 ? r733337 : r733345;
        double r733347 = r733335 ? r733340 : r733346;
        double r733348 = r733331 ? r733333 : r733347;
        return r733348;
}

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
Target17.6
Herbie17.8
\[\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.485144449769119e+83

    1. Initial program 49.8

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

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

    if -6.485144449769119e+83 < x < 9.194803090293717e-296 or 1.1600661433813666e-208 < x < 1.2142912145306137e+146

    1. Initial program 19.9

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

    if 9.194803090293717e-296 < x < 1.1600661433813666e-208

    1. Initial program 31.5

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

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

    if 1.2142912145306137e+146 < x

    1. Initial program 62.0

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -6.4851444497691187 \cdot 10^{83}:\\ \;\;\;\;-1 \cdot x\\ \mathbf{elif}\;x \le 9.19480309029371711 \cdot 10^{-296}:\\ \;\;\;\;\sqrt{x \cdot x + y \cdot y}\\ \mathbf{elif}\;x \le 1.1600661433813666 \cdot 10^{-208}:\\ \;\;\;\;y\\ \mathbf{elif}\;x \le 1.21429121453061369 \cdot 10^{146}:\\ \;\;\;\;\sqrt{x \cdot x + y \cdot y}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array}\]

Reproduce

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