Average Error: 21.1 → 0.2
Time: 7.3s
Precision: 64
\[\sqrt{x \cdot x + y}\]
\[\begin{array}{l} \mathbf{if}\;x \le -1.337989668827540065379086468393576900525 \cdot 10^{154}:\\ \;\;\;\;\frac{-1}{2} \cdot \frac{y}{x} - x\\ \mathbf{elif}\;x \le 2.427949032860909146895905637732438337929 \cdot 10^{93}:\\ \;\;\;\;\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.337989668827540065379086468393576900525 \cdot 10^{154}:\\
\;\;\;\;\frac{-1}{2} \cdot \frac{y}{x} - x\\

\mathbf{elif}\;x \le 2.427949032860909146895905637732438337929 \cdot 10^{93}:\\
\;\;\;\;\sqrt{x \cdot x + y}\\

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

\end{array}
double f(double x, double y) {
        double r369488 = x;
        double r369489 = r369488 * r369488;
        double r369490 = y;
        double r369491 = r369489 + r369490;
        double r369492 = sqrt(r369491);
        return r369492;
}

double f(double x, double y) {
        double r369493 = x;
        double r369494 = -1.33798966882754e+154;
        bool r369495 = r369493 <= r369494;
        double r369496 = -0.5;
        double r369497 = y;
        double r369498 = r369497 / r369493;
        double r369499 = r369496 * r369498;
        double r369500 = r369499 - r369493;
        double r369501 = 2.427949032860909e+93;
        bool r369502 = r369493 <= r369501;
        double r369503 = r369493 * r369493;
        double r369504 = r369503 + r369497;
        double r369505 = sqrt(r369504);
        double r369506 = 0.5;
        double r369507 = r369498 * r369506;
        double r369508 = r369507 + r369493;
        double r369509 = r369502 ? r369505 : r369508;
        double r369510 = r369495 ? r369500 : r369509;
        return r369510;
}

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.1
Target0.4
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.33798966882754e+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.33798966882754e+154 < x < 2.427949032860909e+93

    1. Initial program 0.0

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

    if 2.427949032860909e+93 < x

    1. Initial program 47.5

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

      \[\leadsto \color{blue}{x + \frac{1}{2} \cdot \frac{y}{x}}\]
    3. Simplified1.0

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

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

Reproduce

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