Average Error: 19.8 → 0.7
Time: 7.1s
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 r27062980 = x;
        double r27062981 = r27062980 * r27062980;
        double r27062982 = y;
        double r27062983 = r27062981 + r27062982;
        double r27062984 = sqrt(r27062983);
        return r27062984;
}

double f(double x, double y) {
        double r27062985 = x;
        double r27062986 = -1.3323185489366894e+154;
        bool r27062987 = r27062985 <= r27062986;
        double r27062988 = -0.5;
        double r27062989 = y;
        double r27062990 = r27062989 / r27062985;
        double r27062991 = r27062988 * r27062990;
        double r27062992 = r27062991 - r27062985;
        double r27062993 = 1.3070827329489974e+38;
        bool r27062994 = r27062985 <= r27062993;
        double r27062995 = r27062985 * r27062985;
        double r27062996 = r27062995 + r27062989;
        double r27062997 = sqrt(r27062996);
        double r27062998 = 0.5;
        double r27062999 = r27062990 * r27062998;
        double r27063000 = r27062999 + r27062985;
        double r27063001 = r27062994 ? r27062997 : r27063000;
        double r27063002 = r27062987 ? r27062992 : r27063001;
        return r27063002;
}

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