Average Error: 31.2 → 17.2
Time: 920.0ms
Precision: 64
\[\sqrt{x \cdot x + y \cdot y}\]
\[\begin{array}{l} \mathbf{if}\;x \le -1.5701395123872976 \cdot 10^{96}:\\ \;\;\;\;-1 \cdot x\\ \mathbf{elif}\;x \le 1.5292574126268538 \cdot 10^{125}:\\ \;\;\;\;\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 -1.5701395123872976 \cdot 10^{96}:\\
\;\;\;\;-1 \cdot x\\

\mathbf{elif}\;x \le 1.5292574126268538 \cdot 10^{125}:\\
\;\;\;\;\sqrt{x \cdot x + y \cdot y}\\

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

\end{array}
double f(double x, double y) {
        double r872678 = x;
        double r872679 = r872678 * r872678;
        double r872680 = y;
        double r872681 = r872680 * r872680;
        double r872682 = r872679 + r872681;
        double r872683 = sqrt(r872682);
        return r872683;
}

double f(double x, double y) {
        double r872684 = x;
        double r872685 = -1.5701395123872976e+96;
        bool r872686 = r872684 <= r872685;
        double r872687 = -1.0;
        double r872688 = r872687 * r872684;
        double r872689 = 1.5292574126268538e+125;
        bool r872690 = r872684 <= r872689;
        double r872691 = r872684 * r872684;
        double r872692 = y;
        double r872693 = r872692 * r872692;
        double r872694 = r872691 + r872693;
        double r872695 = sqrt(r872694);
        double r872696 = r872690 ? r872695 : r872684;
        double r872697 = r872686 ? r872688 : r872696;
        return r872697;
}

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.3
Herbie17.2
\[\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 < -1.5701395123872976e+96

    1. Initial program 50.6

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

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

    if -1.5701395123872976e+96 < x < 1.5292574126268538e+125

    1. Initial program 20.7

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

    if 1.5292574126268538e+125 < x

    1. Initial program 57.7

      \[\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.2

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -1.5701395123872976 \cdot 10^{96}:\\ \;\;\;\;-1 \cdot x\\ \mathbf{elif}\;x \le 1.5292574126268538 \cdot 10^{125}:\\ \;\;\;\;\sqrt{x \cdot x + y \cdot y}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array}\]

Reproduce

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