Average Error: 31.5 → 17.4
Time: 5.9s
Precision: 64
\[\sqrt{x \cdot x + y \cdot y}\]
\[\begin{array}{l} \mathbf{if}\;x \le -4.1094940511471951 \cdot 10^{119}:\\ \;\;\;\;-x\\ \mathbf{elif}\;x \le 1.1032025771158766 \cdot 10^{142}:\\ \;\;\;\;\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 -4.1094940511471951 \cdot 10^{119}:\\
\;\;\;\;-x\\

\mathbf{elif}\;x \le 1.1032025771158766 \cdot 10^{142}:\\
\;\;\;\;\sqrt{x \cdot x + y \cdot y}\\

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

\end{array}
double f(double x, double y) {
        double r847683 = x;
        double r847684 = r847683 * r847683;
        double r847685 = y;
        double r847686 = r847685 * r847685;
        double r847687 = r847684 + r847686;
        double r847688 = sqrt(r847687);
        return r847688;
}

double f(double x, double y) {
        double r847689 = x;
        double r847690 = -4.109494051147195e+119;
        bool r847691 = r847689 <= r847690;
        double r847692 = -r847689;
        double r847693 = 1.1032025771158766e+142;
        bool r847694 = r847689 <= r847693;
        double r847695 = r847689 * r847689;
        double r847696 = y;
        double r847697 = r847696 * r847696;
        double r847698 = r847695 + r847697;
        double r847699 = sqrt(r847698);
        double r847700 = r847694 ? r847699 : r847689;
        double r847701 = r847691 ? r847692 : r847700;
        return r847701;
}

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.5
Target17.5
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 < -4.109494051147195e+119

    1. Initial program 55.2

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

      \[\leadsto \color{blue}{-1 \cdot x}\]
    3. Simplified9.8

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

    if -4.109494051147195e+119 < x < 1.1032025771158766e+142

    1. Initial program 20.7

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

    if 1.1032025771158766e+142 < x

    1. Initial program 60.2

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -4.1094940511471951 \cdot 10^{119}:\\ \;\;\;\;-x\\ \mathbf{elif}\;x \le 1.1032025771158766 \cdot 10^{142}:\\ \;\;\;\;\sqrt{x \cdot x + y \cdot y}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array}\]

Reproduce

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