Average Error: 31.0 → 17.3
Time: 5.3s
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 r806304 = x;
        double r806305 = r806304 * r806304;
        double r806306 = y;
        double r806307 = r806306 * r806306;
        double r806308 = r806305 + r806307;
        double r806309 = sqrt(r806308);
        return r806309;
}

double f(double x, double y) {
        double r806310 = x;
        double r806311 = -6.523076260268755e+150;
        bool r806312 = r806310 <= r806311;
        double r806313 = -r806310;
        double r806314 = 1.158407537644574e+105;
        bool r806315 = r806310 <= r806314;
        double r806316 = r806310 * r806310;
        double r806317 = y;
        double r806318 = r806317 * r806317;
        double r806319 = r806316 + r806318;
        double r806320 = sqrt(r806319);
        double r806321 = r806315 ? r806320 : r806310;
        double r806322 = r806312 ? r806313 : r806321;
        return r806322;
}

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))))