Average Error: 32.1 → 18.0
Time: 8.1s
Precision: 64
\[\sqrt{x \cdot x + y \cdot y}\]
\[\begin{array}{l} \mathbf{if}\;x \le -1.517398075841731978978804721327597516736 \cdot 10^{145}:\\ \;\;\;\;-x\\ \mathbf{elif}\;x \le 3.124646515557250636636448302358723230911 \cdot 10^{95}:\\ \;\;\;\;\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 -1.517398075841731978978804721327597516736 \cdot 10^{145}:\\
\;\;\;\;-x\\

\mathbf{elif}\;x \le 3.124646515557250636636448302358723230911 \cdot 10^{95}:\\
\;\;\;\;\sqrt{x \cdot x + y \cdot y}\\

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

\end{array}
double f(double x, double y) {
        double r560361 = x;
        double r560362 = r560361 * r560361;
        double r560363 = y;
        double r560364 = r560363 * r560363;
        double r560365 = r560362 + r560364;
        double r560366 = sqrt(r560365);
        return r560366;
}

double f(double x, double y) {
        double r560367 = x;
        double r560368 = -1.517398075841732e+145;
        bool r560369 = r560367 <= r560368;
        double r560370 = -r560367;
        double r560371 = 3.1246465155572506e+95;
        bool r560372 = r560367 <= r560371;
        double r560373 = r560367 * r560367;
        double r560374 = y;
        double r560375 = r560374 * r560374;
        double r560376 = r560373 + r560375;
        double r560377 = sqrt(r560376);
        double r560378 = r560372 ? r560377 : r560367;
        double r560379 = r560369 ? r560370 : r560378;
        return r560379;
}

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.1
Target18.1
Herbie18.0
\[\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 < -1.517398075841732e+145

    1. Initial program 61.0

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

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

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

    if -1.517398075841732e+145 < x < 3.1246465155572506e+95

    1. Initial program 21.8

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

    if 3.1246465155572506e+95 < x

    1. Initial program 50.5

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -1.517398075841731978978804721327597516736 \cdot 10^{145}:\\ \;\;\;\;-x\\ \mathbf{elif}\;x \le 3.124646515557250636636448302358723230911 \cdot 10^{95}:\\ \;\;\;\;\sqrt{x \cdot x + y \cdot y}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array}\]

Reproduce

herbie shell --seed 2019305 
(FPCore (x y)
  :name "Data.Octree.Internal:octantDistance  from Octree-0.5.4.2"
  :precision binary64

  :herbie-target
  (if (< x -1.123695082659983e145) (- x) (if (< x 1.11655762118336204e93) (sqrt (+ (* x x) (* y y))) x))

  (sqrt (+ (* x x) (* y y))))