Average Error: 19.7 → 0.1
Time: 2.3s
Precision: 64
\[\sqrt{x \cdot x + y}\]
\[\begin{array}{l} \mathbf{if}\;x \le -1.3377295553932065 \cdot 10^{+154}:\\ \;\;\;\;\frac{-1}{2} \cdot \frac{y}{x} - x\\ \mathbf{elif}\;x \le 1.7307959125595267 \cdot 10^{+118}:\\ \;\;\;\;\sqrt{x \cdot x + y}\\ \mathbf{else}:\\ \;\;\;\;\frac{y}{x} \cdot \frac{1}{2} + x\\ \end{array}\]
\sqrt{x \cdot x + y}
\begin{array}{l}
\mathbf{if}\;x \le -1.3377295553932065 \cdot 10^{+154}:\\
\;\;\;\;\frac{-1}{2} \cdot \frac{y}{x} - x\\

\mathbf{elif}\;x \le 1.7307959125595267 \cdot 10^{+118}:\\
\;\;\;\;\sqrt{x \cdot x + y}\\

\mathbf{else}:\\
\;\;\;\;\frac{y}{x} \cdot \frac{1}{2} + x\\

\end{array}
double f(double x, double y) {
        double r10172622 = x;
        double r10172623 = r10172622 * r10172622;
        double r10172624 = y;
        double r10172625 = r10172623 + r10172624;
        double r10172626 = sqrt(r10172625);
        return r10172626;
}

double f(double x, double y) {
        double r10172627 = x;
        double r10172628 = -1.3377295553932065e+154;
        bool r10172629 = r10172627 <= r10172628;
        double r10172630 = -0.5;
        double r10172631 = y;
        double r10172632 = r10172631 / r10172627;
        double r10172633 = r10172630 * r10172632;
        double r10172634 = r10172633 - r10172627;
        double r10172635 = 1.7307959125595267e+118;
        bool r10172636 = r10172627 <= r10172635;
        double r10172637 = r10172627 * r10172627;
        double r10172638 = r10172637 + r10172631;
        double r10172639 = sqrt(r10172638);
        double r10172640 = 0.5;
        double r10172641 = r10172632 * r10172640;
        double r10172642 = r10172641 + r10172627;
        double r10172643 = r10172636 ? r10172639 : r10172642;
        double r10172644 = r10172629 ? r10172634 : r10172643;
        return r10172644;
}

Error

Bits error versus x

Bits error versus y

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original19.7
Target0.4
Herbie0.1
\[\begin{array}{l} \mathbf{if}\;x \lt -1.5097698010472593 \cdot 10^{+153}:\\ \;\;\;\;-\left(\frac{1}{2} \cdot \frac{y}{x} + x\right)\\ \mathbf{elif}\;x \lt 5.582399551122541 \cdot 10^{+57}:\\ \;\;\;\;\sqrt{x \cdot x + y}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{2} \cdot \frac{y}{x} + x\\ \end{array}\]

Derivation

  1. Split input into 3 regimes
  2. if x < -1.3377295553932065e+154

    1. Initial program 59.6

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

      \[\leadsto \color{blue}{-\left(x + \frac{1}{2} \cdot \frac{y}{x}\right)}\]
    3. Simplified0

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

    if -1.3377295553932065e+154 < x < 1.7307959125595267e+118

    1. Initial program 0.0

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

    if 1.7307959125595267e+118 < x

    1. Initial program 49.0

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

      \[\leadsto \color{blue}{x + \frac{1}{2} \cdot \frac{y}{x}}\]
  3. Recombined 3 regimes into one program.
  4. Final simplification0.1

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -1.3377295553932065 \cdot 10^{+154}:\\ \;\;\;\;\frac{-1}{2} \cdot \frac{y}{x} - x\\ \mathbf{elif}\;x \le 1.7307959125595267 \cdot 10^{+118}:\\ \;\;\;\;\sqrt{x \cdot x + y}\\ \mathbf{else}:\\ \;\;\;\;\frac{y}{x} \cdot \frac{1}{2} + x\\ \end{array}\]

Reproduce

herbie shell --seed 2019156 
(FPCore (x y)
  :name "Linear.Quaternion:$clog from linear-1.19.1.3"

  :herbie-target
  (if (< x -1.5097698010472593e+153) (- (+ (* 1/2 (/ y x)) x)) (if (< x 5.582399551122541e+57) (sqrt (+ (* x x) y)) (+ (* 1/2 (/ y x)) x)))

  (sqrt (+ (* x x) y)))