Average Error: 31.5 → 17.5
Time: 2.3s
Precision: 64
\[\sqrt{x \cdot x + y \cdot y}\]
\[\begin{array}{l} \mathbf{if}\;x \le -4.019634613598924703951801238213161238145 \cdot 10^{134}:\\ \;\;\;\;-x\\ \mathbf{elif}\;x \le 1.407306448838225519879757223457047572583 \cdot 10^{108}:\\ \;\;\;\;\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.019634613598924703951801238213161238145 \cdot 10^{134}:\\
\;\;\;\;-x\\

\mathbf{elif}\;x \le 1.407306448838225519879757223457047572583 \cdot 10^{108}:\\
\;\;\;\;\sqrt{x \cdot x + y \cdot y}\\

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

\end{array}
double f(double x, double y) {
        double r460210 = x;
        double r460211 = r460210 * r460210;
        double r460212 = y;
        double r460213 = r460212 * r460212;
        double r460214 = r460211 + r460213;
        double r460215 = sqrt(r460214);
        return r460215;
}

double f(double x, double y) {
        double r460216 = x;
        double r460217 = -4.019634613598925e+134;
        bool r460218 = r460216 <= r460217;
        double r460219 = -r460216;
        double r460220 = 1.4073064488382255e+108;
        bool r460221 = r460216 <= r460220;
        double r460222 = r460216 * r460216;
        double r460223 = y;
        double r460224 = r460223 * r460223;
        double r460225 = r460222 + r460224;
        double r460226 = sqrt(r460225);
        double r460227 = r460221 ? r460226 : r460216;
        double r460228 = r460218 ? r460219 : r460227;
        return r460228;
}

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.5
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 < -4.019634613598925e+134

    1. Initial program 58.4

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

      \[\leadsto \color{blue}{-1 \cdot x}\]
    3. Simplified8.5

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

    if -4.019634613598925e+134 < x < 1.4073064488382255e+108

    1. Initial program 21.2

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

    if 1.4073064488382255e+108 < x

    1. Initial program 52.1

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -4.019634613598924703951801238213161238145 \cdot 10^{134}:\\ \;\;\;\;-x\\ \mathbf{elif}\;x \le 1.407306448838225519879757223457047572583 \cdot 10^{108}:\\ \;\;\;\;\sqrt{x \cdot x + y \cdot y}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array}\]

Reproduce

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