Average Error: 32.2 → 18.4
Time: 1.0s
Precision: 64
\[\sqrt{x \cdot x + y \cdot y}\]
\[\begin{array}{l} \mathbf{if}\;x \le -4.2696195727379345 \cdot 10^{139}:\\ \;\;\;\;-1 \cdot x\\ \mathbf{elif}\;x \le -3.5543765182763856 \cdot 10^{-161}:\\ \;\;\;\;\sqrt{x \cdot x + y \cdot y}\\ \mathbf{elif}\;x \le 2.2436091775473112 \cdot 10^{-248}:\\ \;\;\;\;y\\ \mathbf{elif}\;x \le 6.3015272029718245 \cdot 10^{96}:\\ \;\;\;\;\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.2696195727379345 \cdot 10^{139}:\\
\;\;\;\;-1 \cdot x\\

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

\mathbf{elif}\;x \le 2.2436091775473112 \cdot 10^{-248}:\\
\;\;\;\;y\\

\mathbf{elif}\;x \le 6.3015272029718245 \cdot 10^{96}:\\
\;\;\;\;\sqrt{x \cdot x + y \cdot y}\\

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

\end{array}
double f(double x, double y) {
        double r891411 = x;
        double r891412 = r891411 * r891411;
        double r891413 = y;
        double r891414 = r891413 * r891413;
        double r891415 = r891412 + r891414;
        double r891416 = sqrt(r891415);
        return r891416;
}

double f(double x, double y) {
        double r891417 = x;
        double r891418 = -4.2696195727379345e+139;
        bool r891419 = r891417 <= r891418;
        double r891420 = -1.0;
        double r891421 = r891420 * r891417;
        double r891422 = -3.5543765182763856e-161;
        bool r891423 = r891417 <= r891422;
        double r891424 = r891417 * r891417;
        double r891425 = y;
        double r891426 = r891425 * r891425;
        double r891427 = r891424 + r891426;
        double r891428 = sqrt(r891427);
        double r891429 = 2.243609177547311e-248;
        bool r891430 = r891417 <= r891429;
        double r891431 = 6.3015272029718245e+96;
        bool r891432 = r891417 <= r891431;
        double r891433 = r891432 ? r891428 : r891417;
        double r891434 = r891430 ? r891425 : r891433;
        double r891435 = r891423 ? r891428 : r891434;
        double r891436 = r891419 ? r891421 : r891435;
        return r891436;
}

Error

Bits error versus x

Bits error versus y

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original32.2
Target18.2
Herbie18.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 x < -4.2696195727379345e+139

    1. Initial program 59.5

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

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

    if -4.2696195727379345e+139 < x < -3.5543765182763856e-161 or 2.243609177547311e-248 < x < 6.3015272029718245e+96

    1. Initial program 18.8

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

    if -3.5543765182763856e-161 < x < 2.243609177547311e-248

    1. Initial program 32.3

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

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

    if 6.3015272029718245e+96 < x

    1. Initial program 51.2

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -4.2696195727379345 \cdot 10^{139}:\\ \;\;\;\;-1 \cdot x\\ \mathbf{elif}\;x \le -3.5543765182763856 \cdot 10^{-161}:\\ \;\;\;\;\sqrt{x \cdot x + y \cdot y}\\ \mathbf{elif}\;x \le 2.2436091775473112 \cdot 10^{-248}:\\ \;\;\;\;y\\ \mathbf{elif}\;x \le 6.3015272029718245 \cdot 10^{96}:\\ \;\;\;\;\sqrt{x \cdot x + y \cdot y}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array}\]

Reproduce

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