Average Error: 31.6 → 17.5
Time: 4.1s
Precision: 64
\[\sqrt{x \cdot x + y \cdot y}\]
\[\begin{array}{l} \mathbf{if}\;x \le -3.229656712329738935737994487338299567174 \cdot 10^{112}:\\ \;\;\;\;-1 \cdot x\\ \mathbf{elif}\;x \le -5.08697951464219784890620928937007113919 \cdot 10^{-205}:\\ \;\;\;\;\sqrt{x \cdot x + y \cdot y}\\ \mathbf{elif}\;x \le -2.196597309232864908492796515168661297752 \cdot 10^{-301}:\\ \;\;\;\;y\\ \mathbf{elif}\;x \le 2.828273761560498175312293875676889182986 \cdot 10^{75}:\\ \;\;\;\;\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 -3.229656712329738935737994487338299567174 \cdot 10^{112}:\\
\;\;\;\;-1 \cdot x\\

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

\mathbf{elif}\;x \le -2.196597309232864908492796515168661297752 \cdot 10^{-301}:\\
\;\;\;\;y\\

\mathbf{elif}\;x \le 2.828273761560498175312293875676889182986 \cdot 10^{75}:\\
\;\;\;\;\sqrt{x \cdot x + y \cdot y}\\

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

\end{array}
double f(double x, double y) {
        double r572736 = x;
        double r572737 = r572736 * r572736;
        double r572738 = y;
        double r572739 = r572738 * r572738;
        double r572740 = r572737 + r572739;
        double r572741 = sqrt(r572740);
        return r572741;
}

double f(double x, double y) {
        double r572742 = x;
        double r572743 = -3.229656712329739e+112;
        bool r572744 = r572742 <= r572743;
        double r572745 = -1.0;
        double r572746 = r572745 * r572742;
        double r572747 = -5.086979514642198e-205;
        bool r572748 = r572742 <= r572747;
        double r572749 = r572742 * r572742;
        double r572750 = y;
        double r572751 = r572750 * r572750;
        double r572752 = r572749 + r572751;
        double r572753 = sqrt(r572752);
        double r572754 = -2.196597309232865e-301;
        bool r572755 = r572742 <= r572754;
        double r572756 = 2.828273761560498e+75;
        bool r572757 = r572742 <= r572756;
        double r572758 = r572757 ? r572753 : r572742;
        double r572759 = r572755 ? r572750 : r572758;
        double r572760 = r572748 ? r572753 : r572759;
        double r572761 = r572744 ? r572746 : r572760;
        return r572761;
}

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.6
Target17.0
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 4 regimes
  2. if x < -3.229656712329739e+112

    1. Initial program 54.5

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

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

    if -3.229656712329739e+112 < x < -5.086979514642198e-205 or -2.196597309232865e-301 < x < 2.828273761560498e+75

    1. Initial program 19.8

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

    if -5.086979514642198e-205 < x < -2.196597309232865e-301

    1. Initial program 30.5

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

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

    if 2.828273761560498e+75 < x

    1. Initial program 47.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 simplification17.5

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -3.229656712329738935737994487338299567174 \cdot 10^{112}:\\ \;\;\;\;-1 \cdot x\\ \mathbf{elif}\;x \le -5.08697951464219784890620928937007113919 \cdot 10^{-205}:\\ \;\;\;\;\sqrt{x \cdot x + y \cdot y}\\ \mathbf{elif}\;x \le -2.196597309232864908492796515168661297752 \cdot 10^{-301}:\\ \;\;\;\;y\\ \mathbf{elif}\;x \le 2.828273761560498175312293875676889182986 \cdot 10^{75}:\\ \;\;\;\;\sqrt{x \cdot x + y \cdot y}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array}\]

Reproduce

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