Average Error: 31.2 → 17.5
Time: 14.2s
Precision: 64
\[\sqrt{x \cdot x + y \cdot y}\]
\[\begin{array}{l} \mathbf{if}\;x \le -8.953163933293596454341424469878526728026 \cdot 10^{119}:\\ \;\;\;\;-x\\ \mathbf{elif}\;x \le 2.93160876788335701324895973715263720284 \cdot 10^{138}:\\ \;\;\;\;\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 -8.953163933293596454341424469878526728026 \cdot 10^{119}:\\
\;\;\;\;-x\\

\mathbf{elif}\;x \le 2.93160876788335701324895973715263720284 \cdot 10^{138}:\\
\;\;\;\;\sqrt{x \cdot x + y \cdot y}\\

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

\end{array}
double f(double x, double y) {
        double r615340 = x;
        double r615341 = r615340 * r615340;
        double r615342 = y;
        double r615343 = r615342 * r615342;
        double r615344 = r615341 + r615343;
        double r615345 = sqrt(r615344);
        return r615345;
}

double f(double x, double y) {
        double r615346 = x;
        double r615347 = -8.953163933293596e+119;
        bool r615348 = r615346 <= r615347;
        double r615349 = -r615346;
        double r615350 = 2.931608767883357e+138;
        bool r615351 = r615346 <= r615350;
        double r615352 = r615346 * r615346;
        double r615353 = y;
        double r615354 = r615353 * r615353;
        double r615355 = r615352 + r615354;
        double r615356 = sqrt(r615355);
        double r615357 = r615351 ? r615356 : r615346;
        double r615358 = r615348 ? r615349 : r615357;
        return r615358;
}

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.2
Target17.6
Herbie17.5
\[\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 < -8.953163933293596e+119

    1. Initial program 55.7

      \[\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 -8.953163933293596e+119 < x < 2.931608767883357e+138

    1. Initial program 20.9

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

    if 2.931608767883357e+138 < x

    1. Initial program 59.0

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -8.953163933293596454341424469878526728026 \cdot 10^{119}:\\ \;\;\;\;-x\\ \mathbf{elif}\;x \le 2.93160876788335701324895973715263720284 \cdot 10^{138}:\\ \;\;\;\;\sqrt{x \cdot x + y \cdot y}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array}\]

Reproduce

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

  :herbie-target
  (if (< x -1.123695082659983e145) (- x) (if (< x 1.11655762118336204e93) (sqrt (+ (* x x) (* y y))) x))

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