Average Error: 31.1 → 17.2
Time: 2.2s
Precision: 64
\[\sqrt{x \cdot x + y \cdot y}\]
\[\begin{array}{l} \mathbf{if}\;x \le -3.4968122243654856 \cdot 10^{112}:\\ \;\;\;\;-1 \cdot x\\ \mathbf{elif}\;x \le -8.7350730255718 \cdot 10^{-293}:\\ \;\;\;\;\sqrt{x \cdot x + y \cdot y}\\ \mathbf{elif}\;x \le 1.2918788242355971 \cdot 10^{-219}:\\ \;\;\;\;y\\ \mathbf{elif}\;x \le 1.23023028256962109 \cdot 10^{151}:\\ \;\;\;\;\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.4968122243654856 \cdot 10^{112}:\\
\;\;\;\;-1 \cdot x\\

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

\mathbf{elif}\;x \le 1.2918788242355971 \cdot 10^{-219}:\\
\;\;\;\;y\\

\mathbf{elif}\;x \le 1.23023028256962109 \cdot 10^{151}:\\
\;\;\;\;\sqrt{x \cdot x + y \cdot y}\\

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

\end{array}
double f(double x, double y) {
        double r808547 = x;
        double r808548 = r808547 * r808547;
        double r808549 = y;
        double r808550 = r808549 * r808549;
        double r808551 = r808548 + r808550;
        double r808552 = sqrt(r808551);
        return r808552;
}

double f(double x, double y) {
        double r808553 = x;
        double r808554 = -3.4968122243654856e+112;
        bool r808555 = r808553 <= r808554;
        double r808556 = -1.0;
        double r808557 = r808556 * r808553;
        double r808558 = -8.7350730255718e-293;
        bool r808559 = r808553 <= r808558;
        double r808560 = r808553 * r808553;
        double r808561 = y;
        double r808562 = r808561 * r808561;
        double r808563 = r808560 + r808562;
        double r808564 = sqrt(r808563);
        double r808565 = 1.2918788242355971e-219;
        bool r808566 = r808553 <= r808565;
        double r808567 = 1.2302302825696211e+151;
        bool r808568 = r808553 <= r808567;
        double r808569 = r808568 ? r808564 : r808553;
        double r808570 = r808566 ? r808561 : r808569;
        double r808571 = r808559 ? r808564 : r808570;
        double r808572 = r808555 ? r808557 : r808571;
        return r808572;
}

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.1
Target17.2
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 4 regimes
  2. if x < -3.4968122243654856e+112

    1. Initial program 52.8

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

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

    if -3.4968122243654856e+112 < x < -8.7350730255718e-293 or 1.2918788242355971e-219 < x < 1.2302302825696211e+151

    1. Initial program 19.1

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

    if -8.7350730255718e-293 < x < 1.2918788242355971e-219

    1. Initial program 31.1

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

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

    if 1.2302302825696211e+151 < x

    1. Initial program 63.0

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -3.4968122243654856 \cdot 10^{112}:\\ \;\;\;\;-1 \cdot x\\ \mathbf{elif}\;x \le -8.7350730255718 \cdot 10^{-293}:\\ \;\;\;\;\sqrt{x \cdot x + y \cdot y}\\ \mathbf{elif}\;x \le 1.2918788242355971 \cdot 10^{-219}:\\ \;\;\;\;y\\ \mathbf{elif}\;x \le 1.23023028256962109 \cdot 10^{151}:\\ \;\;\;\;\sqrt{x \cdot x + y \cdot y}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array}\]

Reproduce

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