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 r828619 = x;
        double r828620 = r828619 * r828619;
        double r828621 = y;
        double r828622 = r828621 * r828621;
        double r828623 = r828620 + r828622;
        double r828624 = sqrt(r828623);
        return r828624;
}

double f(double x, double y) {
        double r828625 = x;
        double r828626 = -1.5057522058365376e+136;
        bool r828627 = r828625 <= r828626;
        double r828628 = -1.0;
        double r828629 = r828628 * r828625;
        double r828630 = -3.2005633984364917e-257;
        bool r828631 = r828625 <= r828630;
        double r828632 = r828625 * r828625;
        double r828633 = y;
        double r828634 = r828633 * r828633;
        double r828635 = r828632 + r828634;
        double r828636 = sqrt(r828635);
        double r828637 = 3.8197786805557845e-227;
        bool r828638 = r828625 <= r828637;
        double r828639 = 8.439330033545885e+67;
        bool r828640 = r828625 <= r828639;
        double r828641 = r828640 ? r828636 : r828625;
        double r828642 = r828638 ? r828633 : r828641;
        double r828643 = r828631 ? r828636 : r828642;
        double r828644 = r828627 ? r828629 : r828643;
        return r828644;
}

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))))