Average Error: 21.1 → 0.2
Time: 7.4s
Precision: 64
\[\sqrt{x \cdot x + y}\]
\[\begin{array}{l} \mathbf{if}\;x \le -1.30145221513962733 \cdot 10^{154}:\\ \;\;\;\;\frac{y}{x} \cdot \frac{-1}{2} - x\\ \mathbf{elif}\;x \le 1.0458219696427684 \cdot 10^{97}:\\ \;\;\;\;\sqrt{x \cdot x + y}\\ \mathbf{else}:\\ \;\;\;\;x + \frac{1}{2} \cdot \frac{y}{x}\\ \end{array}\]
\sqrt{x \cdot x + y}
\begin{array}{l}
\mathbf{if}\;x \le -1.30145221513962733 \cdot 10^{154}:\\
\;\;\;\;\frac{y}{x} \cdot \frac{-1}{2} - x\\

\mathbf{elif}\;x \le 1.0458219696427684 \cdot 10^{97}:\\
\;\;\;\;\sqrt{x \cdot x + y}\\

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

\end{array}
double f(double x, double y) {
        double r424533 = x;
        double r424534 = r424533 * r424533;
        double r424535 = y;
        double r424536 = r424534 + r424535;
        double r424537 = sqrt(r424536);
        return r424537;
}

double f(double x, double y) {
        double r424538 = x;
        double r424539 = -1.3014522151396273e+154;
        bool r424540 = r424538 <= r424539;
        double r424541 = y;
        double r424542 = r424541 / r424538;
        double r424543 = -0.5;
        double r424544 = r424542 * r424543;
        double r424545 = r424544 - r424538;
        double r424546 = 1.0458219696427684e+97;
        bool r424547 = r424538 <= r424546;
        double r424548 = r424538 * r424538;
        double r424549 = r424548 + r424541;
        double r424550 = sqrt(r424549);
        double r424551 = 0.5;
        double r424552 = r424551 * r424542;
        double r424553 = r424538 + r424552;
        double r424554 = r424547 ? r424550 : r424553;
        double r424555 = r424540 ? r424545 : r424554;
        return r424555;
}

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

    if -1.3014522151396273e+154 < x < 1.0458219696427684e+97

    1. Initial program 0.0

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

    if 1.0458219696427684e+97 < x

    1. Initial program 47.1

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

Reproduce

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