Average Error: 31.7 → 18.2
Time: 3.2s
Precision: 64
\[\sqrt{x \cdot x + y \cdot y}\]
\[\begin{array}{l} \mathbf{if}\;x \le -2.27109209614237641 \cdot 10^{59}:\\ \;\;\;\;-1 \cdot x\\ \mathbf{elif}\;x \le 9.6349667233636427 \cdot 10^{131}:\\ \;\;\;\;\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 -2.27109209614237641 \cdot 10^{59}:\\
\;\;\;\;-1 \cdot x\\

\mathbf{elif}\;x \le 9.6349667233636427 \cdot 10^{131}:\\
\;\;\;\;\sqrt{x \cdot x + y \cdot y}\\

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

\end{array}
double f(double x, double y) {
        double r824958 = x;
        double r824959 = r824958 * r824958;
        double r824960 = y;
        double r824961 = r824960 * r824960;
        double r824962 = r824959 + r824961;
        double r824963 = sqrt(r824962);
        return r824963;
}

double f(double x, double y) {
        double r824964 = x;
        double r824965 = -2.2710920961423764e+59;
        bool r824966 = r824964 <= r824965;
        double r824967 = -1.0;
        double r824968 = r824967 * r824964;
        double r824969 = 9.634966723363643e+131;
        bool r824970 = r824964 <= r824969;
        double r824971 = r824964 * r824964;
        double r824972 = y;
        double r824973 = r824972 * r824972;
        double r824974 = r824971 + r824973;
        double r824975 = sqrt(r824974);
        double r824976 = r824970 ? r824975 : r824964;
        double r824977 = r824966 ? r824968 : r824976;
        return r824977;
}

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.7
Target17.9
Herbie18.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 < -2.2710920961423764e+59

    1. Initial program 45.1

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

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

    if -2.2710920961423764e+59 < x < 9.634966723363643e+131

    1. Initial program 22.0

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

    if 9.634966723363643e+131 < x

    1. Initial program 57.8

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -2.27109209614237641 \cdot 10^{59}:\\ \;\;\;\;-1 \cdot x\\ \mathbf{elif}\;x \le 9.6349667233636427 \cdot 10^{131}:\\ \;\;\;\;\sqrt{x \cdot x + y \cdot y}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array}\]

Reproduce

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