Average Error: 31.0 → 17.5
Time: 1.1s
Precision: 64
\[\sqrt{x \cdot x + y \cdot y}\]
\[\begin{array}{l} \mathbf{if}\;x \le -1.505752205836537605611230467447200313868 \cdot 10^{136}:\\ \;\;\;\;-1 \cdot x\\ \mathbf{elif}\;x \le -3.200563398436491693418328268892598073539 \cdot 10^{-257}:\\ \;\;\;\;\sqrt{x \cdot x + y \cdot y}\\ \mathbf{elif}\;x \le 3.819778680555784511216531232393990012128 \cdot 10^{-227}:\\ \;\;\;\;y\\ \mathbf{elif}\;x \le 8.439330033545885045213726212950052594665 \cdot 10^{67}:\\ \;\;\;\;\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.505752205836537605611230467447200313868 \cdot 10^{136}:\\
\;\;\;\;-1 \cdot x\\

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

\mathbf{elif}\;x \le 3.819778680555784511216531232393990012128 \cdot 10^{-227}:\\
\;\;\;\;y\\

\mathbf{elif}\;x \le 8.439330033545885045213726212950052594665 \cdot 10^{67}:\\
\;\;\;\;\sqrt{x \cdot x + y \cdot y}\\

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

\end{array}
double f(double x, double y) {
        double r835803 = x;
        double r835804 = r835803 * r835803;
        double r835805 = y;
        double r835806 = r835805 * r835805;
        double r835807 = r835804 + r835806;
        double r835808 = sqrt(r835807);
        return r835808;
}

double f(double x, double y) {
        double r835809 = x;
        double r835810 = -1.5057522058365376e+136;
        bool r835811 = r835809 <= r835810;
        double r835812 = -1.0;
        double r835813 = r835812 * r835809;
        double r835814 = -3.2005633984364917e-257;
        bool r835815 = r835809 <= r835814;
        double r835816 = r835809 * r835809;
        double r835817 = y;
        double r835818 = r835817 * r835817;
        double r835819 = r835816 + r835818;
        double r835820 = sqrt(r835819);
        double r835821 = 3.8197786805557845e-227;
        bool r835822 = r835809 <= r835821;
        double r835823 = 8.439330033545885e+67;
        bool r835824 = r835809 <= r835823;
        double r835825 = r835824 ? r835820 : r835809;
        double r835826 = r835822 ? r835817 : r835825;
        double r835827 = r835815 ? r835820 : r835826;
        double r835828 = r835811 ? r835813 : r835827;
        return r835828;
}

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.0
Target17.2
Herbie17.5
\[\begin{array}{l} \mathbf{if}\;x \lt -1.123695082659982632437974301616192301785 \cdot 10^{145}:\\ \;\;\;\;-x\\ \mathbf{elif}\;x \lt 1.116557621183362039388201959321597704512 \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 < -1.5057522058365376e+136

    1. Initial program 58.9

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

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

    if -1.5057522058365376e+136 < x < -3.2005633984364917e-257 or 3.8197786805557845e-227 < x < 8.439330033545885e+67

    1. Initial program 18.7

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

    if -3.2005633984364917e-257 < x < 3.8197786805557845e-227

    1. Initial program 30.2

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

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

    if 8.439330033545885e+67 < x

    1. Initial program 46.7

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -1.505752205836537605611230467447200313868 \cdot 10^{136}:\\ \;\;\;\;-1 \cdot x\\ \mathbf{elif}\;x \le -3.200563398436491693418328268892598073539 \cdot 10^{-257}:\\ \;\;\;\;\sqrt{x \cdot x + y \cdot y}\\ \mathbf{elif}\;x \le 3.819778680555784511216531232393990012128 \cdot 10^{-227}:\\ \;\;\;\;y\\ \mathbf{elif}\;x \le 8.439330033545885045213726212950052594665 \cdot 10^{67}:\\ \;\;\;\;\sqrt{x \cdot x + y \cdot y}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array}\]

Reproduce

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