Average Error: 31.3 → 17.2
Time: 6.1s
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 r619280 = x;
        double r619281 = r619280 * r619280;
        double r619282 = y;
        double r619283 = r619282 * r619282;
        double r619284 = r619281 + r619283;
        double r619285 = sqrt(r619284);
        return r619285;
}

double f(double x, double y) {
        double r619286 = x;
        double r619287 = -1.1817931832138217e+151;
        bool r619288 = r619286 <= r619287;
        double r619289 = -r619286;
        double r619290 = 5.948234035126459e+127;
        bool r619291 = r619286 <= r619290;
        double r619292 = y;
        double r619293 = r619292 * r619292;
        double r619294 = r619286 * r619286;
        double r619295 = r619293 + r619294;
        double r619296 = sqrt(r619295);
        double r619297 = r619291 ? r619296 : r619286;
        double r619298 = r619288 ? r619289 : r619297;
        return r619298;
}

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