Average Error: 31.3 → 17.2
Time: 6.7s
Precision: 64
\[\sqrt{x \cdot x + y \cdot y}\]
\[\begin{array}{l} \mathbf{if}\;x \le -1.181793183213821728908776663248811693415 \cdot 10^{151}:\\ \;\;\;\;-x\\ \mathbf{elif}\;x \le 5.94823403512645934829207680164770844431 \cdot 10^{127}:\\ \;\;\;\;\sqrt{y \cdot y + x \cdot x}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array}\]
\sqrt{x \cdot x + y \cdot y}
\begin{array}{l}
\mathbf{if}\;x \le -1.181793183213821728908776663248811693415 \cdot 10^{151}:\\
\;\;\;\;-x\\

\mathbf{elif}\;x \le 5.94823403512645934829207680164770844431 \cdot 10^{127}:\\
\;\;\;\;\sqrt{y \cdot y + x \cdot x}\\

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

\end{array}
double f(double x, double y) {
        double r39047347 = x;
        double r39047348 = r39047347 * r39047347;
        double r39047349 = y;
        double r39047350 = r39047349 * r39047349;
        double r39047351 = r39047348 + r39047350;
        double r39047352 = sqrt(r39047351);
        return r39047352;
}

double f(double x, double y) {
        double r39047353 = x;
        double r39047354 = -1.1817931832138217e+151;
        bool r39047355 = r39047353 <= r39047354;
        double r39047356 = -r39047353;
        double r39047357 = 5.948234035126459e+127;
        bool r39047358 = r39047353 <= r39047357;
        double r39047359 = y;
        double r39047360 = r39047359 * r39047359;
        double r39047361 = r39047353 * r39047353;
        double r39047362 = r39047360 + r39047361;
        double r39047363 = sqrt(r39047362);
        double r39047364 = r39047358 ? r39047363 : r39047353;
        double r39047365 = r39047355 ? r39047356 : r39047364;
        return r39047365;
}

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.3
Target17.3
Herbie17.2
\[\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.1817931832138217e+151

    1. Initial program 63.1

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

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

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

    if -1.1817931832138217e+151 < x < 5.948234035126459e+127

    1. Initial program 20.4

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

    if 5.948234035126459e+127 < x

    1. Initial program 56.6

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -1.181793183213821728908776663248811693415 \cdot 10^{151}:\\ \;\;\;\;-x\\ \mathbf{elif}\;x \le 5.94823403512645934829207680164770844431 \cdot 10^{127}:\\ \;\;\;\;\sqrt{y \cdot y + x \cdot x}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array}\]

Reproduce

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

  :herbie-target
  (if (< x -1.1236950826599826e+145) (- x) (if (< x 1.116557621183362e+93) (sqrt (+ (* x x) (* y y))) x))

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