Average Error: 31.0 → 17.3
Time: 10.6s
Precision: 64
\[\sqrt{x \cdot x + y \cdot y}\]
\[\begin{array}{l} \mathbf{if}\;x \le -6.52307626026875473 \cdot 10^{150}:\\ \;\;\;\;-x\\ \mathbf{elif}\;x \le 1.15840753764457407 \cdot 10^{105}:\\ \;\;\;\;\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 -6.52307626026875473 \cdot 10^{150}:\\
\;\;\;\;-x\\

\mathbf{elif}\;x \le 1.15840753764457407 \cdot 10^{105}:\\
\;\;\;\;\sqrt{x \cdot x + y \cdot y}\\

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

\end{array}
double f(double x, double y) {
        double r694736 = x;
        double r694737 = r694736 * r694736;
        double r694738 = y;
        double r694739 = r694738 * r694738;
        double r694740 = r694737 + r694739;
        double r694741 = sqrt(r694740);
        return r694741;
}

double f(double x, double y) {
        double r694742 = x;
        double r694743 = -6.523076260268755e+150;
        bool r694744 = r694742 <= r694743;
        double r694745 = -r694742;
        double r694746 = 1.158407537644574e+105;
        bool r694747 = r694742 <= r694746;
        double r694748 = r694742 * r694742;
        double r694749 = y;
        double r694750 = r694749 * r694749;
        double r694751 = r694748 + r694750;
        double r694752 = sqrt(r694751);
        double r694753 = r694747 ? r694752 : r694742;
        double r694754 = r694744 ? r694745 : r694753;
        return r694754;
}

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.0
Target17.5
Herbie17.3
\[\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 3 regimes
  2. if x < -6.523076260268755e+150

    1. Initial program 63.1

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

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

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

    if -6.523076260268755e+150 < x < 1.158407537644574e+105

    1. Initial program 20.8

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

    if 1.158407537644574e+105 < x

    1. Initial program 51.1

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -6.52307626026875473 \cdot 10^{150}:\\ \;\;\;\;-x\\ \mathbf{elif}\;x \le 1.15840753764457407 \cdot 10^{105}:\\ \;\;\;\;\sqrt{x \cdot x + y \cdot y}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array}\]

Reproduce

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