Average Error: 30.9 → 17.2
Time: 2.6s
Precision: 64
\[\sqrt{x \cdot x + y \cdot y}\]
\[\begin{array}{l} \mathbf{if}\;x \le -9.850726757232304656097215039461175225007 \cdot 10^{116}:\\ \;\;\;\;-x\\ \mathbf{elif}\;x \le 5.637979099701820103283669167726628154584 \cdot 10^{53}:\\ \;\;\;\;\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 -9.850726757232304656097215039461175225007 \cdot 10^{116}:\\
\;\;\;\;-x\\

\mathbf{elif}\;x \le 5.637979099701820103283669167726628154584 \cdot 10^{53}:\\
\;\;\;\;\sqrt{y \cdot y + x \cdot x}\\

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

\end{array}
double f(double x, double y) {
        double r556393 = x;
        double r556394 = r556393 * r556393;
        double r556395 = y;
        double r556396 = r556395 * r556395;
        double r556397 = r556394 + r556396;
        double r556398 = sqrt(r556397);
        return r556398;
}

double f(double x, double y) {
        double r556399 = x;
        double r556400 = -9.850726757232305e+116;
        bool r556401 = r556399 <= r556400;
        double r556402 = -r556399;
        double r556403 = 5.63797909970182e+53;
        bool r556404 = r556399 <= r556403;
        double r556405 = y;
        double r556406 = r556405 * r556405;
        double r556407 = r556399 * r556399;
        double r556408 = r556406 + r556407;
        double r556409 = sqrt(r556408);
        double r556410 = r556404 ? r556409 : r556399;
        double r556411 = r556401 ? r556402 : r556410;
        return r556411;
}

Error

Bits error versus x

Bits error versus y

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original30.9
Target17.0
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 < -9.850726757232305e+116

    1. Initial program 55.5

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

      \[\leadsto \color{blue}{-1 \cdot x}\]
    3. Simplified9.5

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

    if -9.850726757232305e+116 < x < 5.63797909970182e+53

    1. Initial program 20.7

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

    if 5.63797909970182e+53 < x

    1. Initial program 43.9

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -9.850726757232304656097215039461175225007 \cdot 10^{116}:\\ \;\;\;\;-x\\ \mathbf{elif}\;x \le 5.637979099701820103283669167726628154584 \cdot 10^{53}:\\ \;\;\;\;\sqrt{y \cdot y + x \cdot x}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array}\]

Reproduce

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