Average Error: 31.7 → 18.2
Time: 1.0s
Precision: 64
\[\sqrt{x \cdot x + y \cdot y}\]
\[\begin{array}{l} \mathbf{if}\;x \le -8.7623037487145096 \cdot 10^{143}:\\ \;\;\;\;-1 \cdot x\\ \mathbf{elif}\;x \le -1.1808330835219091 \cdot 10^{-161}:\\ \;\;\;\;\sqrt{x \cdot x + y \cdot y}\\ \mathbf{elif}\;x \le -3.561866723012927 \cdot 10^{-267}:\\ \;\;\;\;y\\ \mathbf{elif}\;x \le 1.10774424975994648 \cdot 10^{54}:\\ \;\;\;\;\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 -8.7623037487145096 \cdot 10^{143}:\\
\;\;\;\;-1 \cdot x\\

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

\mathbf{elif}\;x \le -3.561866723012927 \cdot 10^{-267}:\\
\;\;\;\;y\\

\mathbf{elif}\;x \le 1.10774424975994648 \cdot 10^{54}:\\
\;\;\;\;\sqrt{x \cdot x + y \cdot y}\\

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

\end{array}
double f(double x, double y) {
        double r761879 = x;
        double r761880 = r761879 * r761879;
        double r761881 = y;
        double r761882 = r761881 * r761881;
        double r761883 = r761880 + r761882;
        double r761884 = sqrt(r761883);
        return r761884;
}

double f(double x, double y) {
        double r761885 = x;
        double r761886 = -8.76230374871451e+143;
        bool r761887 = r761885 <= r761886;
        double r761888 = -1.0;
        double r761889 = r761888 * r761885;
        double r761890 = -1.180833083521909e-161;
        bool r761891 = r761885 <= r761890;
        double r761892 = r761885 * r761885;
        double r761893 = y;
        double r761894 = r761893 * r761893;
        double r761895 = r761892 + r761894;
        double r761896 = sqrt(r761895);
        double r761897 = -3.561866723012927e-267;
        bool r761898 = r761885 <= r761897;
        double r761899 = 1.1077442497599465e+54;
        bool r761900 = r761885 <= r761899;
        double r761901 = r761900 ? r761896 : r761885;
        double r761902 = r761898 ? r761893 : r761901;
        double r761903 = r761891 ? r761896 : r761902;
        double r761904 = r761887 ? r761889 : r761903;
        return r761904;
}

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

    1. Initial program 60.9

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

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

    if -8.76230374871451e+143 < x < -1.180833083521909e-161 or -3.561866723012927e-267 < x < 1.1077442497599465e+54

    1. Initial program 20.3

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

    if -1.180833083521909e-161 < x < -3.561866723012927e-267

    1. Initial program 31.5

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

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

    if 1.1077442497599465e+54 < x

    1. Initial program 43.8

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -8.7623037487145096 \cdot 10^{143}:\\ \;\;\;\;-1 \cdot x\\ \mathbf{elif}\;x \le -1.1808330835219091 \cdot 10^{-161}:\\ \;\;\;\;\sqrt{x \cdot x + y \cdot y}\\ \mathbf{elif}\;x \le -3.561866723012927 \cdot 10^{-267}:\\ \;\;\;\;y\\ \mathbf{elif}\;x \le 1.10774424975994648 \cdot 10^{54}:\\ \;\;\;\;\sqrt{x \cdot x + y \cdot y}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array}\]

Reproduce

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