Average Error: 21.6 → 0.2
Time: 17.3s
Precision: 64
\[\sqrt{x \cdot x + y}\]
\[\begin{array}{l} \mathbf{if}\;x \le -1.3410577693198698 \cdot 10^{+154}:\\ \;\;\;\;\frac{y}{x} \cdot \frac{-1}{2} - x\\ \mathbf{elif}\;x \le 3.9127043430585563 \cdot 10^{+87}:\\ \;\;\;\;\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.3410577693198698 \cdot 10^{+154}:\\
\;\;\;\;\frac{y}{x} \cdot \frac{-1}{2} - x\\

\mathbf{elif}\;x \le 3.9127043430585563 \cdot 10^{+87}:\\
\;\;\;\;\sqrt{x \cdot x + y}\\

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

\end{array}
double f(double x, double y) {
        double r20849235 = x;
        double r20849236 = r20849235 * r20849235;
        double r20849237 = y;
        double r20849238 = r20849236 + r20849237;
        double r20849239 = sqrt(r20849238);
        return r20849239;
}

double f(double x, double y) {
        double r20849240 = x;
        double r20849241 = -1.3410577693198698e+154;
        bool r20849242 = r20849240 <= r20849241;
        double r20849243 = y;
        double r20849244 = r20849243 / r20849240;
        double r20849245 = -0.5;
        double r20849246 = r20849244 * r20849245;
        double r20849247 = r20849246 - r20849240;
        double r20849248 = 3.9127043430585563e+87;
        bool r20849249 = r20849240 <= r20849248;
        double r20849250 = r20849240 * r20849240;
        double r20849251 = r20849250 + r20849243;
        double r20849252 = sqrt(r20849251);
        double r20849253 = 0.5;
        double r20849254 = r20849244 * r20849253;
        double r20849255 = r20849254 + r20849240;
        double r20849256 = r20849249 ? r20849252 : r20849255;
        double r20849257 = r20849242 ? r20849247 : r20849256;
        return r20849257;
}

Error

Bits error versus x

Bits error versus y

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

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

Derivation

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

    1. Initial program 64.0

      \[\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{y}{x} \cdot \frac{-1}{2} - x}\]

    if -1.3410577693198698e+154 < x < 3.9127043430585563e+87

    1. Initial program 0.0

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

    if 3.9127043430585563e+87 < x

    1. Initial program 45.4

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

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

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

Reproduce

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

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

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