Average Error: 31.2 → 17.5
Time: 7.3s
Precision: 64
\[\sqrt{x \cdot x + y \cdot y}\]
\[\begin{array}{l} \mathbf{if}\;x \le -8.953163933293596454341424469878526728026 \cdot 10^{119}:\\ \;\;\;\;-1 \cdot 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}:\\
\;\;\;\;-1 \cdot 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 r548981 = x;
        double r548982 = r548981 * r548981;
        double r548983 = y;
        double r548984 = r548983 * r548983;
        double r548985 = r548982 + r548984;
        double r548986 = sqrt(r548985);
        return r548986;
}

double f(double x, double y) {
        double r548987 = x;
        double r548988 = -8.953163933293596e+119;
        bool r548989 = r548987 <= r548988;
        double r548990 = -1.0;
        double r548991 = r548990 * r548987;
        double r548992 = 2.931608767883357e+138;
        bool r548993 = r548987 <= r548992;
        double r548994 = r548987 * r548987;
        double r548995 = y;
        double r548996 = r548995 * r548995;
        double r548997 = r548994 + r548996;
        double r548998 = sqrt(r548997);
        double r548999 = r548993 ? r548998 : r548987;
        double r549000 = r548989 ? r548991 : r548999;
        return r549000;
}

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}\]

    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}:\\ \;\;\;\;-1 \cdot 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))))