Average Error: 19.8 → 0.7
Time: 7.3s
Precision: 64
\[\sqrt{x \cdot x + y}\]
\[\begin{array}{l} \mathbf{if}\;x \le -1.3323185489366894 \cdot 10^{+154}:\\ \;\;\;\;\frac{-1}{2} \cdot \frac{y}{x} - x\\ \mathbf{elif}\;x \le 1.3070827329489974 \cdot 10^{+38}:\\ \;\;\;\;\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.3323185489366894 \cdot 10^{+154}:\\
\;\;\;\;\frac{-1}{2} \cdot \frac{y}{x} - x\\

\mathbf{elif}\;x \le 1.3070827329489974 \cdot 10^{+38}:\\
\;\;\;\;\sqrt{x \cdot x + y}\\

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

\end{array}
double f(double x, double y) {
        double r25376479 = x;
        double r25376480 = r25376479 * r25376479;
        double r25376481 = y;
        double r25376482 = r25376480 + r25376481;
        double r25376483 = sqrt(r25376482);
        return r25376483;
}

double f(double x, double y) {
        double r25376484 = x;
        double r25376485 = -1.3323185489366894e+154;
        bool r25376486 = r25376484 <= r25376485;
        double r25376487 = -0.5;
        double r25376488 = y;
        double r25376489 = r25376488 / r25376484;
        double r25376490 = r25376487 * r25376489;
        double r25376491 = r25376490 - r25376484;
        double r25376492 = 1.3070827329489974e+38;
        bool r25376493 = r25376484 <= r25376492;
        double r25376494 = r25376484 * r25376484;
        double r25376495 = r25376494 + r25376488;
        double r25376496 = sqrt(r25376495);
        double r25376497 = 0.5;
        double r25376498 = r25376489 * r25376497;
        double r25376499 = r25376498 + r25376484;
        double r25376500 = r25376493 ? r25376496 : r25376499;
        double r25376501 = r25376486 ? r25376491 : r25376500;
        return r25376501;
}

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.8
Target0.5
Herbie0.7
\[\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.3323185489366894e+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.3323185489366894e+154 < x < 1.3070827329489974e+38

    1. Initial program 0.0

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

    if 1.3070827329489974e+38 < x

    1. Initial program 36.4

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

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

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

Reproduce

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