Average Error: 32.1 → 17.8
Time: 1.2s
Precision: 64
\[\sqrt{x \cdot x + y \cdot y}\]
\[\begin{array}{l} \mathbf{if}\;x \le -4.219332295965777137041720193068407814529 \cdot 10^{82}:\\ \;\;\;\;-1 \cdot x\\ \mathbf{elif}\;x \le -3.743447547042940916879606925039648794356 \cdot 10^{-217}:\\ \;\;\;\;\sqrt{x \cdot x + y \cdot y}\\ \mathbf{elif}\;x \le 4.769025653725654548986941102749859144285 \cdot 10^{-305}:\\ \;\;\;\;y\\ \mathbf{elif}\;x \le 2.419375064734749687649336536979338940651 \cdot 10^{132}:\\ \;\;\;\;\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.219332295965777137041720193068407814529 \cdot 10^{82}:\\
\;\;\;\;-1 \cdot x\\

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

\mathbf{elif}\;x \le 4.769025653725654548986941102749859144285 \cdot 10^{-305}:\\
\;\;\;\;y\\

\mathbf{elif}\;x \le 2.419375064734749687649336536979338940651 \cdot 10^{132}:\\
\;\;\;\;\sqrt{x \cdot x + y \cdot y}\\

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

\end{array}
double f(double x, double y) {
        double r702381 = x;
        double r702382 = r702381 * r702381;
        double r702383 = y;
        double r702384 = r702383 * r702383;
        double r702385 = r702382 + r702384;
        double r702386 = sqrt(r702385);
        return r702386;
}

double f(double x, double y) {
        double r702387 = x;
        double r702388 = -4.219332295965777e+82;
        bool r702389 = r702387 <= r702388;
        double r702390 = -1.0;
        double r702391 = r702390 * r702387;
        double r702392 = -3.743447547042941e-217;
        bool r702393 = r702387 <= r702392;
        double r702394 = r702387 * r702387;
        double r702395 = y;
        double r702396 = r702395 * r702395;
        double r702397 = r702394 + r702396;
        double r702398 = sqrt(r702397);
        double r702399 = 4.769025653725655e-305;
        bool r702400 = r702387 <= r702399;
        double r702401 = 2.4193750647347497e+132;
        bool r702402 = r702387 <= r702401;
        double r702403 = r702402 ? r702398 : r702387;
        double r702404 = r702400 ? r702395 : r702403;
        double r702405 = r702393 ? r702398 : r702404;
        double r702406 = r702389 ? r702391 : r702405;
        return r702406;
}

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
Target17.8
Herbie17.8
\[\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 4 regimes
  2. if x < -4.219332295965777e+82

    1. Initial program 49.1

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

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

    if -4.219332295965777e+82 < x < -3.743447547042941e-217 or 4.769025653725655e-305 < x < 2.4193750647347497e+132

    1. Initial program 20.0

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

    if -3.743447547042941e-217 < x < 4.769025653725655e-305

    1. Initial program 33.9

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

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

    if 2.4193750647347497e+132 < x

    1. Initial program 58.5

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -4.219332295965777137041720193068407814529 \cdot 10^{82}:\\ \;\;\;\;-1 \cdot x\\ \mathbf{elif}\;x \le -3.743447547042940916879606925039648794356 \cdot 10^{-217}:\\ \;\;\;\;\sqrt{x \cdot x + y \cdot y}\\ \mathbf{elif}\;x \le 4.769025653725654548986941102749859144285 \cdot 10^{-305}:\\ \;\;\;\;y\\ \mathbf{elif}\;x \le 2.419375064734749687649336536979338940651 \cdot 10^{132}:\\ \;\;\;\;\sqrt{x \cdot x + y \cdot y}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array}\]

Reproduce

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