Average Error: 21.3 → 0.1
Time: 7.1s
Precision: 64
\[\sqrt{x \cdot x + y}\]
\[\begin{array}{l} \mathbf{if}\;x \le -1.345714450053187989263445330915097289846 \cdot 10^{154}:\\ \;\;\;\;\frac{y}{x} \cdot \frac{-1}{2} - x\\ \mathbf{elif}\;x \le 1.666665935899026866978309593021789775966 \cdot 10^{110}:\\ \;\;\;\;\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.345714450053187989263445330915097289846 \cdot 10^{154}:\\
\;\;\;\;\frac{y}{x} \cdot \frac{-1}{2} - x\\

\mathbf{elif}\;x \le 1.666665935899026866978309593021789775966 \cdot 10^{110}:\\
\;\;\;\;\sqrt{x \cdot x + y}\\

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

\end{array}
double f(double x, double y) {
        double r22851838 = x;
        double r22851839 = r22851838 * r22851838;
        double r22851840 = y;
        double r22851841 = r22851839 + r22851840;
        double r22851842 = sqrt(r22851841);
        return r22851842;
}

double f(double x, double y) {
        double r22851843 = x;
        double r22851844 = -1.345714450053188e+154;
        bool r22851845 = r22851843 <= r22851844;
        double r22851846 = y;
        double r22851847 = r22851846 / r22851843;
        double r22851848 = -0.5;
        double r22851849 = r22851847 * r22851848;
        double r22851850 = r22851849 - r22851843;
        double r22851851 = 1.666665935899027e+110;
        bool r22851852 = r22851843 <= r22851851;
        double r22851853 = r22851843 * r22851843;
        double r22851854 = r22851853 + r22851846;
        double r22851855 = sqrt(r22851854);
        double r22851856 = 0.5;
        double r22851857 = r22851847 * r22851856;
        double r22851858 = r22851857 + r22851843;
        double r22851859 = r22851852 ? r22851855 : r22851858;
        double r22851860 = r22851845 ? r22851850 : r22851859;
        return r22851860;
}

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.3
Target0.5
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.345714450053188e+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.345714450053188e+154 < x < 1.666665935899027e+110

    1. Initial program 0.0

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

    if 1.666665935899027e+110 < x

    1. Initial program 49.0

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

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

Reproduce

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