Average Error: 19.8 → 0.1
Time: 3.2s
Precision: 64
\[\sqrt{x \cdot x + y}\]
\[\begin{array}{l} \mathbf{if}\;x \le -1.345714450053188 \cdot 10^{+154}:\\ \;\;\;\;\frac{-1}{2} \cdot \frac{y}{x} - x\\ \mathbf{elif}\;x \le 1.666665935899027 \cdot 10^{+110}:\\ \;\;\;\;\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.345714450053188 \cdot 10^{+154}:\\
\;\;\;\;\frac{-1}{2} \cdot \frac{y}{x} - x\\

\mathbf{elif}\;x \le 1.666665935899027 \cdot 10^{+110}:\\
\;\;\;\;\sqrt{x \cdot x + y}\\

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

\end{array}
double f(double x, double y) {
        double r24249044 = x;
        double r24249045 = r24249044 * r24249044;
        double r24249046 = y;
        double r24249047 = r24249045 + r24249046;
        double r24249048 = sqrt(r24249047);
        return r24249048;
}

double f(double x, double y) {
        double r24249049 = x;
        double r24249050 = -1.345714450053188e+154;
        bool r24249051 = r24249049 <= r24249050;
        double r24249052 = -0.5;
        double r24249053 = y;
        double r24249054 = r24249053 / r24249049;
        double r24249055 = r24249052 * r24249054;
        double r24249056 = r24249055 - r24249049;
        double r24249057 = 1.666665935899027e+110;
        bool r24249058 = r24249049 <= r24249057;
        double r24249059 = r24249049 * r24249049;
        double r24249060 = r24249059 + r24249053;
        double r24249061 = sqrt(r24249060);
        double r24249062 = 0.5;
        double r24249063 = r24249054 * r24249062;
        double r24249064 = r24249063 + r24249049;
        double r24249065 = r24249058 ? r24249061 : r24249064;
        double r24249066 = r24249051 ? r24249056 : r24249065;
        return r24249066;
}

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.1
\[\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.345714450053188e+154

    1. Initial program 59.5

      \[\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.345714450053188e+154 < x < 1.666665935899027e+110

    1. Initial program 0.0

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

    if 1.666665935899027e+110 < x

    1. Initial program 45.6

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

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

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

Reproduce

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