Average Error: 20.1 → 0.2
Time: 4.8s
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 r22666481 = x;
        double r22666482 = r22666481 * r22666481;
        double r22666483 = y;
        double r22666484 = r22666482 + r22666483;
        double r22666485 = sqrt(r22666484);
        return r22666485;
}

double f(double x, double y) {
        double r22666486 = x;
        double r22666487 = -1.3410577693198698e+154;
        bool r22666488 = r22666486 <= r22666487;
        double r22666489 = y;
        double r22666490 = r22666489 / r22666486;
        double r22666491 = -0.5;
        double r22666492 = r22666490 * r22666491;
        double r22666493 = r22666492 - r22666486;
        double r22666494 = 3.9127043430585563e+87;
        bool r22666495 = r22666486 <= r22666494;
        double r22666496 = r22666486 * r22666486;
        double r22666497 = r22666496 + r22666489;
        double r22666498 = sqrt(r22666497);
        double r22666499 = 0.5;
        double r22666500 = r22666490 * r22666499;
        double r22666501 = r22666500 + r22666486;
        double r22666502 = r22666495 ? r22666498 : r22666501;
        double r22666503 = r22666488 ? r22666493 : r22666502;
        return r22666503;
}

Error

Bits error versus x

Bits error versus y

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original20.1
Target0.5
Herbie0.2
\[\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.3410577693198698e+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{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 42.3

      \[\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) (- (+ (* 1/2 (/ y x)) x)) (if (< x 5.582399551122541e+57) (sqrt (+ (* x x) y)) (+ (* 1/2 (/ y x)) x)))

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