Average Error: 19.7 → 0.4
Time: 11.8s
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 r26798650 = x;
        double r26798651 = r26798650 * r26798650;
        double r26798652 = y;
        double r26798653 = r26798651 + r26798652;
        double r26798654 = sqrt(r26798653);
        return r26798654;
}

double f(double x, double y) {
        double r26798655 = x;
        double r26798656 = -1.3262598264970426e+154;
        bool r26798657 = r26798655 <= r26798656;
        double r26798658 = -0.5;
        double r26798659 = y;
        double r26798660 = r26798659 / r26798655;
        double r26798661 = r26798658 * r26798660;
        double r26798662 = r26798661 - r26798655;
        double r26798663 = 9.943288082924311e+67;
        bool r26798664 = r26798655 <= r26798663;
        double r26798665 = r26798655 * r26798655;
        double r26798666 = r26798665 + r26798659;
        double r26798667 = sqrt(r26798666);
        double r26798668 = 0.5;
        double r26798669 = r26798660 * r26798668;
        double r26798670 = r26798669 + r26798655;
        double r26798671 = r26798664 ? r26798667 : r26798670;
        double r26798672 = r26798657 ? r26798662 : r26798671;
        return r26798672;
}

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)))