Average Error: 20.9 → 0.3
Time: 9.3s
Precision: 64
\[\sqrt{x \cdot x + y}\]
\[\begin{array}{l} \mathbf{if}\;x \le -1.369499690488931210940314873390714060144 \cdot 10^{154}:\\ \;\;\;\;\frac{-1}{2} \cdot \frac{y}{x} - x\\ \mathbf{elif}\;x \le 1.496275485111779573801266363185889396502 \cdot 10^{83}:\\ \;\;\;\;\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.369499690488931210940314873390714060144 \cdot 10^{154}:\\
\;\;\;\;\frac{-1}{2} \cdot \frac{y}{x} - x\\

\mathbf{elif}\;x \le 1.496275485111779573801266363185889396502 \cdot 10^{83}:\\
\;\;\;\;\sqrt{x \cdot x + y}\\

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

\end{array}
double f(double x, double y) {
        double r26785793 = x;
        double r26785794 = r26785793 * r26785793;
        double r26785795 = y;
        double r26785796 = r26785794 + r26785795;
        double r26785797 = sqrt(r26785796);
        return r26785797;
}

double f(double x, double y) {
        double r26785798 = x;
        double r26785799 = -1.3694996904889312e+154;
        bool r26785800 = r26785798 <= r26785799;
        double r26785801 = -0.5;
        double r26785802 = y;
        double r26785803 = r26785802 / r26785798;
        double r26785804 = r26785801 * r26785803;
        double r26785805 = r26785804 - r26785798;
        double r26785806 = 1.4962754851117796e+83;
        bool r26785807 = r26785798 <= r26785806;
        double r26785808 = r26785798 * r26785798;
        double r26785809 = r26785808 + r26785802;
        double r26785810 = sqrt(r26785809);
        double r26785811 = 0.5;
        double r26785812 = r26785803 * r26785811;
        double r26785813 = r26785812 + r26785798;
        double r26785814 = r26785807 ? r26785810 : r26785813;
        double r26785815 = r26785800 ? r26785805 : r26785814;
        return r26785815;
}

Error

Bits error versus x

Bits error versus y

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original20.9
Target0.5
Herbie0.3
\[\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.3694996904889312e+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.3694996904889312e+154 < x < 1.4962754851117796e+83

    1. Initial program 0.0

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

    if 1.4962754851117796e+83 < x

    1. Initial program 43.9

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

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

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

Reproduce

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