Average Error: 31.2 → 17.5
Time: 14.5s
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 r509760 = x;
        double r509761 = r509760 * r509760;
        double r509762 = y;
        double r509763 = r509762 * r509762;
        double r509764 = r509761 + r509763;
        double r509765 = sqrt(r509764);
        return r509765;
}

double f(double x, double y) {
        double r509766 = x;
        double r509767 = -8.953163933293596e+119;
        bool r509768 = r509766 <= r509767;
        double r509769 = -r509766;
        double r509770 = 2.931608767883357e+138;
        bool r509771 = r509766 <= r509770;
        double r509772 = r509766 * r509766;
        double r509773 = y;
        double r509774 = r509773 * r509773;
        double r509775 = r509772 + r509774;
        double r509776 = sqrt(r509775);
        double r509777 = r509771 ? r509776 : r509766;
        double r509778 = r509768 ? r509769 : r509777;
        return r509778;
}

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