Average Error: 19.4 → 0.3
Time: 6.4s
Precision: 64
\[\sqrt{x \cdot x + y}\]
\[\begin{array}{l} \mathbf{if}\;x \le -1.3359776254393746 \cdot 10^{+154}:\\ \;\;\;\;\frac{-1}{2} \cdot \frac{y}{x} - x\\ \mathbf{elif}\;x \le 2.8410325872827527 \cdot 10^{+74}:\\ \;\;\;\;\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.3359776254393746 \cdot 10^{+154}:\\
\;\;\;\;\frac{-1}{2} \cdot \frac{y}{x} - x\\

\mathbf{elif}\;x \le 2.8410325872827527 \cdot 10^{+74}:\\
\;\;\;\;\sqrt{x \cdot x + y}\\

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

\end{array}
double f(double x, double y) {
        double r25577298 = x;
        double r25577299 = r25577298 * r25577298;
        double r25577300 = y;
        double r25577301 = r25577299 + r25577300;
        double r25577302 = sqrt(r25577301);
        return r25577302;
}

double f(double x, double y) {
        double r25577303 = x;
        double r25577304 = -1.3359776254393746e+154;
        bool r25577305 = r25577303 <= r25577304;
        double r25577306 = -0.5;
        double r25577307 = y;
        double r25577308 = r25577307 / r25577303;
        double r25577309 = r25577306 * r25577308;
        double r25577310 = r25577309 - r25577303;
        double r25577311 = 2.8410325872827527e+74;
        bool r25577312 = r25577303 <= r25577311;
        double r25577313 = r25577303 * r25577303;
        double r25577314 = r25577313 + r25577307;
        double r25577315 = sqrt(r25577314);
        double r25577316 = 0.5;
        double r25577317 = r25577308 * r25577316;
        double r25577318 = r25577317 + r25577303;
        double r25577319 = r25577312 ? r25577315 : r25577318;
        double r25577320 = r25577305 ? r25577310 : r25577319;
        return r25577320;
}

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.4
Target0.4
Herbie0.3
\[\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.3359776254393746e+154

    1. Initial program 59.5

      \[\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.3359776254393746e+154 < x < 2.8410325872827527e+74

    1. Initial program 0.0

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

    if 2.8410325872827527e+74 < x

    1. Initial program 40.5

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

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

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

Reproduce

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