Average Error: 31.9 → 17.5
Time: 4.3s
Precision: 64
\[\sqrt{x \cdot x + y \cdot y}\]
\[\begin{array}{l} \mathbf{if}\;x \le -4.844506481309793477015811086474695118347 \cdot 10^{101}:\\ \;\;\;\;-x\\ \mathbf{elif}\;x \le 2.534314230587066174958520593782804386096 \cdot 10^{96}:\\ \;\;\;\;\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 -4.844506481309793477015811086474695118347 \cdot 10^{101}:\\
\;\;\;\;-x\\

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

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

\end{array}
double f(double x, double y) {
        double r39649408 = x;
        double r39649409 = r39649408 * r39649408;
        double r39649410 = y;
        double r39649411 = r39649410 * r39649410;
        double r39649412 = r39649409 + r39649411;
        double r39649413 = sqrt(r39649412);
        return r39649413;
}

double f(double x, double y) {
        double r39649414 = x;
        double r39649415 = -4.8445064813097935e+101;
        bool r39649416 = r39649414 <= r39649415;
        double r39649417 = -r39649414;
        double r39649418 = 2.534314230587066e+96;
        bool r39649419 = r39649414 <= r39649418;
        double r39649420 = y;
        double r39649421 = r39649420 * r39649420;
        double r39649422 = r39649414 * r39649414;
        double r39649423 = r39649421 + r39649422;
        double r39649424 = sqrt(r39649423);
        double r39649425 = r39649419 ? r39649424 : r39649414;
        double r39649426 = r39649416 ? r39649417 : r39649425;
        return r39649426;
}

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.5
Herbie17.5
\[\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 < -4.8445064813097935e+101

    1. Initial program 52.4

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

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

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

    if -4.8445064813097935e+101 < x < 2.534314230587066e+96

    1. Initial program 21.7

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

    if 2.534314230587066e+96 < x

    1. Initial program 51.2

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -4.844506481309793477015811086474695118347 \cdot 10^{101}:\\ \;\;\;\;-x\\ \mathbf{elif}\;x \le 2.534314230587066174958520593782804386096 \cdot 10^{96}:\\ \;\;\;\;\sqrt{y \cdot y + x \cdot x}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array}\]

Reproduce

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