Average Error: 19.8 → 0.5
Time: 7.1s
Precision: 64
\[\sqrt{x \cdot x + y}\]
\[\begin{array}{l} \mathbf{if}\;x \le -1.3298271535226257 \cdot 10^{+154}:\\ \;\;\;\;\frac{-1}{2} \cdot \frac{y}{x} - x\\ \mathbf{elif}\;x \le 3.890409410163301 \cdot 10^{+59}:\\ \;\;\;\;\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.3298271535226257 \cdot 10^{+154}:\\
\;\;\;\;\frac{-1}{2} \cdot \frac{y}{x} - x\\

\mathbf{elif}\;x \le 3.890409410163301 \cdot 10^{+59}:\\
\;\;\;\;\sqrt{x \cdot x + y}\\

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

\end{array}
double f(double x, double y) {
        double r24319340 = x;
        double r24319341 = r24319340 * r24319340;
        double r24319342 = y;
        double r24319343 = r24319341 + r24319342;
        double r24319344 = sqrt(r24319343);
        return r24319344;
}

double f(double x, double y) {
        double r24319345 = x;
        double r24319346 = -1.3298271535226257e+154;
        bool r24319347 = r24319345 <= r24319346;
        double r24319348 = -0.5;
        double r24319349 = y;
        double r24319350 = r24319349 / r24319345;
        double r24319351 = r24319348 * r24319350;
        double r24319352 = r24319351 - r24319345;
        double r24319353 = 3.890409410163301e+59;
        bool r24319354 = r24319345 <= r24319353;
        double r24319355 = r24319345 * r24319345;
        double r24319356 = r24319355 + r24319349;
        double r24319357 = sqrt(r24319356);
        double r24319358 = 0.5;
        double r24319359 = r24319350 * r24319358;
        double r24319360 = r24319359 + r24319345;
        double r24319361 = r24319354 ? r24319357 : r24319360;
        double r24319362 = r24319347 ? r24319352 : r24319361;
        return r24319362;
}

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.5
\[\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.3298271535226257e+154

    1. Initial program 59.6

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

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

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

    if -1.3298271535226257e+154 < x < 3.890409410163301e+59

    1. Initial program 0.0

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

    if 3.890409410163301e+59 < x

    1. Initial program 38.7

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

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

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

Reproduce

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