Average Error: 21.5 → 0.0
Time: 9.3s
Precision: 64
\[\sqrt{x \cdot x + y}\]
\[\begin{array}{l} \mathbf{if}\;x \le -1.352732562381551610191380298409879181488 \cdot 10^{154}:\\ \;\;\;\;\frac{-1}{2} \cdot \frac{y}{x} - x\\ \mathbf{elif}\;x \le 8.914808959129563024978640207181522528947 \cdot 10^{145}:\\ \;\;\;\;\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.352732562381551610191380298409879181488 \cdot 10^{154}:\\
\;\;\;\;\frac{-1}{2} \cdot \frac{y}{x} - x\\

\mathbf{elif}\;x \le 8.914808959129563024978640207181522528947 \cdot 10^{145}:\\
\;\;\;\;\sqrt{x \cdot x + y}\\

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

\end{array}
double f(double x, double y) {
        double r30615107 = x;
        double r30615108 = r30615107 * r30615107;
        double r30615109 = y;
        double r30615110 = r30615108 + r30615109;
        double r30615111 = sqrt(r30615110);
        return r30615111;
}

double f(double x, double y) {
        double r30615112 = x;
        double r30615113 = -1.3527325623815516e+154;
        bool r30615114 = r30615112 <= r30615113;
        double r30615115 = -0.5;
        double r30615116 = y;
        double r30615117 = r30615116 / r30615112;
        double r30615118 = r30615115 * r30615117;
        double r30615119 = r30615118 - r30615112;
        double r30615120 = 8.914808959129563e+145;
        bool r30615121 = r30615112 <= r30615120;
        double r30615122 = r30615112 * r30615112;
        double r30615123 = r30615122 + r30615116;
        double r30615124 = sqrt(r30615123);
        double r30615125 = 0.5;
        double r30615126 = r30615117 * r30615125;
        double r30615127 = r30615126 + r30615112;
        double r30615128 = r30615121 ? r30615124 : r30615127;
        double r30615129 = r30615114 ? r30615119 : r30615128;
        return r30615129;
}

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.5
Target0.4
Herbie0.0
\[\begin{array}{l} \mathbf{if}\;x \lt -1.509769801047259255153812752081023359759 \cdot 10^{153}:\\ \;\;\;\;-\left(0.5 \cdot \frac{y}{x} + x\right)\\ \mathbf{elif}\;x \lt 5.582399551122540716781541767466805967807 \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.3527325623815516e+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{-1}{2} \cdot \frac{y}{x} - x}\]

    if -1.3527325623815516e+154 < x < 8.914808959129563e+145

    1. Initial program 0.0

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

    if 8.914808959129563e+145 < x

    1. Initial program 61.0

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

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

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

Reproduce

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