Average Error: 19.7 → 0.4
Time: 12.3s
Precision: 64
\[\sqrt{x \cdot x + y}\]
\[\begin{array}{l} \mathbf{if}\;x \le -1.3262598264970426 \cdot 10^{+154}:\\ \;\;\;\;\frac{-1}{2} \cdot \frac{y}{x} - x\\ \mathbf{elif}\;x \le 9.943288082924311 \cdot 10^{+67}:\\ \;\;\;\;\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.3262598264970426 \cdot 10^{+154}:\\
\;\;\;\;\frac{-1}{2} \cdot \frac{y}{x} - x\\

\mathbf{elif}\;x \le 9.943288082924311 \cdot 10^{+67}:\\
\;\;\;\;\sqrt{x \cdot x + y}\\

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

\end{array}
double f(double x, double y) {
        double r27920009 = x;
        double r27920010 = r27920009 * r27920009;
        double r27920011 = y;
        double r27920012 = r27920010 + r27920011;
        double r27920013 = sqrt(r27920012);
        return r27920013;
}

double f(double x, double y) {
        double r27920014 = x;
        double r27920015 = -1.3262598264970426e+154;
        bool r27920016 = r27920014 <= r27920015;
        double r27920017 = -0.5;
        double r27920018 = y;
        double r27920019 = r27920018 / r27920014;
        double r27920020 = r27920017 * r27920019;
        double r27920021 = r27920020 - r27920014;
        double r27920022 = 9.943288082924311e+67;
        bool r27920023 = r27920014 <= r27920022;
        double r27920024 = r27920014 * r27920014;
        double r27920025 = r27920024 + r27920018;
        double r27920026 = sqrt(r27920025);
        double r27920027 = 0.5;
        double r27920028 = r27920019 * r27920027;
        double r27920029 = r27920028 + r27920014;
        double r27920030 = r27920023 ? r27920026 : r27920029;
        double r27920031 = r27920016 ? r27920021 : r27920030;
        return r27920031;
}

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.7
Target0.5
Herbie0.4
\[\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.3262598264970426e+154

    1. Initial program 59.6

      \[\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.3262598264970426e+154 < x < 9.943288082924311e+67

    1. Initial program 0.0

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

    if 9.943288082924311e+67 < x

    1. Initial program 38.6

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

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

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

Reproduce

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