Average Error: 31.8 → 17.4
Time: 926.0ms
Precision: 64
\[\sqrt{x \cdot x + y \cdot y}\]
\[\begin{array}{l} \mathbf{if}\;x \le -1.17117052004380529 \cdot 10^{89}:\\ \;\;\;\;-1 \cdot x\\ \mathbf{elif}\;x \le 2.0168808923777661 \cdot 10^{94}:\\ \;\;\;\;\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.17117052004380529 \cdot 10^{89}:\\
\;\;\;\;-1 \cdot x\\

\mathbf{elif}\;x \le 2.0168808923777661 \cdot 10^{94}:\\
\;\;\;\;\sqrt{x \cdot x + y \cdot y}\\

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

\end{array}
double f(double x, double y) {
        double r699746 = x;
        double r699747 = r699746 * r699746;
        double r699748 = y;
        double r699749 = r699748 * r699748;
        double r699750 = r699747 + r699749;
        double r699751 = sqrt(r699750);
        return r699751;
}

double f(double x, double y) {
        double r699752 = x;
        double r699753 = -1.1711705200438053e+89;
        bool r699754 = r699752 <= r699753;
        double r699755 = -1.0;
        double r699756 = r699755 * r699752;
        double r699757 = 2.016880892377766e+94;
        bool r699758 = r699752 <= r699757;
        double r699759 = r699752 * r699752;
        double r699760 = y;
        double r699761 = r699760 * r699760;
        double r699762 = r699759 + r699761;
        double r699763 = sqrt(r699762);
        double r699764 = r699758 ? r699763 : r699752;
        double r699765 = r699754 ? r699756 : r699764;
        return r699765;
}

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.3
Herbie17.4
\[\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.1711705200438053e+89

    1. Initial program 50.6

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

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

    if -1.1711705200438053e+89 < x < 2.016880892377766e+94

    1. Initial program 21.6

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

    if 2.016880892377766e+94 < x

    1. Initial program 51.1

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -1.17117052004380529 \cdot 10^{89}:\\ \;\;\;\;-1 \cdot x\\ \mathbf{elif}\;x \le 2.0168808923777661 \cdot 10^{94}:\\ \;\;\;\;\sqrt{x \cdot x + y \cdot y}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array}\]

Reproduce

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