Average Error: 20.0 → 5.2
Time: 7.7s
Precision: 64
\[0.0 \lt x \lt 1 \land y \lt 1\]
\[\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y}\]
\[\begin{array}{l} \mathbf{if}\;y \le -6.379960110729305952978237513299639776117 \cdot 10^{150}:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \le -1.501676546694868344414885960149825649924 \cdot 10^{-155}:\\ \;\;\;\;\frac{x \cdot x}{x \cdot x + y \cdot y} - \frac{y \cdot y}{x \cdot x + y \cdot y}\\ \mathbf{elif}\;y \le 1.665640808899109568529030107036989846971 \cdot 10^{-162}:\\ \;\;\;\;1\\ \mathbf{else}:\\ \;\;\;\;\frac{x \cdot x}{x \cdot x + y \cdot y} - \frac{y \cdot y}{x \cdot x + y \cdot y}\\ \end{array}\]
\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y}
\begin{array}{l}
\mathbf{if}\;y \le -6.379960110729305952978237513299639776117 \cdot 10^{150}:\\
\;\;\;\;-1\\

\mathbf{elif}\;y \le -1.501676546694868344414885960149825649924 \cdot 10^{-155}:\\
\;\;\;\;\frac{x \cdot x}{x \cdot x + y \cdot y} - \frac{y \cdot y}{x \cdot x + y \cdot y}\\

\mathbf{elif}\;y \le 1.665640808899109568529030107036989846971 \cdot 10^{-162}:\\
\;\;\;\;1\\

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

\end{array}
double f(double x, double y) {
        double r3930765 = x;
        double r3930766 = y;
        double r3930767 = r3930765 - r3930766;
        double r3930768 = r3930765 + r3930766;
        double r3930769 = r3930767 * r3930768;
        double r3930770 = r3930765 * r3930765;
        double r3930771 = r3930766 * r3930766;
        double r3930772 = r3930770 + r3930771;
        double r3930773 = r3930769 / r3930772;
        return r3930773;
}

double f(double x, double y) {
        double r3930774 = y;
        double r3930775 = -6.379960110729306e+150;
        bool r3930776 = r3930774 <= r3930775;
        double r3930777 = -1.0;
        double r3930778 = -1.5016765466948683e-155;
        bool r3930779 = r3930774 <= r3930778;
        double r3930780 = x;
        double r3930781 = r3930780 * r3930780;
        double r3930782 = r3930774 * r3930774;
        double r3930783 = r3930781 + r3930782;
        double r3930784 = r3930781 / r3930783;
        double r3930785 = r3930782 / r3930783;
        double r3930786 = r3930784 - r3930785;
        double r3930787 = 1.6656408088991096e-162;
        bool r3930788 = r3930774 <= r3930787;
        double r3930789 = 1.0;
        double r3930790 = r3930788 ? r3930789 : r3930786;
        double r3930791 = r3930779 ? r3930786 : r3930790;
        double r3930792 = r3930776 ? r3930777 : r3930791;
        return r3930792;
}

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.0
Target0.0
Herbie5.2
\[\begin{array}{l} \mathbf{if}\;0.5 \lt \left|\frac{x}{y}\right| \lt 2:\\ \;\;\;\;\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y}\\ \mathbf{else}:\\ \;\;\;\;1 - \frac{2}{1 + \frac{x}{y} \cdot \frac{x}{y}}\\ \end{array}\]

Derivation

  1. Split input into 3 regimes
  2. if y < -6.379960110729306e+150

    1. Initial program 62.9

      \[\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y}\]
    2. Simplified62.9

      \[\leadsto \color{blue}{\frac{x \cdot x}{x \cdot x + y \cdot y} - \frac{y \cdot y}{x \cdot x + y \cdot y}}\]
    3. Taylor expanded around 0 0

      \[\leadsto \color{blue}{-1}\]

    if -6.379960110729306e+150 < y < -1.5016765466948683e-155 or 1.6656408088991096e-162 < y

    1. Initial program 0.0

      \[\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y}\]
    2. Simplified0.0

      \[\leadsto \color{blue}{\frac{x \cdot x}{x \cdot x + y \cdot y} - \frac{y \cdot y}{x \cdot x + y \cdot y}}\]

    if -1.5016765466948683e-155 < y < 1.6656408088991096e-162

    1. Initial program 29.7

      \[\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y}\]
    2. Simplified29.7

      \[\leadsto \color{blue}{\frac{x \cdot x}{x \cdot x + y \cdot y} - \frac{y \cdot y}{x \cdot x + y \cdot y}}\]
    3. Taylor expanded around inf 16.4

      \[\leadsto \color{blue}{1}\]
  3. Recombined 3 regimes into one program.
  4. Final simplification5.2

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \le -6.379960110729305952978237513299639776117 \cdot 10^{150}:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \le -1.501676546694868344414885960149825649924 \cdot 10^{-155}:\\ \;\;\;\;\frac{x \cdot x}{x \cdot x + y \cdot y} - \frac{y \cdot y}{x \cdot x + y \cdot y}\\ \mathbf{elif}\;y \le 1.665640808899109568529030107036989846971 \cdot 10^{-162}:\\ \;\;\;\;1\\ \mathbf{else}:\\ \;\;\;\;\frac{x \cdot x}{x \cdot x + y \cdot y} - \frac{y \cdot y}{x \cdot x + y \cdot y}\\ \end{array}\]

Reproduce

herbie shell --seed 2019172 
(FPCore (x y)
  :name "Kahan p9 Example"
  :pre (and (< 0.0 x 1.0) (< y 1.0))

  :herbie-target
  (if (< 0.5 (fabs (/ x y)) 2.0) (/ (* (- x y) (+ x y)) (+ (* x x) (* y y))) (- 1.0 (/ 2.0 (+ 1.0 (* (/ x y) (/ x y))))))

  (/ (* (- x y) (+ x y)) (+ (* x x) (* y y))))