Average Error: 31.9 → 18.0
Time: 1.2s
Precision: 64
\[\sqrt{x \cdot x + y \cdot y}\]
\[\begin{array}{l} \mathbf{if}\;x \le -4.00847790071649149 \cdot 10^{147}:\\ \;\;\;\;-1 \cdot x\\ \mathbf{elif}\;x \le 4.7344679219365152 \cdot 10^{65}:\\ \;\;\;\;\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 -4.00847790071649149 \cdot 10^{147}:\\
\;\;\;\;-1 \cdot x\\

\mathbf{elif}\;x \le 4.7344679219365152 \cdot 10^{65}:\\
\;\;\;\;\sqrt{x \cdot x + y \cdot y}\\

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

\end{array}
double f(double x, double y) {
        double r783044 = x;
        double r783045 = r783044 * r783044;
        double r783046 = y;
        double r783047 = r783046 * r783046;
        double r783048 = r783045 + r783047;
        double r783049 = sqrt(r783048);
        return r783049;
}

double f(double x, double y) {
        double r783050 = x;
        double r783051 = -4.0084779007164915e+147;
        bool r783052 = r783050 <= r783051;
        double r783053 = -1.0;
        double r783054 = r783053 * r783050;
        double r783055 = 4.734467921936515e+65;
        bool r783056 = r783050 <= r783055;
        double r783057 = r783050 * r783050;
        double r783058 = y;
        double r783059 = r783058 * r783058;
        double r783060 = r783057 + r783059;
        double r783061 = sqrt(r783060);
        double r783062 = r783056 ? r783061 : r783050;
        double r783063 = r783052 ? r783054 : r783062;
        return r783063;
}

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.9
Target18.0
Herbie18.0
\[\begin{array}{l} \mathbf{if}\;x \lt -1.123695082659983 \cdot 10^{145}:\\ \;\;\;\;-x\\ \mathbf{elif}\;x \lt 1.11655762118336204 \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 < -4.0084779007164915e+147

    1. Initial program 62.0

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

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

    if -4.0084779007164915e+147 < x < 4.734467921936515e+65

    1. Initial program 21.7

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

    if 4.734467921936515e+65 < x

    1. Initial program 47.4

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -4.00847790071649149 \cdot 10^{147}:\\ \;\;\;\;-1 \cdot x\\ \mathbf{elif}\;x \le 4.7344679219365152 \cdot 10^{65}:\\ \;\;\;\;\sqrt{x \cdot x + y \cdot y}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array}\]

Reproduce

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

  :herbie-target
  (if (< x -1.123695082659983e+145) (- x) (if (< x 1.116557621183362e+93) (sqrt (+ (* x x) (* y y))) x))

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