Average Error: 32.3 → 18.0
Time: 970.0ms
Precision: 64
\[\sqrt{x \cdot x + y \cdot y}\]
\[\begin{array}{l} \mathbf{if}\;x \le -8.15024475259887937 \cdot 10^{153}:\\ \;\;\;\;-1 \cdot x\\ \mathbf{elif}\;x \le -9.52817244882649108 \cdot 10^{-265}:\\ \;\;\;\;\sqrt{x \cdot x + y \cdot y}\\ \mathbf{elif}\;x \le 1.04745553524127593 \cdot 10^{-281}:\\ \;\;\;\;y\\ \mathbf{elif}\;x \le 2.70835173311075 \cdot 10^{105}:\\ \;\;\;\;\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.15024475259887937 \cdot 10^{153}:\\
\;\;\;\;-1 \cdot x\\

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

\mathbf{elif}\;x \le 1.04745553524127593 \cdot 10^{-281}:\\
\;\;\;\;y\\

\mathbf{elif}\;x \le 2.70835173311075 \cdot 10^{105}:\\
\;\;\;\;\sqrt{x \cdot x + y \cdot y}\\

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

\end{array}
double f(double x, double y) {
        double r934662 = x;
        double r934663 = r934662 * r934662;
        double r934664 = y;
        double r934665 = r934664 * r934664;
        double r934666 = r934663 + r934665;
        double r934667 = sqrt(r934666);
        return r934667;
}

double f(double x, double y) {
        double r934668 = x;
        double r934669 = -8.15024475259888e+153;
        bool r934670 = r934668 <= r934669;
        double r934671 = -1.0;
        double r934672 = r934671 * r934668;
        double r934673 = -9.528172448826491e-265;
        bool r934674 = r934668 <= r934673;
        double r934675 = r934668 * r934668;
        double r934676 = y;
        double r934677 = r934676 * r934676;
        double r934678 = r934675 + r934677;
        double r934679 = sqrt(r934678);
        double r934680 = 1.047455535241276e-281;
        bool r934681 = r934668 <= r934680;
        double r934682 = 2.70835173311075e+105;
        bool r934683 = r934668 <= r934682;
        double r934684 = r934683 ? r934679 : r934668;
        double r934685 = r934681 ? r934676 : r934684;
        double r934686 = r934674 ? r934679 : r934685;
        double r934687 = r934670 ? r934672 : r934686;
        return r934687;
}

Error

Bits error versus x

Bits error versus y

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original32.3
Target17.9
Herbie18.0
\[\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.15024475259888e+153

    1. Initial program 63.9

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

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

    if -8.15024475259888e+153 < x < -9.528172448826491e-265 or 1.047455535241276e-281 < x < 2.70835173311075e+105

    1. Initial program 21.0

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

    if -9.528172448826491e-265 < x < 1.047455535241276e-281

    1. Initial program 30.8

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

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

    if 2.70835173311075e+105 < x

    1. Initial program 52.5

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -8.15024475259887937 \cdot 10^{153}:\\ \;\;\;\;-1 \cdot x\\ \mathbf{elif}\;x \le -9.52817244882649108 \cdot 10^{-265}:\\ \;\;\;\;\sqrt{x \cdot x + y \cdot y}\\ \mathbf{elif}\;x \le 1.04745553524127593 \cdot 10^{-281}:\\ \;\;\;\;y\\ \mathbf{elif}\;x \le 2.70835173311075 \cdot 10^{105}:\\ \;\;\;\;\sqrt{x \cdot x + y \cdot y}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array}\]

Reproduce

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