Average Error: 31.3 → 18.0
Time: 12.0s
Precision: 64
\[\sqrt{x \cdot x + y \cdot y}\]
\[\begin{array}{l} \mathbf{if}\;x \le -6.380870002726310342811700587071868218435 \cdot 10^{59}:\\ \;\;\;\;-x\\ \mathbf{elif}\;x \le 2.566938280750767851167015199229297462562 \cdot 10^{114}:\\ \;\;\;\;\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 -6.380870002726310342811700587071868218435 \cdot 10^{59}:\\
\;\;\;\;-x\\

\mathbf{elif}\;x \le 2.566938280750767851167015199229297462562 \cdot 10^{114}:\\
\;\;\;\;\sqrt{x \cdot x + y \cdot y}\\

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

\end{array}
double f(double x, double y) {
        double r447230 = x;
        double r447231 = r447230 * r447230;
        double r447232 = y;
        double r447233 = r447232 * r447232;
        double r447234 = r447231 + r447233;
        double r447235 = sqrt(r447234);
        return r447235;
}

double f(double x, double y) {
        double r447236 = x;
        double r447237 = -6.38087000272631e+59;
        bool r447238 = r447236 <= r447237;
        double r447239 = -r447236;
        double r447240 = 2.566938280750768e+114;
        bool r447241 = r447236 <= r447240;
        double r447242 = r447236 * r447236;
        double r447243 = y;
        double r447244 = r447243 * r447243;
        double r447245 = r447242 + r447244;
        double r447246 = sqrt(r447245);
        double r447247 = r447241 ? r447246 : r447236;
        double r447248 = r447238 ? r447239 : r447247;
        return r447248;
}

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.3
Target17.7
Herbie18.0
\[\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 < -6.38087000272631e+59

    1. Initial program 44.7

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

      \[\leadsto \color{blue}{-1 \cdot x}\]
    3. Simplified12.7

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

    if -6.38087000272631e+59 < x < 2.566938280750768e+114

    1. Initial program 21.7

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

    if 2.566938280750768e+114 < x

    1. Initial program 53.4

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -6.380870002726310342811700587071868218435 \cdot 10^{59}:\\ \;\;\;\;-x\\ \mathbf{elif}\;x \le 2.566938280750767851167015199229297462562 \cdot 10^{114}:\\ \;\;\;\;\sqrt{x \cdot x + y \cdot y}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array}\]

Reproduce

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