Average Error: 21.5 → 0.2
Time: 13.6s
Precision: 64
\[\sqrt{x \cdot x + y}\]
\[\begin{array}{l} \mathbf{if}\;x \le -1.335728053209796214179137167831695743037 \cdot 10^{154}:\\ \;\;\;\;\frac{-1}{2} \cdot \frac{y}{x} - x\\ \mathbf{elif}\;x \le 3.200301816232115926663695869716028224145 \cdot 10^{89}:\\ \;\;\;\;\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.335728053209796214179137167831695743037 \cdot 10^{154}:\\
\;\;\;\;\frac{-1}{2} \cdot \frac{y}{x} - x\\

\mathbf{elif}\;x \le 3.200301816232115926663695869716028224145 \cdot 10^{89}:\\
\;\;\;\;\sqrt{x \cdot x + y}\\

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

\end{array}
double f(double x, double y) {
        double r24492728 = x;
        double r24492729 = r24492728 * r24492728;
        double r24492730 = y;
        double r24492731 = r24492729 + r24492730;
        double r24492732 = sqrt(r24492731);
        return r24492732;
}

double f(double x, double y) {
        double r24492733 = x;
        double r24492734 = -1.3357280532097962e+154;
        bool r24492735 = r24492733 <= r24492734;
        double r24492736 = -0.5;
        double r24492737 = y;
        double r24492738 = r24492737 / r24492733;
        double r24492739 = r24492736 * r24492738;
        double r24492740 = r24492739 - r24492733;
        double r24492741 = 3.200301816232116e+89;
        bool r24492742 = r24492733 <= r24492741;
        double r24492743 = r24492733 * r24492733;
        double r24492744 = r24492743 + r24492737;
        double r24492745 = sqrt(r24492744);
        double r24492746 = 0.5;
        double r24492747 = r24492738 * r24492746;
        double r24492748 = r24492747 + r24492733;
        double r24492749 = r24492742 ? r24492745 : r24492748;
        double r24492750 = r24492735 ? r24492740 : r24492749;
        return r24492750;
}

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.5
Herbie0.2
\[\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.3357280532097962e+154

    1. Initial program 64.0

      \[\sqrt{x \cdot x + y}\]
    2. Using strategy rm
    3. Applied add-cbrt-cube64.0

      \[\leadsto \color{blue}{\sqrt[3]{\left(\sqrt{x \cdot x + y} \cdot \sqrt{x \cdot x + y}\right) \cdot \sqrt{x \cdot x + y}}}\]
    4. Simplified64.0

      \[\leadsto \sqrt[3]{\color{blue}{\sqrt{x \cdot x + y} \cdot \left(x \cdot x + y\right)}}\]
    5. Taylor expanded around -inf 0

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

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

    if -1.3357280532097962e+154 < x < 3.200301816232116e+89

    1. Initial program 0.0

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

    if 3.200301816232116e+89 < x

    1. Initial program 45.8

      \[\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.335728053209796214179137167831695743037 \cdot 10^{154}:\\ \;\;\;\;\frac{-1}{2} \cdot \frac{y}{x} - x\\ \mathbf{elif}\;x \le 3.200301816232115926663695869716028224145 \cdot 10^{89}:\\ \;\;\;\;\sqrt{x \cdot x + y}\\ \mathbf{else}:\\ \;\;\;\;\frac{y}{x} \cdot \frac{1}{2} + x\\ \end{array}\]

Reproduce

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