Average Error: 31.9 → 17.7
Time: 4.1s
Precision: 64
\[\sqrt{x \cdot x + y \cdot y}\]
\[\begin{array}{l} \mathbf{if}\;x \le -6.4397722734901768 \cdot 10^{138}:\\ \;\;\;\;-x\\ \mathbf{elif}\;x \le 1.95063775952267208 \cdot 10^{126}:\\ \;\;\;\;\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.4397722734901768 \cdot 10^{138}:\\
\;\;\;\;-x\\

\mathbf{elif}\;x \le 1.95063775952267208 \cdot 10^{126}:\\
\;\;\;\;\sqrt{x \cdot x + y \cdot y}\\

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

\end{array}
double f(double x, double y) {
        double r555628 = x;
        double r555629 = r555628 * r555628;
        double r555630 = y;
        double r555631 = r555630 * r555630;
        double r555632 = r555629 + r555631;
        double r555633 = sqrt(r555632);
        return r555633;
}

double f(double x, double y) {
        double r555634 = x;
        double r555635 = -6.439772273490177e+138;
        bool r555636 = r555634 <= r555635;
        double r555637 = -r555634;
        double r555638 = 1.950637759522672e+126;
        bool r555639 = r555634 <= r555638;
        double r555640 = r555634 * r555634;
        double r555641 = y;
        double r555642 = r555641 * r555641;
        double r555643 = r555640 + r555642;
        double r555644 = sqrt(r555643);
        double r555645 = r555639 ? r555644 : r555634;
        double r555646 = r555636 ? r555637 : r555645;
        return r555646;
}

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
Target17.9
Herbie17.7
\[\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 < -6.439772273490177e+138

    1. Initial program 59.2

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

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

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

    if -6.439772273490177e+138 < x < 1.950637759522672e+126

    1. Initial program 21.4

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

    if 1.950637759522672e+126 < x

    1. Initial program 56.2

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -6.4397722734901768 \cdot 10^{138}:\\ \;\;\;\;-x\\ \mathbf{elif}\;x \le 1.95063775952267208 \cdot 10^{126}:\\ \;\;\;\;\sqrt{x \cdot x + y \cdot y}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array}\]

Reproduce

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

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

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