Average Error: 31.8 → 18.0
Time: 1.5s
Precision: 64
\[\sqrt{x \cdot x + y \cdot y}\]
\[\begin{array}{l} \mathbf{if}\;x \le -3.00186750331876538 \cdot 10^{143}:\\ \;\;\;\;-1 \cdot x\\ \mathbf{elif}\;x \le -2.02785725229385748 \cdot 10^{-184}:\\ \;\;\;\;\sqrt{x \cdot x + y \cdot y}\\ \mathbf{elif}\;x \le -9.306218889451781 \cdot 10^{-290}:\\ \;\;\;\;y\\ \mathbf{elif}\;x \le 1.74948149916647803 \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 -3.00186750331876538 \cdot 10^{143}:\\
\;\;\;\;-1 \cdot x\\

\mathbf{elif}\;x \le -2.02785725229385748 \cdot 10^{-184}:\\
\;\;\;\;\sqrt{x \cdot x + y \cdot y}\\

\mathbf{elif}\;x \le -9.306218889451781 \cdot 10^{-290}:\\
\;\;\;\;y\\

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

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

\end{array}
double f(double x, double y) {
        double r820749 = x;
        double r820750 = r820749 * r820749;
        double r820751 = y;
        double r820752 = r820751 * r820751;
        double r820753 = r820750 + r820752;
        double r820754 = sqrt(r820753);
        return r820754;
}

double f(double x, double y) {
        double r820755 = x;
        double r820756 = -3.0018675033187654e+143;
        bool r820757 = r820755 <= r820756;
        double r820758 = -1.0;
        double r820759 = r820758 * r820755;
        double r820760 = -2.0278572522938575e-184;
        bool r820761 = r820755 <= r820760;
        double r820762 = r820755 * r820755;
        double r820763 = y;
        double r820764 = r820763 * r820763;
        double r820765 = r820762 + r820764;
        double r820766 = sqrt(r820765);
        double r820767 = -9.306218889451781e-290;
        bool r820768 = r820755 <= r820767;
        double r820769 = 1.749481499166478e+126;
        bool r820770 = r820755 <= r820769;
        double r820771 = r820770 ? r820766 : r820755;
        double r820772 = r820768 ? r820763 : r820771;
        double r820773 = r820761 ? r820766 : r820772;
        double r820774 = r820757 ? r820759 : r820773;
        return r820774;
}

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.8
Target17.6
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 4 regimes
  2. if x < -3.0018675033187654e+143

    1. Initial program 60.8

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

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

    if -3.0018675033187654e+143 < x < -2.0278572522938575e-184 or -9.306218889451781e-290 < x < 1.749481499166478e+126

    1. Initial program 19.5

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

    if -2.0278572522938575e-184 < x < -9.306218889451781e-290

    1. Initial program 30.6

      \[\sqrt{x \cdot x + y \cdot y}\]
    2. Taylor expanded around 0 36.6

      \[\leadsto \color{blue}{y}\]

    if 1.749481499166478e+126 < x

    1. Initial program 56.8

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -3.00186750331876538 \cdot 10^{143}:\\ \;\;\;\;-1 \cdot x\\ \mathbf{elif}\;x \le -2.02785725229385748 \cdot 10^{-184}:\\ \;\;\;\;\sqrt{x \cdot x + y \cdot y}\\ \mathbf{elif}\;x \le -9.306218889451781 \cdot 10^{-290}:\\ \;\;\;\;y\\ \mathbf{elif}\;x \le 1.74948149916647803 \cdot 10^{126}:\\ \;\;\;\;\sqrt{x \cdot x + y \cdot y}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array}\]

Reproduce

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