Average Error: 19.4 → 0.3
Time: 8.6s
Precision: 64
\[\sqrt{x \cdot x + y}\]
\[\begin{array}{l} \mathbf{if}\;x \le -1.3359776254393746 \cdot 10^{+154}:\\ \;\;\;\;\frac{-1}{2} \cdot \frac{y}{x} - x\\ \mathbf{elif}\;x \le 2.8410325872827527 \cdot 10^{+74}:\\ \;\;\;\;\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.3359776254393746 \cdot 10^{+154}:\\
\;\;\;\;\frac{-1}{2} \cdot \frac{y}{x} - x\\

\mathbf{elif}\;x \le 2.8410325872827527 \cdot 10^{+74}:\\
\;\;\;\;\sqrt{x \cdot x + y}\\

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

\end{array}
double f(double x, double y) {
        double r34752436 = x;
        double r34752437 = r34752436 * r34752436;
        double r34752438 = y;
        double r34752439 = r34752437 + r34752438;
        double r34752440 = sqrt(r34752439);
        return r34752440;
}

double f(double x, double y) {
        double r34752441 = x;
        double r34752442 = -1.3359776254393746e+154;
        bool r34752443 = r34752441 <= r34752442;
        double r34752444 = -0.5;
        double r34752445 = y;
        double r34752446 = r34752445 / r34752441;
        double r34752447 = r34752444 * r34752446;
        double r34752448 = r34752447 - r34752441;
        double r34752449 = 2.8410325872827527e+74;
        bool r34752450 = r34752441 <= r34752449;
        double r34752451 = r34752441 * r34752441;
        double r34752452 = r34752451 + r34752445;
        double r34752453 = sqrt(r34752452);
        double r34752454 = 0.5;
        double r34752455 = r34752446 * r34752454;
        double r34752456 = r34752455 + r34752441;
        double r34752457 = r34752450 ? r34752453 : r34752456;
        double r34752458 = r34752443 ? r34752448 : r34752457;
        return r34752458;
}

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.4
Target0.4
Herbie0.3
\[\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.3359776254393746e+154

    1. Initial program 59.5

      \[\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.3359776254393746e+154 < x < 2.8410325872827527e+74

    1. Initial program 0.0

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

    if 2.8410325872827527e+74 < x

    1. Initial program 40.5

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

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

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

Reproduce

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