Average Error: 21.4 → 0.1
Time: 4.0s
Precision: 64
\[\sqrt{x \cdot x + y}\]
\[\begin{array}{l} \mathbf{if}\;x \le -1.33627491053925200483497266921088186961 \cdot 10^{154}:\\ \;\;\;\;\frac{y}{x} \cdot \frac{-1}{2} - x\\ \mathbf{elif}\;x \le 2.216128794604703682435523417006564161481 \cdot 10^{123}:\\ \;\;\;\;\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.33627491053925200483497266921088186961 \cdot 10^{154}:\\
\;\;\;\;\frac{y}{x} \cdot \frac{-1}{2} - x\\

\mathbf{elif}\;x \le 2.216128794604703682435523417006564161481 \cdot 10^{123}:\\
\;\;\;\;\sqrt{x \cdot x + y}\\

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

\end{array}
double f(double x, double y) {
        double r93970934 = x;
        double r93970935 = r93970934 * r93970934;
        double r93970936 = y;
        double r93970937 = r93970935 + r93970936;
        double r93970938 = sqrt(r93970937);
        return r93970938;
}

double f(double x, double y) {
        double r93970939 = x;
        double r93970940 = -1.336274910539252e+154;
        bool r93970941 = r93970939 <= r93970940;
        double r93970942 = y;
        double r93970943 = r93970942 / r93970939;
        double r93970944 = -0.5;
        double r93970945 = r93970943 * r93970944;
        double r93970946 = r93970945 - r93970939;
        double r93970947 = 2.2161287946047037e+123;
        bool r93970948 = r93970939 <= r93970947;
        double r93970949 = r93970939 * r93970939;
        double r93970950 = r93970949 + r93970942;
        double r93970951 = sqrt(r93970950);
        double r93970952 = 0.5;
        double r93970953 = r93970952 * r93970943;
        double r93970954 = r93970939 + r93970953;
        double r93970955 = r93970948 ? r93970951 : r93970954;
        double r93970956 = r93970941 ? r93970946 : r93970955;
        return r93970956;
}

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.4
Target0.6
Herbie0.1
\[\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.336274910539252e+154

    1. Initial program 64.0

      \[\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{y}{x} \cdot \frac{-1}{2} - x}\]

    if -1.336274910539252e+154 < x < 2.2161287946047037e+123

    1. Initial program 0.0

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

    if 2.2161287946047037e+123 < x

    1. Initial program 53.4

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

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

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

Reproduce

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