Average Error: 31.3 → 17.2
Time: 6.5s
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{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 -1.181793183213821728908776663248811693415 \cdot 10^{151}:\\
\;\;\;\;-x\\

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

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

\end{array}
double f(double x, double y) {
        double r50531566 = x;
        double r50531567 = r50531566 * r50531566;
        double r50531568 = y;
        double r50531569 = r50531568 * r50531568;
        double r50531570 = r50531567 + r50531569;
        double r50531571 = sqrt(r50531570);
        return r50531571;
}

double f(double x, double y) {
        double r50531572 = x;
        double r50531573 = -1.1817931832138217e+151;
        bool r50531574 = r50531572 <= r50531573;
        double r50531575 = -r50531572;
        double r50531576 = 5.948234035126459e+127;
        bool r50531577 = r50531572 <= r50531576;
        double r50531578 = r50531572 * r50531572;
        double r50531579 = y;
        double r50531580 = r50531579 * r50531579;
        double r50531581 = r50531578 + r50531580;
        double r50531582 = sqrt(r50531581);
        double r50531583 = r50531577 ? r50531582 : r50531572;
        double r50531584 = r50531574 ? r50531575 : r50531583;
        return r50531584;
}

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{x \cdot x + y \cdot y}\\ \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))))