Average Error: 20.5 → 5.2
Time: 23.5s
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 -8.334937415174087689151411360396824572633 \cdot 10^{151}:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \le -1.980279493290019398980720829046319269044 \cdot 10^{-182}:\\ \;\;\;\;\frac{-1}{\frac{x \cdot x + y \cdot y}{y \cdot y - x \cdot x}}\\ \mathbf{elif}\;y \le -8.125759275196954844976374495366451720031 \cdot 10^{-201}:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \le 2.44765369794749908002547762808273602123 \cdot 10^{-162}:\\ \;\;\;\;1\\ \mathbf{else}:\\ \;\;\;\;\frac{-1}{\frac{x \cdot x + y \cdot y}{y \cdot y - x \cdot x}}\\ \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 -8.334937415174087689151411360396824572633 \cdot 10^{151}:\\
\;\;\;\;-1\\

\mathbf{elif}\;y \le -1.980279493290019398980720829046319269044 \cdot 10^{-182}:\\
\;\;\;\;\frac{-1}{\frac{x \cdot x + y \cdot y}{y \cdot y - x \cdot x}}\\

\mathbf{elif}\;y \le -8.125759275196954844976374495366451720031 \cdot 10^{-201}:\\
\;\;\;\;-1\\

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

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

\end{array}
double f(double x, double y) {
        double r5822676 = x;
        double r5822677 = y;
        double r5822678 = r5822676 - r5822677;
        double r5822679 = r5822676 + r5822677;
        double r5822680 = r5822678 * r5822679;
        double r5822681 = r5822676 * r5822676;
        double r5822682 = r5822677 * r5822677;
        double r5822683 = r5822681 + r5822682;
        double r5822684 = r5822680 / r5822683;
        return r5822684;
}

double f(double x, double y) {
        double r5822685 = y;
        double r5822686 = -8.334937415174088e+151;
        bool r5822687 = r5822685 <= r5822686;
        double r5822688 = -1.0;
        double r5822689 = -1.9802794932900194e-182;
        bool r5822690 = r5822685 <= r5822689;
        double r5822691 = x;
        double r5822692 = r5822691 * r5822691;
        double r5822693 = r5822685 * r5822685;
        double r5822694 = r5822692 + r5822693;
        double r5822695 = r5822693 - r5822692;
        double r5822696 = r5822694 / r5822695;
        double r5822697 = r5822688 / r5822696;
        double r5822698 = -8.125759275196955e-201;
        bool r5822699 = r5822685 <= r5822698;
        double r5822700 = 2.447653697947499e-162;
        bool r5822701 = r5822685 <= r5822700;
        double r5822702 = 1.0;
        double r5822703 = r5822701 ? r5822702 : r5822697;
        double r5822704 = r5822699 ? r5822688 : r5822703;
        double r5822705 = r5822690 ? r5822697 : r5822704;
        double r5822706 = r5822687 ? r5822688 : r5822705;
        return r5822706;
}

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.5
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 < -8.334937415174088e+151 or -1.9802794932900194e-182 < y < -8.125759275196955e-201

    1. Initial program 59.8

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

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

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

    if -8.334937415174088e+151 < y < -1.9802794932900194e-182 or 2.447653697947499e-162 < y

    1. Initial program 1.1

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

      \[\leadsto \color{blue}{-\frac{y \cdot y - x \cdot x}{x \cdot x + y \cdot y}}\]
    3. Using strategy rm
    4. Applied clear-num1.2

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

    if -8.125759275196955e-201 < y < 2.447653697947499e-162

    1. Initial program 30.2

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \le -8.334937415174087689151411360396824572633 \cdot 10^{151}:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \le -1.980279493290019398980720829046319269044 \cdot 10^{-182}:\\ \;\;\;\;\frac{-1}{\frac{x \cdot x + y \cdot y}{y \cdot y - x \cdot x}}\\ \mathbf{elif}\;y \le -8.125759275196954844976374495366451720031 \cdot 10^{-201}:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \le 2.44765369794749908002547762808273602123 \cdot 10^{-162}:\\ \;\;\;\;1\\ \mathbf{else}:\\ \;\;\;\;\frac{-1}{\frac{x \cdot x + y \cdot y}{y \cdot y - x \cdot x}}\\ \end{array}\]

Reproduce

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