Average Error: 21.6 → 0.1
Time: 4.7s
Precision: 64
\[\sqrt{x \cdot x + y}\]
\[\begin{array}{l} \mathbf{if}\;x \le -1.34406943704910861 \cdot 10^{154}:\\ \;\;\;\;\frac{y}{x} \cdot \frac{-1}{2} - x\\ \mathbf{elif}\;x \le 2.0914354496123656 \cdot 10^{108}:\\ \;\;\;\;\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.34406943704910861 \cdot 10^{154}:\\
\;\;\;\;\frac{y}{x} \cdot \frac{-1}{2} - x\\

\mathbf{elif}\;x \le 2.0914354496123656 \cdot 10^{108}:\\
\;\;\;\;\sqrt{x \cdot x + y}\\

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

\end{array}
double f(double x, double y) {
        double r401951 = x;
        double r401952 = r401951 * r401951;
        double r401953 = y;
        double r401954 = r401952 + r401953;
        double r401955 = sqrt(r401954);
        return r401955;
}

double f(double x, double y) {
        double r401956 = x;
        double r401957 = -1.3440694370491086e+154;
        bool r401958 = r401956 <= r401957;
        double r401959 = y;
        double r401960 = r401959 / r401956;
        double r401961 = -0.5;
        double r401962 = r401960 * r401961;
        double r401963 = r401962 - r401956;
        double r401964 = 2.0914354496123656e+108;
        bool r401965 = r401956 <= r401964;
        double r401966 = r401956 * r401956;
        double r401967 = r401966 + r401959;
        double r401968 = sqrt(r401967);
        double r401969 = 0.5;
        double r401970 = r401969 * r401960;
        double r401971 = r401956 + r401970;
        double r401972 = r401965 ? r401968 : r401971;
        double r401973 = r401958 ? r401963 : r401972;
        return r401973;
}

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.6
Target0.6
Herbie0.1
\[\begin{array}{l} \mathbf{if}\;x \lt -1.5097698010472593 \cdot 10^{153}:\\ \;\;\;\;-\left(0.5 \cdot \frac{y}{x} + x\right)\\ \mathbf{elif}\;x \lt 5.5823995511225407 \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.3440694370491086e+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{y}{x} \cdot \frac{-1}{2} - x}\]

    if -1.3440694370491086e+154 < x < 2.0914354496123656e+108

    1. Initial program 0.0

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

    if 2.0914354496123656e+108 < x

    1. Initial program 48.6

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

Reproduce

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